Form.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <template>
  2. <LayoutContainer>
  3. <v-form
  4. ref="form"
  5. v-model="valid"
  6. lazy-validation
  7. >
  8. <v-container>
  9. <h4>
  10. Veuillez remplir le formulaire ci-dessous
  11. </h4>
  12. <i>Les champs dont le nom est suivi d'une astérisque (*) sont obligatoires</i>
  13. <h6>
  14. Vos coordonnées
  15. </h6>
  16. <!-- Gender selection -->
  17. <v-row>
  18. <v-col cols="12">
  19. <v-radio-group
  20. v-model="gender"
  21. row
  22. mandatory
  23. inline
  24. >
  25. <v-radio label="Madame" value="Madame" />
  26. <v-radio label="Monsieur" value="Monsieur" />
  27. </v-radio-group>
  28. </v-col>
  29. </v-row>
  30. <!-- Name and Surname -->
  31. <v-row>
  32. <v-col cols="12" md="6">
  33. <v-text-field
  34. v-model="name"
  35. :rules="[validateName]"
  36. label="Nom*"
  37. required
  38. />
  39. </v-col>
  40. <v-col cols="12" md="6">
  41. <v-text-field
  42. v-model="surname"
  43. :rules="[validateSurname]"
  44. label="Prénom*"
  45. required
  46. />
  47. </v-col>
  48. </v-row>
  49. <!-- Postal code and city -->
  50. <v-row>
  51. <v-col cols="12" md="6">
  52. <v-text-field
  53. v-model="postalCode"
  54. label="Code postal*"
  55. :rules="[validatePostalCode]"
  56. />
  57. </v-col>
  58. <v-col cols="12" md="6">
  59. <v-text-field
  60. v-model="city"
  61. label="Ville"
  62. />
  63. </v-col>
  64. </v-row>
  65. <!-- Email and phone on the same line -->
  66. <v-row>
  67. <v-col cols="12" md="6">
  68. <v-text-field
  69. v-model="email"
  70. :rules="[validateEmail]"
  71. label="Email*"
  72. required
  73. type="email"
  74. />
  75. </v-col>
  76. <v-col cols="12" md="6">
  77. <!-- TODO: remplacer par un input dédié aux nums de téléphone -->
  78. <v-text-field
  79. v-model="phone"
  80. label="Téléphone*"
  81. type="tel"
  82. />
  83. </v-col>
  84. </v-row>
  85. <!-- Structure name -->
  86. <v-row>
  87. <v-col cols="12">
  88. <v-text-field
  89. v-model="structureName"
  90. :rules="[validateStructureName]"
  91. label="Nom de la structure*"
  92. required
  93. />
  94. </v-col>
  95. </v-row>
  96. <h6>
  97. Votre demande concerne
  98. </h6>
  99. <!-- Request type and product concerned -->
  100. <v-row>
  101. <v-col cols="12" md="6">
  102. <v-select
  103. v-model="requestType"
  104. :items="requestTypes"
  105. label="Votre demande concerne*"
  106. outlined
  107. dense
  108. />
  109. </v-col>
  110. <v-col cols="12" md="6">
  111. <v-text-field
  112. v-model="concernedProduct"
  113. label="Le produit concerné"
  114. outlined
  115. dense
  116. />
  117. </v-col>
  118. </v-row>
  119. <h6>
  120. Votre message
  121. </h6>
  122. <!-- Message -->
  123. <v-row>
  124. <v-col cols="12">
  125. <v-textarea
  126. v-model="message"
  127. :rules="[validateMessageLength]"
  128. label="Votre message*"
  129. required
  130. outlined
  131. dense
  132. maxlength="400"
  133. />
  134. </v-col>
  135. </v-row>
  136. <!-- Policy and checkboxes -->
  137. <v-checkbox
  138. v-model="privacyPolicy"
  139. :rules="[(v) => !!v || 'You must accept the privacy policy']"
  140. label="J'ai pris connaissance de la politique de confidentialité et j'accepte le traitement de mes données personnelles par Opentalent."
  141. />
  142. <v-checkbox
  143. v-model="newsletterSubscription"
  144. label="Je souhaite recevoir des communications d'Opentalent par email (promotions, informations logiciel…). Je pourrai me désinscrire à tout moment."
  145. />
  146. <!-- TODO: Remplacer par un vrai captcha
  147. voir:
  148. - https://nuxt.com/modules/recaptcha
  149. - https://nuxt.com/modules/turnstile
  150. -->
  151. <v-checkbox
  152. v-model="captchaChecked"
  153. :rules="[(v) => !!v || 'You must pass the captcha']"
  154. label="Captcha"
  155. />
  156. <!-- Submit Button -->
  157. <v-row>
  158. <v-col cols="12">
  159. <v-btn
  160. :disabled="!valid"
  161. @click="submitForm"
  162. >
  163. Envoyer
  164. </v-btn>
  165. </v-col>
  166. </v-row>
  167. </v-container>
  168. </v-form>
  169. <div v-if="submissionStatus">
  170. {{ submissionStatus }}
  171. </div>
  172. </LayoutContainer>
  173. </template>
  174. <script setup lang="ts">
  175. import { ComputedRef } from "vue";
  176. import type { ContactFormData } from "~/types/interface";
  177. const route = useRoute();
  178. const defaultRequestType = route.query.request;
  179. // --- Constants ---
  180. const requestTypes: Array<string> = [
  181. "Demande d'information",
  182. "Demande de devis",
  183. "Demande de démonstration",
  184. "Demande d'option supplémentaire",
  185. "Autre",
  186. ];
  187. // --- Refs ---
  188. const name: Ref<string | null> = ref(null);
  189. const surname: Ref<string | null> = ref(null);
  190. const email: Ref<string | null> = ref(null);
  191. const structureName: Ref<string | null> = ref(null);
  192. const message: Ref<string | null> = ref(null);
  193. const privacyPolicy: Ref<boolean> = ref(false);
  194. const gender: Ref<string | null> = ref(null);
  195. const postalCode: Ref<string | null> = ref(null);
  196. const city: Ref<string | null> = ref(null);
  197. const phone: Ref<string | null> = ref(null);
  198. const concernedProduct: Ref<string | null> = ref(null);
  199. const newsletterSubscription: Ref<boolean> = ref(false);
  200. const captchaChecked: Ref<boolean> = ref(false);
  201. const submissionStatus: Ref<string | null> = ref(null);
  202. // --- Validation ---
  203. const validateName = (name: string | null) => !!name || "Le nom est obligatoire";
  204. const validateSurname = (surname: string | null) => !!surname || "Le prénom est obligatoire";
  205. const validatePostalCode = (postalCode: string | null) =>
  206. (!!postalCode && /^\d{5}$/.test(postalCode)) || "Le code postal doit être valide";
  207. const validateEmail = (email: string | null) =>
  208. (!!email && /.+@.+\..+/.test(email)) || "L'adresse e-mail doit être valide";
  209. const validateStructureName = (structureName: string | null) =>
  210. !!structureName || "Le nom de la structure est requis";
  211. const validateMessageLength = (message: string | null) =>
  212. (!!message && message.length <= 400) ||
  213. "Le message ne doit pas dépasser 400 caractères";
  214. // TODO: revoir la validation, ça devrait être géré directement dans le v-form
  215. const valid: ComputedRef<boolean> = computed(() => {
  216. return (
  217. validateName(name.value) === true &&
  218. validateSurname(surname.value) === true &&
  219. validatePostalCode(postalCode.value) === true &&
  220. validateEmail(email.value) === true &&
  221. validateStructureName(structureName.value) === true &&
  222. validateMessageLength(message.value) === true &&
  223. privacyPolicy.value === true &&
  224. captchaChecked.value === true
  225. );
  226. });
  227. // --- Form data (voir si utile) ---
  228. const formData: ContactFormData = reactive({
  229. gender: null,
  230. postalCode: null,
  231. city: "",
  232. phone: null,
  233. requestType: null,
  234. concernedProduct: "",
  235. newsletterSubscription,
  236. });
  237. const formRefs = {
  238. ...toRefs(formData),
  239. name,
  240. surname,
  241. email,
  242. structureName,
  243. message,
  244. privacyPolicy,
  245. valid,
  246. };
  247. // --- Methods ---
  248. const submitForm = () => {
  249. if (valid.value) {
  250. // Logique d'envoi du formulaire
  251. // TODO: implémenter
  252. submissionStatus.value = "Mail envoyé à contact@opentalent.fr";
  253. } else {
  254. console.log("Validation failed!");
  255. submissionStatus.value = "";
  256. }
  257. };
  258. const requestType: Ref<string | null> = ref(
  259. defaultRequestType === "demo" ? "Demande de démonstration" : null
  260. );
  261. </script>
  262. <style scoped lang="scss">
  263. .v-form {
  264. max-width: 1400px;
  265. margin: 0 auto;
  266. h4 {
  267. font-size: 40px;
  268. line-height: 95px;
  269. margin-bottom: 1rem;
  270. }
  271. h6 {
  272. margin-top: 32px;
  273. font-size: 20px;
  274. margin-bottom: 1rem;
  275. }
  276. }
  277. </style>