Cotisation.vue 3.2 KB

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