feat(material): add toast
This commit is contained in:
@@ -7,6 +7,9 @@ import Header from '~/components/pub/custom-ui/nav-header/prep.vue'
|
||||
import AppEquipmentEntryForm from '~/components/app/equipment/entry-form.vue'
|
||||
import RecordConfirmation from '~/components/pub/custom-ui/confirmation/record-confirmation.vue'
|
||||
|
||||
// helpers
|
||||
import { toast } from "~/components/pub/ui/toast"
|
||||
|
||||
// Types
|
||||
import type { Uom } from '~/models/uom'
|
||||
|
||||
@@ -147,10 +150,10 @@ onMounted(async () => {
|
||||
@submit="
|
||||
(values: MaterialFormData, resetForm: any) => {
|
||||
if (recId > 0) {
|
||||
handleActionEdit(recId, values, getEquipmentList, resetForm)
|
||||
handleActionEdit(recId, values, getEquipmentList, resetForm, toast)
|
||||
return
|
||||
}
|
||||
handleActionSave(values, getEquipmentList, resetForm)
|
||||
handleActionSave(values, getEquipmentList, resetForm, toast)
|
||||
}
|
||||
"
|
||||
@cancel="handleCancelForm"
|
||||
@@ -162,7 +165,7 @@ onMounted(async () => {
|
||||
v-model:open="isRecordConfirmationOpen"
|
||||
action="delete"
|
||||
:record="recItem"
|
||||
@confirm="() => handleActionRemove(recId, getEquipmentList)"
|
||||
@confirm="() => handleActionRemove(recId, getEquipmentList, toast)"
|
||||
@cancel=""
|
||||
>
|
||||
<template #default="{ record }">
|
||||
|
||||
@@ -17,18 +17,27 @@ function onResetState() {
|
||||
recItem.value = null
|
||||
}
|
||||
|
||||
export async function handleActionSave(values: any, refresh: () => void, reset: () => void) {
|
||||
export async function handleActionSave(
|
||||
values: any,
|
||||
refresh: () => void,
|
||||
reset: () => void,
|
||||
toast: (params: any) => void,
|
||||
) {
|
||||
let isSuccess = false
|
||||
isProcessing.value = true
|
||||
try {
|
||||
const result = await postSourceMaterial(values)
|
||||
if (result.success) {
|
||||
toast({ title: 'Berhasil', description: 'Data berhasil disimpan', variant: 'default' })
|
||||
isFormEntryDialogOpen.value = false
|
||||
isSuccess = true
|
||||
if (refresh) refresh()
|
||||
} else {
|
||||
toast({ title: 'Gagal', description: 'Gagal menyimpan data', variant: 'destructive' })
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Error saving form:', error)
|
||||
toast({ title: 'Gagal', description: 'Gagal menyimpan data', variant: 'destructive' })
|
||||
isSuccess = false
|
||||
} finally {
|
||||
if (isSuccess) {
|
||||
@@ -40,18 +49,28 @@ export async function handleActionSave(values: any, refresh: () => void, reset:
|
||||
}
|
||||
}
|
||||
|
||||
export async function handleActionEdit(id: number | string, values: any, refresh: () => void, reset: () => void) {
|
||||
export async function handleActionEdit(
|
||||
id: number | string,
|
||||
values: any,
|
||||
refresh: () => void,
|
||||
reset: () => void,
|
||||
toast: (params: any) => void,
|
||||
) {
|
||||
let isSuccess = false
|
||||
isProcessing.value = true
|
||||
try {
|
||||
const result = await patchSourceMaterial(id, values)
|
||||
if (result.success) {
|
||||
toast({ title: 'Berhasil', description: 'Data berhasil diubah', variant: 'default' })
|
||||
isFormEntryDialogOpen.value = false
|
||||
isSuccess = true
|
||||
if (refresh) refresh()
|
||||
} else {
|
||||
toast({ title: 'Gagal', description: 'Gagal mengubah data', variant: 'destructive' })
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Error editing form:', error)
|
||||
toast({ title: 'Gagal', description: 'Gagal mengubah data', variant: 'destructive' })
|
||||
isSuccess = false
|
||||
} finally {
|
||||
if (isSuccess) {
|
||||
@@ -63,15 +82,19 @@ export async function handleActionEdit(id: number | string, values: any, refresh
|
||||
}
|
||||
}
|
||||
|
||||
export async function handleActionRemove(id: number | string, refresh: () => void) {
|
||||
export async function handleActionRemove(id: number | string, refresh: () => void, toast: (params: any) => void) {
|
||||
isProcessing.value = true
|
||||
try {
|
||||
const result = await removeSourceMaterial(id)
|
||||
if (result.success) {
|
||||
toast({ title: 'Berhasil', description: 'Data berhasil dihapus', variant: 'default' })
|
||||
if (refresh) refresh()
|
||||
} else {
|
||||
toast({ title: 'Gagal', description: 'Gagal menghapus data', variant: 'destructive' })
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error deleting record:', error)
|
||||
toast({ title: 'Gagal', description: 'Gagal menghapus data', variant: 'destructive' })
|
||||
} finally {
|
||||
onResetState()
|
||||
isProcessing.value = false
|
||||
|
||||
Reference in New Issue
Block a user