Cotisation.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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="show"
  10. :text="$t(alertTextKey)"
  11. icon="fas fa-info-circle"
  12. :on-click="alertOnClick"
  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. const show: Ref<boolean> = ref(false)
  66. const alertTextKey: Ref<string> = ref('')
  67. const alertOnClick: Ref<() => void> = ref(() => {})
  68. if (cotisation.value !== null) {
  69. cotisationYear.value = cotisation.value.cotisationYear
  70. show.value = true
  71. switch(cotisation.value.alertState) {
  72. case ALERT_STATE_COTISATION.AFFILIATION :
  73. alertTextKey.value = 'cotisation_access'
  74. alertOnClick.value = goToCotisation
  75. break;
  76. case ALERT_STATE_COTISATION.INVOICE :
  77. alertTextKey.value = 'upload_cotisation_invoice'
  78. alertOnClick.value = openInvoiceWindow
  79. break;
  80. case ALERT_STATE_COTISATION.INSURANCE :
  81. alertTextKey.value = 'renew_insurance_cmf'
  82. alertOnClick.value = goToInsurancePage
  83. break;
  84. case ALERT_STATE_COTISATION.ADVERTISINGINSURANCE :
  85. alertTextKey.value = 'insurance_cmf_subscription'
  86. alertOnClick.value = openCmfSubscriptionPage
  87. break;
  88. }
  89. }
  90. </script>