SwitchYear.vue 2.4 KB

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