Cotisation.vue 3.1 KB

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