feat(material): add toast
This commit is contained in:
@@ -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