Inscription.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <c-header title="BDLG Inscription Benevole" />
  3. <div style="display: flex; justify-content: center">
  4. <dots v-if="status == 'Loading'" />
  5. <h2 v-if="status.startsWith('Error')">{{ status }}</h2>
  6. <div v-if="status == 'Loaded'" class="inscription-container">
  7. <questionnaire
  8. :competences="competences"
  9. :introduction="introduction"
  10. :questions="questions"
  11. :uuid="uuid"
  12. :evtName="evtName"
  13. :emailList="emailList"
  14. @newRegistration="status = 'Completed'"
  15. />
  16. </div>
  17. <div v-if="status == 'Completed'">
  18. <h2>Inscription Validée</h2>
  19. <p>Votre incription à bien été validée</p>
  20. <button class="btn small primary" @click="refresh">Nouvelle Inscription</button>
  21. </div>
  22. </div>
  23. <c-footer />
  24. </template>
  25. <script lang="ts">
  26. import { defineComponent } from "vue";
  27. import { validate as validateUuid } from "uuid";
  28. import cHeader from "@/components/Header.vue";
  29. import cFooter from "@/components/Footer.vue";
  30. import Questionnaire from "@/components/Questionaire.vue";
  31. import dots from "@/components/Dots.vue";
  32. import { StateJSON } from "@/store/State";
  33. import Benevole, { BenevoleJSON } from "@/models/Benevole";
  34. import Competence from "@/models/Competence";
  35. import getQuestionnaire from "./mixins/getQuestionnaire";
  36. import "@/assets/css/button.css";
  37. const API_URL = process.env.VUE_APP_API_URL;
  38. export default defineComponent({
  39. components: { cHeader, cFooter, dots, Questionnaire },
  40. mixins: [getQuestionnaire],
  41. data() {
  42. return {
  43. uuid: location.pathname.split("/").pop(),
  44. status: "Loading",
  45. data: null as StateJSON | null,
  46. registration: [] as Array<Benevole>,
  47. competences: [] as Array<Competence>,
  48. };
  49. },
  50. computed: {
  51. evtName(): string {
  52. return this.data?.evenement.name ?? "";
  53. },
  54. emailList(): Array<string> {
  55. return this.registration.map((b) => b.email);
  56. },
  57. },
  58. methods: {
  59. addBenevoles(data: Array<BenevoleJSON>) {
  60. this.registration.push(...data.map((o) => Benevole.fromJSON(o)));
  61. },
  62. refresh() {
  63. // eslint-disable-next-line no-self-assign
  64. location.href = location.href;
  65. },
  66. },
  67. mounted() {
  68. // Get event data
  69. const uuid = this.uuid;
  70. if (uuid && validateUuid(uuid)) {
  71. this.getQuestionnaire(uuid);
  72. fetch(`${API_URL}api/evenements/${uuid}`)
  73. .then((res) => {
  74. if (res.status == 200) {
  75. this.status = "Loaded";
  76. return res.json();
  77. } else {
  78. this.status = "Error 404";
  79. throw new Error(res.statusText);
  80. }
  81. })
  82. .then((data: StateJSON) => {
  83. this.data = data;
  84. this.competences = data.competences.map((o) => Competence.fromJSON(o));
  85. this.addBenevoles(data.benevoles);
  86. });
  87. // Get existing registration
  88. fetch(`${API_URL}api/inscription/${uuid}`)
  89. .then((res) => {
  90. if (res.status == 200) {
  91. return res.json();
  92. } else {
  93. throw new Error(res.statusText);
  94. }
  95. })
  96. .then((data: Array<BenevoleJSON>) => this.addBenevoles(data));
  97. } else {
  98. this.status = "Error 404";
  99. }
  100. },
  101. });
  102. </script>
  103. <style scoped>
  104. .inscription-container {
  105. max-width: 600px;
  106. padding: 8px;
  107. }
  108. </style>