[#356] modification front page admin bovin #37
@@ -82,7 +82,10 @@
|
|||||||
"list": "Impossible de récupérer la liste des camions."
|
"list": "Impossible de récupérer la liste des camions."
|
||||||
},
|
},
|
||||||
"bovin": {
|
"bovin": {
|
||||||
"list": "Impossible de récupérer la liste des races de bovins."
|
"list": "Impossible de récupérer la liste des races de bovins.",
|
||||||
|
"fetch": "Impossible de récupérer le type bovin.",
|
||||||
|
"create": "Impossible de créer le type bovin.",
|
||||||
|
"update": "Impossible de mettre à jour le type bovin."
|
||||||
},
|
},
|
||||||
"carrier": {
|
"carrier": {
|
||||||
"list": "Impossible de récupérer la liste des transporteurs.",
|
"list": "Impossible de récupérer la liste des transporteurs.",
|
||||||
@@ -133,6 +136,10 @@
|
|||||||
"update": "Transporteur mis à jour",
|
"update": "Transporteur mis à jour",
|
||||||
"create": "Transporteur créé"
|
"create": "Transporteur créé"
|
||||||
},
|
},
|
||||||
|
"bovin": {
|
||||||
|
"update": "Type bovin mis à jour avec succès.",
|
||||||
|
"create": "Type bovin créé avec succès."
|
||||||
|
},
|
||||||
"weight": {
|
"weight": {
|
||||||
"update": "Pesée mis à jour"
|
"update": "Pesée mis à jour"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,9 +22,9 @@
|
|||||||
<UiButton
|
<UiButton
|
||||||
type="submit"
|
type="submit"
|
||||||
:disabled="isLoading || isHydrating"
|
:disabled="isLoading || isHydrating"
|
||||||
class="inline-flex items-center justify-center text-xl min-w-[194px] text-white uppercase bg-primary-500 h-[50px] px-8 rounded hover:opacity-80 gap-2 justify-self-end"
|
class="inline-flex items-center justify-center text-xl min-w-[194px] text-white uppercase bg-primary-500 h-[50px] rounded hover:opacity-80 justify-self-end"
|
||||||
>
|
>
|
||||||
{{ isEdit ? 'Valider' : 'Ajouter' }}
|
Valider
|
||||||
</UiButton>
|
</UiButton>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@@ -37,6 +37,8 @@ const router = useRouter()
|
|||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const isLoading = ref(false)
|
const isLoading = ref(false)
|
||||||
const isHydrating = ref(false)
|
const isHydrating = ref(false)
|
||||||
|
const idBovin = computed(() => resolveId(route.params.id))
|
||||||
|
const isEdit = computed(() => idBovin.value !== null)
|
||||||
|
|
||||||
function resolveId(param: unknown) {
|
function resolveId(param: unknown) {
|
||||||
const idStr = Array.isArray(param) ? param[0] : param
|
const idStr = Array.isArray(param) ? param[0] : param
|
||||||
@@ -45,9 +47,6 @@ function resolveId(param: unknown) {
|
|||||||
return Number.isFinite(id) ? id : null
|
return Number.isFinite(id) ? id : null
|
||||||
}
|
}
|
||||||
|
|
||||||
const idBovin = computed(() => resolveId(route.params.id))
|
|
||||||
const isEdit = computed(() => idBovin.value !== null)
|
|
||||||
|
|
||||||
const form = reactive<BovinFormData>({
|
const form = reactive<BovinFormData>({
|
||||||
label: '',
|
label: '',
|
||||||
code: ''
|
code: ''
|
||||||
@@ -100,7 +99,6 @@ async function validate() {
|
|||||||
} else {
|
} else {
|
||||||
await createBovin(basePayload)
|
await createBovin(basePayload)
|
||||||
}
|
}
|
||||||
await navigate()
|
|
||||||
} finally {
|
} finally {
|
||||||
isLoading.value = false
|
isLoading.value = false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,11 +101,10 @@ async function validate() {
|
|||||||
|
|
||||||
if(idCarrier.value){
|
if(idCarrier.value){
|
||||||
await updateCarrier(idCarrier.value, basePayload)
|
await updateCarrier(idCarrier.value, basePayload)
|
||||||
navigate()
|
|
||||||
return
|
return
|
||||||
|
}else{
|
||||||
|
await createCarrier(basePayload)
|
||||||
}
|
}
|
||||||
await createCarrier(basePayload)
|
|
||||||
navigate()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function navigate(){
|
function navigate(){
|
||||||
|
|||||||
@@ -24,19 +24,27 @@ export async function getBovineTypeList(): Promise<BovineTypeData[]> {
|
|||||||
|
|
||||||
export async function getBovin(id: number): Promise<BovineTypeData> {
|
export async function getBovin(id: number): Promise<BovineTypeData> {
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
const response = await api.get<BovineTypeData>(`bovine_types/${id}`)
|
const response = await api.get<BovineTypeData>(`bovine_types/${id}`, {}, {
|
||||||
|
toastErrorKey: 'errors.bovin.fetch'
|
||||||
|
})
|
||||||
return mapToBovineTypeData(response)
|
return mapToBovineTypeData(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createBovin(payload: BovinPayload = {}): Promise<BovineTypeData> {
|
export async function createBovin(payload: BovinPayload = {}): Promise<BovineTypeData> {
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
const response = await api.post<BovineTypeData>('bovine_types', toBovineTypePayload(payload))
|
const response = await api.post<BovineTypeData>('bovine_types', toBovineTypePayload(payload), {
|
||||||
|
toastErrorKey: 'errors.bovin.create',
|
||||||
|
toastSuccessKey: 'success.bovin.create'
|
||||||
|
})
|
||||||
return mapToBovineTypeData(response)
|
return mapToBovineTypeData(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateBovin(id: number, payload: BovinPayload = {}): Promise<BovineTypeData> {
|
export async function updateBovin(id: number, payload: BovinPayload = {}): Promise<BovineTypeData> {
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
const response = await api.patch<BovineTypeData>(`bovine_types/${id}`, toBovineTypePayload(payload))
|
const response = await api.patch<BovineTypeData>(`bovine_types/${id}`, toBovineTypePayload(payload), {
|
||||||
|
toastErrorKey: 'errors.bovin.update',
|
||||||
|
toastSuccessKey: 'success.bovin.update'
|
||||||
|
})
|
||||||
return mapToBovineTypeData(response)
|
return mapToBovineTypeData(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user