Form.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template>
  2. <LayoutContainer>
  3. <div id="anchor" />
  4. <v-form
  5. v-if="!contactRequestSent"
  6. ref="form"
  7. v-model="isValid"
  8. lazy-validation
  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. <vue-hcaptcha :sitekey="runtimeConfig.hCaptchaSiteKey" />
  152. <!-- Submit Button -->
  153. <v-row>
  154. <v-col cols="12">
  155. <v-btn
  156. :disabled="!isValid"
  157. @click="submitForm"
  158. >
  159. Envoyer
  160. </v-btn>
  161. </v-col>
  162. </v-row>
  163. </v-container>
  164. </v-form>
  165. <div v-else class="confirmation-message d-flex flex-row justify-center">
  166. <v-card>
  167. <v-icon icon="fas fa-check mr-1"/>
  168. Votre demande de contact a bien été enregistrée, nous reviendrons vers vous dès que possible.
  169. </v-card>
  170. </div>
  171. </LayoutContainer>
  172. </template>
  173. <script setup lang="ts">
  174. import VueHcaptcha from '@hcaptcha/vue3-hcaptcha';
  175. import ContactRequest from "~/models/Maestro/ContactRequest";
  176. import { useEntityManager } from "~/composables/data/useEntityManager";
  177. import { useRouter } from "vue-router";
  178. const route = useRoute();
  179. const router = useRouter()
  180. const runtimeConfig = useRuntimeConfig()
  181. const { em } = useEntityManager()
  182. const requestTypes: Array<{id: string, label: string}> = [
  183. { id: "CONTACT_REQUEST_INFORMATION", label: "Demande d'information"},
  184. { id: "CONTACT_REQUEST_ESTIMATE", label: "Demande de devis"},
  185. { id: "CONTACT_REQUEST_DEMO", label: "Demande de démonstration"},
  186. { id: "CONTACT_REQUEST_OPTION", label: "Demande d'option supplémentaire"},
  187. { id: "CONTACT_REQUEST_OTHER", label: "Autre"}
  188. ]
  189. const defaultRequestType = route.query.request ?? 'CONTACT_REQUEST_INFORMATION'
  190. //@ts-ignore
  191. const contactRequest: ContactRequest = reactive(em.newInstance(ContactRequest, { requestType: defaultRequestType }))
  192. const isValid: Ref<boolean> = ref(true)
  193. // --- Validation ---
  194. const validateName = (name: string | null) => !!name || "Le nom est obligatoire";
  195. const validateSurname = (surname: string | null) => !!surname || "Le prénom est obligatoire";
  196. const validatePostalCode = (postalCode: string | null) =>
  197. (!!postalCode && /^\d{5}$/.test(postalCode)) || "Le code postal doit être valide";
  198. const validateEmail = (email: string | null) =>
  199. (!!email && /.+@.+\..+/.test(email)) || "L'adresse e-mail doit être valide";
  200. const validatePhone = (email: string | null) =>
  201. (!!email && /^((\+|00)33\s?|0)[67]([\s.]?\d{2}){4}$/.test(email)) || "Le numéro de téléphone doit être valide";
  202. const validateStructureName = (structureName: string | null) =>
  203. !!structureName || "Le nom de la structure est requis";
  204. const validateNonEmptyMessage = (message: string | null) =>
  205. (!!message && !(message.length > 0)) ||
  206. "Le message ne peut pas être vide";
  207. const validateMessageLength = (message: string | null) =>
  208. (!!message && message.length <= 400) ||
  209. "Le message ne doit pas dépasser 400 caractères";
  210. const contactRequestSent: Ref<boolean> = ref(false);
  211. /**
  212. * Submits the contact form.
  213. *
  214. * This function validates the form and sets the value of a variable to indicate whether the form submission was successful.
  215. *
  216. * @function
  217. * @name submitForm
  218. *
  219. * @returns {void}
  220. */
  221. const submitForm = () => {
  222. if (!isValid.value) {
  223. console.log("Validation failed!")
  224. contactRequestSent.value = false
  225. return
  226. }
  227. // Défile vers le début de page pour afficher le message de confirmation
  228. router.push({ path: '', hash: '#anchor' })
  229. // TODO: implémenter
  230. contactRequestSent.value = true;
  231. };
  232. </script>
  233. <style scoped lang="scss">
  234. .v-form {
  235. max-width: 1400px;
  236. margin: 0 auto;
  237. h4 {
  238. font-size: 40px;
  239. line-height: 95px;
  240. margin-bottom: 1rem;
  241. }
  242. h6 {
  243. margin-top: 32px;
  244. font-size: 20px;
  245. margin-bottom: 1rem;
  246. }
  247. }
  248. .confirmation-message {
  249. .v-card {
  250. .v-icon {
  251. color: green;
  252. }
  253. max-width: 1200px;
  254. padding: 24px;
  255. margin: 128px 0;
  256. font-weight: 500;
  257. }
  258. }
  259. </style>