SwitchYear.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 {$useForm} from "~/composables/form/useForm";
  16. import { useMyProfile } from '~/composables/data/useMyProfile'
  17. export default defineComponent({
  18. setup () {
  19. const { store } = useContext()
  20. const { markFormAsNotDirty } = $useForm()
  21. const { updateMyProfile, setHistorical, setActivityYear } = useMyProfile()
  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. if(profileOrganization.currentActivityYear)
  36. setActivityYear(profileOrganization.currentActivityYear)
  37. markFormAsNotDirty()
  38. await updateMyProfile()
  39. window.location.reload()
  40. }
  41. return {
  42. isShow,
  43. resetYear
  44. }
  45. }
  46. })
  47. </script>
  48. <style scoped>
  49. </style>