Form.vue 4.0 KB

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