Form.vue 11 KB

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