ActivityYear.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <main class="d-flex">
  3. <span class="mr-2 ot-dark_grey--text font-weight-bold">{{ $t(label) }} : </span>
  4. <UiXeditableText
  5. class="activity-year-input"
  6. type="number"
  7. :data="activityYear"
  8. @update="updateActivityYear"
  9. >
  10. <template #xeditable.read="{inputValue}">
  11. <v-icon aria-hidden="false" class="ot-green--text" x-small>
  12. fas fa-edit
  13. </v-icon>
  14. <strong class="ot-green--text"> {{ inputValue }} <span v-if="yearPlusOne">/ {{ parseInt(inputValue) + 1 }}</span></strong>
  15. </template>
  16. </UiXeditableText>
  17. </main>
  18. </template>
  19. <script setup lang="ts">
  20. import {useEntityManager} from "~/composables/data/useEntityManager";
  21. import {useFormStore} from "~/stores/form";
  22. import {useOrganizationProfileStore} from "~/stores/organizationProfile";
  23. import {useAccessProfileStore} from "~/stores/accessProfile";
  24. const { em } = useEntityManager()
  25. const { activityYear } = useAccessProfileStore()
  26. const { isManagerProduct, isSchool, isArtist } = useOrganizationProfileStore()
  27. const { setDirty } = useFormStore()
  28. const setActivityYear = async (activityYear: number) => {
  29. if (!(1900 < activityYear) || !(activityYear <= 2100)) {
  30. throw new Error("Error: 'year' shall be a valid year")
  31. }
  32. await em.updateProfile({'activityYear': activityYear})
  33. }
  34. const yearPlusOne: boolean = !isManagerProduct
  35. const label: string = isSchool ? 'schooling_year' : isArtist ? 'season_year' : 'cotisation_year'
  36. const updateActivityYear = async (newDate: number) => {
  37. setDirty(false)
  38. await setActivityYear(newDate)
  39. window.location.reload()
  40. }
  41. </script>
  42. <style lang="scss">
  43. .activity-year-input{
  44. max-height: 20px;
  45. input{
  46. font-size: 14px;
  47. width: 55px !important;
  48. }
  49. }
  50. </style>