Form.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <v-card>
  3. <v-card-title
  4. class="text-center"
  5. >
  6. Formulaire de Candidature
  7. </v-card-title>
  8. <v-card-text>
  9. <v-form
  10. v-if="!jobApplicationSent"
  11. ref="form"
  12. validate-on="submit lazy"
  13. @submit.prevent="submit"
  14. >
  15. <v-text-field
  16. id="jobApplicationName"
  17. v-model="jobApplication.name"
  18. :rules="[validateName]"
  19. label="Nom*"
  20. required
  21. />
  22. <v-text-field
  23. id="jobApplicationSurname"
  24. v-model="jobApplication.surname"
  25. :rules="[validateSurname]"
  26. label="Prénom*"
  27. required
  28. />
  29. <v-text-field
  30. id="jobApplicationPhone"
  31. v-model="jobApplication.phone"
  32. :rules="[validatePhone]"
  33. label="Téléphone*"
  34. required
  35. />
  36. <v-text-field
  37. id="jobApplicationEmail"
  38. v-model="jobApplication.email"
  39. :rules="[validateEmail]"
  40. label="Email*"
  41. required
  42. />
  43. <v-file-input
  44. id="jobApplicationResume"
  45. v-model="jobApplication.resume"
  46. label="Dépôt de CV*"
  47. accept=".pdf, .jpeg, .png"
  48. required
  49. />
  50. <v-file-input
  51. id="jobApplicationMotivationLetter"
  52. v-model="jobApplication.motivationLetter"
  53. label="Dépôt de lettre de motivation"
  54. accept=".pdf, .jpeg, .png"
  55. />
  56. <v-textarea
  57. id="jobApplicationMessage"
  58. v-model="jobApplication.message"
  59. :rules="[validateNonEmptyMessage, validateMessageLength]"
  60. label="Message*"
  61. required
  62. />
  63. <span class="remaining-cars-notice">{{ leftCars }} caractères restants</span>
  64. </v-form>
  65. </v-card-text>
  66. <p class="text-right mr-6">
  67. * Champs obligatoires
  68. </p>
  69. <v-card-actions class="justify-center">
  70. <v-btn
  71. class="btn-more mb-4"
  72. @click="submit"
  73. >
  74. Envoyer
  75. </v-btn>
  76. </v-card-actions>
  77. </v-card>
  78. </template>
  79. <script setup lang="ts">
  80. import ContactRequest from "~/models/Maestro/ContactRequest";
  81. import { useEntityManager } from "~/composables/data/useEntityManager";
  82. import JobApplication from "~/models/Maestro/JobApplication";
  83. const { em } = useEntityManager()
  84. const form: Ref<any | null> = ref(null)
  85. const jobApplicationSent: Ref<boolean> = ref(false)
  86. const emit = defineEmits(['submit'])
  87. //@ts-ignore
  88. const jobApplication: ContactRequest = reactive(em.newInstance(JobApplication))
  89. // --- Validation ---
  90. const maxMessageLength = 2000
  91. const leftCars: ComputedRef<number> = computed(() =>
  92. maxMessageLength - (jobApplication.message ? jobApplication.message.length : 0)
  93. )
  94. const validateName = (name: string | null) => !!name || "Le nom est obligatoire";
  95. const validateSurname = (surname: string | null) => !!surname || "Le prénom est obligatoire";
  96. const validateEmail = (email: string | null) =>
  97. (!!email && /.+@.+\..+/.test(email)) || "L'adresse e-mail doit être valide";
  98. const validatePhone = (email: string | null) =>
  99. (!!email && /^((\+|00)33\s?|0)[1-7]([\s.]?\d{2}){4}$/.test(email)) || "Le numéro de téléphone doit être valide";
  100. const validateNonEmptyMessage = (message: string | null) =>
  101. (!!message && message.length > 0) ||
  102. "Le message ne peut pas être vide";
  103. const validateMessageLength = (message: string | null) =>
  104. (!!message && message.length <= maxMessageLength) ||
  105. "Le message ne doit pas dépasser " + maxMessageLength + " caractères";
  106. /**
  107. * Soumet le formulaire de candidature (boite de dialogue)
  108. */
  109. const submit = async () => {
  110. const { valid } = await form.value.validate()
  111. if (!valid) {
  112. jobApplicationSent.value = false
  113. return
  114. }
  115. await em.persist(JobApplication, jobApplication)
  116. jobApplicationSent.value = true;
  117. emit('submit')
  118. };
  119. </script>
  120. <style scoped lang="scss">
  121. </style>