From 465339cdd6b74db5ddcb4b25c2edc1456b09dac2 Mon Sep 17 00:00:00 2001 From: tristan Date: Wed, 18 Mar 2026 17:53:17 +0100 Subject: [PATCH] =?UTF-8?q?fix=20:=20order=20navbar=20+=20modification=20c?= =?UTF-8?q?r=C3=A9ation=20fournisseur=20et=20client?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/workspace.xml | 31 +++++++++-------- frontend/layouts/default.vue | 34 +++++++++--------- frontend/pages/admin/customer/[[id]].vue | 44 ++++++++++++++++++++++++ frontend/pages/admin/supplier/[[id]].vue | 44 ++++++++++++++++++++++++ 4 files changed, 122 insertions(+), 31 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 78c4c30..97f6447 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,9 +4,12 @@ - @@ -790,7 +792,8 @@ - diff --git a/frontend/layouts/default.vue b/frontend/layouts/default.vue index 0b3ebf0..4b9e9e7 100644 --- a/frontend/layouts/default.vue +++ b/frontend/layouts/default.vue @@ -72,23 +72,6 @@ - - - Transporteurs - - - + + + Transporteurs + + + +
+ + + +
+
+ + +
+
+
+ @@ -84,6 +99,8 @@ import {computed, reactive, ref, watch} from "vue" import {createCustomer, getCustomer, updateCustomer} from "~/services/customer" import type {CustomerData, CustomerFormData, CustomerPayload} from "~/services/dto/customer-data" +import {createAddress, type AddressPayload} from "~/services/address" +import {getCommunesByPostalCode, type CommuneData} from "~/services/geo" import {useAuthStore} from "~/stores/auth" const route = useRoute() @@ -106,6 +123,30 @@ const form = reactive({ addresses: [], }) +// Address form (creation mode only) +const addressForm = reactive({ + street: "", street2: null, postalCode: "", city: "", countryCode: "FR", +}) +const communes = ref([]) +const isLoadingCities = ref(false) +const communeOptions = computed(() => communes.value.map(c => ({ value: c.nom, label: c.nom }))) + +let debounceTimer: ReturnType | null = null +watch(() => addressForm.postalCode, (cp) => { + if (debounceTimer) clearTimeout(debounceTimer) + if (!cp || cp.length < 5) { communes.value = []; addressForm.city = ''; return } + if (cp.length === 5) { + debounceTimer = setTimeout(async () => { + isLoadingCities.value = true + try { + communes.value = await getCommunesByPostalCode(cp) + if (communes.value.length === 1) addressForm.city = communes.value[0].nom + else addressForm.city = '' + } finally { isLoadingCities.value = false } + }, 300) + } +}) + const goToAddAddress = () => { if (customerId.value === null || !auth.isAdmin) return router.push({ @@ -187,8 +228,11 @@ async function validate() { await updateCustomer(customerId.value, customerPayload) targetId = customerId.value } else { + const addressData = await createAddress({ ...addressForm }) + const addressIRI = `/api/addresses/${addressData.id}` const creationPayload = { ...customerPayload, + addresses: [addressIRI], ...(auth.user?.id ? { createdBy: `/api/users/${auth.user.id}` } : {}), } const created = await createCustomer(creationPayload) diff --git a/frontend/pages/admin/supplier/[[id]].vue b/frontend/pages/admin/supplier/[[id]].vue index 618ae87..ae64212 100644 --- a/frontend/pages/admin/supplier/[[id]].vue +++ b/frontend/pages/admin/supplier/[[id]].vue @@ -15,6 +15,19 @@
+
+ + + +
+
+ + +
+
+
+ @@ -85,6 +100,8 @@ import {computed, reactive, ref, watch} from "vue" import {createSupplier, getSupplier, updateSupplier} from "~/services/supplier" import type {SupplierData, SupplierFormData, SupplierPayload} from "~/services/dto/supplier-data" +import {createAddress, type AddressPayload} from "~/services/address" +import {getCommunesByPostalCode, type CommuneData} from "~/services/geo" import {useAuthStore} from "~/stores/auth" const route = useRoute() @@ -107,6 +124,30 @@ const form = reactive({ addresses: [], }) +// Address form (creation mode only) +const addressForm = reactive({ + street: "", street2: null, postalCode: "", city: "", countryCode: "FR", +}) +const communes = ref([]) +const isLoadingCities = ref(false) +const communeOptions = computed(() => communes.value.map(c => ({ value: c.nom, label: c.nom }))) + +let debounceTimer: ReturnType | null = null +watch(() => addressForm.postalCode, (cp) => { + if (debounceTimer) clearTimeout(debounceTimer) + if (!cp || cp.length < 5) { communes.value = []; addressForm.city = ''; return } + if (cp.length === 5) { + debounceTimer = setTimeout(async () => { + isLoadingCities.value = true + try { + communes.value = await getCommunesByPostalCode(cp) + if (communes.value.length === 1) addressForm.city = communes.value[0].nom + else addressForm.city = '' + } finally { isLoadingCities.value = false } + }, 300) + } +}) + const goToAddAddress = () => { if (supplierId.value === null || !auth.isAdmin) return router.push({ @@ -190,8 +231,11 @@ async function validate() { await updateSupplier(supplierId.value, supplierPayload) targetId = supplierId.value } else { + const addressData = await createAddress({ ...addressForm }) + const addressIRI = `/api/addresses/${addressData.id}` const creationPayload = { ...supplierPayload, + addresses: [addressIRI], ...(auth.user?.id ? { createdBy: `/api/users/${auth.user.id}` } : {}), } const created = await createSupplier(creationPayload)