refactor(FE): Improve delete handlers with success and error feedback

This commit is contained in:
rstubryan
2026-03-10 11:13:46 +07:00
parent cc08e3af15
commit 058f9f403d
2 changed files with 17 additions and 6 deletions
@@ -586,12 +586,17 @@ const RecordingTable = () => {
const singleDeleteHandler = async () => { const singleDeleteHandler = async () => {
setIsDeleteLoading(true); setIsDeleteLoading(true);
await RecordingApi.delete(selectedRecording?.id as number); const response = await RecordingApi.delete(selectedRecording?.id as number);
refreshRecordings();
singleDeleteModal.closeModal(); singleDeleteModal.closeModal();
toast.success('Successfully delete Recording!');
setIsDeleteLoading(false); setIsDeleteLoading(false);
if (isResponseSuccess(response)) {
toast.success(response?.message || 'Successfully delete Recording!');
refreshRecordings();
} else {
toast.error(response?.message || 'Failed to delete Recording');
}
}; };
const approveHandler = async (notes: string) => { const approveHandler = async (notes: string) => {
@@ -371,11 +371,17 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
if (!initialValues?.id) return; if (!initialValues?.id) return;
setIsDeleteLoading(true); setIsDeleteLoading(true);
await RecordingApi.delete(initialValues.id); const response = await RecordingApi.delete(initialValues.id);
deleteModal.closeModal(); deleteModal.closeModal();
toast.success('Successfully delete Recording!');
setIsDeleteLoading(false); setIsDeleteLoading(false);
router.push('/production/recording');
if (isResponseSuccess(response)) {
toast.success(response?.message || 'Successfully delete Recording!');
router.push('/production/recording');
} else {
toast.error(response?.message || 'Failed to delete Recording');
}
}, [deleteModal, initialValues?.id, router]); }, [deleteModal, initialValues?.id, router]);
// ===== API DATA FETCHING ===== // ===== API DATA FETCHING =====