PlanningPage.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <c-header title="BDLG Planner" titleTo="/planner" />
  3. <div class="main-container">
  4. <div v-if="isLoading" class="loading">Chargement en cours <br /><dots /></div>
  5. <template v-else-if="hasData">
  6. <h1 style="text-align: center">{{ title }}</h1>
  7. <auto-complete-input
  8. id="benevole-selection-input"
  9. label="Entrée votre nom"
  10. :autocompleteList="autocompleteData"
  11. :strictAutocomplete="true"
  12. v-model="benevoleId"
  13. />
  14. <planning :benevoleId="benevoleId" />
  15. </template>
  16. <div class="no-info" v-else>
  17. <i class="material-icons">travel_explore</i>
  18. <div>Planning introuvable<br />Veuillez vérifier votre lien</div>
  19. </div>
  20. </div>
  21. </template>
  22. <script lang="ts">
  23. import { defineComponent } from "vue";
  24. import Planning from "@/views/PlanningPersonnel.vue";
  25. import AutoCompleteInput from "@/components/AutoCompleteInput.vue";
  26. import Dots from "@/components/Dots.vue";
  27. import cHeader from "@/components/Header.vue";
  28. import importJsonState from "@/mixins/ImportJsonState";
  29. import Toast from "./utils/Toast";
  30. import Benevole from "./models/Benevole";
  31. import AutocompleteValues from "./models/AutocompleteOptions";
  32. const API_URL = process.env.VUE_APP_API_URL;
  33. const uuidv4check = /^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i;
  34. export default defineComponent({
  35. mixins: [importJsonState],
  36. components: { Planning, Dots, cHeader, AutoCompleteInput },
  37. data() {
  38. return { isLoading: true, hasData: false, benevoleValue: "" };
  39. },
  40. computed: {
  41. title(): string {
  42. return this.$store.state.evenement.name;
  43. },
  44. benevoleId(): number {
  45. return parseInt(this.benevoleValue) ?? -1;
  46. },
  47. benevoleList(): Array<Benevole> {
  48. return this.$store.state.benevoleList;
  49. },
  50. autocompleteData(): Array<AutocompleteValues> {
  51. return this.benevoleList.map((o) => {
  52. return { id: o.id.toString(), name: o.fullname };
  53. });
  54. },
  55. },
  56. mounted() {
  57. Toast({ html: "Bienvenue" });
  58. const uuid = document.location.pathname.split("/").reverse()[0];
  59. if (uuidv4check.test(uuid)) {
  60. const url = `${API_URL}api/evenements/${uuid}`;
  61. fetch(url)
  62. .then((res) => {
  63. if (res.status == 200) {
  64. return res.json();
  65. } else {
  66. throw Error(res.statusText);
  67. }
  68. })
  69. .then((data) => {
  70. this.hasData = true;
  71. this.isLoading = false;
  72. this.importJsonState(data);
  73. })
  74. .catch((reason) => {
  75. this.isLoading = false;
  76. Toast({ html: reason });
  77. });
  78. } else {
  79. this.isLoading = false;
  80. }
  81. },
  82. });
  83. </script>
  84. <style scoped>
  85. .no-info {
  86. display: flex;
  87. flex-direction: column;
  88. font-size: 1.5em;
  89. margin: 16px;
  90. }
  91. .no-info > .material-icons {
  92. font-size: 9em;
  93. line-height: 1.1em;
  94. text-align: center;
  95. color: var(--color-neutral-800);
  96. }
  97. .no-info > div {
  98. text-align: center;
  99. line-height: 1.5em;
  100. color: var(--color-neutral-200);
  101. }
  102. .loading {
  103. text-align: center;
  104. font-size: 30px;
  105. margin: 40px 8px;
  106. }
  107. @media (min-width: 600px) {
  108. .no-info {
  109. font-size: 2em;
  110. }
  111. .loading {
  112. margin-top: 60px;
  113. font-size: 40px;
  114. }
  115. }
  116. </style>