Просмотр исходного кода

minor refact of cotisation alert bar

Olivier Massot 2 лет назад
Родитель
Сommit
a6784df7a7
2 измененных файлов с 17 добавлено и 27 удалено
  1. 17 25
      components/Layout/AlertBar/Cotisation.vue
  2. 0 2
      components/Layout/AlertBar/Env.vue

+ 17 - 25
components/Layout/AlertBar/Cotisation.vue

@@ -8,10 +8,10 @@ Barre d'alerte qui s'affiche pour donner l'état de la cotisation
   <main>
     <!-- TODO : vérifier le bon fonctionnement -->
     <UiSystemBar
-        v-if="show"
-        :text="$t(alertTextKey)"
+        v-if="alert !== null"
+        :text="$t(alert.text)"
         icon="fas fa-info-circle"
-        :on-click="alertOnClick"
+        :on-click="alert.callback"
         background-color="ot-info"
         text-color="ot-white"
     />
@@ -76,32 +76,24 @@ if (!organizationProfile.id) {
 const { fetch } = useEntityFetch()
 const { data: cotisation } = await fetch(Cotisation, organizationProfile.id)
 
-const show: Ref<boolean> = ref(false)
-const alertTextKey: Ref<string> = ref('')
-const alertOnClick: Ref<() => void> = ref(() => {})
+interface Alert {
+  text: string
+  callback: () => void
+}
+
+const alert: Ref<Alert | null> = ref(null)
 
 if (cotisation.value !== null) {
   cotisationYear.value = cotisation.value.cotisationYear
-  show.value = true
-
-  switch(cotisation.value.alertState) {
-    case ALERT_STATE_COTISATION.AFFILIATION :
-      alertTextKey.value = 'cotisation_access'
-      alertOnClick.value = goToCotisation
-      break;
-    case ALERT_STATE_COTISATION.INVOICE :
-      alertTextKey.value = 'upload_cotisation_invoice'
-      alertOnClick.value = openInvoiceWindow
-      break;
-    case ALERT_STATE_COTISATION.INSURANCE :
-      alertTextKey.value = 'renew_insurance_cmf'
-      alertOnClick.value = goToInsurancePage
-      break;
-    case ALERT_STATE_COTISATION.ADVERTISINGINSURANCE :
-      alertTextKey.value = 'insurance_cmf_subscription'
-      alertOnClick.value = openCmfSubscriptionPage
-      break;
+
+  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 },
   }
+
+  alert.value = mapping[cotisation.value.alertState as ALERT_STATE_COTISATION]
 }
 
 </script>

+ 0 - 2
components/Layout/AlertBar/Env.vue

@@ -17,7 +17,5 @@ Barre d'alerte qui s'affiche lorsque l'utilisateur n'est pas dans un environneme
   const runtimeConfig = useRuntimeConfig()
 
   const env = runtimeConfig.env ?? 'unknown'
-
-  console.log(env)
   const show = env !== 'production'
 </script>