Cotisation.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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"
  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 {Ref} from "vue";
  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(baseLegacyUrl, '/cotisation/cotisation_steps', organizationProfile.id, 'steps/1')
  35. }
  36. /**
  37. * Ouvre la page facturation dans un nouvel onglet
  38. */
  39. const openInvoiceWindow = () => {
  40. if (!cotisationYear.value) {
  41. throw new Error('no cotisation year defined')
  42. }
  43. window.open(UrlUtils.join(baseLegacyUrl, 'cotisation/invoice', cotisationYear.value), '_blank')
  44. }
  45. /**
  46. * Redirige l'utilisateur vers la page des assurances
  47. */
  48. const goToInsurancePage = () => {
  49. window.location.href = UrlUtils.join(baseLegacyUrl, 'cotisation/insuranceedit')
  50. }
  51. /**
  52. * Redirige (dans un nouvel onglet) l'utilsateur vers le site web de la CMF
  53. */
  54. const openCmfSubscriptionPage = () => {
  55. window.open('https://www.cmf-musique.org/services/assurances/assurance-de-groupe/', '_blank')
  56. }
  57. // On récupère l'état des cotisations via l'API
  58. if (!organizationProfile.id) {
  59. throw new Error('missing organization id')
  60. }
  61. const { fetch } = useEntityFetch()
  62. const { data: cotisation } = await fetch(Cotisation, organizationProfile.id)
  63. interface Alert {
  64. text: string
  65. callback: () => void
  66. }
  67. const alert: Ref<Alert | null> = ref(null)
  68. if (cotisation.value !== null) {
  69. cotisationYear.value = cotisation.value.cotisationYear
  70. const mapping: Record<ALERT_STATE_COTISATION, Alert> = {
  71. 'AFFILIATION': { text: 'cotisation_access', callback: goToCotisation },
  72. 'INVOICE': { text: 'upload_cotisation_invoice', callback: openInvoiceWindow },
  73. 'INSURANCE': { text: 'renew_insurance_cmf', callback: goToInsurancePage },
  74. 'ADVERTISINGINSURANCE': { text: 'insurance_cmf_subscription', callback: openCmfSubscriptionPage },
  75. }
  76. alert.value = mapping[cotisation.value.alertState as ALERT_STATE_COTISATION]
  77. }
  78. </script>
  79. <style scoped lang="scss">
  80. :deep(.clickable:hover) {
  81. text-decoration: none !important;
  82. }
  83. </style>