SwitchYear.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <!--
  2. Switch year bar
  3. Barre d'alerte qui s'affiche lorsque l'utilisateur n'est pas sur l'année courante.
  4. -->
  5. <template>
  6. <!-- TODO : fonctionnement à valider -->
  7. <UiSystemBar v-if="show" class="theme-warning">
  8. {{$t('not_current_year')}}
  9. <a @click="resetYear" class="text-decoration-none on-warning" style="cursor: pointer;">
  10. <strong class="pl-2 text-neutral-strong">
  11. {{$t('not_current_year_reset')}}
  12. </strong>
  13. </a>
  14. </UiSystemBar>
  15. </template>
  16. <script setup lang="ts">
  17. import {useAccessProfileStore} from "~/stores/accessProfile";
  18. import {useOrganizationProfileStore} from "~/stores/organizationProfile";
  19. import {ComputedRef} from "@vue/reactivity";
  20. import {useFormStore} from "~/stores/form";
  21. import Access from "~/models/Access/Access";
  22. import {usePageStore} from "~/stores/page";
  23. import {useEntityManager} from "~/composables/data/useEntityManager";
  24. import {useRefreshProfile} from "~/composables/data/useRefreshProfile";
  25. const { em } = useEntityManager()
  26. const accessProfile = useAccessProfileStore()
  27. const organizationProfile = useOrganizationProfileStore()
  28. const { setDirty } = useFormStore()
  29. const pageStore = usePageStore()
  30. const { refreshProfile } = useRefreshProfile()
  31. const show: ComputedRef<boolean> = computed(() => {
  32. return (
  33. accessProfile.historical.past || accessProfile.historical.future ||
  34. (accessProfile.historical.dateStart && accessProfile.historical.dateStart.length > 0) ||
  35. (accessProfile.historical.dateEnd && accessProfile.historical.dateEnd.length > 0) ||
  36. accessProfile.activityYear !== organizationProfile.currentActivityYear
  37. )
  38. })
  39. const resetYear = async () => {
  40. const defaultValues = {
  41. historical: {
  42. "future": false,
  43. "past": false,
  44. "present": true,
  45. },
  46. activityYear: organizationProfile.currentActivityYear
  47. }
  48. // Il faut ajouter un patch sur le profile ici
  49. setDirty(false)
  50. pageStore.loading = true
  51. await em.patch(Access, accessProfile.currentAccessId, defaultValues)
  52. if (process.server) {
  53. // Force profile refresh server side to avoid a bug where server and client stores diverge on profile refresh
  54. await refreshProfile()
  55. }
  56. window.location.reload()
  57. }
  58. </script>
  59. <style scoped lang="scss">
  60. .v-system-bar {
  61. font-size: 14px;
  62. }
  63. .v-icon {
  64. height: 20px;
  65. margin: 0 6px;
  66. }
  67. #resetLink:hover {
  68. cursor: pointer;
  69. }
  70. </style>