Selaa lähdekoodia

fix minor error in console

Olivier Massot 2 vuotta sitten
vanhempi
commit
dc16318a3b
1 muutettua tiedostoa jossa 11 lisäystä ja 8 poistoa
  1. 11 8
      components/Layout/AlertBar/Cotisation.vue

+ 11 - 8
components/Layout/AlertBar/Cotisation.vue

@@ -7,7 +7,7 @@ Barre d'alerte qui s'affiche pour donner l'état de la cotisation
 <template>
   <main>
     <UiSystemBar
-        v-if="alert !== null"
+        v-if="alert && alert.text && alert.callback"
         :text="$t(alert.text)"
         icon="fas fa-info-circle"
         :on-click="alert.callback"
@@ -71,16 +71,18 @@ if (!organizationProfile.id) {
 }
 
 const { fetch } = useEntityFetch()
-const { data: cotisation } = await fetch(Cotisation, organizationProfile.id)
+const { data: cotisation, pending } = await fetch(Cotisation, organizationProfile.id)
 
 interface Alert {
   text: string
   callback: () => void
 }
 
-const alert: Ref<Alert | null> = ref(null)
+const alert: ComputedRef<Alert | null> = computed(() => {
+  if (pending.value) {
+    return null
+  }
 
-if (cotisation.value !== null) {
   cotisationYear.value = cotisation.value.cotisationYear
 
   const mapping: Record<ALERT_STATE_COTISATION, Alert> = {
@@ -90,11 +92,12 @@ if (cotisation.value !== null) {
     'ADVERTISINGINSURANCE': { text: 'insurance_cmf_subscription', callback: openCmfSubscriptionPage },
   }
 
-  alert.value = mapping[cotisation.value.alertState as ALERT_STATE_COTISATION]
-}
-
-
+  if (!cotisation.value.alertState) {
+    return null
+  }
 
+  return mapping[cotisation.value.alertState as ALERT_STATE_COTISATION]
+})
 
 </script>