Form.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <LayoutContainer>
  3. <div id="anchor" />
  4. <v-form
  5. v-if="!contactRequestSent"
  6. ref="form"
  7. validate-on="submit lazy"
  8. @submit.prevent="submit"
  9. >
  10. <v-container>
  11. <h4>
  12. Veuillez remplir le formulaire ci-dessous
  13. </h4>
  14. <i>Les champs dont le nom est suivi d'une astérisque (*) sont obligatoires</i>
  15. <h6>
  16. Vos coordonnées
  17. </h6>
  18. <!-- Gender selection -->
  19. <v-row>
  20. <v-col cols="12">
  21. <v-radio-group
  22. v-model="contactRequest.gender"
  23. row
  24. mandatory
  25. inline
  26. >
  27. <v-radio label="Madame" value="Madame" />
  28. <v-radio label="Monsieur" value="Monsieur" />
  29. </v-radio-group>
  30. </v-col>
  31. </v-row>
  32. <!-- Name and Surname -->
  33. <v-row>
  34. <v-col cols="12" md="6">
  35. <v-text-field
  36. v-model="contactRequest.name"
  37. :rules="[validateName]"
  38. label="Nom*"
  39. required
  40. />
  41. </v-col>
  42. <v-col cols="12" md="6">
  43. <v-text-field
  44. v-model="contactRequest.surname"
  45. :rules="[validateSurname]"
  46. label="Prénom*"
  47. required
  48. />
  49. </v-col>
  50. </v-row>
  51. <!-- Postal code and city -->
  52. <v-row>
  53. <v-col cols="12" md="6">
  54. <v-text-field
  55. v-model="contactRequest.postalCode"
  56. label="Code postal*"
  57. :rules="[validatePostalCode]"
  58. />
  59. </v-col>
  60. <v-col cols="12" md="6">
  61. <v-text-field
  62. v-model="contactRequest.city"
  63. label="Ville"
  64. />
  65. </v-col>
  66. </v-row>
  67. <!-- Email and phone on the same line -->
  68. <v-row>
  69. <v-col cols="12" md="6">
  70. <v-text-field
  71. v-model="contactRequest.email"
  72. :rules="[validateEmail]"
  73. label="Email*"
  74. required
  75. type="email"
  76. />
  77. </v-col>
  78. <v-col cols="12" md="6">
  79. <v-text-field
  80. v-model="contactRequest.phone"
  81. :rules="[validatePhone]"
  82. label="Téléphone*"
  83. type="tel"
  84. />
  85. </v-col>
  86. </v-row>
  87. <!-- Structure name -->
  88. <v-row>
  89. <v-col cols="12">
  90. <v-text-field
  91. v-model="contactRequest.structureName"
  92. :rules="[validateStructureName]"
  93. label="Nom de la structure*"
  94. required
  95. />
  96. </v-col>
  97. </v-row>
  98. <h6>
  99. Votre demande concerne
  100. </h6>
  101. <!-- Request type and product concerned -->
  102. <v-row>
  103. <v-col cols="12" md="6">
  104. <v-select
  105. v-model="contactRequest.requestType"
  106. :items="requestTypes"
  107. item-value="id"
  108. item-title="label"
  109. label="Votre demande concerne *"
  110. outlined
  111. dense
  112. />
  113. </v-col>
  114. <v-col cols="12" md="6">
  115. <v-text-field
  116. v-model="contactRequest.concernedProduct"
  117. label="Le produit concerné"
  118. outlined
  119. dense
  120. />
  121. </v-col>
  122. </v-row>
  123. <h6>
  124. Votre message
  125. </h6>
  126. <!-- Message -->
  127. <v-row>
  128. <v-col cols="12">
  129. <v-textarea
  130. v-model="contactRequest.message"
  131. :rules="[validateNonEmptyMessage, validateMessageLength]"
  132. label="Votre message*"
  133. required
  134. outlined
  135. dense
  136. maxlength="400"
  137. />
  138. </v-col>
  139. </v-row>
  140. <!-- Policy and checkboxes -->
  141. <v-checkbox
  142. v-model="contactRequest.privacyPolicyAccepted"
  143. :rules="[(v) => !!v || 'Vous devez accepter la politique de confidentialité']"
  144. label="J'ai pris connaissance de la politique de confidentialité et j'accepte le traitement de mes données personnelles par Opentalent."
  145. />
  146. <v-checkbox
  147. v-model="contactRequest.newsletterSubscription"
  148. label="Je souhaite recevoir des communications d'Opentalent par email (promotions, informations logiciel…). Je pourrai me désinscrire à tout moment."
  149. />
  150. <!-- @see https://github.com/hCaptcha/vue-hcaptcha -->
  151. <LayoutCaptcha/>
  152. <!-- Submit Button -->
  153. <v-row class="mt-12">
  154. <v-col cols="12">
  155. <v-btn type="submit">
  156. Envoyer
  157. </v-btn>
  158. </v-col>
  159. </v-row>
  160. </v-container>
  161. </v-form>
  162. <div v-else class="confirmation-message d-flex flex-row justify-center">
  163. <v-card>
  164. <v-icon icon="fas fa-check mr-1"/>
  165. Votre demande de contact a bien été enregistrée, nous reviendrons vers vous dès que possible.
  166. </v-card>
  167. </div>
  168. </LayoutContainer>
  169. </template>
  170. <script setup lang="ts">
  171. import ContactRequest from "~/models/Maestro/ContactRequest";
  172. import { useEntityManager } from "~/composables/data/useEntityManager";
  173. import { useRouter } from "vue-router";
  174. const route = useRoute();
  175. const router = useRouter()
  176. const { em } = useEntityManager()
  177. const form: Ref<any | null> = ref(null)
  178. const requestTypes: Array<{id: string, label: string}> = [
  179. { id: "CONTACT_REQUEST_INFORMATION", label: "Demande d'information"},
  180. { id: "CONTACT_REQUEST_ESTIMATE", label: "Demande de devis"},
  181. { id: "CONTACT_REQUEST_DEMO", label: "Demande de démonstration"},
  182. { id: "CONTACT_REQUEST_OPTION", label: "Demande d'option supplémentaire"},
  183. { id: "CONTACT_REQUEST_OTHER", label: "Autre"}
  184. ]
  185. const defaultRequestType = route.query.request ?? 'CONTACT_REQUEST_INFORMATION'
  186. //@ts-ignore
  187. const contactRequest: ContactRequest = reactive(em.newInstance(ContactRequest, { requestType: defaultRequestType }))
  188. // --- Validation ---
  189. const validateName = (name: string | null) => !!name || "Le nom est obligatoire";
  190. const validateSurname = (surname: string | null) => !!surname || "Le prénom est obligatoire";
  191. const validatePostalCode = (postalCode: string | null) =>
  192. (!!postalCode && /^\d{5}$/.test(postalCode)) || "Le code postal doit être valide";
  193. const validateEmail = (email: string | null) =>
  194. (!!email && /.+@.+\..+/.test(email)) || "L'adresse e-mail doit être valide";
  195. const validatePhone = (email: string | null) =>
  196. (!!email && /^((\+|00)33\s?|0)[1-7]([\s.]?\d{2}){4}$/.test(email)) || "Le numéro de téléphone doit être valide";
  197. const validateStructureName = (structureName: string | null) =>
  198. !!structureName || "Le nom de la structure est requis";
  199. const validateNonEmptyMessage = (message: string | null) =>
  200. (!!message && message.length > 0) ||
  201. "Le message ne peut pas être vide";
  202. const validateMessageLength = (message: string | null) =>
  203. (!!message && message.length <= 400) ||
  204. "Le message ne doit pas dépasser 400 caractères";
  205. const contactRequestSent: Ref<boolean> = ref(false);
  206. /**
  207. * Submits the contact form.
  208. *
  209. * This function validates the form and sets the value of a variable to indicate whether the form submission was successful.
  210. *
  211. * @function
  212. * @name submitForm
  213. *
  214. * @returns {void}
  215. */
  216. const submit = async (): Promise<void> => {
  217. const { valid } = await form.value.validate()
  218. if (!valid) {
  219. console.log("Validation failed!")
  220. contactRequestSent.value = false
  221. return
  222. }
  223. await em.persist(ContactRequest, contactRequest)
  224. contactRequestSent.value = true;
  225. // Défile vers le début de page pour afficher le message de confirmation
  226. setTimeout(
  227. () => router.push({ path: '', hash: '#anchor' }),
  228. 30
  229. )
  230. };
  231. </script>
  232. <style scoped lang="scss">
  233. .v-form {
  234. max-width: 1400px;
  235. margin: 0 auto;
  236. h4 {
  237. font-size: 40px;
  238. line-height: 95px;
  239. margin-bottom: 1rem;
  240. }
  241. h6 {
  242. margin-top: 32px;
  243. font-size: 20px;
  244. margin-bottom: 1rem;
  245. }
  246. }
  247. .confirmation-message {
  248. .v-card {
  249. .v-icon {
  250. color: green;
  251. }
  252. max-width: 1200px;
  253. padding: 24px;
  254. margin: 128px 0;
  255. font-weight: 500;
  256. }
  257. }
  258. </style>