ActivityYear.vue 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <main class="d-flex flex-row align-center">
  3. <span v-show="mdAndUp"
  4. class="mr-2 font-weight-bold on-neutral">
  5. {{ $t(label) }} :
  6. </span>
  7. <UiXeditableText
  8. class="activity-year-input"
  9. type="number"
  10. :data="currentActivityYear"
  11. @update="setActivityYear"
  12. >
  13. <template #xeditable.read="{inputValue}">
  14. <div class="d-flex align-center on-neutral--clickable">
  15. <v-icon aria-hidden="false" size="small" class="mr-1" icon="fas fa-edit" />
  16. <strong >
  17. {{ inputValue }}
  18. <span v-if="yearPlusOne">
  19. / {{ parseInt(inputValue) + 1 }}
  20. </span>
  21. </strong>
  22. </div>
  23. </template>
  24. </UiXeditableText>
  25. </main>
  26. </template>
  27. <script setup lang="ts">
  28. import {useEntityManager} from "~/composables/data/useEntityManager";
  29. import {useFormStore} from "~/stores/form";
  30. import {useOrganizationProfileStore} from "~/stores/organizationProfile";
  31. import {useAccessProfileStore} from "~/stores/accessProfile";
  32. import Access from "~/models/Access/Access";
  33. import {useDisplay} from "vuetify";
  34. import {usePageStore} from "~/stores/page";
  35. import {useRefreshProfile} from "~/composables/data/useRefreshProfile";
  36. const { em } = useEntityManager()
  37. const accessProfileStore = useAccessProfileStore()
  38. const organizationProfileStore = useOrganizationProfileStore()
  39. const formStore = useFormStore()
  40. const pageStore = usePageStore()
  41. const { mdAndUp } = useDisplay()
  42. const { refreshProfile } = useRefreshProfile()
  43. const currentActivityYear: ComputedRef<number | undefined> = computed(() => accessProfileStore.activityYear ?? undefined)
  44. const yearPlusOne: boolean = !organizationProfileStore.isManagerProduct
  45. const label: string = organizationProfileStore.isSchool ? 'schooling_year' : organizationProfileStore.isArtist ? 'season_year' : 'cotisation_year'
  46. /**
  47. * Persist a new activityYear
  48. * @param event
  49. */
  50. const setActivityYear = async (event: string) => {
  51. const activityYear = parseInt(event)
  52. if (!(1900 < activityYear) || !(activityYear <= 2100)) {
  53. throw new Error("Error: 'year' shall be a valid year")
  54. }
  55. formStore.setDirty(false)
  56. pageStore.loading = true
  57. await em.patch(Access, accessProfileStore.currentAccessId, { activityYear: activityYear })
  58. if (process.server) {
  59. // Force profile refresh server side to avoid a bug where server and client stores diverge on profile refresh
  60. await refreshProfile()
  61. }
  62. window.location.reload()
  63. }
  64. </script>
  65. <style lang="scss">
  66. .activity-year-input {
  67. width: 120px;
  68. max-height: 20px;
  69. .v-input {
  70. min-width: 70px;
  71. }
  72. input{
  73. font-size: 14px;
  74. width: 55px !important;
  75. padding: 0 !important;
  76. margin-top: 0 !important;
  77. min-height: 24px;
  78. height: 24px;
  79. }
  80. }
  81. </style>