Form.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. <span class="line" /> Veuillez remplir le formulaire ci-dessous
  13. </h4>
  14. <i>Les champs dont le nom est suivi d'un 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. variant="outlined"
  110. />
  111. </v-col>
  112. <v-col cols="12" md="6">
  113. <v-select
  114. v-model="contactRequest.concernedProduct"
  115. label="Produit concerné (facultatif)"
  116. :items="products"
  117. item-value="id"
  118. item-title="label"
  119. />
  120. </v-col>
  121. </v-row>
  122. <h6>
  123. Votre message
  124. </h6>
  125. <!-- Message -->
  126. <v-row class="mb-8">
  127. <v-col cols="12">
  128. <v-textarea
  129. v-model="contactRequest.message"
  130. :rules="[validateNonEmptyMessage, validateMessageLength]"
  131. label="Votre message*"
  132. required
  133. maxlength="400"
  134. />
  135. <span class="remaining-cars-notice">{{ leftCars }} caractères restants</span>
  136. </v-col>
  137. </v-row>
  138. <!-- Policy and checkboxes -->
  139. <v-checkbox
  140. v-model="contactRequest.privacyPolicyAccepted"
  141. :rules="[(v: boolean) => v || 'Vous devez accepter la politique de confidentialité']"
  142. label="J'ai pris connaissance de la politique de confidentialité et j'accepte le traitement de mes données personnelles par Opentalent."
  143. />
  144. <v-checkbox
  145. v-model="contactRequest.newsletterSubscription"
  146. label="Je souhaite recevoir des communications d'Opentalent par email (promotions, informations logiciel…). Je pourrai me désinscrire à tout moment."
  147. />
  148. <div class="d-flex flex-row justify-center">
  149. <!-- @see https://github.com/hCaptcha/vue-hcaptcha -->
  150. <LayoutCaptcha/>
  151. </div>
  152. <!-- Submit Button -->
  153. <div class="d-flex flex-row justify-center my-10">
  154. <v-btn
  155. type="submit"
  156. variant="outlined"
  157. :height="54"
  158. :width="180"
  159. class="submit-btn"
  160. >
  161. Envoyer
  162. </v-btn>
  163. </div>
  164. </v-container>
  165. <div class="legal">
  166. Les données recueillies par Opentalent sont utilisées pour le traitement de votre demande et pour vous informer sur nos offres.
  167. Elles sont destinées aux services Opentalent et à ses sous-traitants pour l’exécution des contrats. Conformément à la loi
  168. "Informatique et Libertés du 6 Janvier 1978", vous disposez d’un droit d’accès, de modifications, de rectification et de suppression
  169. des données vous concernant. Pour toute demande, adressez-vous à : Opentalent, 217 rue Raoul Follereau, 74300 CLUSES,
  170. opentalent.fr s’engage à la confidentialité et à la protection de vos données.
  171. </div>
  172. </v-form>
  173. <div v-else class="confirmation-message d-flex flex-row justify-center">
  174. <v-card>
  175. <v-icon icon="fas fa-check mr-1"/>
  176. Votre demande de contact a bien été enregistrée, nous reviendrons vers vous dès que possible.
  177. </v-card>
  178. </div>
  179. </LayoutContainer>
  180. </template>
  181. <script setup lang="ts">
  182. import ContactRequest from "~/models/Maestro/ContactRequest";
  183. import { useEntityManager } from "~/composables/data/useEntityManager";
  184. import { useRouter } from "vue-router";
  185. const route = useRoute();
  186. const router = useRouter()
  187. const { em } = useEntityManager()
  188. const form: Ref<any | null> = ref(null)
  189. const requestTypes: Array<{id: string, label: string}> = [
  190. { id: "CONTACT_REQUEST_INFORMATION", label: "Demande d'information"},
  191. { id: "CONTACT_REQUEST_ESTIMATE", label: "Demande de devis"},
  192. { id: "CONTACT_REQUEST_DEMO", label: "Demande de démonstration"},
  193. { id: "CONTACT_REQUEST_OPTION", label: "Demande d'option supplémentaire"},
  194. { id: "CONTACT_REQUEST_OTHER", label: "Autre"}
  195. ]
  196. const products: Array<{id: string, label: string}> = [
  197. { id: "PRODUCT_AGENDA", label: "Agenda culturel"},
  198. { id: "PRODUCT_ARTIST", label: "Opentalent Artist"},
  199. { id: "PRODUCT_SCHOOL", label: "Opentalent School"},
  200. { id: "PRODUCT_MANAGER", label: "Opentalent Manager"},
  201. { id: "PRODUCT_ADVERTISING", label: "Publicité"},
  202. { id: "PRODUCT_OTHER", label: "Autre"}
  203. ]
  204. const defaultRequestType = route.query.request ?? 'CONTACT_REQUEST_INFORMATION'
  205. //@ts-ignore
  206. const contactRequest: ContactRequest = reactive(em.newInstance(ContactRequest, { requestType: defaultRequestType }))
  207. // --- Validation ---
  208. const maxMessageLength = 2000
  209. const leftCars: ComputedRef<number> = computed(() =>
  210. maxMessageLength - (contactRequest.message ? contactRequest.message.length : 0)
  211. )
  212. const validateName = (name: string | null) => !!name || "Le nom est obligatoire";
  213. const validateSurname = (surname: string | null) => !!surname || "Le prénom est obligatoire";
  214. const validatePostalCode = (postalCode: string | null) =>
  215. (!!postalCode && /^\d{5}$/.test(postalCode)) || "Le code postal doit être valide";
  216. const validateEmail = (email: string | null) =>
  217. (!!email && /.+@.+\..+/.test(email)) || "L'adresse e-mail doit être valide";
  218. const validatePhone = (email: string | null) =>
  219. (!!email && /^((\+|00)33\s?|0)[1-7]([\s.]?\d{2}){4}$/.test(email)) || "Le numéro de téléphone doit être valide";
  220. const validateStructureName = (structureName: string | null) =>
  221. !!structureName || "Le nom de la structure est requis";
  222. const validateNonEmptyMessage = (message: string | null) =>
  223. (!!message && message.length > 0) ||
  224. "Le message ne peut pas être vide";
  225. const validateMessageLength = (message: string | null) =>
  226. (!!message && message.length <= maxMessageLength) ||
  227. "Le message ne doit pas dépasser " + maxMessageLength + " caractères";
  228. const contactRequestSent: Ref<boolean> = ref(false);
  229. /**
  230. * Submits the contact form.
  231. *
  232. * This function validates the form and sets the value of a variable to indicate whether the form submission was successful.
  233. *
  234. * @function
  235. *
  236. * @returns {void}
  237. */
  238. const submit = async (): Promise<void> => {
  239. const { valid } = await form.value.validate()
  240. if (!valid) {
  241. contactRequestSent.value = false
  242. return
  243. }
  244. await em.persist(ContactRequest, contactRequest)
  245. contactRequestSent.value = true;
  246. // Défile vers le début de page pour afficher le message de confirmation
  247. setTimeout(
  248. () => router.push({ path: '', hash: '#anchor' }),
  249. 30
  250. )
  251. };
  252. </script>
  253. <style scoped lang="scss">
  254. .v-form {
  255. max-width: 1400px;
  256. margin: 0 auto;
  257. h4 {
  258. display: flex;
  259. flex-direction: row;
  260. font-size: 40px;
  261. line-height: 95px;
  262. margin-bottom: 1rem;
  263. align-items: center;
  264. font-weight: 100;
  265. .line {
  266. display: block;
  267. height: 1px;
  268. width: 64px;
  269. min-width: 64px;
  270. border-top: solid 1px var(--on-neutral-color);
  271. margin-right: 18px;
  272. }
  273. }
  274. h6 {
  275. margin-top: 32px;
  276. font-size: 16px;
  277. margin-bottom: 1rem;
  278. text-transform: uppercase;
  279. font-weight: 600;
  280. letter-spacing: 0.1em;
  281. }
  282. .v-select {
  283. .v-field {
  284. border-radius: 0;
  285. }
  286. }
  287. .remaining-cars-notice {
  288. font-size: 13px;
  289. font-weight: 550;
  290. opacity: 0.6;
  291. }
  292. .submit-btn {
  293. border-radius: 0;
  294. font-weight: 600;
  295. }
  296. .legal {
  297. opacity: 0.7;
  298. }
  299. }
  300. .confirmation-message {
  301. .v-card {
  302. .v-icon {
  303. color: green;
  304. }
  305. max-width: 1200px;
  306. padding: 24px;
  307. margin: 128px 0;
  308. font-weight: 500;
  309. }
  310. }
  311. </style>