SwitchYear.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <!--
  2. Switch year bar : Barre qui s'affiche lorsque l'utilisateur n'est pas sur l'année courante.
  3. -->
  4. <template>
  5. <UiSystemBar color="ot_warning" v-if="isShow">
  6. <template #bar.text>
  7. {{$t('not_current_year')}}
  8. <a @click="resetYear"><strong class="ot_black--text">{{$t('not_current_year_reset')}}</strong></a>
  9. </template>
  10. </UiSystemBar>
  11. </template>
  12. <script lang="ts">
  13. import { defineComponent, useContext, computed} from '@nuxtjs/composition-api'
  14. import {accessState, organizationState} from "~/types/interfaces";
  15. import {$useDirtyForm} from "~/use/form/useDirtyForm";
  16. import {$useMyProfileUpdater} from "~/use/updater/useMyProfileUpdater";
  17. export default defineComponent({
  18. setup () {
  19. const { store, $dataPersister } = useContext()
  20. const { markFormAsNotDirty } = $useDirtyForm(store)
  21. const { updateMyProfile, setHistorical, setActivityYear } = $useMyProfileUpdater(store, $dataPersister)
  22. const profileAccess:accessState = store.state.profile.access
  23. const profileOrganization:organizationState = store.state.profile.organization
  24. const isShow = computed(() => {
  25. return (
  26. profileAccess.historical.past || profileAccess.historical.future
  27. ||
  28. profileAccess.historical.dateStart || profileAccess.historical.dateEnd
  29. ||
  30. profileAccess.activityYear !== profileOrganization.currentActivityYear
  31. )
  32. })
  33. const resetYear = async () =>{
  34. setHistorical(['present'])
  35. setActivityYear(profileOrganization.currentActivityYear)
  36. markFormAsNotDirty()
  37. await updateMyProfile()
  38. window.location.reload()
  39. }
  40. return {
  41. isShow,
  42. resetYear
  43. }
  44. }
  45. })
  46. </script>
  47. <style scoped>
  48. </style>