| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <!--
- Cotisation bar
- Barre d'alerte qui s'affiche pour donner l'état de la cotisation
- -->
- <template>
- <main>
- <UiSystemBar
- v-if="alert && alert.text && alert.callback"
- :text="$t(alert.text)"
- icon="fas fa-info-circle"
- :on-click="alert.callback"
- class="theme-info"
- />
- </main>
- </template>
- <script setup lang="ts">
- import { useOrganizationProfileStore } from '~/stores/organizationProfile'
- import UrlUtils from '~/services/utils/urlUtils'
- import type { ALERT_STATE_COTISATION } from '~/types/enum/enums'
- import { useEntityFetch } from '~/composables/data/useEntityFetch'
- import Cotisation from '~/models/Organization/Cotisation'
- const organizationProfile = useOrganizationProfileStore()
- const runtimeConfig = useRuntimeConfig()
- const baseLegacyUrl: string = runtimeConfig.baseUrlAdminLegacy
- // On récupère l'état des cotisations via l'API
- if (!organizationProfile.id) {
- throw new Error('missing organization id')
- }
- const { fetch } = useEntityFetch()
- const { data: cotisation, pending } = await fetch(
- Cotisation,
- organizationProfile.id,
- )
- interface Alert {
- text: string
- callback: () => void
- }
- const cotisationYear: ComputedRef<number | null> = computed(() => {
- if (pending.value || cotisation.value === null) {
- return null
- }
- return cotisation.value.cotisationYear
- })
- const alert: ComputedRef<Alert | null> = computed(() => {
- if (pending.value || cotisation.value === null) {
- return null
- }
- const mapping: Record<ALERT_STATE_COTISATION, Alert> = {
- AFFILIATION: { text: 'cotisation_access', callback: goToCotisation },
- INVOICE: { text: 'upload_cotisation_invoice', callback: openInvoiceWindow },
- INSURANCE: { text: 'renew_insurance_cmf', callback: goToInsurancePage },
- ADVERTISINGINSURANCE: {
- text: 'insurance_cmf_subscription',
- callback: openCmfSubscriptionPage,
- },
- }
- if (!cotisation.value.alertState) {
- return null
- }
- return mapping[cotisation.value.alertState as ALERT_STATE_COTISATION]
- })
- /**
- * Redirige l'utilisateur vers la page des cotisations
- */
- const goToCotisation = () => {
- if (!organizationProfile.id) {
- throw new Error('missing organization id')
- }
- window.location.href = UrlUtils.join(
- baseLegacyUrl,
- '/cotisation/cotisation_steps',
- organizationProfile.id,
- 'steps/1',
- )
- }
- /**
- * Ouvre la page facturation dans un nouvel onglet
- */
- const openInvoiceWindow = () => {
- if (!cotisationYear.value) {
- throw new Error('no cotisation year defined')
- }
- window.open(
- UrlUtils.join(baseLegacyUrl, 'cotisation/invoice', cotisationYear.value),
- '_blank',
- )
- }
- /**
- * Redirige l'utilisateur vers la page des assurances
- */
- const goToInsurancePage = () => {
- window.location.href = UrlUtils.join(
- baseLegacyUrl,
- 'cotisation/insuranceedit',
- )
- }
- /**
- * Redirige (dans un nouvel onglet) l'utilsateur vers le site web de la CMF
- */
- const openCmfSubscriptionPage = () => {
- window.open(
- 'https://www.cmf-musique.org/services/assurances/assurance-de-groupe/',
- '_blank',
- )
- }
- </script>
- <style scoped lang="scss">
- :deep(.clickable:hover) {
- text-decoration: none !important;
- }
- </style>
|