Browse Source

various fixes

Olivier Massot 10 months ago
parent
commit
5dec9544b4

+ 12 - 0
composables/utils/useRouteUtils.ts

@@ -0,0 +1,12 @@
+export const useRouteUtils = () => {
+  const route = useRoute()
+
+  const getIdFromRoute = (): number => {
+    if (!route.params.id || !/\d+/.test(route.params.id as string)) {
+      throw new Error('No id found in route')
+    }
+    return parseInt(route.params.id as string)
+  }
+
+  return { getIdFromRoute }
+}

+ 2 - 1
i18n/lang/fr.json

@@ -705,5 +705,6 @@
   "teachers": "Professeurs",
   "pupils-members": "Élèves / Adhérents / Membres",
   "id": "Id",
-  "missing_name": "Nom manquant"
+  "missing_name": "Nom manquant",
+  "warning": "Avertissement",
 }

+ 4 - 5
pages/parameters/subdomains/[id].vue

@@ -44,19 +44,18 @@ import { useEntityManager } from '~/composables/data/useEntityManager'
 import { usePageStore } from '~/stores/page'
 import { TYPE_ALERT } from '~/types/enum/enums'
 import { useRefreshProfile } from '~/composables/data/useRefreshProfile'
+import { useRouteUtils } from '~/composables/utils/useRouteUtils'
 
 const { em } = useEntityManager()
 const { fetch } = useEntityFetch()
 
 const router = useRouter()
-const route = useRoute()
 
 const { refreshProfile } = useRefreshProfile()
 
-if (!route.params.id || /\d+/.test(route.params.id as string)) {
-  throw new Error('no id found')
-}
-const id: number = parseInt(route.params.id as string)
+const { getIdFromRoute } = useRouteUtils()
+
+const id = getIdFromRoute()
 
 const { data: subdomain, pending } = fetch(Subdomain, id)
 

+ 9 - 2
pages/parameters/subdomains/new.vue

@@ -3,7 +3,7 @@
     <LayoutContainer>
       <UiForm
         ref="form"
-        v-model="parameters"
+        v-model="subdomain"
         :submit-actions="submitActions"
         :validation-pending="validationPending"
         :refresh-profile="true"
@@ -65,8 +65,15 @@ const i18n = useI18n()
 const { em } = useEntityManager()
 const { subdomainValidation } = useSubdomainValidation()
 
+const organizationProfileStore = useOrganizationProfileStore()
+
 // @ts-expect-error TODO à résoudre quand l'EM pourra gérer les types génériques
-const subdomain: Ref<Subdomain> = ref(em.newInstance(Subdomain))
+const subdomain: Ref<Subdomain> = ref(
+  em.newInstance(
+    Subdomain,
+    { organization: organizationProfileStore.id }
+  )
+)
 
 const submitActions = computed(() => {
   const actions: AnyJson = {}

+ 5 - 5
pages/parameters/website.vue

@@ -175,7 +175,6 @@ const canAddNewSubdomain: ComputedRef<boolean> = computed(
 )
 
 const goToEditPage = (id: number) => {
-  console.log(parameters.value)
   navigateTo(`/parameters/subdomains/${id}`)
 }
 
@@ -225,12 +224,13 @@ const onDialogYesBtnClick = () => {
   border-left: solid 2px rgb(var(--v-theme-neutral));
 }
 
-.subdomainItem.active td:first-child {
-  border-left: solid 2px rgb(var(--v-theme-primary));
-}
-.subdomainItem.active td:last-child {
+.subdomainItem td:last-child {
   border-top: solid 1px rgb(var(--v-theme-neutral));
   border-bottom: solid 1px rgb(var(--v-theme-neutral));
   border-right: solid 1px rgb(var(--v-theme-neutral));
 }
+
+.subdomainItem.active td:first-child {
+  border-left: solid 2px rgb(var(--v-theme-primary));
+}
 </style>

+ 7 - 2
plugins/init.server.ts

@@ -8,7 +8,7 @@ export default defineNuxtPlugin(async () => {
 
   const bearer: CookieRef<string | null> = useCookie('BEARER') ?? null
   const accessCookieId: CookieRef<string | null> = useCookie('AccessId') ?? null
-  const switchId: CookieRef<string | null> = useCookie('SwitchAccessId') ?? null
+  const switchCookieId: CookieRef<string | null> = useCookie('SwitchAccessId') ?? null
 
   if (accessCookieId.value === null || Number.isNaN(accessCookieId.value)) {
     redirectToLogout()
@@ -21,13 +21,18 @@ export default defineNuxtPlugin(async () => {
     return
   }
 
+  let switchId: number | null = parseInt(switchCookieId.value ?? '')
+  if (isNaN(switchId)) {
+    switchId = null
+  }
+
   const { initiateProfile } = useRefreshProfile()
 
   try {
     await initiateProfile(
       accessId,
       bearer.value ?? '',
-      switchId.value !== null ? parseInt(switchId.value) : null,
+      switchId,
     )
   } catch (error) {
     if (error instanceof UnauthorizedError) {