Form.vue 10 KB

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