Cotisation.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 type {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, pending } = await fetch(Cotisation, organizationProfile.id)
  63. interface Alert {
  64. text: string
  65. callback: () => void
  66. }
  67. const alert: ComputedRef<Alert | null> = computed(() => {
  68. if (pending.value) {
  69. return null
  70. }
  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. if (!cotisation.value.alertState) {
  79. return null
  80. }
  81. return mapping[cotisation.value.alertState as ALERT_STATE_COTISATION]
  82. })
  83. </script>
  84. <style scoped lang="scss">
  85. :deep(.clickable:hover) {
  86. text-decoration: none !important;
  87. }
  88. </style>