Cotisation.vue 2.8 KB

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