Inscription.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. />
  15. </div>
  16. </div>
  17. <c-footer />
  18. </template>
  19. <script lang="ts">
  20. import { defineComponent } from "vue";
  21. import { validate as validateUuid } from "uuid";
  22. import cHeader from "@/components/Header.vue";
  23. import cFooter from "@/components/Footer.vue";
  24. import Questionnaire from "@/components/Questionaire.vue";
  25. import dots from "@/components/Dots.vue";
  26. import { StateJSON } from "@/store/State";
  27. import Benevole, { BenevoleJSON } from "@/models/Benevole";
  28. import Competence from "@/models/Competence";
  29. import getQuestionnaire from "./mixins/getQuestionnaire";
  30. const API_URL = process.env.VUE_APP_API_URL;
  31. export default defineComponent({
  32. components: { cHeader, cFooter, dots, Questionnaire },
  33. mixins: [getQuestionnaire],
  34. data() {
  35. return {
  36. uuid: location.pathname.split("/").pop(),
  37. status: "Loading",
  38. data: null as StateJSON | null,
  39. registration: [] as Array<Benevole>,
  40. competences: [] as Array<Competence>,
  41. };
  42. },
  43. computed: {
  44. evtName(): string {
  45. return this.data?.evenement.name ?? "";
  46. },
  47. emailList(): Array<string> {
  48. return this.registration.map((b) => b.email);
  49. },
  50. },
  51. methods: {
  52. addBenevoles(data: Array<BenevoleJSON>) {
  53. this.registration.push(...data.map((o) => Benevole.fromJSON(o)));
  54. },
  55. },
  56. mounted() {
  57. // Get event data
  58. const uuid = this.uuid;
  59. if (uuid && validateUuid(uuid)) {
  60. this.getQuestionnaire(uuid);
  61. fetch(`${API_URL}api/evenements/${uuid}`)
  62. .then((res) => {
  63. if (res.status == 200) {
  64. this.status = "Loaded";
  65. return res.json();
  66. } else {
  67. this.status = "Error 404";
  68. throw new Error(res.statusText);
  69. }
  70. })
  71. .then((data: StateJSON) => {
  72. this.data = data;
  73. this.competences = data.competences.map((o) => Competence.fromJSON(o));
  74. this.addBenevoles(data.benevoles);
  75. });
  76. // Get existing registration
  77. fetch(`${API_URL}api/inscription/${uuid}`)
  78. .then((res) => {
  79. if (res.status == 200) {
  80. return res.json();
  81. } else {
  82. throw new Error(res.statusText);
  83. }
  84. })
  85. .then((data: Array<BenevoleJSON>) => this.addBenevoles(data));
  86. } else {
  87. this.status = "Error 404";
  88. }
  89. },
  90. });
  91. </script>
  92. <style scoped>
  93. .inscription-container {
  94. max-width: 600px;
  95. padding: 8px;
  96. }
  97. </style>