Compare commits
14 Commits
v0.0.40
...
b4e024590e
| Author | SHA1 | Date | |
|---|---|---|---|
| b4e024590e | |||
| 74af5d30ba | |||
| b905cb66aa | |||
| 5f4139fde3 | |||
| 0181d72144 | |||
| bffdc88701 | |||
| 42c5a3b2d2 | |||
| 28d5bc7599 | |||
| 69d047fca0 | |||
| ba4375f609 | |||
| e249d44e78 | |||
| e8189a4d04 | |||
| 081c2ef403 | |||
| 5fd2ab8470 |
@@ -40,7 +40,6 @@ Ajouter dans le fichier .env du frontend
|
|||||||
* [#273] Créer une nouvelle expédition (étape 3)
|
* [#273] Créer une nouvelle expédition (étape 3)
|
||||||
* [#256] Créer une nouvelle réception (étape 3 - bovin)
|
* [#256] Créer une nouvelle réception (étape 3 - bovin)
|
||||||
* [#314] Création d'une page d'administration : listing des utilisateurs
|
* [#314] Création d'une page d'administration : listing des utilisateurs
|
||||||
* [#313] Admin modification creation fournisseur
|
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
parameters:
|
parameters:
|
||||||
app.version: '0.0.40'
|
app.version: '0.0.38'
|
||||||
|
|||||||
@@ -1,81 +0,0 @@
|
|||||||
<template>
|
|
||||||
<form @submit.prevent="validateForm">
|
|
||||||
<div class="flex items-center justify-between gap-10">
|
|
||||||
<div>
|
|
||||||
<h1 class="text-3xl font-bold uppercase">
|
|
||||||
{{ props.address ? "Modification d'une adresse" : "Ajout d'une adresse" }}
|
|
||||||
</h1>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button
|
|
||||||
class="text-xl uppercase bg-primary-500 text-white h-[50px] w-[272px]"
|
|
||||||
type="submit"
|
|
||||||
:disabled="isLoading"
|
|
||||||
>
|
|
||||||
{{ props.address? "Sauvegarder" : "Ajouter" }}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="grid grid-cols-2 gap-y-16 gap-x-12 mb-16 mt-10">
|
|
||||||
<UiTextInput id="address-label" v-model="form.label" label="Libellé" />
|
|
||||||
<UiTextInput id="address-street" v-model="form.street" label="Rue" />
|
|
||||||
<UiTextInput id="address-street2" v-model="form.street2" label="Complément" />
|
|
||||||
<UiTextInput id="address-postalCode" v-model="form.postalCode" label="Code postal" />
|
|
||||||
<UiTextInput id="address-city" v-model="form.city" label="Ville" />
|
|
||||||
<UiTextInput id="address-country" v-model="form.countryCode" label="Pays" />
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
|
||||||
import { AddressPayload } from "~/services/address"
|
|
||||||
|
|
||||||
|
|
||||||
const route = useRoute()
|
|
||||||
const router = useRouter()
|
|
||||||
|
|
||||||
const props = defineProps<{
|
|
||||||
type?: "supplier" | "customer",
|
|
||||||
address?: AddressPayload | null
|
|
||||||
}>()
|
|
||||||
|
|
||||||
const isLoading = ref(false)
|
|
||||||
|
|
||||||
const emptyForm = (): AddressPayload => ({
|
|
||||||
label: "",
|
|
||||||
street: "",
|
|
||||||
street2: null,
|
|
||||||
postalCode: "",
|
|
||||||
city: "",
|
|
||||||
countryCode: "",
|
|
||||||
})
|
|
||||||
|
|
||||||
const form = reactive<AddressPayload>(emptyForm())
|
|
||||||
|
|
||||||
const hydrateForm = (address?: AddressPayload | null) => {
|
|
||||||
const data = address ?? emptyForm()
|
|
||||||
form.label = data.label ?? ""
|
|
||||||
form.street = data.street ?? ""
|
|
||||||
form.street2 = data.street2 ?? null
|
|
||||||
form.postalCode = data.postalCode ?? ""
|
|
||||||
form.city = data.city ?? ""
|
|
||||||
form.countryCode = data.countryCode ?? ""
|
|
||||||
}
|
|
||||||
|
|
||||||
watch(
|
|
||||||
() => props.address,
|
|
||||||
(addr) => {
|
|
||||||
hydrateForm(addr)
|
|
||||||
},
|
|
||||||
{ immediate: true }
|
|
||||||
)
|
|
||||||
|
|
||||||
const validateForm = () => {
|
|
||||||
if (isLoading.value) return
|
|
||||||
emit("validate", {...form})
|
|
||||||
}
|
|
||||||
|
|
||||||
const emit = defineEmits<{
|
|
||||||
(event: 'validate', form: AddressPayload): void
|
|
||||||
}>()
|
|
||||||
</script>
|
|
||||||
@@ -56,27 +56,7 @@
|
|||||||
"delete": "Impossible de supprimer le bovin."
|
"delete": "Impossible de supprimer le bovin."
|
||||||
},
|
},
|
||||||
"supplier": {
|
"supplier": {
|
||||||
"list": "Impossible de récupérer la liste des fournisseurs.",
|
"list": "Impossible de récupérer la liste des fournisseurs."
|
||||||
"fetch": "Impossible de récupérer le fournisseur.",
|
|
||||||
"create": "Impossible de créer le fournisseur.",
|
|
||||||
"update": "Impossible de mettre à jour le fournisseur.",
|
|
||||||
"nameRequired": "Le nom du fournisseur est obligatoire."
|
|
||||||
},
|
|
||||||
"address": {
|
|
||||||
"fetch": "Impossible de récupérer l'adresse.",
|
|
||||||
"create": "Impossible de créer l'adresse.",
|
|
||||||
"update": "Impossible de mettre à jour l'adresse.",
|
|
||||||
"entityNotFound": "Entité introuvable.",
|
|
||||||
"streetRequired": "La rue est obligatoire.",
|
|
||||||
"postalCodeRequired": "Le code postal est obligatoire.",
|
|
||||||
"cityRequired": "La ville est obligatoire.",
|
|
||||||
"countryCodeInvalid": "Le pays doit être un code ISO2 (2 lettres)."
|
|
||||||
},
|
|
||||||
"customer": {
|
|
||||||
"list": "Impossible de récupérer la liste des clients.",
|
|
||||||
"fetch": "Impossible de récupérer le client.",
|
|
||||||
"create": "Impossible de créer le client.",
|
|
||||||
"update": "Impossible de mettre à jour le client."
|
|
||||||
},
|
},
|
||||||
"truck": {
|
"truck": {
|
||||||
"list": "Impossible de récupérer la liste des camions."
|
"list": "Impossible de récupérer la liste des camions."
|
||||||
@@ -111,14 +91,6 @@
|
|||||||
"shipment": {
|
"shipment": {
|
||||||
"update": "Éxpedition mise à jour avec succès."
|
"update": "Éxpedition mise à jour avec succès."
|
||||||
},
|
},
|
||||||
"supplier": {
|
|
||||||
"create": "Fournisseur créé avec succès.",
|
|
||||||
"update": "Fournisseur mis à jour avec succès."
|
|
||||||
},
|
|
||||||
"address": {
|
|
||||||
"create": "Adresse créée avec succès.",
|
|
||||||
"update": "Adresse mise à jour avec succès."
|
|
||||||
},
|
|
||||||
"auth": {
|
"auth": {
|
||||||
"update": "Utilisateur mis à jour avec succès.",
|
"update": "Utilisateur mis à jour avec succès.",
|
||||||
"create": "Utilisateur créé avec succès.",
|
"create": "Utilisateur créé avec succès.",
|
||||||
|
|||||||
@@ -1,194 +0,0 @@
|
|||||||
<template>
|
|
||||||
<form @submit.prevent="validate">
|
|
||||||
<div class="flex items-center justify-between gap-10">
|
|
||||||
<h1 class="text-3xl font-bold uppercase">
|
|
||||||
{{ supplierId ? "Modifications du fournisseur" : "Ajout d'un fournisseur" }}
|
|
||||||
</h1>
|
|
||||||
|
|
||||||
<button
|
|
||||||
class="text-xl uppercase bg-primary-500 text-white h-[50px] w-[272px]"
|
|
||||||
type="submit"
|
|
||||||
:disabled="isLoading || !auth.isAdmin"
|
|
||||||
>
|
|
||||||
{{ supplierId ? "Sauvegarder" : "Ajouter" }}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="grid grid-cols-2 gap-y-16 gap-x-12 mb-10 py-12 border-b border-black ">
|
|
||||||
<UiTextInput id="supplier-name" v-model="form.name" label="Nom du fournisseur" :disabled="!auth.isAdmin"/>
|
|
||||||
<UiTextInput id="supplier-email" v-model="form.email" label="Email" :disabled="!auth.isAdmin"/>
|
|
||||||
<UiTextInput id="supplier-phone" v-model="form.phone" label="Téléphone" :disabled="!auth.isAdmin"/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="flex items-center justify-between mb-4 py-6 border-t border-black"></div>
|
|
||||||
<div class="flex items-center justify-between mb-4">
|
|
||||||
<h2 class="text-3xl font-bold uppercase">Adresses fournisseur</h2>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="text-xl uppercase bg-primary-500 text-white h-[50px] w-[272px]"
|
|
||||||
:disabled="supplierId === null || !auth.isAdmin"
|
|
||||||
@click="goToAddAddress"
|
|
||||||
>
|
|
||||||
Ajouter
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div class="overflow-x-auto mb-10">
|
|
||||||
<table class="w-full border-collapse">
|
|
||||||
<thead>
|
|
||||||
<tr class="text-left border-b border-gray-200">
|
|
||||||
<th class="py-3 pr-4 text-sm uppercase">Libellé</th>
|
|
||||||
<th class="py-3 pr-4 text-sm uppercase">Rue</th>
|
|
||||||
<th class="py-3 pr-4 text-sm uppercase">Complément</th>
|
|
||||||
<th class="py-3 pr-4 text-sm uppercase">Code postal</th>
|
|
||||||
<th class="py-3 pr-4 text-sm uppercase">Ville</th>
|
|
||||||
<th class="py-3 pr-4 text-sm uppercase">Pays</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<template v-if="form.addresses.length === 0">
|
|
||||||
<tr>
|
|
||||||
<td colspan="6" class="py-4 text-slate-400">
|
|
||||||
Aucune adresse.
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</template>
|
|
||||||
<template v-else>
|
|
||||||
<tr
|
|
||||||
v-for="(address, index) in form.addresses"
|
|
||||||
:key="address.id ?? index"
|
|
||||||
class="border-b border-gray-100 hover:bg-slate-50"
|
|
||||||
:class="auth.isAdmin ? 'cursor-pointer' : 'cursor-not-allowed opacity-60'"
|
|
||||||
@click="goToEditAddress(address.id ?? null)"
|
|
||||||
>
|
|
||||||
<td class="py-3 pr-4">{{ address.label || "—" }}</td>
|
|
||||||
<td class="py-3 pr-4">{{ address.street || "—" }}</td>
|
|
||||||
<td class="py-3 pr-4">{{ address.street2 || "—" }}</td>
|
|
||||||
<td class="py-3 pr-4">{{ address.postalCode || "—" }}</td>
|
|
||||||
<td class="py-3 pr-4">{{ address.city || "—" }}</td>
|
|
||||||
<td class="py-3 pr-4">{{ address.countryCode || "—" }}</td>
|
|
||||||
</tr>
|
|
||||||
</template>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
|
||||||
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 {useAuthStore} from "~/stores/auth"
|
|
||||||
|
|
||||||
definePageMeta({layout: "admin"})
|
|
||||||
|
|
||||||
const route = useRoute()
|
|
||||||
const router = useRouter()
|
|
||||||
const auth = useAuthStore()
|
|
||||||
|
|
||||||
const resolveId = (param: unknown) => {
|
|
||||||
const idStr = Array.isArray(param) ? param[0] : param
|
|
||||||
if (!idStr) return null
|
|
||||||
const id = Number(idStr)
|
|
||||||
return Number.isFinite(id) ? id : null
|
|
||||||
}
|
|
||||||
const supplierId = computed(() => resolveId(route.params.id))
|
|
||||||
const isLoading = ref(false)
|
|
||||||
const form = reactive<SupplierFormData>({
|
|
||||||
name: "",
|
|
||||||
email: "",
|
|
||||||
phone: "",
|
|
||||||
addresses: [],
|
|
||||||
})
|
|
||||||
|
|
||||||
const goToAddAddress = () => {
|
|
||||||
if (supplierId.value === null || !auth.isAdmin) return
|
|
||||||
router.push({
|
|
||||||
path: "/admin/supplier/address",
|
|
||||||
query: {
|
|
||||||
supplierId: String(supplierId.value),
|
|
||||||
fromSupplier: "1",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const goToEditAddress = (addressId: number | null) => {
|
|
||||||
if (supplierId.value === null || addressId === null || !auth.isAdmin) return
|
|
||||||
router.push({
|
|
||||||
path: "/admin/supplier/address",
|
|
||||||
query: {
|
|
||||||
supplierId: String(supplierId.value),
|
|
||||||
addressId: String(addressId),
|
|
||||||
fromSupplier: "1",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const hydrateFromSupplier = (supplier: SupplierData | null) => {
|
|
||||||
if (!supplier) return
|
|
||||||
form.name = supplier.name ?? ""
|
|
||||||
form.email = supplier.email ?? ""
|
|
||||||
form.phone = supplier.phone ?? ""
|
|
||||||
if (!Array.isArray(supplier.addresses) || supplier.addresses.length === 0) {
|
|
||||||
form.addresses = []
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (typeof supplier.addresses[0] === "string") {
|
|
||||||
form.addresses = []
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
form.addresses = supplier.addresses.map((address) => ({
|
|
||||||
id: address.id ?? null,
|
|
||||||
label: address.label ?? "",
|
|
||||||
street: address.street ?? "",
|
|
||||||
street2: address.street2 ?? null,
|
|
||||||
postalCode: address.postalCode ?? "",
|
|
||||||
city: address.city ?? "",
|
|
||||||
countryCode: address.countryCode ?? "",
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
watch(
|
|
||||||
() => supplierId.value,
|
|
||||||
async (id) => {
|
|
||||||
if (id === null) return
|
|
||||||
isLoading.value = true
|
|
||||||
try {
|
|
||||||
const supplier = await getSupplier(id)
|
|
||||||
hydrateFromSupplier(supplier)
|
|
||||||
} finally {
|
|
||||||
isLoading.value = false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{immediate: true}
|
|
||||||
)
|
|
||||||
|
|
||||||
async function validate() {
|
|
||||||
if (isLoading.value) return
|
|
||||||
if (!auth.isAdmin) return
|
|
||||||
isLoading.value = true
|
|
||||||
|
|
||||||
try {
|
|
||||||
const name = form.name.trim()
|
|
||||||
const email = (form.email ?? "").trim() || null
|
|
||||||
const phone = (form.phone ?? "").trim() || null
|
|
||||||
|
|
||||||
const supplierPayload: SupplierPayload = {
|
|
||||||
name,
|
|
||||||
email,
|
|
||||||
phone,
|
|
||||||
}
|
|
||||||
|
|
||||||
if (supplierId.value !== null) {
|
|
||||||
await updateSupplier(supplierId.value, supplierPayload)
|
|
||||||
} else {
|
|
||||||
await createSupplier(supplierPayload)
|
|
||||||
}
|
|
||||||
|
|
||||||
await router.push("/admin/supplier/supplier-list")
|
|
||||||
} finally {
|
|
||||||
isLoading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
<template>
|
|
||||||
<Address type="supplier" :address="address" @validate="validate"/>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
|
||||||
import type {AddressData, AddressPayload} from "~/services/address";
|
|
||||||
import {createAddress, getAddress, updateAddress} from "~/services/address";
|
|
||||||
import {getSupplier, updateSupplier} from "~/services/supplier";
|
|
||||||
import type {SupplierData} from "~/services/dto/supplier-data";
|
|
||||||
|
|
||||||
definePageMeta({ layout: "admin" })
|
|
||||||
|
|
||||||
const route = useRoute()
|
|
||||||
const router = useRouter()
|
|
||||||
const supplierId = computed(() => { return Number(route.query.supplierId) })
|
|
||||||
const supplier = ref<SupplierData|null>(null);
|
|
||||||
const addressId = computed(() => { return route.query.addressId !== undefined ? Number(route.query.addressId) : null })
|
|
||||||
const address = ref<AddressData|null>(null)
|
|
||||||
|
|
||||||
const validate = async (address: AddressPayload) => {
|
|
||||||
try {
|
|
||||||
if (addressId.value !== null) {
|
|
||||||
await updateAddress(addressId.value, address)
|
|
||||||
} else {
|
|
||||||
await addAddress(address)
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
await router.push('/admin/supplier/' + supplierId.value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const addAddress = async (address: AddressPayload) => {
|
|
||||||
const response: AddressData = await createAddress(address)
|
|
||||||
const addressIRI = `/api/addresses/${response.id}`
|
|
||||||
const existingIris = (supplier.value.addresses ?? []).map((item: any) => `/api/addresses/${item.id}`)
|
|
||||||
const next = [...new Set([...existingIris, addressIRI])]
|
|
||||||
|
|
||||||
return await updateSupplier(supplierId.value, { addresses: next })
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(async () => {
|
|
||||||
supplier.value = await getSupplier(supplierId.value)
|
|
||||||
if (addressId.value !== null) {
|
|
||||||
address.value = await getAddress(addressId.value)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
@@ -1,20 +1,16 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="flex items-center justify-between">
|
<div class="flex items-center justify-between">
|
||||||
<h1 class="text-3xl font-bold uppercase">Fournisseurs</h1>
|
<h1 class="text-3xl font-bold uppercase"> Fournisseurs </h1>
|
||||||
<NuxtLink
|
<NuxtLink to="/admin/supplier"
|
||||||
to="/admin/supplier"
|
class="flex items-center justify-center text-xl uppercase bg-primary-500 text-white h-[50px] w-[272px]"
|
||||||
class="flex items-center justify-center text-xl uppercase bg-primary-500 text-white h-[50px] w-[272px]"
|
|
||||||
:class="auth.isAdmin ? '' : 'cursor-not-allowed opacity-60'"
|
|
||||||
@click="handleAddClick"
|
|
||||||
>
|
>
|
||||||
Ajouter
|
Ajouter
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="mt-6 border border-slate-200 mb-16">
|
||||||
<div v-if="auth.isAdmin" class="mt-6 border border-slate-200 mb-16">
|
|
||||||
<div class="max-h-96 overflow-y-auto">
|
<div class="max-h-96 overflow-y-auto">
|
||||||
<div
|
<div
|
||||||
class="sticky top-0 z-10 grid grid-cols-7 gap-4 bg-slate-100 px-4 py-3 text-sm font-semibold uppercase tracking-wide"
|
class="sticky top-0 z-10 grid grid-cols-6 gap-4 bg-slate-100 px-4 py-3 text-sm font-semibold uppercase tracking-wide"
|
||||||
>
|
>
|
||||||
<div>Nom</div>
|
<div>Nom</div>
|
||||||
<div>Mail</div>
|
<div>Mail</div>
|
||||||
@@ -22,91 +18,57 @@
|
|||||||
<div>Complément</div>
|
<div>Complément</div>
|
||||||
<div>Code Postal</div>
|
<div>Code Postal</div>
|
||||||
<div>Ville</div>
|
<div>Ville</div>
|
||||||
<div>Pays</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="supplierList.length === 0" class="px-4 py-6 text-slate-400">
|
|
||||||
Aucun fournisseur.
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-for="supplier in supplierList" :key="supplier.id">
|
<div v-for="supplier in supplierList" :key="supplier.id">
|
||||||
<div
|
<template v-if="supplier.addresses?.length">
|
||||||
v-if="!supplier.addresses || supplier.addresses.length === 0"
|
|
||||||
class="grid grid-cols-7 border-t gap-4 px-4 py-2 hover:bg-slate-50 cursor-pointer"
|
|
||||||
@click="goToSupplier(supplier.id)"
|
|
||||||
>
|
|
||||||
<div class="truncate">{{ supplier.name }}</div>
|
|
||||||
<div class="truncate">{{ supplier.email }}</div>
|
|
||||||
<div class="col-span-1">Pas d'adresse</div>
|
|
||||||
<div class="uppercase truncate">{{"—"}}</div>
|
|
||||||
<div class="uppercase truncate">{{"—"}}</div>
|
|
||||||
<div class="uppercase truncate">{{"—"}}</div>
|
|
||||||
<div class="uppercase truncate">{{"—"}}</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<template v-else-if="supplier.addresses.length > 0">
|
|
||||||
<div
|
<div
|
||||||
v-for="(address, idx) in supplier.addresses"
|
v-for="addr in supplier.addresses"
|
||||||
:key="address.id ?? `${supplier.id}-${idx}-${address.street}-${address.postalCode}`"
|
:key="addr.id"
|
||||||
class="grid grid-cols-7 hover:bg-slate-50 border-t gap-4 px-4 py-2 cursor-pointer"
|
class="grid grid-cols-6 hover:bg-slate-50 border-t gap-4 px-4 py-2"
|
||||||
:class="idx > 0 ? 'pl-4 border-l-4 border-l-slate-200 bg-slate-50' : ''"
|
|
||||||
@click="goToSupplier(supplier.id)"
|
@click="goToSupplier(supplier.id)"
|
||||||
>
|
>
|
||||||
<div class="truncate">
|
<div class="truncate">
|
||||||
{{ idx === 0 ? supplier.name : "↳" }}
|
{{ supplier.name }}
|
||||||
</div>
|
</div>
|
||||||
<div class="truncate">{{ idx === 0 ? supplier.email : "" }}</div>
|
<div class="truncate">
|
||||||
<div class="truncate">{{ address.street || "—" }}</div>
|
{{ supplier.email }}
|
||||||
<div class="truncate">{{ address.street2 || "—" }}</div>
|
</div>
|
||||||
<div>{{ address.postalCode || "—" }}</div>
|
<div class="truncate">
|
||||||
<div class="uppercase truncate">{{ address.city || "—" }}</div>
|
{{ addr.street }}
|
||||||
<div class="uppercase truncate">{{ address.countryCode || "—" }}</div>
|
</div>
|
||||||
</div>
|
<div class="truncate">
|
||||||
</template>
|
{{ addr.street2 }}
|
||||||
|
</div>
|
||||||
<template v-else>
|
<div>{{ addr.postalCode }}</div>
|
||||||
<div
|
<div class="uppercase truncate">
|
||||||
class="grid grid-cols-7 hover:bg-slate-50 border-t gap-4 px-4 py-2 cursor-pointer"
|
{{ addr.city }}
|
||||||
@click="goToSupplier(supplier.id)"
|
|
||||||
>
|
|
||||||
<div class="truncate">{{ supplier.name }}</div>
|
|
||||||
<div class="truncate">{{ supplier.email }}</div>
|
|
||||||
<div class="col-span-5 text-slate-400">
|
|
||||||
Adresses non chargées
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="mt-6 border border-slate-200 mb-16 px-4 py-6 text-slate-400">
|
|
||||||
Accès réservé aux administrateurs.
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { getSupplierList } from "~/services/supplier"
|
import type {SupplierData} from "~/services/dto/supplier-data"
|
||||||
import type { SupplierData } from "~/services/dto/supplier-data"
|
import {getSupplierList} from "~/services/supplier"
|
||||||
import { useAuthStore } from "~/stores/auth"
|
|
||||||
|
|
||||||
definePageMeta({ layout: "admin" })
|
definePageMeta({layout: "admin"})
|
||||||
|
|
||||||
const supplierList = ref<SupplierData[]>([])
|
const supplierList = ref<SupplierData[]>([])
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const auth = useAuthStore()
|
|
||||||
|
|
||||||
const goToSupplier = (id: number) => {
|
const goToSupplier = (id: number) => {
|
||||||
if (!auth.isAdmin) return
|
|
||||||
router.push(`/admin/supplier/${id}`)
|
router.push(`/admin/supplier/${id}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleAddClick = (event: Event) => {
|
|
||||||
if (auth.isAdmin) return
|
|
||||||
event.preventDefault()
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
if (!auth.isAdmin) return
|
supplierList.value = (await getSupplierList(false)) ?? []
|
||||||
supplierList.value = await getSupplierList()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
import { useApi } from '~/composables/useApi'
|
|
||||||
import type { AddressData } from '~/services/dto/address-data'
|
|
||||||
export interface AddressPayload {
|
|
||||||
label: string
|
|
||||||
street: string
|
|
||||||
street2?: string | null
|
|
||||||
postalCode: string
|
|
||||||
city: string
|
|
||||||
countryCode: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface AddressData extends AddressPayload {
|
|
||||||
id: number
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function createAddress(
|
|
||||||
payload: AddressPayload
|
|
||||||
): Promise<AddressData> {
|
|
||||||
const api = useApi()
|
|
||||||
|
|
||||||
return await api.post<AddressData>('addresses', payload, {
|
|
||||||
toastErrorKey: 'errors.address.create',
|
|
||||||
toastSuccessKey: 'success.address.create',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function updateAddress(
|
|
||||||
id: number,
|
|
||||||
payload: AddressPayload
|
|
||||||
): Promise<AddressData> {
|
|
||||||
const api = useApi()
|
|
||||||
|
|
||||||
return await api.patch<AddressData>(`addresses/${id}`, payload, {
|
|
||||||
toastErrorKey: 'errors.address.update',
|
|
||||||
toastSuccessKey: 'success.address.update',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getAddress(id: number): Promise<AddressData> {
|
|
||||||
const api = useApi()
|
|
||||||
|
|
||||||
return await api.get<AddressData>(`addresses/${id}`, {}, {
|
|
||||||
toastErrorKey: 'errors.address.fetch',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -6,14 +6,5 @@ export interface AddressData {
|
|||||||
postalCode: string
|
postalCode: string
|
||||||
city: string
|
city: string
|
||||||
countryCode: string
|
countryCode: string
|
||||||
}
|
fullAddress?: string
|
||||||
|
|
||||||
export interface AddressFormData {
|
|
||||||
id?: number | null
|
|
||||||
label: string
|
|
||||||
street: string
|
|
||||||
street2?: string | null
|
|
||||||
postalCode: string
|
|
||||||
city: string
|
|
||||||
countryCode: string
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,9 @@
|
|||||||
import type { AddressFormData } from "~/services/dto/address-data"
|
import type { AddressData } from '~/services/dto/address-data'
|
||||||
|
|
||||||
export type SupplierAddresses = AddressFormData[] | string[]
|
|
||||||
|
|
||||||
export interface SupplierData {
|
export interface SupplierData {
|
||||||
id: number
|
id: number
|
||||||
name: string
|
name: string
|
||||||
email?: string | null
|
email?: string | null
|
||||||
phone?: string | null
|
phone?: string | null
|
||||||
addresses: SupplierAddresses
|
addresses?: AddressData[] | null
|
||||||
}
|
|
||||||
|
|
||||||
export interface SupplierFormData {
|
|
||||||
name: string
|
|
||||||
email?: string
|
|
||||||
phone?: string
|
|
||||||
addresses: AddressFormData[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export type SupplierPayload = {
|
|
||||||
name: string
|
|
||||||
email?: string | null
|
|
||||||
phone?: string | null
|
|
||||||
addresses?: string[]
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,42 +1,23 @@
|
|||||||
import { useApi } from "~/composables/useApi"
|
import { useApi } from '~/composables/useApi'
|
||||||
import type { SupplierData, SupplierPayload } from "~/services/dto/supplier-data"
|
import type { SupplierData } from '~/services/dto/supplier-data'
|
||||||
|
|
||||||
export type SupplierListResponse =
|
export type SupplierListResponse =
|
||||||
| SupplierData[]
|
| SupplierData[]
|
||||||
| { "hydra:member"?: SupplierData[] }
|
| { 'hydra:member'?: SupplierData[] }
|
||||||
|
|
||||||
export async function getSupplierList(): Promise<SupplierData[]> {
|
export async function getSupplierList(): Promise<SupplierData[]> {
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
const response = await api.get<SupplierListResponse>("suppliers", {}, {
|
const response = await api.get<SupplierListResponse>('suppliers', {}, {
|
||||||
toastErrorKey: "errors.supplier.list",
|
toastErrorKey: 'errors.supplier.list'
|
||||||
})
|
})
|
||||||
|
|
||||||
if (Array.isArray(response)) return response
|
if (Array.isArray(response)) {
|
||||||
if (response && typeof response === "object" && Array.isArray(response["hydra:member"])) {
|
return response
|
||||||
return response["hydra:member"]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (response && typeof response === 'object' && Array.isArray(response['hydra:member'])) {
|
||||||
|
return response['hydra:member']
|
||||||
|
}
|
||||||
|
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getSupplier(id: number): Promise<SupplierData> {
|
|
||||||
const api = useApi()
|
|
||||||
return api.get<SupplierData>(`suppliers/${id}`, {}, {
|
|
||||||
toastErrorKey: "errors.supplier.fetch",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function updateSupplier(id: number, payload: Partial<SupplierPayload>): Promise<SupplierData> {
|
|
||||||
const api = useApi()
|
|
||||||
return api.patch<SupplierData>(`suppliers/${id}`, payload, {
|
|
||||||
toastErrorKey: "errors.supplier.update",
|
|
||||||
toastSuccessKey: "success.supplier.update",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function createSupplier(payload: SupplierPayload): Promise<SupplierData> {
|
|
||||||
const api = useApi()
|
|
||||||
return api.post<SupplierData>("suppliers", payload, {
|
|
||||||
toastErrorKey: "errors.supplier.create",
|
|
||||||
toastSuccessKey: "success.supplier.create",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ namespace App\Entity;
|
|||||||
use ApiPlatform\Metadata\ApiResource;
|
use ApiPlatform\Metadata\ApiResource;
|
||||||
use ApiPlatform\Metadata\Get;
|
use ApiPlatform\Metadata\Get;
|
||||||
use ApiPlatform\Metadata\GetCollection;
|
use ApiPlatform\Metadata\GetCollection;
|
||||||
use ApiPlatform\Metadata\Patch;
|
|
||||||
use ApiPlatform\Metadata\Post;
|
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
@@ -25,16 +23,6 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
|||||||
new GetCollection(
|
new GetCollection(
|
||||||
normalizationContext: ['groups' => ['address:read']],
|
normalizationContext: ['groups' => ['address:read']],
|
||||||
),
|
),
|
||||||
new Post(
|
|
||||||
normalizationContext: ['groups' => ['address:read']],
|
|
||||||
denormalizationContext: ['groups' => ['address:write']],
|
|
||||||
security: "is_granted('ROLE_ADMIN')",
|
|
||||||
),
|
|
||||||
new Patch(
|
|
||||||
normalizationContext: ['groups' => ['address:read']],
|
|
||||||
denormalizationContext: ['groups' => ['address:write']],
|
|
||||||
security: "is_granted('ROLE_ADMIN')",
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
security: "is_granted('ROLE_USER')",
|
security: "is_granted('ROLE_USER')",
|
||||||
)]
|
)]
|
||||||
@@ -47,27 +35,27 @@ class Address
|
|||||||
private ?int $id = null;
|
private ?int $id = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 120)]
|
#[ORM\Column(length: 120)]
|
||||||
#[Groups(['address:read', 'supplier:read', 'reception:read', 'customer:read', 'shipment:read', 'address:write'])]
|
#[Groups(['address:read', 'supplier:read', 'reception:read', 'customer:read', 'shipment:read'])]
|
||||||
private string $label = '';
|
private string $label = '';
|
||||||
|
|
||||||
#[ORM\Column(length: 180)]
|
#[ORM\Column(length: 180)]
|
||||||
#[Groups(['address:read', 'supplier:read', 'reception:read', 'customer:read', 'shipment:read', 'address:write'])]
|
#[Groups(['address:read', 'supplier:read', 'reception:read', 'customer:read', 'shipment:read'])]
|
||||||
private string $street = '';
|
private string $street = '';
|
||||||
|
|
||||||
#[ORM\Column(name: 'street2', length: 180, nullable: true)]
|
#[ORM\Column(name: 'street2', length: 180, nullable: true)]
|
||||||
#[Groups(['address:read', 'supplier:read', 'reception:read', 'customer:read', 'shipment:read', 'address:write'])]
|
#[Groups(['address:read', 'supplier:read', 'reception:read', 'customer:read', 'shipment:read'])]
|
||||||
private ?string $street2 = null;
|
private ?string $street2 = null;
|
||||||
|
|
||||||
#[ORM\Column(name: 'postal_code', length: 20)]
|
#[ORM\Column(name: 'postal_code', length: 20)]
|
||||||
#[Groups(['address:read', 'supplier:read', 'reception:read', 'customer:read', 'shipment:read', 'address:write'])]
|
#[Groups(['address:read', 'supplier:read', 'reception:read', 'customer:read', 'shipment:read'])]
|
||||||
private string $postalCode = '';
|
private string $postalCode = '';
|
||||||
|
|
||||||
#[ORM\Column(length: 120)]
|
#[ORM\Column(length: 120)]
|
||||||
#[Groups(['address:read', 'supplier:read', 'reception:read', 'customer:read', 'shipment:read', 'address:write'])]
|
#[Groups(['address:read', 'supplier:read', 'reception:read', 'customer:read', 'shipment:read'])]
|
||||||
private string $city = '';
|
private string $city = '';
|
||||||
|
|
||||||
#[ORM\Column(name: 'country_code', length: 2)]
|
#[ORM\Column(name: 'country_code', length: 2)]
|
||||||
#[Groups(['address:read', 'supplier:read', 'customer:read', 'address:write'])]
|
#[Groups(['address:read', 'supplier:read', 'customer:read'])]
|
||||||
private string $countryCode = '';
|
private string $countryCode = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ use ApiPlatform\Metadata\ApiProperty;
|
|||||||
use ApiPlatform\Metadata\ApiResource;
|
use ApiPlatform\Metadata\ApiResource;
|
||||||
use ApiPlatform\Metadata\Get;
|
use ApiPlatform\Metadata\Get;
|
||||||
use ApiPlatform\Metadata\GetCollection;
|
use ApiPlatform\Metadata\GetCollection;
|
||||||
use ApiPlatform\Metadata\Patch;
|
|
||||||
use ApiPlatform\Metadata\Post;
|
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
@@ -26,21 +24,6 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
|||||||
new GetCollection(
|
new GetCollection(
|
||||||
normalizationContext: ['groups' => ['supplier:read']],
|
normalizationContext: ['groups' => ['supplier:read']],
|
||||||
),
|
),
|
||||||
new GetCollection(
|
|
||||||
uriTemplate: '/admin/suppliers',
|
|
||||||
normalizationContext: ['groups' => ['supplier:read']],
|
|
||||||
security: "is_granted('ROLE_ADMIN')"
|
|
||||||
),
|
|
||||||
new Post(
|
|
||||||
normalizationContext: ['groups' => ['supplier:read']],
|
|
||||||
denormalizationContext: ['groups' => ['supplier:write']],
|
|
||||||
security: "is_granted('ROLE_ADMIN')",
|
|
||||||
),
|
|
||||||
new Patch(
|
|
||||||
normalizationContext: ['groups' => ['supplier:read']],
|
|
||||||
denormalizationContext: ['groups' => ['supplier:write']],
|
|
||||||
security: "is_granted('ROLE_ADMIN')",
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
security: "is_granted('ROLE_USER')",
|
security: "is_granted('ROLE_USER')",
|
||||||
)]
|
)]
|
||||||
@@ -53,15 +36,15 @@ class Supplier
|
|||||||
private ?int $id = null;
|
private ?int $id = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 180)]
|
#[ORM\Column(length: 180)]
|
||||||
#[Groups(['supplier:read', 'reception:read', 'supplier:write'])]
|
#[Groups(['supplier:read', 'reception:read'])]
|
||||||
private string $name = '';
|
private string $name = '';
|
||||||
|
|
||||||
#[ORM\Column(length: 180, nullable: true)]
|
#[ORM\Column(length: 180, nullable: true)]
|
||||||
#[Groups(['supplier:read', 'reception:read', 'supplier:write'])]
|
#[Groups(['supplier:read', 'reception:read'])]
|
||||||
private ?string $email = null;
|
private ?string $email = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 40, nullable: true)]
|
#[ORM\Column(length: 40, nullable: true)]
|
||||||
#[Groups(['supplier:read', 'reception:read', 'supplier:write'])]
|
#[Groups(['supplier:read', 'reception:read'])]
|
||||||
private ?string $phone = null;
|
private ?string $phone = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -69,7 +52,7 @@ class Supplier
|
|||||||
*/
|
*/
|
||||||
#[ORM\ManyToMany(targetEntity: Address::class, inversedBy: 'suppliers')]
|
#[ORM\ManyToMany(targetEntity: Address::class, inversedBy: 'suppliers')]
|
||||||
#[ORM\JoinTable(name: 'supplier_address')]
|
#[ORM\JoinTable(name: 'supplier_address')]
|
||||||
#[Groups(['supplier:read', 'supplier:write'])]
|
#[Groups(['supplier:read'])]
|
||||||
#[ApiProperty(readableLink: true)]
|
#[ApiProperty(readableLink: true)]
|
||||||
private Collection $addresses;
|
private Collection $addresses;
|
||||||
|
|
||||||
@@ -126,30 +109,4 @@ class Supplier
|
|||||||
{
|
{
|
||||||
return $this->addresses;
|
return $this->addresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setAddresses(iterable $addresses): self
|
|
||||||
{
|
|
||||||
$this->addresses->clear();
|
|
||||||
foreach ($addresses as $address) {
|
|
||||||
$this->addAddress($address);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addAddress(Address $address): self
|
|
||||||
{
|
|
||||||
if (!$this->addresses->contains($address)) {
|
|
||||||
$this->addresses->add($address);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function removeAddress(Address $address): self
|
|
||||||
{
|
|
||||||
$this->addresses->removeElement($address);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user