Cotisation.vue 3.0 KB

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