Cotisation.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <!--
  2. Cotisation bar
  3. Barre d'alerte qui s'affiche pour donner l'état de la cotisation
  4. -->
  5. <template>
  6. <main>
  7. <UiSystemBar
  8. v-if="alert && alert.text && alert.callback"
  9. :text="$t(alert.text)"
  10. icon="fas fa-info-circle"
  11. :on-click="alert.callback"
  12. class="theme-info"
  13. />
  14. </main>
  15. </template>
  16. <script setup lang="ts">
  17. import { computed, type ComputedRef } from 'vue'
  18. import { useRuntimeConfig } from '#app'
  19. import { useOrganizationProfileStore } from '~/stores/organizationProfile'
  20. import UrlUtils from '~/services/utils/urlUtils'
  21. import type { ALERT_STATE_COTISATION } from '~/types/enum/enums'
  22. import { useEntityFetch } from '~/composables/data/useEntityFetch'
  23. import Cotisation from '~/models/Organization/Cotisation'
  24. import {FETCHING_STATUS} from "~/types/enum/data";
  25. const organizationProfile = useOrganizationProfileStore()
  26. const runtimeConfig = useRuntimeConfig()
  27. const baseLegacyUrl: string = runtimeConfig.baseUrlAdminLegacy as string
  28. // On récupère l'état des cotisations via l'API
  29. if (!organizationProfile.id) {
  30. throw new Error('missing organization id')
  31. }
  32. const { fetch } = useEntityFetch()
  33. const { data: cotisation, status } = await fetch(
  34. Cotisation,
  35. organizationProfile.id,
  36. )
  37. interface Alert {
  38. text: string
  39. callback: () => void
  40. }
  41. const cotisationYear: ComputedRef<number | null> = computed(() => {
  42. if (status.value == FETCHING_STATUS.PENDING || cotisation.value === null) {
  43. return null
  44. }
  45. return cotisation.value.cotisationYear
  46. })
  47. const alert: ComputedRef<Alert | null> = computed(() => {
  48. if (status.value == FETCHING_STATUS.PENDING || cotisation.value === null) {
  49. return null
  50. }
  51. const mapping: Record<ALERT_STATE_COTISATION, Alert> = {
  52. AFFILIATION: { text: 'cotisation_access', callback: goToCotisation },
  53. INVOICE: { text: 'upload_cotisation_invoice', callback: openInvoiceWindow },
  54. INSURANCE: { text: 'renew_insurance_cmf', callback: goToInsurancePage },
  55. ADVERTISINGINSURANCE: {
  56. text: 'insurance_cmf_subscription',
  57. callback: openCmfSubscriptionPage,
  58. },
  59. }
  60. if (!cotisation.value.alertState) {
  61. return null
  62. }
  63. return mapping[cotisation.value.alertState as ALERT_STATE_COTISATION]
  64. })
  65. /**
  66. * Redirige l'utilisateur vers la page des cotisations
  67. */
  68. const goToCotisation = () => {
  69. if (!organizationProfile.id) {
  70. throw new Error('missing organization id')
  71. }
  72. window.location.href = UrlUtils.join(
  73. baseLegacyUrl,
  74. '/cotisation/cotisation_steps',
  75. organizationProfile.id,
  76. 'steps/1',
  77. )
  78. }
  79. /**
  80. * Ouvre la page facturation dans un nouvel onglet
  81. */
  82. const openInvoiceWindow = () => {
  83. if (!cotisationYear.value) {
  84. throw new Error('no cotisation year defined')
  85. }
  86. window.open(
  87. UrlUtils.join(baseLegacyUrl, 'cotisation/invoice', cotisationYear.value),
  88. '_blank',
  89. )
  90. }
  91. /**
  92. * Redirige l'utilisateur vers la page des assurances
  93. */
  94. const goToInsurancePage = () => {
  95. window.location.href = UrlUtils.join(
  96. baseLegacyUrl,
  97. 'cotisation/insuranceedit',
  98. )
  99. }
  100. /**
  101. * Redirige (dans un nouvel onglet) l'utilsateur vers le site web de la CMF
  102. */
  103. const openCmfSubscriptionPage = () => {
  104. window.open(
  105. 'https://www.cmf-musique.org/services/assurances/assurance-de-groupe/',
  106. '_blank',
  107. )
  108. }
  109. </script>
  110. <style scoped lang="scss">
  111. :deep(.clickable:hover) {
  112. text-decoration: none !important;
  113. }
  114. </style>