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 @@
-
+
-
+
+
+
+
@@ -321,15 +324,7 @@
-
-
-
-
- 1769094376813
-
-
-
- 1769094376813
+
@@ -715,7 +710,15 @@
1773842791819
-
+
+
+ 1773843922376
+
+
+
+ 1773843922377
+
+
@@ -765,7 +768,6 @@
-
@@ -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
+
+
+
+
+
+
+
+
+
+
+
Adresses du client
@@ -77,6 +91,7 @@
Ajouter
+
@@ -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 @@
+
+
+
+
+
+
+
+
Adresses du fournisseur
@@ -78,6 +92,7 @@
Ajouter
+
@@ -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)