store/resources/js/composables/useDestroy.ts
Yoga Pangestu 15e2b7ec5b
Some checks are pending
linter / quality (push) Waiting to run
tests / ci (8.3) (push) Waiting to run
tests / ci (8.4) (push) Waiting to run
tests / ci (8.5) (push) Waiting to run
feat: add material_result field to CuttingMaterial and CuttingMaterialCombination; update validation rules and service logic to handle new material result calculations; enhance frontend components for displaying material results in cutting management
2026-07-04 23:14:37 +07:00

49 lines
1.2 KiB
TypeScript

import { router } from '@inertiajs/vue3';
import { ref } from 'vue';
import { toast } from 'vue-sonner';
interface UseDestroyOptions {
url: string;
preserveScroll?: boolean;
errorMessage?: string;
onSuccess?: () => void;
onError?: (errors: Record<string, string>) => string | void;
}
export function useDestroy({ url, preserveScroll = true, errorMessage, onSuccess, onError }: UseDestroyOptions) {
const open = ref(false);
const processing = ref(false);
function destroy() {
processing.value = true;
router.delete(url, {
preserveScroll,
onSuccess: () => {
open.value = false;
onSuccess?.();
},
onError: (errors) => {
if (onError) {
const result = onError(errors);
if (typeof result === 'string') {
toast.error(result);
return;
}
}
if (errorMessage) {
toast.error(errorMessage);
}
},
onFinish: () => {
processing.value = false;
},
});
}
return { open, processing, destroy };
}