fix : review MR
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 items-start gap-y-8 gap-x-40 py-12">
|
||||
<UiTextInput label="Nom du bovin" id="bovin-name" v-model="form.name" />
|
||||
<UiTextInput label="Nom du bovin" id="bovin-label" v-model="form.label" />
|
||||
<UiTextInput label="Code bovin" id="code-id" v-model="form.code" />
|
||||
</div>
|
||||
</form>
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import {createBovin, getBovin, updateBovin} from "~/services/bovine-type";
|
||||
import type {BovinData, BovinFormData} from "~/services/dto/bovine-type-data";
|
||||
import type {BovineTypeData, BovinFormData} from "~/services/dto/bovine-type-data";
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
const isLoading = ref(false)
|
||||
@@ -41,17 +41,17 @@ const idBovin = computed(() => resolveId(route.params.id))
|
||||
const isEdit = computed(() => idBovin.value !== null)
|
||||
|
||||
const form = reactive<BovinFormData>({
|
||||
name: '',
|
||||
label: '',
|
||||
code: ''
|
||||
})
|
||||
|
||||
|
||||
const hydrateFromBovin = (bovin: BovinData | null) => {
|
||||
const hydrateFromBovin = (bovin: BovineTypeData | null) => {
|
||||
if (!bovin) {
|
||||
return
|
||||
}
|
||||
isHydrating.value = true
|
||||
form.name = bovin.name ?? ''
|
||||
form.label = bovin.label ?? ''
|
||||
form.code = bovin.code ?? ''
|
||||
isHydrating.value = false
|
||||
}
|
||||
@@ -76,22 +76,26 @@ async function validate() {
|
||||
if (isLoading.value || isHydrating.value) return
|
||||
|
||||
const normalizedBovinCode = form.code.trim()
|
||||
const normalizedBovinName = form.name.trim()
|
||||
const normalizedBovinLabel = form.label.trim()
|
||||
|
||||
|
||||
const basePayload = {
|
||||
name: normalizedBovinName,
|
||||
label: normalizedBovinLabel,
|
||||
code: normalizedBovinCode
|
||||
|
||||
}
|
||||
|
||||
if(idBovin.value){
|
||||
await updateBovin(idBovin.value, basePayload)
|
||||
isLoading.value = true
|
||||
try {
|
||||
if (isEdit.value && idBovin.value !== null) {
|
||||
await updateBovin(idBovin.value, basePayload)
|
||||
} else {
|
||||
await createBovin(basePayload)
|
||||
}
|
||||
await navigate()
|
||||
return
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
await createBovin(basePayload)
|
||||
await navigate()
|
||||
}
|
||||
|
||||
async function navigate(){
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
<template>
|
||||
<div class="flex items-center justify-between">
|
||||
<h1 class="text-3xl font-bold text-primary-500 uppercase">Liste des bovins</h1>
|
||||
<h1 class="text-3xl font-bold text-primary-500 uppercase">Liste des types bovins</h1>
|
||||
<NuxtLink
|
||||
to="/admin/bovin"
|
||||
class="inline-flex items-center justify-center
|
||||
text-xl text-white uppercase
|
||||
bg-primary-500 h-[50px] px-8 rounded
|
||||
hover:opacity-80 gap-2"
|
||||
>
|
||||
@click="handleAddClick"
|
||||
>
|
||||
<Icon name="mdi:plus" size="28" />
|
||||
Ajouter
|
||||
</NuxtLink>
|
||||
@@ -21,7 +22,7 @@
|
||||
font-semibold uppercase
|
||||
tracking-wide"
|
||||
>
|
||||
<div class="col-span-1">Label</div>
|
||||
<div class="col-span-1">Nom</div>
|
||||
<div class="col-span-1">Code</div>
|
||||
</div>
|
||||
<div v-if="bovinList.length === 0" class="px-4 py-6 text-slate-400">
|
||||
|
||||
Reference in New Issue
Block a user