Cotisation.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <!--
  2. Cotisation bar
  3. Barre d'alerte qui s'affiche pour donner l'état de la cotisation
  4. -->
  5. <template>
  6. <main>
  7. <!-- TODO : vérifier le bon fonctionnement -->
  8. <UiSystemBar
  9. v-if="alert !== null"
  10. :text="$t(alert.text)"
  11. icon="fas fa-info-circle"
  12. :on-click="alert.callback"
  13. background-color="ot-info"
  14. text-color="ot-white"
  15. />
  16. </main>
  17. </template>
  18. <script setup lang="ts">
  19. import {useOrganizationProfileStore} from "~/stores/organizationProfile";
  20. import {Ref} from "vue";
  21. import UrlUtils from "~/services/utils/urlUtils";
  22. import {ALERT_STATE_COTISATION} from "~/types/enum/enums";
  23. import {useEntityFetch} from "~/composables/data/useEntityFetch";
  24. import Cotisation from "~/models/Organization/Cotisation";
  25. const organizationProfile = useOrganizationProfileStore()
  26. const runtimeConfig = useRuntimeConfig()
  27. const baseLegacyUrl: string = runtimeConfig.baseUrlAdminLegacy
  28. const cotisationYear: Ref<number | null> = ref(null)
  29. /**
  30. * Redirige l'utilisateur vers la page des cotisations
  31. */
  32. const goToCotisation = () => {
  33. if (!organizationProfile.id) {
  34. throw new Error('missing organization id')
  35. }
  36. window.location.href = UrlUtils.join(baseLegacyUrl, '/cotisation/cotisation_steps', organizationProfile.id, 'steps/1')
  37. }
  38. /**
  39. * Ouvre la page facturation dans un nouvel onglet
  40. */
  41. const openInvoiceWindow = () => {
  42. if (!cotisationYear.value) {
  43. throw new Error('no cotisation year defined')
  44. }
  45. window.open(UrlUtils.join(baseLegacyUrl, 'cotisation/invoice', cotisationYear.value), '_blank')
  46. }
  47. /**
  48. * Redirige l'utilisateur vers la page des assurances
  49. */
  50. const goToInsurancePage = () => {
  51. window.location.href = UrlUtils.join(baseLegacyUrl, 'cotisation/insuranceedit')
  52. }
  53. /**
  54. * Redirige (dans un nouvel onglet) l'utilsateur vers le site web de la CMF
  55. */
  56. const openCmfSubscriptionPage = () => {
  57. window.open('https://www.cmf-musique.org/services/assurances/assurance-de-groupe/', '_blank')
  58. }
  59. // On récupère l'état des cotisations via l'API
  60. if (!organizationProfile.id) {
  61. throw new Error('missing organization id')
  62. }
  63. const { fetch } = useEntityFetch()
  64. const { data: cotisation } = await fetch(Cotisation, organizationProfile.id)
  65. interface Alert {
  66. text: string
  67. callback: () => void
  68. }
  69. const alert: Ref<Alert | null> = ref(null)
  70. if (cotisation.value !== null) {
  71. cotisationYear.value = cotisation.value.cotisationYear
  72. const mapping: Record<ALERT_STATE_COTISATION, Alert> = {
  73. 'AFFILIATION': { text: 'cotisation_access', callback: goToCotisation },
  74. 'INVOICE': { text: 'upload_cotisation_invoice', callback: openInvoiceWindow },
  75. 'INSURANCE': { text: 'renew_insurance_cmf', callback: goToInsurancePage },
  76. 'ADVERTISINGINSURANCE': { text: 'insurance_cmf_subscription', callback: openCmfSubscriptionPage },
  77. }
  78. alert.value = mapping[cotisation.value.alertState as ALERT_STATE_COTISATION]
  79. }
  80. </script>