alert for approval transaction

This commit is contained in:
wayanrivan
2025-04-28 15:24:20 +07:00
parent 99f2cd14ac
commit 99687023a3
3 changed files with 41 additions and 25 deletions

View File

@ -80,6 +80,7 @@
"styled-components": "^6.1.13", "styled-components": "^6.1.13",
"stylis": "^4.3.4", "stylis": "^4.3.4",
"stylis-plugin-rtl": "^2.1.1", "stylis-plugin-rtl": "^2.1.1",
"sweetalert2": "^11.19.1",
"tabs": "^0.2.0", "tabs": "^0.2.0",
"tailwind-merge": "^2.5.4", "tailwind-merge": "^2.5.4",
"tailwindcss-animate": "^1.0.7", "tailwindcss-animate": "^1.0.7",

View File

@ -1,2 +1,3 @@
export * from './BasicSettings'; export * from './BasicSettings';
export * from './Password'; export * from './Password';
export * from './PinCode';

View File

@ -22,6 +22,7 @@ import { doSaveLogActivity } from '@/actions/GlobalActions';
import { toast } from 'sonner'; import { toast } from 'sonner';
import { Input } from '@/components/ui/input'; import { Input } from '@/components/ui/input';
import { DefaultTooltip, KeenIcon, useDataGrid } from '@/components'; import { DefaultTooltip, KeenIcon, useDataGrid } from '@/components';
import Swal from 'sweetalert2'; // ✅ IMPORT sweetalert2
const API_URL = apiConfig.transaction; const API_URL = apiConfig.transaction;
@ -63,6 +64,23 @@ const ApprovalDialog = () => {
return; return;
} }
// ✅ TUTUP Dialog sebelum munculkan SweetAlert
setShowApprovalDialog(false);
// ✅ TAMPILKAN SWEETALERT
const result = await Swal.fire({
title: 'Are you sure?',
text: "You want to save changes?",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, save it!',
cancelButtonText: 'Cancel'
});
if (result.isConfirmed) {
// ✅ Kalau tekan YES, baru tembak API
const response = await PostData(`${API_URL}/transaction/set-approval`, { const response = await PostData(`${API_URL}/transaction/set-approval`, {
id_transaction: transactionDetails.id, id_transaction: transactionDetails.id,
notes: formField.notes, notes: formField.notes,
@ -71,15 +89,11 @@ const ApprovalDialog = () => {
}); });
if (response?.status === false) { if (response?.status === false) {
setAlert({ toast.error(response?.message?.error?.message || 'Approval failed');
show: true,
message: response?.message?.error?.message || 'Approval failed',
});
return; return;
} }
if (response?.status) { if (response?.status) {
setAlert({ show: false, message: '' });
toast.success('Success Update Approval'); toast.success('Success Update Approval');
const createActivity = { const createActivity = {
module: 'Approval Transaction', module: 'Approval Transaction',
@ -87,10 +101,11 @@ const ApprovalDialog = () => {
action: 'U', action: 'U',
}; };
doSaveLogActivity(createActivity); doSaveLogActivity(createActivity);
setShowApprovalDialog(false);
reload(); reload();
}
} else { } else {
setAlert({ show: true, message: response?.message }); // ✅ Kalau tekan Cancel
console.log('User cancelled');
} }
}, },
[formField, transactionDetails] [formField, transactionDetails]
@ -102,7 +117,7 @@ const ApprovalDialog = () => {
transaction_code: '', transaction_code: '',
notes: '', notes: '',
status: '', status: '',
pin:'' pin: ''
}); });
setTransactionDetails(null); setTransactionDetails(null);
setAlert({ show: false, message: '' }); setAlert({ show: false, message: '' });
@ -171,7 +186,6 @@ const ApprovalDialog = () => {
</div> </div>
</div> </div>
<div className="flex items-center flex-wrap gap-2.5 mt-3 mb-3"> <div className="flex items-center flex-wrap gap-2.5 mt-3 mb-3">
<label className="form-label max-w-56">PIN</label> <label className="form-label max-w-56">PIN</label>
<div className="grow"> <div className="grow">
<Input <Input