Merge branch 'master' of https://git.shiblysolution.id/TPAY/dashboard
This commit is contained in:
@ -27,7 +27,7 @@ const App = () => {
|
|||||||
<PathnameProvider>
|
<PathnameProvider>
|
||||||
<AppRouting />
|
<AppRouting />
|
||||||
</PathnameProvider>
|
</PathnameProvider>
|
||||||
<Toaster />
|
<Toaster expand visibleToasts={20} duration={3000} />
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -6,12 +6,12 @@ import { apiConfig } from '@/config/api.config';
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogBody,
|
DialogBody,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogDescription,
|
DialogDescription,
|
||||||
DialogHeader,
|
DialogHeader,
|
||||||
DialogTitle
|
DialogTitle
|
||||||
} from '@/components/ui/dialog';
|
} from '@/components/ui/dialog';
|
||||||
import TransactionLogViewer from './DetailTransactionLog';
|
import TransactionLogViewer from './DetailTransactionLog';
|
||||||
|
|
||||||
@ -29,125 +29,182 @@ const statusMap: Record<StatusCode, StatusInfo> = {
|
|||||||
W: { label: 'Waiting Schedule', bg: 'bg-yellow-100', text: 'text-yellow-600' },
|
W: { label: 'Waiting Schedule', bg: 'bg-yellow-100', text: 'text-yellow-600' },
|
||||||
O: { label: 'On Process', bg: 'bg-blue-100', text: 'text-blue-600' },
|
O: { label: 'On Process', bg: 'bg-blue-100', text: 'text-blue-600' },
|
||||||
F: { label: 'Fail', bg: 'bg-red-100', text: 'text-red-600' },
|
F: { label: 'Fail', bg: 'bg-red-100', text: 'text-red-600' },
|
||||||
D: { label: 'Done', bg: 'bg-green-100', text: 'text-green-600' },
|
D: { label: 'Done', bg: 'bg-green-100', text: 'text-green-600' }
|
||||||
};
|
};
|
||||||
|
|
||||||
export const renderStatusBadge = (statusRaw: string | null | undefined) => {
|
export const renderStatusBadge = (statusRaw: string | null | undefined) => {
|
||||||
const status = statusRaw as StatusCode;
|
const status = statusRaw as StatusCode;
|
||||||
const { label, bg, text } = statusMap[status] ?? {
|
const { label, bg, text } = statusMap[status] ?? {
|
||||||
label: 'Unknown',
|
label: 'Unknown',
|
||||||
bg: 'bg-gray-100',
|
bg: 'bg-gray-100',
|
||||||
text: 'text-gray-600',
|
text: 'text-gray-600'
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span className={`px-2 py-1 text-xs font-semibold rounded-full ${bg} ${text}`}>
|
<span className={`px-2 py-1 text-xs font-semibold rounded-full ${bg} ${text}`}>{label}</span>
|
||||||
{label}
|
);
|
||||||
</span>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const DetailTransaction = () => {
|
const DetailTransaction = () => {
|
||||||
const { GetData } = useCallApi();
|
const { GetData } = useCallApi();
|
||||||
const {
|
const {
|
||||||
showDetailDialog,
|
showDetailDialog,
|
||||||
setShowDetailDialog,
|
setShowDetailDialog,
|
||||||
selectedTransactionId,
|
selectedTransactionId,
|
||||||
setShowDetailLogDialog,
|
setShowDetailLogDialog,
|
||||||
setDetailLogData
|
setDetailLogData
|
||||||
} = useTransactionContext();
|
} = useTransactionContext();
|
||||||
|
|
||||||
const [transactionDetails, setTransactionDetails] = useState<any>(null);
|
const [transactionDetails, setTransactionDetails] = useState<any>(null);
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchTransactionDetails = async () => {
|
const fetchTransactionDetails = async () => {
|
||||||
if (selectedTransactionId) {
|
setIsLoading(true);
|
||||||
try {
|
if (selectedTransactionId) {
|
||||||
const response = await GetData(`${API_URL}/transaction/history/${selectedTransactionId}`, {
|
try {
|
||||||
id: selectedTransactionId
|
const response = await GetData(
|
||||||
});
|
`${API_URL}/transaction/history/${selectedTransactionId}`,
|
||||||
// console.log(response?.data);
|
{
|
||||||
setTransactionDetails(response?.data);
|
id: selectedTransactionId
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching transaction', error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
);
|
||||||
|
// console.log(response?.data);
|
||||||
if (showDetailDialog && selectedTransactionId) {
|
setTransactionDetails(response?.data);
|
||||||
fetchTransactionDetails();
|
} catch (error) {
|
||||||
|
console.error('Error fetching transaction', error);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
}, [showDetailDialog, selectedTransactionId, GetData]);
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const [activeTab, setActiveTab] = useState('detail'); // 'detail', 'log', 'approve'
|
if (showDetailDialog && selectedTransactionId) {
|
||||||
|
fetchTransactionDetails();
|
||||||
|
}
|
||||||
|
}, [showDetailDialog, selectedTransactionId, GetData]);
|
||||||
|
|
||||||
return (
|
const [activeTab, setActiveTab] = useState('detail'); // 'detail', 'log', 'approve'
|
||||||
<Dialog open={showDetailDialog} onOpenChange={setShowDetailDialog}>
|
|
||||||
<DialogContent className="container-fixed max-w-[1024px] flex flex-col p-5 overflow-hidden">
|
|
||||||
<DialogHeader>
|
|
||||||
<DialogTitle>Transaction Details</DialogTitle>
|
|
||||||
</DialogHeader>
|
|
||||||
<DialogBody>
|
|
||||||
{/* Tab Content */}
|
|
||||||
<div className="py-4 overflow-y-auto max-h-[400px]">
|
|
||||||
<div className="space-y-4">
|
|
||||||
<div className="border rounded-lg overflow-x-auto">
|
|
||||||
<table className="min-w-full table-auto">
|
|
||||||
<thead>
|
|
||||||
<tr className="bg-gray-100">
|
|
||||||
<th className="px-4 py-2 text-left text-sm text-gray-500">Username</th>
|
|
||||||
<th className="px-4 py-2 text-left text-sm text-gray-500">Fullname</th>
|
|
||||||
<th className="px-4 py-2 text-left text-sm text-gray-500">Amount</th>
|
|
||||||
<th className="px-4 py-2 text-left text-sm text-gray-500">Status</th>
|
|
||||||
<th className="px-4 py-2 text-left text-sm text-gray-500">Process Date</th>
|
|
||||||
<th className="px-4 py-2 text-left text-sm text-gray-500">Invoice Number</th>
|
|
||||||
<th className="px-4 py-2 text-left text-sm text-gray-500">Actions</th>
|
|
||||||
|
|
||||||
</tr>
|
const resetForm = () => {
|
||||||
</thead>
|
setTransactionDetails(null);
|
||||||
<tbody>
|
};
|
||||||
{transactionDetails?.log && transactionDetails?.log.length > 0 ? (
|
|
||||||
transactionDetails.log.map((log: { id: number, customer: any, amount: number, remark: string, reference: string, request_date: string, payment_response: string, status: string}, index: number) => (
|
|
||||||
<tr key={index} className="border-t">
|
|
||||||
<td className="px-4 py-2 text-sm text-gray-500">{log.customer.username ?? '-'}</td>
|
|
||||||
<td className="px-4 py-2 text-sm text-gray-500">{log.customer.fullname ?? '-'}</td>
|
|
||||||
<td className="px-4 py-2 text-sm text-gray-500">{log.amount ?? '-'}</td>
|
|
||||||
<td className="px-4 py-2 text-sm text-gray-500">{renderStatusBadge(log.status) ?? '-'}</td>
|
|
||||||
<td className="px-4 py-2 text-sm text-gray-500">{log.request_date && moment(log.request_date).isValid() ? moment(log.request_date).format('DD/MM/YYYY HH:mm:ss') : '-'}</td>
|
|
||||||
<td className="px-4 py-2 text-sm text-gray-500">{log.reference ?? '-'}</td>
|
|
||||||
<td className="px-4 py-2 text-sm text-gray-500">
|
|
||||||
<div key={`actions-${log.id}`}>
|
|
||||||
<button
|
|
||||||
className="btn btn-sm btn-icon btn-clear btn-light"
|
|
||||||
onClick={() => {
|
|
||||||
setDetailLogData(log)
|
|
||||||
setShowDetailLogDialog(true);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<KeenIcon icon="eye" />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
|
|
||||||
</tr>
|
useEffect(() => {
|
||||||
))
|
if (!showDetailDialog) {
|
||||||
) : (
|
resetForm();
|
||||||
<tr>
|
}
|
||||||
<td colSpan={8} className="px-4 py-2 text-center text-sm text-gray-500">
|
}, [showDetailDialog]);
|
||||||
No logs available
|
|
||||||
</td>
|
return (
|
||||||
</tr>
|
<Dialog open={showDetailDialog} onOpenChange={setShowDetailDialog}>
|
||||||
)}
|
<DialogContent className="container-fixed max-w-[1024px] flex flex-col p-5 overflow-hidden">
|
||||||
</tbody>
|
<DialogHeader>
|
||||||
</table>
|
<DialogTitle>Transaction Details</DialogTitle>
|
||||||
</div>
|
</DialogHeader>
|
||||||
|
<DialogBody>
|
||||||
|
{/* Tab Content */}
|
||||||
|
<div className="py-4 overflow-y-auto max-h-[400px]">
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="border rounded-lg overflow-x-auto">
|
||||||
|
{isLoading ? (
|
||||||
|
<div className="flex flex-col items-center justify-center p-8">
|
||||||
|
<div className="animate-pulse flex space-x-4 w-full">
|
||||||
|
<div className="flex-1 space-y-4 py-1">
|
||||||
|
<div className="h-4 bg-gray-200 rounded w-3/4"></div>
|
||||||
|
<div className="space-y-2">
|
||||||
|
<div className="h-4 bg-gray-200 rounded"></div>
|
||||||
|
<div className="h-4 bg-gray-200 rounded w-5/6"></div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</DialogBody>
|
<p className="mt-4 text-gray-500">Loading Logs Details...</p>
|
||||||
</DialogContent>
|
</div>
|
||||||
</Dialog>
|
) : (
|
||||||
);
|
<table className="min-w-full table-auto">
|
||||||
|
<thead>
|
||||||
|
<tr className="bg-gray-100">
|
||||||
|
<th className="px-4 py-2 text-left text-sm text-gray-500">Username</th>
|
||||||
|
<th className="px-4 py-2 text-left text-sm text-gray-500">Fullname</th>
|
||||||
|
<th className="px-4 py-2 text-left text-sm text-gray-500">Amount</th>
|
||||||
|
<th className="px-4 py-2 text-left text-sm text-gray-500">Status</th>
|
||||||
|
<th className="px-4 py-2 text-left text-sm text-gray-500">Process Date</th>
|
||||||
|
<th className="px-4 py-2 text-left text-sm text-gray-500">
|
||||||
|
Invoice Number
|
||||||
|
</th>
|
||||||
|
<th className="px-4 py-2 text-left text-sm text-gray-500">Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{transactionDetails?.log && transactionDetails.log.length > 0 ? (
|
||||||
|
transactionDetails.log.map(
|
||||||
|
(
|
||||||
|
log: {
|
||||||
|
id: number;
|
||||||
|
customer: any;
|
||||||
|
amount: number;
|
||||||
|
remark: string;
|
||||||
|
reference: string;
|
||||||
|
request_date: string;
|
||||||
|
payment_response: string;
|
||||||
|
status: string;
|
||||||
|
},
|
||||||
|
index: number
|
||||||
|
) => (
|
||||||
|
<tr key={index} className="border-t">
|
||||||
|
<td className="px-4 py-2 text-sm text-gray-500">
|
||||||
|
{log.customer?.username ?? 'Not Found'}
|
||||||
|
</td>
|
||||||
|
<td className="px-4 py-2 text-sm text-gray-500">
|
||||||
|
{log.customer?.fullname ?? 'Not Found'}
|
||||||
|
</td>
|
||||||
|
<td className="px-4 py-2 text-sm text-gray-500">
|
||||||
|
{log.amount ?? '-'}
|
||||||
|
</td>
|
||||||
|
<td className="px-4 py-2 text-sm text-gray-500">
|
||||||
|
{renderStatusBadge(log.status) ?? '-'}
|
||||||
|
</td>
|
||||||
|
<td className="px-4 py-2 text-sm text-gray-500">
|
||||||
|
{log.request_date && moment(log.request_date).isValid()
|
||||||
|
? moment(log.request_date).format('DD/MM/YYYY HH:mm:ss')
|
||||||
|
: '-'}
|
||||||
|
</td>
|
||||||
|
<td className="px-4 py-2 text-sm text-gray-500">
|
||||||
|
{log.reference ?? '-'}
|
||||||
|
</td>
|
||||||
|
<td className="px-4 py-2 text-sm text-gray-500">
|
||||||
|
<div key={`actions-${log.id}`}>
|
||||||
|
<button
|
||||||
|
className="btn btn-sm btn-icon btn-clear btn-light"
|
||||||
|
onClick={() => {
|
||||||
|
setDetailLogData(log);
|
||||||
|
setShowDetailLogDialog(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<KeenIcon icon="eye" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)
|
||||||
|
)
|
||||||
|
) : (
|
||||||
|
<tr>
|
||||||
|
<td colSpan={8} className="px-4 py-2 text-center text-sm text-gray-500">
|
||||||
|
No logs available
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</DialogBody>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default DetailTransaction;
|
export default DetailTransaction;
|
||||||
|
|||||||
@ -31,7 +31,7 @@ const ListToolbar = () => {
|
|||||||
|
|
||||||
const handleFilterData = useCallback(() => {
|
const handleFilterData = useCallback(() => {
|
||||||
try {
|
try {
|
||||||
table.getColumn('transaction_date')?.setFilterValue(trxDate);
|
table.getColumn('execution_date')?.setFilterValue(trxDate);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast.error('Error applying filter');
|
toast.error('Error applying filter');
|
||||||
console.error('Error applying filter:', error);
|
console.error('Error applying filter:', error);
|
||||||
|
|||||||
@ -35,6 +35,7 @@ import {
|
|||||||
import { useManageConversionContext } from '../hooks/useManageConversionContext';
|
import { useManageConversionContext } from '../hooks/useManageConversionContext';
|
||||||
import { doSaveLogActivity } from '@/actions/GlobalActions';
|
import { doSaveLogActivity } from '@/actions/GlobalActions';
|
||||||
import { RefreshCw } from 'lucide-react';
|
import { RefreshCw } from 'lucide-react';
|
||||||
|
import { initialStateConversion, validateFormConversion } from './Types';
|
||||||
interface CurrencyProps {
|
interface CurrencyProps {
|
||||||
ID: string;
|
ID: string;
|
||||||
name: string;
|
name: string;
|
||||||
@ -50,27 +51,15 @@ const AddDialog = () => {
|
|||||||
const parsedUser = getAuth()?.user;
|
const parsedUser = getAuth()?.user;
|
||||||
const [currencies, setCurrencies] = useState<CurrencyProps[]>([]);
|
const [currencies, setCurrencies] = useState<CurrencyProps[]>([]);
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [alert, setAlert] = useState({
|
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||||
show: false,
|
const [formField, setFormField] = useState(initialStateConversion);
|
||||||
message: ''
|
|
||||||
});
|
|
||||||
const initialState = {
|
|
||||||
status: '',
|
|
||||||
id_currency_origin: '',
|
|
||||||
id_currency_destination: '',
|
|
||||||
buy: 0,
|
|
||||||
sell: 0,
|
|
||||||
created_by: '',
|
|
||||||
created_at: ''
|
|
||||||
};
|
|
||||||
const [formField, setFormField] = useState(initialState);
|
|
||||||
const created_time = new Date();
|
const created_time = new Date();
|
||||||
const formattedTime = created_time.toISOString().slice(0, 19).replace('T', ' ');
|
const formattedTime = created_time.toISOString().slice(0, 19).replace('T', ' ');
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
|
|
||||||
const resetForm = () => {
|
const resetForm = () => {
|
||||||
setFormField(initialState);
|
setFormField(initialStateConversion);
|
||||||
setAlert({ show: false, message: '' });
|
setErrors({});
|
||||||
};
|
};
|
||||||
|
|
||||||
const doCreateConversion = useCallback(
|
const doCreateConversion = useCallback(
|
||||||
@ -94,8 +83,7 @@ const AddDialog = () => {
|
|||||||
doSaveLogActivity(createActivity);
|
doSaveLogActivity(createActivity);
|
||||||
reload();
|
reload();
|
||||||
} else {
|
} else {
|
||||||
toast.error('Error Create Conversion');
|
toast.error(response?.message);
|
||||||
setAlert({ show: true, message: response?.message });
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast.error('Something Went Wrong');
|
toast.error('Something Went Wrong');
|
||||||
@ -126,20 +114,11 @@ const AddDialog = () => {
|
|||||||
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
if (
|
if (!validateFormConversion(formField, setErrors)) {
|
||||||
formField.id_currency_origin === '' ||
|
|
||||||
formField.id_currency_destination === '' ||
|
|
||||||
formField.buy === 0 ||
|
|
||||||
formField.sell === 0 ||
|
|
||||||
formField.status === ''
|
|
||||||
) {
|
|
||||||
setAlert({ show: true, message: 'Please fill in all required fields.' });
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
doCreateConversion(e);
|
doCreateConversion(e);
|
||||||
// console.log(formField);
|
|
||||||
setAlert({ show: false, message: '' });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -171,12 +150,6 @@ const AddDialog = () => {
|
|||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<DialogBody ref={parentRef}>
|
<DialogBody ref={parentRef}>
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
{alert.show && (
|
|
||||||
<Alert variant="danger">
|
|
||||||
<h3>{alert.message}</h3>
|
|
||||||
</Alert>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<form onSubmit={handleSubmit}>
|
<form onSubmit={handleSubmit}>
|
||||||
<div className="card-body grid gap-5">
|
<div className="card-body grid gap-5">
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
@ -185,11 +158,14 @@ const AddDialog = () => {
|
|||||||
</label>
|
</label>
|
||||||
<Select
|
<Select
|
||||||
value={formField.id_currency_origin}
|
value={formField.id_currency_origin}
|
||||||
onValueChange={(id_currency_origin) =>
|
onValueChange={(id_currency_origin) => {
|
||||||
setFormField((prev) => ({ ...prev, id_currency_origin }))
|
setFormField((prev) => ({ ...prev, id_currency_origin }));
|
||||||
}
|
setErrors((prev) => ({ ...prev, id_currency_destination: '' }));
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger
|
||||||
|
className={errors.id_currency_destination ? 'border-red-500' : ''}
|
||||||
|
>
|
||||||
<SelectValue placeholder="Select Currency" />
|
<SelectValue placeholder="Select Currency" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
@ -200,6 +176,11 @@ const AddDialog = () => {
|
|||||||
))}
|
))}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
|
{errors.id_currency_destination && (
|
||||||
|
<span className="text-red-500 text-xs mt-1">
|
||||||
|
{errors.id_currency_destination}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<label className="form-label">
|
<label className="form-label">
|
||||||
@ -207,11 +188,12 @@ const AddDialog = () => {
|
|||||||
</label>
|
</label>
|
||||||
<Select
|
<Select
|
||||||
value={formField.id_currency_destination}
|
value={formField.id_currency_destination}
|
||||||
onValueChange={(id_currency_destination) =>
|
onValueChange={(id_currency_destination) => {
|
||||||
setFormField((prev) => ({ ...prev, id_currency_destination }))
|
setFormField((prev) => ({ ...prev, id_currency_destination }));
|
||||||
}
|
setErrors((prev) => ({ ...prev, id_currency_origin: '' }));
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger className={errors.id_currency_origin ? 'border-red-500' : ''}>
|
||||||
<SelectValue placeholder="Select Currency" />
|
<SelectValue placeholder="Select Currency" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
@ -222,13 +204,16 @@ const AddDialog = () => {
|
|||||||
))}
|
))}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
|
{errors.id_currency_origin && (
|
||||||
|
<span className="text-red-500 text-xs mt-1">{errors.id_currency_origin}</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<label className="form-label">
|
<label className="form-label">
|
||||||
Buy<span className="text-red-500">*</span>
|
Buy<span className="text-red-500">*</span>
|
||||||
</label>
|
</label>
|
||||||
<NumericFormat
|
<NumericFormat
|
||||||
className="input"
|
className={`input ${errors.buy ? 'border-red-500' : ''}`}
|
||||||
value={formField.buy}
|
value={formField.buy}
|
||||||
thousandSeparator="."
|
thousandSeparator="."
|
||||||
decimalSeparator=","
|
decimalSeparator=","
|
||||||
@ -236,11 +221,13 @@ const AddDialog = () => {
|
|||||||
onValueChange={(values) => {
|
onValueChange={(values) => {
|
||||||
setFormField((prev) => ({
|
setFormField((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
buy: values.floatValue || 0
|
buy: values.floatValue ?? null
|
||||||
}));
|
}));
|
||||||
|
setErrors((prev) => ({ ...prev, buy: '' }));
|
||||||
}}
|
}}
|
||||||
placeholder="Enter Buy"
|
placeholder="Enter Buy"
|
||||||
/>
|
/>
|
||||||
|
{errors.buy && <span className="text-red-500 text-xs mt-1">{errors.buy}</span>}
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<label className="form-label">
|
<label className="form-label">
|
||||||
@ -248,7 +235,7 @@ const AddDialog = () => {
|
|||||||
<span className="text-red-500">*</span>
|
<span className="text-red-500">*</span>
|
||||||
</label>
|
</label>
|
||||||
<NumericFormat
|
<NumericFormat
|
||||||
className="input"
|
className={`input ${errors.sell ? 'border-red-500' : ''}`}
|
||||||
value={formField.sell}
|
value={formField.sell}
|
||||||
thousandSeparator="."
|
thousandSeparator="."
|
||||||
decimalSeparator=","
|
decimalSeparator=","
|
||||||
@ -256,11 +243,13 @@ const AddDialog = () => {
|
|||||||
onValueChange={(values) => {
|
onValueChange={(values) => {
|
||||||
setFormField((prev) => ({
|
setFormField((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
sell: values.floatValue || 0
|
sell: values.floatValue ?? null
|
||||||
}));
|
}));
|
||||||
|
setErrors((prev) => ({ ...prev, sell: '' }));
|
||||||
}}
|
}}
|
||||||
placeholder="Enter Sell"
|
placeholder="Enter Sell"
|
||||||
/>
|
/>
|
||||||
|
{errors.sell && <span className="text-red-500 text-xs mt-1">{errors.sell}</span>}
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<label className="form-label">
|
<label className="form-label">
|
||||||
@ -271,11 +260,12 @@ const AddDialog = () => {
|
|||||||
<div className="grow">
|
<div className="grow">
|
||||||
<Select
|
<Select
|
||||||
value={formField.status}
|
value={formField.status}
|
||||||
onValueChange={(value) =>
|
onValueChange={(value) => {
|
||||||
setFormField((prev) => ({ ...prev, status: value }))
|
setFormField((prev) => ({ ...prev, status: value }));
|
||||||
}
|
setErrors((prev) => ({ ...prev, status: '' }));
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger className={errors.status ? 'border-red-500' : ''}>
|
||||||
<SelectValue placeholder="Select" />
|
<SelectValue placeholder="Select" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
@ -283,6 +273,9 @@ const AddDialog = () => {
|
|||||||
<SelectItem value="N">Inactive</SelectItem>
|
<SelectItem value="N">Inactive</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
|
{errors.status && (
|
||||||
|
<span className="text-red-500 text-xs mt-1">{errors.status}</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex justify-end gap-5">
|
<div className="flex justify-end gap-5">
|
||||||
|
|||||||
@ -35,6 +35,7 @@ import {
|
|||||||
import { useManageConversionContext } from '../hooks/useManageConversionContext';
|
import { useManageConversionContext } from '../hooks/useManageConversionContext';
|
||||||
import { doSaveLogActivity } from '@/actions/GlobalActions';
|
import { doSaveLogActivity } from '@/actions/GlobalActions';
|
||||||
import { RefreshCw } from 'lucide-react';
|
import { RefreshCw } from 'lucide-react';
|
||||||
|
import { initialStateConversion, validateFormConversion } from './Types';
|
||||||
interface CurrencyProps {
|
interface CurrencyProps {
|
||||||
ID: string;
|
ID: string;
|
||||||
name: string;
|
name: string;
|
||||||
@ -52,26 +53,15 @@ const EditDialog = () => {
|
|||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [alert, setAlert] = useState({
|
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||||
show: false,
|
|
||||||
message: ''
|
const [formField, setFormField] = useState(initialStateConversion);
|
||||||
});
|
|
||||||
const initialState = {
|
|
||||||
status: '',
|
|
||||||
id_currency_origin: '',
|
|
||||||
id_currency_destination: '',
|
|
||||||
buy: 0,
|
|
||||||
sell: 0,
|
|
||||||
created_by: '',
|
|
||||||
created_at: ''
|
|
||||||
};
|
|
||||||
const [formField, setFormField] = useState(initialState);
|
|
||||||
const updated_time = new Date();
|
const updated_time = new Date();
|
||||||
const formattedTime = updated_time.toISOString().slice(0, 19).replace('T', ' ');
|
const formattedTime = updated_time.toISOString().slice(0, 19).replace('T', ' ');
|
||||||
|
|
||||||
const resetForm = () => {
|
const resetForm = () => {
|
||||||
setFormField(initialState);
|
setFormField(initialStateConversion);
|
||||||
setAlert({ show: false, message: '' });
|
setErrors({});
|
||||||
};
|
};
|
||||||
|
|
||||||
const doUpdateConversion = useCallback(
|
const doUpdateConversion = useCallback(
|
||||||
@ -79,6 +69,11 @@ const EditDialog = () => {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setIsSubmitting(true);
|
setIsSubmitting(true);
|
||||||
|
|
||||||
|
if (!validateFormConversion(formField, setErrors)) {
|
||||||
|
setIsSubmitting(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await PutData(`${API_URL}/dashboard/conversion/${selectedConversion}`, {
|
const response = await PutData(`${API_URL}/dashboard/conversion/${selectedConversion}`, {
|
||||||
...formField
|
...formField
|
||||||
@ -97,8 +92,7 @@ const EditDialog = () => {
|
|||||||
doSaveLogActivity(createActivity);
|
doSaveLogActivity(createActivity);
|
||||||
reload();
|
reload();
|
||||||
} else {
|
} else {
|
||||||
toast.error('Error Create Conversion');
|
toast.error(response?.message);
|
||||||
setAlert({ show: true, message: response?.message });
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast.error('Something went wrong');
|
toast.error('Something went wrong');
|
||||||
@ -185,12 +179,6 @@ const EditDialog = () => {
|
|||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<DialogBody ref={parentRef}>
|
<DialogBody ref={parentRef}>
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
{alert.show && (
|
|
||||||
<Alert variant="danger">
|
|
||||||
<h3>{alert.message}</h3>
|
|
||||||
</Alert>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{isLoading ? (
|
{isLoading ? (
|
||||||
<div className="flex flex-col items-center justify-center p-8">
|
<div className="flex flex-col items-center justify-center p-8">
|
||||||
<div className="animate-pulse flex space-x-4 w-full">
|
<div className="animate-pulse flex space-x-4 w-full">
|
||||||
@ -213,11 +201,12 @@ const EditDialog = () => {
|
|||||||
</label>
|
</label>
|
||||||
<Select
|
<Select
|
||||||
value={formField.id_currency_origin}
|
value={formField.id_currency_origin}
|
||||||
onValueChange={(id_currency_origin) =>
|
onValueChange={(id_currency_origin) => {
|
||||||
setFormField((prev) => ({ ...prev, id_currency_origin }))
|
setFormField((prev) => ({ ...prev, id_currency_origin }));
|
||||||
}
|
setErrors((prev) => ({ ...prev, id_currency_origin: '' }));
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger className={errors.id_currency_origin ? 'border-red-500' : ''}>
|
||||||
<SelectValue placeholder="Select Currency" />
|
<SelectValue placeholder="Select Currency" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
@ -228,6 +217,9 @@ const EditDialog = () => {
|
|||||||
))}
|
))}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
|
{errors.id_currency_origin && (
|
||||||
|
<span className="text-red-500 text-xs mt-1">{errors.id_currency_origin}</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<label className="form-label">
|
<label className="form-label">
|
||||||
@ -235,11 +227,14 @@ const EditDialog = () => {
|
|||||||
</label>
|
</label>
|
||||||
<Select
|
<Select
|
||||||
value={formField.id_currency_destination}
|
value={formField.id_currency_destination}
|
||||||
onValueChange={(id_currency_destination) =>
|
onValueChange={(id_currency_destination) => {
|
||||||
setFormField((prev) => ({ ...prev, id_currency_destination }))
|
setFormField((prev) => ({ ...prev, id_currency_destination }));
|
||||||
}
|
setErrors((prev) => ({ ...prev, id_currency_destination: '' }));
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger
|
||||||
|
className={errors.id_currency_destination ? 'border-red-500' : ''}
|
||||||
|
>
|
||||||
<SelectValue placeholder="Select Currency" />
|
<SelectValue placeholder="Select Currency" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
@ -250,6 +245,11 @@ const EditDialog = () => {
|
|||||||
))}
|
))}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
|
{errors.id_currency_destination && (
|
||||||
|
<span className="text-red-500 text-xs mt-1">
|
||||||
|
{errors.id_currency_destination}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<label className="form-label">
|
<label className="form-label">
|
||||||
@ -264,11 +264,13 @@ const EditDialog = () => {
|
|||||||
onValueChange={(values) => {
|
onValueChange={(values) => {
|
||||||
setFormField((prev) => ({
|
setFormField((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
buy: values.floatValue || 0
|
buy: values.floatValue ?? null
|
||||||
}));
|
}));
|
||||||
|
setErrors((prev) => ({ ...prev, buy: '' }));
|
||||||
}}
|
}}
|
||||||
placeholder="Enter Buy"
|
placeholder="Enter Buy"
|
||||||
/>
|
/>
|
||||||
|
{errors.buy && <span className="text-red-500 text-xs mt-1">{errors.buy}</span>}
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<label className="form-label">
|
<label className="form-label">
|
||||||
@ -284,11 +286,15 @@ const EditDialog = () => {
|
|||||||
onValueChange={(values) => {
|
onValueChange={(values) => {
|
||||||
setFormField((prev) => ({
|
setFormField((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
sell: values.floatValue || 0
|
sell: values.floatValue ?? null
|
||||||
}));
|
}));
|
||||||
|
setErrors((prev) => ({ ...prev, sell: '' }));
|
||||||
}}
|
}}
|
||||||
placeholder="Enter Sell"
|
placeholder="Enter Sell"
|
||||||
/>
|
/>
|
||||||
|
{errors.sell && (
|
||||||
|
<span className="text-red-500 text-xs mt-1">{errors.sell}</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<label className="form-label">
|
<label className="form-label">
|
||||||
@ -299,11 +305,12 @@ const EditDialog = () => {
|
|||||||
<div className="grow">
|
<div className="grow">
|
||||||
<Select
|
<Select
|
||||||
value={formField.status}
|
value={formField.status}
|
||||||
onValueChange={(value) =>
|
onValueChange={(value) => {
|
||||||
setFormField((prev) => ({ ...prev, status: value }))
|
setFormField((prev) => ({ ...prev, status: value }));
|
||||||
}
|
setErrors((prev) => ({ ...prev, status: '' }));
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger className={errors.status ? 'border-red-500' : ''}>
|
||||||
<SelectValue placeholder="Select" />
|
<SelectValue placeholder="Select" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
@ -311,6 +318,9 @@ const EditDialog = () => {
|
|||||||
<SelectItem value="N">Inactive</SelectItem>
|
<SelectItem value="N">Inactive</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
|
{errors.status && (
|
||||||
|
<span className="text-red-500 text-xs mt-1">{errors.status}</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex justify-end gap-5">
|
<div className="flex justify-end gap-5">
|
||||||
|
|||||||
50
src/pages/master/conversion/blocks/Types.ts
Normal file
50
src/pages/master/conversion/blocks/Types.ts
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
import { toast } from 'sonner';
|
||||||
|
|
||||||
|
export const validateFormConversion = (
|
||||||
|
formField: typeof initialStateConversion,
|
||||||
|
setErrors: React.Dispatch<React.SetStateAction<Record<string, string>>>
|
||||||
|
) => {
|
||||||
|
const requiredFields = [
|
||||||
|
{ key: 'id_currency_origin', label: 'Currency Origin' },
|
||||||
|
{ key: 'id_currency_destination', label: 'Currency Destination' },
|
||||||
|
{ key: 'buy', label: 'Buy' },
|
||||||
|
{ key: 'sell', label: 'Sell' },
|
||||||
|
{ key: 'status', label: 'Status' }
|
||||||
|
];
|
||||||
|
|
||||||
|
const newErrors: Record<string, string> = {};
|
||||||
|
let isValid = true;
|
||||||
|
|
||||||
|
requiredFields.forEach(({ key, label }) => {
|
||||||
|
if (
|
||||||
|
formField[key as keyof typeof formField] === '' ||
|
||||||
|
formField[key as keyof typeof formField] === null ||
|
||||||
|
formField[key as keyof typeof formField] === undefined
|
||||||
|
) {
|
||||||
|
newErrors[key] = `${label} is required`;
|
||||||
|
toast.error(`${label} is required`);
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
setErrors(newErrors);
|
||||||
|
return isValid;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const initialStateConversion: {
|
||||||
|
status: string;
|
||||||
|
id_currency_origin: string;
|
||||||
|
id_currency_destination: string;
|
||||||
|
buy: number | null;
|
||||||
|
sell: number | null;
|
||||||
|
created_by: string;
|
||||||
|
created_at: string;
|
||||||
|
} = {
|
||||||
|
status: '',
|
||||||
|
id_currency_origin: '',
|
||||||
|
id_currency_destination: '',
|
||||||
|
buy: null,
|
||||||
|
sell: null,
|
||||||
|
created_by: '',
|
||||||
|
created_at: ''
|
||||||
|
};
|
||||||
@ -15,16 +15,6 @@ import {
|
|||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { NumericFormat } from 'react-number-format';
|
import { NumericFormat } from 'react-number-format';
|
||||||
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
|
|
||||||
import {
|
|
||||||
Command,
|
|
||||||
CommandEmpty,
|
|
||||||
CommandGroup,
|
|
||||||
CommandInput,
|
|
||||||
CommandItem,
|
|
||||||
CommandList
|
|
||||||
} from '@/components/ui/command';
|
|
||||||
import { set } from 'date-fns';
|
|
||||||
import {
|
import {
|
||||||
Select,
|
Select,
|
||||||
SelectContent,
|
SelectContent,
|
||||||
@ -33,9 +23,9 @@ import {
|
|||||||
SelectValue
|
SelectValue
|
||||||
} from '@/components/ui/select';
|
} from '@/components/ui/select';
|
||||||
import { useManageCurrencyContext } from '../hooks/useManageCurrencyContext';
|
import { useManageCurrencyContext } from '../hooks/useManageCurrencyContext';
|
||||||
import { prefix } from 'stylis';
|
|
||||||
import { doSaveLogActivity } from '@/actions/GlobalActions';
|
import { doSaveLogActivity } from '@/actions/GlobalActions';
|
||||||
import { RefreshCw } from 'lucide-react';
|
import { RefreshCw } from 'lucide-react';
|
||||||
|
import { initialStateCurrency, validateFormCurrency } from './Types';
|
||||||
interface CurrencyProps {
|
interface CurrencyProps {
|
||||||
ID: string;
|
ID: string;
|
||||||
name: string;
|
name: string;
|
||||||
@ -50,27 +40,15 @@ const AddDialog = () => {
|
|||||||
const { PostData, GetData } = useCallApi();
|
const { PostData, GetData } = useCallApi();
|
||||||
const parsedUser = getAuth()?.user;
|
const parsedUser = getAuth()?.user;
|
||||||
const [currencies, setCurrencies] = useState<CurrencyProps[]>([]);
|
const [currencies, setCurrencies] = useState<CurrencyProps[]>([]);
|
||||||
const [open, setOpen] = useState(false);
|
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
const [alert, setAlert] = useState({
|
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||||
show: false,
|
const [formField, setFormField] = useState(initialStateCurrency);
|
||||||
message: ''
|
|
||||||
});
|
|
||||||
const initialState = {
|
|
||||||
code: '',
|
|
||||||
name: '',
|
|
||||||
prefix: '',
|
|
||||||
status: '',
|
|
||||||
created_by: '',
|
|
||||||
created_at: ''
|
|
||||||
};
|
|
||||||
const [formField, setFormField] = useState(initialState);
|
|
||||||
const created_time = new Date();
|
const created_time = new Date();
|
||||||
const formattedTime = created_time.toISOString().slice(0, 19).replace('T', ' ');
|
const formattedTime = created_time.toISOString().slice(0, 19).replace('T', ' ');
|
||||||
|
|
||||||
const resetForm = () => {
|
const resetForm = () => {
|
||||||
setFormField(initialState);
|
setFormField(initialStateCurrency);
|
||||||
setAlert({ show: false, message: '' });
|
setErrors({});
|
||||||
};
|
};
|
||||||
|
|
||||||
const doCreateCurrency = useCallback(
|
const doCreateCurrency = useCallback(
|
||||||
@ -94,8 +72,7 @@ const AddDialog = () => {
|
|||||||
doSaveLogActivity(createActivity);
|
doSaveLogActivity(createActivity);
|
||||||
reload();
|
reload();
|
||||||
} else {
|
} else {
|
||||||
toast.error('Error Create Currency');
|
toast.error(response?.message);
|
||||||
setAlert({ show: true, message: response?.message });
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast.error('Something went wrong');
|
toast.error('Something went wrong');
|
||||||
@ -109,19 +86,11 @@ const AddDialog = () => {
|
|||||||
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
if (
|
if (!validateFormCurrency(formField, setErrors)) {
|
||||||
formField.code === '' ||
|
|
||||||
formField.name === '' ||
|
|
||||||
formField.prefix === '' ||
|
|
||||||
formField.status === ''
|
|
||||||
) {
|
|
||||||
setAlert({ show: true, message: 'Please fill in all required fields.' });
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
doCreateCurrency(e);
|
doCreateCurrency(e);
|
||||||
// console.log(formField);
|
|
||||||
setAlert({ show: false, message: '' });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -144,17 +113,11 @@ const AddDialog = () => {
|
|||||||
<Dialog open={showAddDialog} onOpenChange={(open) => handleAddDialog(open)}>
|
<Dialog open={showAddDialog} onOpenChange={(open) => handleAddDialog(open)}>
|
||||||
<DialogContent className="container-fixed max-w-[768px] flex flex-col p-5 overflow-hidden">
|
<DialogContent className="container-fixed max-w-[768px] flex flex-col p-5 overflow-hidden">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>Cuurency - Create</DialogTitle>
|
<DialogTitle>Currency - Create</DialogTitle>
|
||||||
<DialogDescription></DialogDescription>
|
<DialogDescription></DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<DialogBody ref={parentRef}>
|
<DialogBody ref={parentRef}>
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
{alert.show && (
|
|
||||||
<Alert variant="danger">
|
|
||||||
<h3>{alert.message}</h3>
|
|
||||||
</Alert>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<form onSubmit={handleSubmit}>
|
<form onSubmit={handleSubmit}>
|
||||||
<div className="card-body grid gap-5">
|
<div className="card-body grid gap-5">
|
||||||
<div className="grid grid-cols-8 gap-2 w-full items-center">
|
<div className="grid grid-cols-8 gap-2 w-full items-center">
|
||||||
@ -163,14 +126,20 @@ const AddDialog = () => {
|
|||||||
</label>
|
</label>
|
||||||
|
|
||||||
<Input
|
<Input
|
||||||
className="input col-span-6"
|
className={`input col-span-6 ${errors.code ? 'border-red-500' : ''}`}
|
||||||
type="text"
|
type="text"
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
value={formField.code}
|
value={formField.code}
|
||||||
onChange={({ target }) =>
|
onChange={({ target }) => {
|
||||||
setFormField((prev) => ({ ...prev, code: target.value }))
|
setFormField((prev) => ({ ...prev, code: target.value }));
|
||||||
}
|
setErrors((prev) => ({ ...prev, code: '' }));
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
|
{errors.code && (
|
||||||
|
<span className="text-red-500 text-xs mt-1 col-span-8 ml-[calc(25%+0.5rem)]">
|
||||||
|
{errors.code}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="grid grid-cols-8 gap-2 w-full items-center">
|
<div className="grid grid-cols-8 gap-2 w-full items-center">
|
||||||
<label className="form-label flex items-center gap-1 col-span-2">
|
<label className="form-label flex items-center gap-1 col-span-2">
|
||||||
@ -178,14 +147,20 @@ const AddDialog = () => {
|
|||||||
</label>
|
</label>
|
||||||
|
|
||||||
<Input
|
<Input
|
||||||
className="input col-span-6"
|
className={`input col-span-6 ${errors.name ? 'border-red-500' : ''}`}
|
||||||
type="text"
|
type="text"
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
value={formField.name}
|
value={formField.name}
|
||||||
onChange={({ target }) =>
|
onChange={({ target }) => {
|
||||||
setFormField((prev) => ({ ...prev, name: target.value }))
|
setFormField((prev) => ({ ...prev, name: target.value }));
|
||||||
}
|
setErrors((prev) => ({ ...prev, name: '' }));
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
|
{errors.name && (
|
||||||
|
<span className="text-red-500 text-xs mt-1 col-span-8 ml-[calc(25%+0.5rem)]">
|
||||||
|
{errors.name}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="grid grid-cols-8 gap-2 w-full items-center">
|
<div className="grid grid-cols-8 gap-2 w-full items-center">
|
||||||
<label className="form-label flex items-center gap-1 col-span-2">
|
<label className="form-label flex items-center gap-1 col-span-2">
|
||||||
@ -193,14 +168,20 @@ const AddDialog = () => {
|
|||||||
</label>
|
</label>
|
||||||
|
|
||||||
<Input
|
<Input
|
||||||
className="input col-span-6"
|
className={`input col-span-6 ${errors.prefix ? 'border-red-500' : ''}`}
|
||||||
type="text"
|
type="text"
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
value={formField.prefix}
|
value={formField.prefix}
|
||||||
onChange={({ target }) =>
|
onChange={({ target }) => {
|
||||||
setFormField((prev) => ({ ...prev, prefix: target.value }))
|
setFormField((prev) => ({ ...prev, prefix: target.value }));
|
||||||
}
|
setErrors((prev) => ({ ...prev, prefix: '' }));
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
|
{errors.prefix && (
|
||||||
|
<span className="text-red-500 text-xs mt-1 col-span-8 ml-[calc(25%+0.5rem)]">
|
||||||
|
{errors.prefix}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="grid grid-cols-8 gap-2 w-full items-center">
|
<div className="grid grid-cols-8 gap-2 w-full items-center">
|
||||||
@ -211,11 +192,12 @@ const AddDialog = () => {
|
|||||||
<div className="col-span-6">
|
<div className="col-span-6">
|
||||||
<Select
|
<Select
|
||||||
value={formField.status}
|
value={formField.status}
|
||||||
onValueChange={(value) =>
|
onValueChange={(value) => {
|
||||||
setFormField((prev) => ({ ...prev, status: value }))
|
setFormField((prev) => ({ ...prev, status: value }));
|
||||||
}
|
setErrors((prev) => ({ ...prev, status: '' }));
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<SelectTrigger className="w-full">
|
<SelectTrigger className={`w-full ${errors.status && 'border-red-500'}`}>
|
||||||
<SelectValue placeholder="Select" />
|
<SelectValue placeholder="Select" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
@ -223,12 +205,12 @@ const AddDialog = () => {
|
|||||||
<SelectItem value="N">Inactive</SelectItem>
|
<SelectItem value="N">Inactive</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
|
{errors.status && (
|
||||||
|
<span className="text-red-500 text-xs mt-1">{errors.status}</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex justify-end gap-5">
|
<div className="flex justify-end gap-5">
|
||||||
<Button type="button" variant="outline" onClick={resetForm}>
|
|
||||||
Reset
|
|
||||||
</Button>
|
|
||||||
<Button variant="default" type="submit" disabled={isSubmitting}>
|
<Button variant="default" type="submit" disabled={isSubmitting}>
|
||||||
{isSubmitting ? (
|
{isSubmitting ? (
|
||||||
<RefreshCw className="animate-spin h-8 w-8 text-white mx-3" />
|
<RefreshCw className="animate-spin h-8 w-8 text-white mx-3" />
|
||||||
|
|||||||
@ -15,16 +15,6 @@ import {
|
|||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { NumericFormat } from 'react-number-format';
|
import { NumericFormat } from 'react-number-format';
|
||||||
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
|
|
||||||
import {
|
|
||||||
Command,
|
|
||||||
CommandEmpty,
|
|
||||||
CommandGroup,
|
|
||||||
CommandInput,
|
|
||||||
CommandItem,
|
|
||||||
CommandList
|
|
||||||
} from '@/components/ui/command';
|
|
||||||
import { set } from 'date-fns';
|
|
||||||
import {
|
import {
|
||||||
Select,
|
Select,
|
||||||
SelectContent,
|
SelectContent,
|
||||||
@ -35,6 +25,7 @@ import {
|
|||||||
import { useManageCurrencyContext } from '../hooks/useManageCurrencyContext';
|
import { useManageCurrencyContext } from '../hooks/useManageCurrencyContext';
|
||||||
import { doSaveLogActivity } from '@/actions/GlobalActions';
|
import { doSaveLogActivity } from '@/actions/GlobalActions';
|
||||||
import { RefreshCw } from 'lucide-react';
|
import { RefreshCw } from 'lucide-react';
|
||||||
|
import { initialStateCurrency, validateFormCurrency } from './Types';
|
||||||
interface CurrencyProps {
|
interface CurrencyProps {
|
||||||
ID: string;
|
ID: string;
|
||||||
name: string;
|
name: string;
|
||||||
@ -49,28 +40,16 @@ const EditDialog = () => {
|
|||||||
const { PostData, GetData, PutData } = useCallApi();
|
const { PostData, GetData, PutData } = useCallApi();
|
||||||
const parsedUser = getAuth()?.user;
|
const parsedUser = getAuth()?.user;
|
||||||
const [currencies, setCurrencies] = useState<CurrencyProps[]>([]);
|
const [currencies, setCurrencies] = useState<CurrencyProps[]>([]);
|
||||||
const [open, setOpen] = useState(false);
|
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [alert, setAlert] = useState({
|
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||||
show: false,
|
const [formField, setFormField] = useState(initialStateCurrency);
|
||||||
message: ''
|
|
||||||
});
|
|
||||||
const initialState = {
|
|
||||||
code: '',
|
|
||||||
name: '',
|
|
||||||
prefix: '',
|
|
||||||
status: '',
|
|
||||||
created_by: '',
|
|
||||||
created_at: ''
|
|
||||||
};
|
|
||||||
const [formField, setFormField] = useState(initialState);
|
|
||||||
const updated_time = new Date();
|
const updated_time = new Date();
|
||||||
const formattedTime = updated_time.toISOString().slice(0, 19).replace('T', ' ');
|
const formattedTime = updated_time.toISOString().slice(0, 19).replace('T', ' ');
|
||||||
|
|
||||||
const resetForm = () => {
|
const resetForm = () => {
|
||||||
setFormField(initialState);
|
setFormField(initialStateCurrency);
|
||||||
setAlert({ show: false, message: '' });
|
setErrors({});
|
||||||
};
|
};
|
||||||
|
|
||||||
const doUpdateCurrency = useCallback(
|
const doUpdateCurrency = useCallback(
|
||||||
@ -78,6 +57,11 @@ const EditDialog = () => {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setIsSubmitting(true);
|
setIsSubmitting(true);
|
||||||
|
|
||||||
|
if (!validateFormCurrency(formField, setErrors)) {
|
||||||
|
setIsSubmitting(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await PutData(
|
const response = await PutData(
|
||||||
`${API_URL}/dashboard/currency/${selectedCurrency}`,
|
`${API_URL}/dashboard/currency/${selectedCurrency}`,
|
||||||
@ -97,8 +81,7 @@ const EditDialog = () => {
|
|||||||
doSaveLogActivity(createActivity);
|
doSaveLogActivity(createActivity);
|
||||||
reload();
|
reload();
|
||||||
} else {
|
} else {
|
||||||
toast.error('Error Create Currency');
|
toast.error(response?.message);
|
||||||
setAlert({ show: true, message: response?.message });
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast.error('Something went wrong');
|
toast.error('Something went wrong');
|
||||||
@ -115,7 +98,6 @@ const EditDialog = () => {
|
|||||||
const fetchData = GetData(`${API_URL}/dashboard/currency/${id}`, { id });
|
const fetchData = GetData(`${API_URL}/dashboard/currency/${id}`, { id });
|
||||||
const [response] = await Promise.all([fetchData, minDelay]);
|
const [response] = await Promise.all([fetchData, minDelay]);
|
||||||
|
|
||||||
// console.log('Transaction Type: ', response?.data);
|
|
||||||
if (response?.status) {
|
if (response?.status) {
|
||||||
setFormField((prev) => ({
|
setFormField((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
@ -126,7 +108,6 @@ const EditDialog = () => {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
// console.log('form fieldd Transaction Type: ', formField);
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -160,12 +141,6 @@ const EditDialog = () => {
|
|||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<DialogBody ref={parentRef}>
|
<DialogBody ref={parentRef}>
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
{alert.show && (
|
|
||||||
<Alert variant="danger">
|
|
||||||
<h3>{alert.message}</h3>
|
|
||||||
</Alert>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{isLoading ? (
|
{isLoading ? (
|
||||||
<div className="flex flex-col items-center justify-center p-8">
|
<div className="flex flex-col items-center justify-center p-8">
|
||||||
<div className="animate-pulse flex space-x-4 w-full">
|
<div className="animate-pulse flex space-x-4 w-full">
|
||||||
@ -182,74 +157,104 @@ const EditDialog = () => {
|
|||||||
) : (
|
) : (
|
||||||
<form onSubmit={doUpdateCurrency}>
|
<form onSubmit={doUpdateCurrency}>
|
||||||
<div className="card-body grid gap-5">
|
<div className="card-body grid gap-5">
|
||||||
<div className="w-full">
|
<div className="grid grid-cols-8 gap-2 w-full items-center">
|
||||||
<label className="form-label">
|
<label className="form-label flex items-center gap-1 col-span-2">
|
||||||
Code
|
Code<span className="text-red-500">*</span>
|
||||||
<span className="text-red-500">*</span>
|
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<Input
|
<Input
|
||||||
|
className={`input col-span-6 ${errors.code ? 'border-red-500' : ''}`}
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Code"
|
autoComplete="off"
|
||||||
value={formField.code}
|
value={formField.code}
|
||||||
onChange={(e) => setFormField((prev) => ({ ...prev, code: e.target.value }))}
|
onChange={({ target }) => {
|
||||||
|
setFormField((prev) => ({ ...prev, code: target.value }));
|
||||||
|
setErrors((prev) => ({ ...prev, code: '' }));
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
|
{errors.code && (
|
||||||
|
<span className="text-red-500 text-xs mt-1 col-span-8 ml-[calc(25%+0.5rem)]">
|
||||||
|
{errors.code}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full">
|
|
||||||
<label className="form-label">
|
<div className="grid grid-cols-8 gap-2 w-full items-center">
|
||||||
Name
|
<label className="form-label flex items-center gap-1 col-span-2">
|
||||||
<span className="text-red-500">*</span>
|
Name<span className="text-red-500">*</span>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<Input
|
<Input
|
||||||
|
className={`input col-span-6 ${errors.name ? 'border-red-500' : ''}`}
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Code"
|
autoComplete="off"
|
||||||
value={formField.name}
|
value={formField.name}
|
||||||
onChange={(e) => setFormField((prev) => ({ ...prev, name: e.target.value }))}
|
onChange={({ target }) => {
|
||||||
|
setFormField((prev) => ({ ...prev, name: target.value }));
|
||||||
|
setErrors((prev) => ({ ...prev, name: '' }));
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
|
{errors.name && (
|
||||||
|
<span className="text-red-500 text-xs mt-1 col-span-8 ml-[calc(25%+0.5rem)]">
|
||||||
|
{errors.name}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="w-full">
|
<div className="grid grid-cols-8 gap-2 w-full items-center">
|
||||||
<label className="form-label">
|
<label className="form-label flex items-center gap-1 col-span-2">
|
||||||
Prefix
|
Prefix<span className="text-red-500">*</span>
|
||||||
<span className="text-red-500">*</span>
|
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<Input
|
<Input
|
||||||
|
className={`input col-span-6 ${errors.prefix ? 'border-red-500' : ''}`}
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Code"
|
autoComplete="off"
|
||||||
value={formField.prefix}
|
value={formField.prefix}
|
||||||
onChange={(e) =>
|
onChange={({ target }) => {
|
||||||
setFormField((prev) => ({ ...prev, prefix: e.target.value }))
|
setFormField((prev) => ({ ...prev, prefix: target.value }));
|
||||||
}
|
setErrors((prev) => ({ ...prev, prefix: '' }));
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
|
{errors.prefix && (
|
||||||
|
<span className="text-red-500 text-xs mt-1 col-span-8 ml-[calc(25%+0.5rem)]">
|
||||||
|
{errors.prefix}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="w-full">
|
<div className="grid grid-cols-8 gap-2 w-full items-center">
|
||||||
<label className="form-label">
|
<label className="form-label flex items-center gap-1 col-span-2">
|
||||||
Status
|
Status<span className="text-red-500">*</span>
|
||||||
<span className="text-red-500">*</span>
|
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<Select
|
<div className="col-span-6">
|
||||||
value={formField.status}
|
<Select
|
||||||
onValueChange={(value) =>
|
value={formField.status}
|
||||||
setFormField((prev) => ({ ...prev, status: value }))
|
onValueChange={(value) => {
|
||||||
}
|
setFormField((prev) => ({ ...prev, status: value }));
|
||||||
>
|
setErrors((prev) => ({ ...prev, status: '' }));
|
||||||
<SelectTrigger className="w-full">
|
}}
|
||||||
<SelectValue placeholder="Select" defaultValue={formField.status} />
|
>
|
||||||
</SelectTrigger>
|
<SelectTrigger className={`w-full ${errors.status && 'border-red-500'}`}>
|
||||||
<SelectContent>
|
<SelectValue placeholder="Select" />
|
||||||
<SelectItem value="Y">Active</SelectItem>
|
</SelectTrigger>
|
||||||
<SelectItem value="N">Inactive</SelectItem>
|
<SelectContent>
|
||||||
</SelectContent>
|
<SelectItem value="Y">Active</SelectItem>
|
||||||
</Select>
|
<SelectItem value="N">Inactive</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
{errors.status && (
|
||||||
|
<span className="text-red-500 text-xs mt-1">{errors.status}</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex justify-end gap-5">
|
<div className="flex justify-end gap-5">
|
||||||
<Button variant="default" type="submit" disabled={isSubmitting}>
|
<Button variant="default" type="submit" disabled={isSubmitting}>
|
||||||
{isSubmitting ? (
|
{isSubmitting ? (
|
||||||
<RefreshCw className="animate-spin h-8 w-8 text-white mx-7" />
|
<RefreshCw className="animate-spin h-8 w-8 text-white mx-3" />
|
||||||
) : (
|
) : (
|
||||||
'Save Changes'
|
'Create'
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
47
src/pages/master/currency/blocks/Types.ts
Normal file
47
src/pages/master/currency/blocks/Types.ts
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import { toast } from 'sonner';
|
||||||
|
|
||||||
|
export const initialStateCurrency: {
|
||||||
|
code: string;
|
||||||
|
name: string;
|
||||||
|
prefix: string;
|
||||||
|
status: string;
|
||||||
|
created_by: string;
|
||||||
|
created_at: string;
|
||||||
|
} = {
|
||||||
|
code: '',
|
||||||
|
name: '',
|
||||||
|
prefix: '',
|
||||||
|
status: '',
|
||||||
|
created_by: '',
|
||||||
|
created_at: ''
|
||||||
|
};
|
||||||
|
|
||||||
|
export const validateFormCurrency = (
|
||||||
|
formField: typeof initialStateCurrency,
|
||||||
|
setErrors: React.Dispatch<React.SetStateAction<Record<string, string>>>
|
||||||
|
) => {
|
||||||
|
const requiredFields = [
|
||||||
|
{ key: 'code', label: 'Code' },
|
||||||
|
{ key: 'name', label: 'Name' },
|
||||||
|
{ key: 'prefix', label: 'Prefix' },
|
||||||
|
{ key: 'status', label: 'Status' }
|
||||||
|
];
|
||||||
|
|
||||||
|
const newErrors: Record<string, string> = {};
|
||||||
|
let isValid = true;
|
||||||
|
|
||||||
|
requiredFields.forEach(({ key, label }) => {
|
||||||
|
if (
|
||||||
|
formField[key as keyof typeof formField] === '' ||
|
||||||
|
formField[key as keyof typeof formField] === null ||
|
||||||
|
formField[key as keyof typeof formField] === undefined
|
||||||
|
) {
|
||||||
|
newErrors[key] = `${label} is required`;
|
||||||
|
toast.error(`${label} is required`);
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
setErrors(newErrors);
|
||||||
|
return isValid;
|
||||||
|
};
|
||||||
@ -155,7 +155,6 @@ const ManageCurrencyContextProvider = ({ children }: { children: React.ReactNode
|
|||||||
order_direction: sorting[0].desc ? 'ASC' : 'DESC'
|
order_direction: sorting[0].desc ? 'ASC' : 'DESC'
|
||||||
// filter: JSON.stringify(filter)
|
// filter: JSON.stringify(filter)
|
||||||
});
|
});
|
||||||
// console.log(response?.data);
|
|
||||||
return { data: response?.data.list, totalCount: response?.data.total_count };
|
return { data: response?.data.list, totalCount: response?.data.total_count };
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -181,7 +180,7 @@ const ManageCurrencyContextProvider = ({ children }: { children: React.ReactNode
|
|||||||
pagination={{ size: 10 }}
|
pagination={{ size: 10 }}
|
||||||
layout={{ card: true }}
|
layout={{ card: true }}
|
||||||
toolbar={<ListToolbar />}
|
toolbar={<ListToolbar />}
|
||||||
sorting={[{ id: 'ID', desc: true }]}
|
sorting={[{ id: 'created_at', desc: false }]}
|
||||||
serverSide={true}
|
serverSide={true}
|
||||||
onFetchData={({ pageIndex, pageSize, sorting }) =>
|
onFetchData={({ pageIndex, pageSize, sorting }) =>
|
||||||
doGetCurrency(pageIndex, pageSize, sorting)
|
doGetCurrency(pageIndex, pageSize, sorting)
|
||||||
|
|||||||
@ -25,6 +25,7 @@ import {
|
|||||||
} from '@/components/ui/select';
|
} from '@/components/ui/select';
|
||||||
import { doSaveLogActivity } from '@/actions/GlobalActions';
|
import { doSaveLogActivity } from '@/actions/GlobalActions';
|
||||||
import { RefreshCw } from 'lucide-react';
|
import { RefreshCw } from 'lucide-react';
|
||||||
|
import { initialStateReward, validateFormReward } from './Types';
|
||||||
|
|
||||||
const API_URL = apiConfig.service_master_data;
|
const API_URL = apiConfig.service_master_data;
|
||||||
|
|
||||||
@ -34,28 +35,16 @@ const AddDialog = () => {
|
|||||||
const { reload } = useDataGrid();
|
const { reload } = useDataGrid();
|
||||||
const { PostData } = useCallApi();
|
const { PostData } = useCallApi();
|
||||||
const parsedUser = getAuth()?.user;
|
const parsedUser = getAuth()?.user;
|
||||||
const [alert, setAlert] = useState({
|
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||||
show: false,
|
|
||||||
message: ''
|
|
||||||
});
|
|
||||||
|
|
||||||
const initialState = {
|
const [formField, setFormField] = useState(initialStateReward);
|
||||||
name: '',
|
|
||||||
type: '',
|
|
||||||
amount: 0,
|
|
||||||
status: '',
|
|
||||||
created_by: '',
|
|
||||||
created_at: ''
|
|
||||||
};
|
|
||||||
|
|
||||||
const [formField, setFormField] = useState(initialState);
|
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
const created_time = new Date();
|
const created_time = new Date();
|
||||||
const formattedTime = created_time.toISOString().slice(0, 19).replace('T', ' ');
|
const formattedTime = created_time.toISOString().slice(0, 19).replace('T', ' ');
|
||||||
|
|
||||||
const resetForm = () => {
|
const resetForm = () => {
|
||||||
setFormField(initialState);
|
setFormField(initialStateReward);
|
||||||
setAlert({ show: false, message: '' });
|
setErrors({});
|
||||||
};
|
};
|
||||||
|
|
||||||
const RewardType = {
|
const RewardType = {
|
||||||
@ -88,8 +77,7 @@ const AddDialog = () => {
|
|||||||
|
|
||||||
doSaveLogActivity(createActivity);
|
doSaveLogActivity(createActivity);
|
||||||
} else {
|
} else {
|
||||||
toast.error('Failed to create reward.');
|
toast.error(response?.message);
|
||||||
setAlert({ show: true, message: response?.message });
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast.error('Something went wrong, please try again.');
|
toast.error('Something went wrong, please try again.');
|
||||||
@ -103,19 +91,11 @@ const AddDialog = () => {
|
|||||||
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
if (
|
if (!validateFormReward(formField, setErrors)) {
|
||||||
formField.name.trim() === '' ||
|
|
||||||
formField.type.trim() === '' ||
|
|
||||||
formField.amount === 0 ||
|
|
||||||
formField.status.trim() === ''
|
|
||||||
) {
|
|
||||||
setAlert({ show: true, message: 'Please fill name field.' });
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
doCreateReward(e);
|
doCreateReward(e);
|
||||||
// console.log(formField);
|
|
||||||
setAlert({ show: false, message: '' });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -135,43 +115,52 @@ const AddDialog = () => {
|
|||||||
}, [showAddDialog]);
|
}, [showAddDialog]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={showAddDialog} onOpenChange={(open) => handleAddDialog(open)}>
|
<Dialog open={showAddDialog} onOpenChange={handleAddDialog}>
|
||||||
<DialogContent className="container-fixed max-w-[768px] flex flex-col p-5 overflow-hidden">
|
<DialogContent className="container-fixed max-w-[768px] flex flex-col p-5 overflow-hidden">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>Reward - Create</DialogTitle>
|
<DialogTitle>Reward - Create</DialogTitle>
|
||||||
<DialogDescription></DialogDescription>
|
<DialogDescription />
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<DialogBody ref={parentRef}>
|
<DialogBody ref={parentRef}>
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
{alert.show && <Alert variant="danger">{alert.message}</Alert>}
|
|
||||||
<form onSubmit={handleSubmit}>
|
<form onSubmit={handleSubmit}>
|
||||||
<div className="card-body grid gap-5">
|
<div className="card-body grid gap-5">
|
||||||
<div className="grid grid-cols-8 gap-2 w-full items-center">
|
{/* Reward Name */}
|
||||||
|
<div className="grid grid-cols-8 gap-2 items-center">
|
||||||
<label className="form-label flex items-center gap-1 col-span-2">
|
<label className="form-label flex items-center gap-1 col-span-2">
|
||||||
Reward Name<span className="text-red-500">*</span>
|
Reward Name<span className="text-red-500">*</span>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<Input
|
<Input
|
||||||
className="input col-span-6"
|
className={`input col-span-6 ${errors.name ? 'border-red-500' : ''}`}
|
||||||
type="text"
|
type="text"
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
value={formField.name}
|
value={formField.name}
|
||||||
onChange={({ target }) =>
|
onChange={({ target }) => {
|
||||||
setFormField((prev) => ({ ...prev, name: target.value }))
|
setFormField((prev) => ({ ...prev, name: target.value }));
|
||||||
}
|
setErrors((prev) => ({ ...prev, name: '' }));
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
|
{errors.name && (
|
||||||
|
<span className="text-red-500 text-xs mt-1 col-span-8 ml-[calc(25%+0.5rem)]">
|
||||||
|
{errors.name}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="grid grid-cols-8 gap-2 w-full items-center">
|
|
||||||
|
{/* Reward Type */}
|
||||||
|
<div className="grid grid-cols-8 gap-2 items-center">
|
||||||
<label className="form-label flex items-center gap-1 col-span-2">
|
<label className="form-label flex items-center gap-1 col-span-2">
|
||||||
Reward Type<span className="text-red-500">*</span>
|
Reward Type<span className="text-red-500">*</span>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<div className="col-span-6">
|
<div className="col-span-6">
|
||||||
<Select
|
<Select
|
||||||
value={formField.type}
|
value={formField.type}
|
||||||
onValueChange={(value) => setFormField((prev) => ({ ...prev, type: value }))}
|
onValueChange={(value) => {
|
||||||
|
setFormField((prev) => ({ ...prev, type: value }));
|
||||||
|
setErrors((prev) => ({ ...prev, type: '' }));
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<SelectTrigger className="w-full">
|
<SelectTrigger className={`w-full ${errors.type ? 'border-red-500' : ''}`}>
|
||||||
<SelectValue placeholder="Select Type" />
|
<SelectValue placeholder="Select Type" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
@ -185,14 +174,20 @@ const AddDialog = () => {
|
|||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
|
{errors.type && (
|
||||||
|
<span className="text-red-500 text-xs mt-1 col-span-8 ml-[calc(25%+0.5rem)]">
|
||||||
|
{errors.type}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="grid grid-cols-8 gap-2 w-full items-center">
|
|
||||||
|
{/* Amount */}
|
||||||
|
<div className="grid grid-cols-8 gap-2 items-center">
|
||||||
<label className="form-label flex items-center gap-1 col-span-2">
|
<label className="form-label flex items-center gap-1 col-span-2">
|
||||||
Amount<span className="text-red-500">*</span>
|
Amount<span className="text-red-500">*</span>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<NumericFormat
|
<NumericFormat
|
||||||
className="input col-span-6"
|
className={`input col-span-6 ${errors.amount ? 'border-red-500' : ''}`}
|
||||||
value={formField.amount}
|
value={formField.amount}
|
||||||
thousandSeparator="."
|
thousandSeparator="."
|
||||||
decimalSeparator=","
|
decimalSeparator=","
|
||||||
@ -200,34 +195,49 @@ const AddDialog = () => {
|
|||||||
onValueChange={(values) => {
|
onValueChange={(values) => {
|
||||||
setFormField((prev) => ({
|
setFormField((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
amount: values.floatValue || 0
|
amount: values.floatValue ?? null
|
||||||
}));
|
}));
|
||||||
|
setErrors((prev) => ({ ...prev, amount: '' }));
|
||||||
}}
|
}}
|
||||||
placeholder="Enter Amount"
|
placeholder="Enter Amount"
|
||||||
/>
|
/>
|
||||||
|
{errors.amount && (
|
||||||
|
<span className="text-red-500 text-xs mt-1 col-span-8 ml-[calc(25%+0.5rem)]">
|
||||||
|
{errors.amount}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="grid grid-cols-8 gap-2 w-full items-center">
|
|
||||||
|
{/* Status */}
|
||||||
|
<div className="grid grid-cols-8 gap-2 items-center">
|
||||||
<label className="form-label flex items-center gap-1 col-span-2">
|
<label className="form-label flex items-center gap-1 col-span-2">
|
||||||
Status<span className="text-red-500">*</span>
|
Status<span className="text-red-500">*</span>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<div className="col-span-6">
|
<div className="col-span-6">
|
||||||
<Select
|
<Select
|
||||||
value={formField.status}
|
value={formField.status}
|
||||||
onValueChange={(value) =>
|
onValueChange={(value) => {
|
||||||
setFormField((prev) => ({ ...prev, status: value }))
|
setFormField((prev) => ({ ...prev, status: value }));
|
||||||
}
|
setErrors((prev) => ({ ...prev, status: '' }));
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<SelectTrigger className="w-full">
|
<SelectTrigger className={`w-full ${errors.status ? 'border-red-500' : ''}`}>
|
||||||
<SelectValue placeholder="Select" />
|
<SelectValue placeholder="Select" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
<SelectItem value="Y">Active</SelectItem>
|
<SelectItem value="Y">Active</SelectItem>
|
||||||
<SelectItem value="N">InActive</SelectItem>
|
<SelectItem value="N">Inactive</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
|
{errors.status && (
|
||||||
|
<span className="text-red-500 text-xs mt-1 col-span-8 ml-[calc(25%+0.5rem)]">
|
||||||
|
{errors.status}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Actions */}
|
||||||
<div className="flex justify-end gap-5">
|
<div className="flex justify-end gap-5">
|
||||||
<Button type="button" variant="outline" onClick={resetForm}>
|
<Button type="button" variant="outline" onClick={resetForm}>
|
||||||
Reset
|
Reset
|
||||||
|
|||||||
@ -25,6 +25,7 @@ import {
|
|||||||
import { useManageRewardContext } from '../hooks/useManageRewardContext';
|
import { useManageRewardContext } from '../hooks/useManageRewardContext';
|
||||||
import { doSaveLogActivity } from '@/actions/GlobalActions';
|
import { doSaveLogActivity } from '@/actions/GlobalActions';
|
||||||
import { RefreshCw } from 'lucide-react';
|
import { RefreshCw } from 'lucide-react';
|
||||||
|
import { initialStateReward, validateFormReward } from './Types';
|
||||||
|
|
||||||
const API_URL = apiConfig.service_master_data;
|
const API_URL = apiConfig.service_master_data;
|
||||||
|
|
||||||
@ -36,27 +37,15 @@ const EditDialog = () => {
|
|||||||
const parsedUser = getAuth()?.user;
|
const parsedUser = getAuth()?.user;
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
const [alert, setAlert] = useState({
|
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||||
show: false,
|
|
||||||
message: ''
|
|
||||||
});
|
|
||||||
|
|
||||||
const initialState = {
|
const [formField, setFormField] = useState(initialStateReward);
|
||||||
name: '',
|
|
||||||
type: '',
|
|
||||||
amount: 0,
|
|
||||||
status: '',
|
|
||||||
updated_by: '',
|
|
||||||
updated_at: ''
|
|
||||||
};
|
|
||||||
|
|
||||||
const [formField, setFormField] = useState(initialState);
|
|
||||||
const updated_time = new Date();
|
const updated_time = new Date();
|
||||||
const formattedTime = updated_time.toISOString().slice(0, 19).replace('T', ' ');
|
const formattedTime = updated_time.toISOString().slice(0, 19).replace('T', ' ');
|
||||||
|
|
||||||
const resetForm = () => {
|
const resetForm = () => {
|
||||||
setFormField(initialState);
|
setFormField(initialStateReward);
|
||||||
setAlert({ show: false, message: '' });
|
setErrors({});
|
||||||
};
|
};
|
||||||
|
|
||||||
const RewardType = {
|
const RewardType = {
|
||||||
@ -73,6 +62,11 @@ const EditDialog = () => {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setIsSubmitting(true);
|
setIsSubmitting(true);
|
||||||
|
|
||||||
|
if (!validateFormReward(formField, setErrors)) {
|
||||||
|
setIsSubmitting(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await PutData(`${API_URL}/reward/update/${selectedReward}`, formField);
|
const response = await PutData(`${API_URL}/reward/update/${selectedReward}`, formField);
|
||||||
|
|
||||||
@ -89,8 +83,7 @@ const EditDialog = () => {
|
|||||||
|
|
||||||
doSaveLogActivity(editActivity);
|
doSaveLogActivity(editActivity);
|
||||||
} else {
|
} else {
|
||||||
toast.error('Error Update Reward');
|
toast.error(response?.message);
|
||||||
setAlert({ show: true, message: response?.message });
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast.error('Something went wrong, please try again.');
|
toast.error('Something went wrong, please try again.');
|
||||||
@ -106,7 +99,6 @@ const EditDialog = () => {
|
|||||||
const minDelay = new Promise((resolve) => setTimeout(resolve, 300));
|
const minDelay = new Promise((resolve) => setTimeout(resolve, 300));
|
||||||
const fetchData = GetData(`${API_URL}/reward/getdata/${id}`, { id });
|
const fetchData = GetData(`${API_URL}/reward/getdata/${id}`, { id });
|
||||||
const [response] = await Promise.all([fetchData, minDelay]);
|
const [response] = await Promise.all([fetchData, minDelay]);
|
||||||
// console.log('API Response:', response);
|
|
||||||
|
|
||||||
if (response?.status) {
|
if (response?.status) {
|
||||||
setFormField((prev) => ({
|
setFormField((prev) => ({
|
||||||
@ -120,24 +112,6 @@ const EditDialog = () => {
|
|||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// const handleUpdate = (e: React.FormEvent<HTMLFormElement>) => {
|
|
||||||
// e.preventDefault();
|
|
||||||
|
|
||||||
// if (
|
|
||||||
// formField.name === '' ||
|
|
||||||
// formField.type === '' ||
|
|
||||||
// formField.amount === 0 ||
|
|
||||||
// formField.status === ''
|
|
||||||
// ) {
|
|
||||||
// setAlert({ show: true, message: 'Please fill in all required fields.' });
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// doUpdateReward(e);
|
|
||||||
// // console.log(formField);
|
|
||||||
// setAlert({ show: false, message: '' });
|
|
||||||
// };
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedReward) {
|
if (selectedReward) {
|
||||||
doFetchData(selectedReward);
|
doFetchData(selectedReward);
|
||||||
@ -169,8 +143,6 @@ const EditDialog = () => {
|
|||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<DialogBody ref={parentRef}>
|
<DialogBody ref={parentRef}>
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
{alert.show && <Alert variant="danger">{alert.message}</Alert>}
|
|
||||||
|
|
||||||
{isLoading ? (
|
{isLoading ? (
|
||||||
<div className="flex flex-col items-center justify-center p-8">
|
<div className="flex flex-col items-center justify-center p-8">
|
||||||
<div className="animate-pulse flex space-x-4 w-full">
|
<div className="animate-pulse flex space-x-4 w-full">
|
||||||
@ -187,31 +159,42 @@ const EditDialog = () => {
|
|||||||
) : (
|
) : (
|
||||||
<form onSubmit={doUpdateReward}>
|
<form onSubmit={doUpdateReward}>
|
||||||
<div className="card-body grid gap-5">
|
<div className="card-body grid gap-5">
|
||||||
<div className="grid grid-cols-8 gap-2 w-full items-center">
|
{/* Reward Name */}
|
||||||
|
<div className="grid grid-cols-8 gap-2 items-center">
|
||||||
<label className="form-label flex items-center gap-1 col-span-2">
|
<label className="form-label flex items-center gap-1 col-span-2">
|
||||||
Reward Name<span className="text-red-500">*</span>
|
Reward Name<span className="text-red-500">*</span>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<Input
|
<Input
|
||||||
className="input col-span-6"
|
className={`input col-span-6 ${errors.name ? 'border-red-500' : ''}`}
|
||||||
type="text"
|
type="text"
|
||||||
|
autoComplete="off"
|
||||||
value={formField.name}
|
value={formField.name}
|
||||||
onChange={(e) => setFormField((prev) => ({ ...prev, name: e.target.value }))}
|
onChange={({ target }) => {
|
||||||
|
setFormField((prev) => ({ ...prev, name: target.value }));
|
||||||
|
setErrors((prev) => ({ ...prev, name: '' }));
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
|
{errors.name && (
|
||||||
|
<span className="text-red-500 text-xs mt-1 col-span-8 ml-[calc(25%+0.5rem)]">
|
||||||
|
{errors.name}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="grid grid-cols-8 gap-2 w-full items-center">
|
|
||||||
|
{/* Reward Type */}
|
||||||
|
<div className="grid grid-cols-8 gap-2 items-center">
|
||||||
<label className="form-label flex items-center gap-1 col-span-2">
|
<label className="form-label flex items-center gap-1 col-span-2">
|
||||||
Reward Type<span className="text-red-500">*</span>
|
Reward Type<span className="text-red-500">*</span>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<div className="col-span-6">
|
<div className="col-span-6">
|
||||||
<Select
|
<Select
|
||||||
value={formField.type}
|
value={formField.type}
|
||||||
onValueChange={(value) =>
|
onValueChange={(value) => {
|
||||||
setFormField((prev) => ({ ...prev, type: value }))
|
setFormField((prev) => ({ ...prev, type: value }));
|
||||||
}
|
setErrors((prev) => ({ ...prev, type: '' }));
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<SelectTrigger className="w-full">
|
<SelectTrigger className={`w-full ${errors.type ? 'border-red-500' : ''}`}>
|
||||||
<SelectValue placeholder="Select Type" />
|
<SelectValue placeholder="Select Type" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
@ -225,14 +208,20 @@ const EditDialog = () => {
|
|||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
|
{errors.type && (
|
||||||
|
<span className="text-red-500 text-xs mt-1 col-span-8 ml-[calc(25%+0.5rem)]">
|
||||||
|
{errors.type}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="grid grid-cols-8 gap-2 w-full items-center">
|
|
||||||
|
{/* Amount */}
|
||||||
|
<div className="grid grid-cols-8 gap-2 items-center">
|
||||||
<label className="form-label flex items-center gap-1 col-span-2">
|
<label className="form-label flex items-center gap-1 col-span-2">
|
||||||
Amount<span className="text-red-500">*</span>
|
Amount<span className="text-red-500">*</span>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<NumericFormat
|
<NumericFormat
|
||||||
className="input col-span-6"
|
className={`input col-span-6 ${errors.amount ? 'border-red-500' : ''}`}
|
||||||
value={formField.amount}
|
value={formField.amount}
|
||||||
thousandSeparator="."
|
thousandSeparator="."
|
||||||
decimalSeparator=","
|
decimalSeparator=","
|
||||||
@ -240,40 +229,60 @@ const EditDialog = () => {
|
|||||||
onValueChange={(values) => {
|
onValueChange={(values) => {
|
||||||
setFormField((prev) => ({
|
setFormField((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
amount: values.floatValue || 0
|
amount: values.floatValue ?? null
|
||||||
}));
|
}));
|
||||||
|
setErrors((prev) => ({ ...prev, amount: '' }));
|
||||||
}}
|
}}
|
||||||
placeholder="Enter Amount"
|
placeholder="Enter Amount"
|
||||||
/>
|
/>
|
||||||
|
{errors.amount && (
|
||||||
|
<span className="text-red-500 text-xs mt-1 col-span-8 ml-[calc(25%+0.5rem)]">
|
||||||
|
{errors.amount}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="grid grid-cols-8 gap-2 w-full items-center">
|
|
||||||
|
{/* Status */}
|
||||||
|
<div className="grid grid-cols-8 gap-2 items-center">
|
||||||
<label className="form-label flex items-center gap-1 col-span-2">
|
<label className="form-label flex items-center gap-1 col-span-2">
|
||||||
Status<span className="text-red-500">*</span>
|
Status<span className="text-red-500">*</span>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<div className="col-span-6">
|
<div className="col-span-6">
|
||||||
<Select
|
<Select
|
||||||
value={formField.status}
|
value={formField.status}
|
||||||
onValueChange={(value) =>
|
onValueChange={(value) => {
|
||||||
setFormField((prev) => ({ ...prev, status: value }))
|
setFormField((prev) => ({ ...prev, status: value }));
|
||||||
}
|
setErrors((prev) => ({ ...prev, status: '' }));
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<SelectTrigger className="w-full">
|
<SelectTrigger
|
||||||
<SelectValue placeholder="Select" defaultValue={formField.status} />
|
className={`w-full ${errors.status ? 'border-red-500' : ''}`}
|
||||||
|
>
|
||||||
|
<SelectValue placeholder="Select" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
<SelectItem value="Y">Active</SelectItem>
|
<SelectItem value="Y">Active</SelectItem>
|
||||||
<SelectItem value="N">InActive</SelectItem>
|
<SelectItem value="N">Inactive</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
|
{errors.status && (
|
||||||
|
<span className="text-red-500 text-xs mt-1 col-span-8 ml-[calc(25%+0.5rem)]">
|
||||||
|
{errors.status}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Actions */}
|
||||||
<div className="flex justify-end gap-5">
|
<div className="flex justify-end gap-5">
|
||||||
|
<Button type="button" variant="outline" onClick={resetForm}>
|
||||||
|
Reset
|
||||||
|
</Button>
|
||||||
<Button variant="default" type="submit" disabled={isSubmitting}>
|
<Button variant="default" type="submit" disabled={isSubmitting}>
|
||||||
{isSubmitting ? (
|
{isSubmitting ? (
|
||||||
<RefreshCw className="animate-spin h-8 w-8 text-white mx-7" />
|
<RefreshCw className="animate-spin h-8 w-8 text-white mx-3" />
|
||||||
) : (
|
) : (
|
||||||
'Save Changes'
|
'Create'
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
47
src/pages/master/reward/blocks/Types.ts
Normal file
47
src/pages/master/reward/blocks/Types.ts
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import { toast } from 'sonner';
|
||||||
|
|
||||||
|
export const initialStateReward: {
|
||||||
|
name: string;
|
||||||
|
type: string;
|
||||||
|
amount: number | null;
|
||||||
|
status: string;
|
||||||
|
created_by: string;
|
||||||
|
created_at: string;
|
||||||
|
} = {
|
||||||
|
name: '',
|
||||||
|
type: '',
|
||||||
|
amount: null,
|
||||||
|
status: '',
|
||||||
|
created_by: '',
|
||||||
|
created_at: ''
|
||||||
|
};
|
||||||
|
|
||||||
|
export const validateFormReward = (
|
||||||
|
formField: typeof initialStateReward,
|
||||||
|
setErrors: React.Dispatch<React.SetStateAction<Record<string, string>>>
|
||||||
|
) => {
|
||||||
|
const requiredFields = [
|
||||||
|
{ key: 'name', label: 'Name' },
|
||||||
|
{ key: 'type', label: 'Type' },
|
||||||
|
{ key: 'amount', label: 'Amount' },
|
||||||
|
{ key: 'status', label: 'Status' }
|
||||||
|
];
|
||||||
|
|
||||||
|
const newErrors: Record<string, string> = {};
|
||||||
|
let isValid = true;
|
||||||
|
|
||||||
|
requiredFields.forEach(({ key, label }) => {
|
||||||
|
if (
|
||||||
|
formField[key as keyof typeof formField] === '' ||
|
||||||
|
formField[key as keyof typeof formField] === null ||
|
||||||
|
formField[key as keyof typeof formField] === undefined
|
||||||
|
) {
|
||||||
|
newErrors[key] = `${label} is required`;
|
||||||
|
toast.error(`${label} is required`);
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
setErrors(newErrors);
|
||||||
|
return isValid;
|
||||||
|
};
|
||||||
@ -159,8 +159,6 @@ const ManageRewardContextProvider = ({ children }: { children: React.ReactNode }
|
|||||||
order_direction: sorting[0].desc == false ? 'ASC' : 'DESC',
|
order_direction: sorting[0].desc == false ? 'ASC' : 'DESC',
|
||||||
filter: JSON.stringify(filter)
|
filter: JSON.stringify(filter)
|
||||||
});
|
});
|
||||||
// console.log('API Response:', response?.data.list);
|
|
||||||
// console.log('reward list :', response);
|
|
||||||
return { data: response?.data.list, totalCount: response?.data.total_count };
|
return { data: response?.data.list, totalCount: response?.data.total_count };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fethcing reward', error);
|
console.error('Error fethcing reward', error);
|
||||||
@ -185,7 +183,7 @@ const ManageRewardContextProvider = ({ children }: { children: React.ReactNode }
|
|||||||
pagination={{ size: 5 }}
|
pagination={{ size: 5 }}
|
||||||
toolbar={<ListToolbar />}
|
toolbar={<ListToolbar />}
|
||||||
layout={{ card: true }}
|
layout={{ card: true }}
|
||||||
sorting={[{ id: 'id', desc: false }]}
|
sorting={[{ id: 'created_at', desc: true }]}
|
||||||
serverSide={true}
|
serverSide={true}
|
||||||
onFetchData={({ pageIndex, pageSize, sorting, columnFilters }) =>
|
onFetchData={({ pageIndex, pageSize, sorting, columnFilters }) =>
|
||||||
getRewardList(pageIndex, pageSize, sorting, columnFilters)
|
getRewardList(pageIndex, pageSize, sorting, columnFilters)
|
||||||
|
|||||||
@ -0,0 +1,187 @@
|
|||||||
|
import { useTransactionContext } from '../hooks/useTransactionContext';
|
||||||
|
import { useCallApi } from '@/hooks';
|
||||||
|
import { apiConfig } from '@/config/api.config';
|
||||||
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogBody,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogDescription,
|
||||||
|
} from '@/components/ui/dialog';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from '@/components/ui/select';
|
||||||
|
import { doSaveLogActivity } from '@/actions/GlobalActions';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import { Input } from '@/components/ui/input';
|
||||||
|
import { DefaultTooltip, KeenIcon, useDataGrid } from '@/components';
|
||||||
|
import Swal from 'sweetalert2'; // ✅ IMPORT sweetalert2
|
||||||
|
|
||||||
|
const API_URL = apiConfig.transaction;
|
||||||
|
|
||||||
|
const RollbackTransaction = () => {
|
||||||
|
const { GetData, PostData } = useCallApi();
|
||||||
|
const { reload } = useDataGrid();
|
||||||
|
|
||||||
|
const {
|
||||||
|
showRollbackDialog,
|
||||||
|
setShowRollbackDialog,
|
||||||
|
selectedTransactionId,
|
||||||
|
} = useTransactionContext();
|
||||||
|
|
||||||
|
|
||||||
|
const [formField, setFormField] = useState({
|
||||||
|
transaction_code: '',
|
||||||
|
notes: '',
|
||||||
|
pin: ''
|
||||||
|
});
|
||||||
|
|
||||||
|
const [alert, setAlert] = useState({
|
||||||
|
show: false,
|
||||||
|
message: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
const doApproval = useCallback(
|
||||||
|
async (e: React.FormEvent<HTMLFormElement>) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
// ✅ TUTUP Dialog sebelum munculkan SweetAlert
|
||||||
|
setShowRollbackDialog(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/rollback`, {
|
||||||
|
id_transaction: selectedTransactionId,
|
||||||
|
notes: formField.notes,
|
||||||
|
pin: formField.pin,
|
||||||
|
});
|
||||||
|
|
||||||
|
// console.log(response?.message?.error?.message,response?.status);
|
||||||
|
|
||||||
|
if (response?.status === false) {
|
||||||
|
// console.log(response);
|
||||||
|
toast.error(JSON.stringify(response));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response?.status) {
|
||||||
|
toast.success('Success Update Approval');
|
||||||
|
const createActivity = {
|
||||||
|
module: 'History Transaction',
|
||||||
|
description: `Rollback Transaction for transaction => ${selectedTransactionId}`,
|
||||||
|
action: 'U',
|
||||||
|
};
|
||||||
|
doSaveLogActivity(createActivity);
|
||||||
|
reload();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// ✅ Kalau tekan Cancel
|
||||||
|
console.log('User cancelled');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[formField]
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (showRollbackDialog) {
|
||||||
|
setFormField({
|
||||||
|
transaction_code: '',
|
||||||
|
notes: '',
|
||||||
|
pin: ''
|
||||||
|
});
|
||||||
|
setAlert({ show: false, message: '' });
|
||||||
|
}
|
||||||
|
}, [showRollbackDialog]);
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={showRollbackDialog} onOpenChange={setShowRollbackDialog}>
|
||||||
|
<DialogContent className="container-fixed max-w-[1024px] flex flex-col p-5 overflow-hidden">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Rollback Transaction</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
<DialogDescription></DialogDescription>
|
||||||
|
<DialogBody>
|
||||||
|
<form onSubmit={doApproval}>
|
||||||
|
<div className="card-body grid gap-5 p-0">
|
||||||
|
<div className="w-full">
|
||||||
|
<div className="flex items-center flex-wrap gap-2.5 mt-4">
|
||||||
|
<label className="form-label max-w-56">Notes</label>
|
||||||
|
<div className="grow">
|
||||||
|
<Input
|
||||||
|
type="text"
|
||||||
|
placeholder="Notes"
|
||||||
|
name="notes"
|
||||||
|
id="notes"
|
||||||
|
value={formField.notes}
|
||||||
|
onChange={(e) =>
|
||||||
|
setFormField((prev) => ({
|
||||||
|
...prev,
|
||||||
|
notes: e.target.value,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center flex-wrap gap-2.5 mt-3 mb-3">
|
||||||
|
<label className="form-label max-w-56">PIN</label>
|
||||||
|
<div className="grow">
|
||||||
|
<Input
|
||||||
|
required
|
||||||
|
type="password"
|
||||||
|
placeholder="PIN"
|
||||||
|
name="pin"
|
||||||
|
id="pin"
|
||||||
|
value={formField.pin}
|
||||||
|
onChange={(e) =>
|
||||||
|
setFormField((prev) => ({
|
||||||
|
...prev,
|
||||||
|
pin: e.target.value,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{alert.show && (
|
||||||
|
<div className="mt-4">
|
||||||
|
<span className="inline-block bg-red-100 text-red-800 text-sm font-medium px-4 py-2 rounded-md">
|
||||||
|
{alert.message}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<hr />
|
||||||
|
<div className="flex justify-end">
|
||||||
|
<Button className="btn btn-primary" type="submit">
|
||||||
|
Save Changes
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</DialogBody>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default RollbackTransaction;
|
||||||
@ -8,6 +8,7 @@ import ListToolbar from '../blocks/ListToolbar';
|
|||||||
import { useNavigate } from 'react-router';
|
import { useNavigate } from 'react-router';
|
||||||
import DetailTransaction from '../blocks/DetailTransaction';
|
import DetailTransaction from '../blocks/DetailTransaction';
|
||||||
import ResendTransaction from '../blocks/ResendTransaction';
|
import ResendTransaction from '../blocks/ResendTransaction';
|
||||||
|
import RollbackTransaction from '../blocks/RollbackTransaction';
|
||||||
|
|
||||||
interface TransactionProps {
|
interface TransactionProps {
|
||||||
id: number;
|
id: number;
|
||||||
@ -25,6 +26,8 @@ interface ContextProps {
|
|||||||
) => Promise<{ data: TransactionProps[]; totalCount: number } | undefined>;
|
) => Promise<{ data: TransactionProps[]; totalCount: number } | undefined>;
|
||||||
showDetailDialog: boolean;
|
showDetailDialog: boolean;
|
||||||
setShowDetailDialog: React.Dispatch<React.SetStateAction<boolean>>;
|
setShowDetailDialog: React.Dispatch<React.SetStateAction<boolean>>;
|
||||||
|
showRollbackDialog: boolean;
|
||||||
|
setShowRollbackDialog: React.Dispatch<React.SetStateAction<boolean>>;
|
||||||
selectedTransactionId: number | null;
|
selectedTransactionId: number | null;
|
||||||
setSelectedTransactionId: React.Dispatch<React.SetStateAction<number | null>>;
|
setSelectedTransactionId: React.Dispatch<React.SetStateAction<number | null>>;
|
||||||
}
|
}
|
||||||
@ -33,6 +36,8 @@ const initialProps: ContextProps = {
|
|||||||
getTransactionLists: async () => ({ data: [], totalCount: 0 }),
|
getTransactionLists: async () => ({ data: [], totalCount: 0 }),
|
||||||
showDetailDialog: false,
|
showDetailDialog: false,
|
||||||
setShowDetailDialog: () => { },
|
setShowDetailDialog: () => { },
|
||||||
|
showRollbackDialog: false,
|
||||||
|
setShowRollbackDialog: () => { },
|
||||||
selectedTransactionId: null,
|
selectedTransactionId: null,
|
||||||
setSelectedTransactionId: () => { }
|
setSelectedTransactionId: () => { }
|
||||||
};
|
};
|
||||||
@ -42,6 +47,7 @@ const API_URL = apiConfig.transaction;
|
|||||||
|
|
||||||
const TransactionProvider = ({ children }: { children: React.ReactNode }) => {
|
const TransactionProvider = ({ children }: { children: React.ReactNode }) => {
|
||||||
const [showDetailDialog, setShowDetailDialog] = useState(false);
|
const [showDetailDialog, setShowDetailDialog] = useState(false);
|
||||||
|
const [showRollbackDialog, setShowRollbackDialog] = useState(false);
|
||||||
const [selectedTransactionId, setSelectedTransactionId] = useState<number | null>(null);
|
const [selectedTransactionId, setSelectedTransactionId] = useState<number | null>(null);
|
||||||
const [transaction, setTransaction] = useState<TransactionProps[]>([]);
|
const [transaction, setTransaction] = useState<TransactionProps[]>([]);
|
||||||
const { GetData } = useCallApi();
|
const { GetData } = useCallApi();
|
||||||
@ -235,6 +241,17 @@ const TransactionProvider = ({ children }: { children: React.ReactNode }) => {
|
|||||||
>
|
>
|
||||||
<KeenIcon icon="eye" />
|
<KeenIcon icon="eye" />
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
className="btn btn-sm btn-icon btn-clear btn-light"
|
||||||
|
onClick={() => {
|
||||||
|
setSelectedTransactionId(row.id);
|
||||||
|
setShowRollbackDialog(true);
|
||||||
|
}}
|
||||||
|
disabled={row.status !== 'C'}
|
||||||
|
>
|
||||||
|
<KeenIcon icon="notepad-edit" />
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -339,6 +356,8 @@ const TransactionProvider = ({ children }: { children: React.ReactNode }) => {
|
|||||||
getTransactionLists,
|
getTransactionLists,
|
||||||
showDetailDialog,
|
showDetailDialog,
|
||||||
setShowDetailDialog,
|
setShowDetailDialog,
|
||||||
|
showRollbackDialog,
|
||||||
|
setShowRollbackDialog,
|
||||||
selectedTransactionId,
|
selectedTransactionId,
|
||||||
setSelectedTransactionId
|
setSelectedTransactionId
|
||||||
}}
|
}}
|
||||||
@ -358,6 +377,7 @@ const TransactionProvider = ({ children }: { children: React.ReactNode }) => {
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
<DetailTransaction />
|
<DetailTransaction />
|
||||||
|
<RollbackTransaction />
|
||||||
<ResendTransaction
|
<ResendTransaction
|
||||||
isOpen={false}
|
isOpen={false}
|
||||||
onClose={() => console.log('Retry Transaction closed')}
|
onClose={() => console.log('Retry Transaction closed')}
|
||||||
|
|||||||
359
src/pages/transaction/withdrawl-saldo/TransactionWithdraw.tsx
Normal file
359
src/pages/transaction/withdrawl-saldo/TransactionWithdraw.tsx
Normal file
@ -0,0 +1,359 @@
|
|||||||
|
import { Alert, Container, DataGridInner } from '@/components';
|
||||||
|
import { TransactionWithdrawProvider } from './hooks/TransactionWithdrawContext';
|
||||||
|
import { Breadcrumbs, Link } from '@mui/material';
|
||||||
|
import { Helmet } from 'react-helmet';
|
||||||
|
import { Input } from '@/components/ui/input';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { useState, useEffect, useRef } from 'react';
|
||||||
|
import { useCallApi } from '@/hooks';
|
||||||
|
import { apiConfig } from '@/config/api.config';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import { getAuth } from '@/auth';
|
||||||
|
import { RefreshCw } from 'lucide-react';
|
||||||
|
|
||||||
|
const TransactionWithdraw = () => {
|
||||||
|
const initialForm: {
|
||||||
|
msisdn: string;
|
||||||
|
amount: string;
|
||||||
|
pin: string;
|
||||||
|
purpose: string;
|
||||||
|
} = {
|
||||||
|
msisdn: '',
|
||||||
|
amount: '',
|
||||||
|
pin: '',
|
||||||
|
purpose: ''
|
||||||
|
};
|
||||||
|
|
||||||
|
const [form, setForm] = useState(initialForm);
|
||||||
|
const [wallets, setWallets] = useState([]);
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [customerMsisdn, setCustomerMsisdn] = useState<{ value: string; label: string }[]>([]);
|
||||||
|
const [searchTerm, setSearchTerm] = useState('');
|
||||||
|
const [dropdownOpen, setDropdownOpen] = useState(false);
|
||||||
|
const { GetData, PostData } = useCallApi();
|
||||||
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
|
const [showConfirmation, setShowConfirmation] = useState(false);
|
||||||
|
const parsedUser = getAuth()?.user;
|
||||||
|
const API_URL = apiConfig.transaction;
|
||||||
|
const API_URL_WALLET = apiConfig.service_wallet;
|
||||||
|
const API_URL_CUSTOMER = apiConfig.service_customer;
|
||||||
|
const dropdownRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
const [alert, setAlert] = useState({
|
||||||
|
show: false,
|
||||||
|
message: ''
|
||||||
|
});
|
||||||
|
|
||||||
|
const fetchWallets = async () => {
|
||||||
|
try {
|
||||||
|
const response = await GetData(
|
||||||
|
`${API_URL_WALLET}/dashboard/balance/account/${parsedUser.customer.id}`,
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
if (response?.status === true) {
|
||||||
|
setWallets(response.data || []);
|
||||||
|
} else {
|
||||||
|
toast.warning(response?.message || 'Failed to fetch wallet data');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
toast.warning('Failed to fetch wallet data');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchCustomerMsisdn = async (sorting: any, filterValue: string) => {
|
||||||
|
const filter: any =
|
||||||
|
filterValue.trim().length === 0
|
||||||
|
? {}
|
||||||
|
: {
|
||||||
|
or: [
|
||||||
|
{ msisdn: { like: `%${filterValue}%` } },
|
||||||
|
{ fullname: { like: `%${filterValue}%` } }
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
const query: any = {
|
||||||
|
limit: 100,
|
||||||
|
page: 1,
|
||||||
|
with_deleted: false,
|
||||||
|
order_field: sorting[0].id,
|
||||||
|
order_direction: sorting[0].desc ? 'DESC' : 'ASC'
|
||||||
|
};
|
||||||
|
|
||||||
|
if (filter && Object.keys(filter).length > 0) {
|
||||||
|
query.filter = JSON.stringify(filter);
|
||||||
|
// query.page = page + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await GetData(`${API_URL_CUSTOMER}/customer/list`, query);
|
||||||
|
setCustomerMsisdn(
|
||||||
|
response?.data.list.map((item: any) => ({
|
||||||
|
value: item.msisdn,
|
||||||
|
label: `${item.msisdn} - ${item.fullname}`
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
toast.error('Failed to fetch customer msisdn');
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const doPostData = async (form: typeof initialForm) => {
|
||||||
|
setIsSubmitting(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
let response = await PostData(`${API_URL}/transaction/transfer`, {
|
||||||
|
msisdn_destination: form.msisdn,
|
||||||
|
amount: form.amount,
|
||||||
|
pin: form.pin,
|
||||||
|
purpose: form.purpose,
|
||||||
|
id_transaction_type: "20c8a690-dc02-463d-b391-324184d1fefa",
|
||||||
|
id_origin_customer: getAuth()?.id
|
||||||
|
});
|
||||||
|
if (response?.status == true) {
|
||||||
|
await fetchWallets();
|
||||||
|
toast.success('Success Request Topup');
|
||||||
|
} else {
|
||||||
|
toast.error(`${response?.message?.message}`);
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
const errorMessage =
|
||||||
|
error?.response?.data?.message || error?.message || 'Something went wrong';
|
||||||
|
toast.error(errorMessage);
|
||||||
|
setAlert({ show: true, message: errorMessage });
|
||||||
|
} finally {
|
||||||
|
setIsSubmitting(false);
|
||||||
|
setShowConfirmation(false);
|
||||||
|
ResetForm();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
if (form.amount == '' || form.msisdn == '' || form.pin == '') {
|
||||||
|
setAlert({
|
||||||
|
show: true,
|
||||||
|
message: 'Please fill in all required fields.'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setAlert({ show: false, message: '' });
|
||||||
|
setShowConfirmation(true);
|
||||||
|
// TODO: Kirim ke backend atau proses lainnya
|
||||||
|
};
|
||||||
|
|
||||||
|
const ResetForm = () => {
|
||||||
|
setForm(initialForm);
|
||||||
|
setAlert({ show: false, message: '' });
|
||||||
|
setSearchTerm('');
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCancelSubmit = () => {
|
||||||
|
setShowConfirmation(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMsisdnSearch = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
setIsLoading(true);
|
||||||
|
setSearchTerm(e.target.value);
|
||||||
|
setDropdownOpen(true);
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
fetchCustomerMsisdn([{ id: 'msisdn', desc: false }], e.target.value);
|
||||||
|
}, 500);
|
||||||
|
return () => clearTimeout(timer);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMsisdnSelect = (msisdn: string) => {
|
||||||
|
setForm({ ...form, msisdn });
|
||||||
|
setDropdownOpen(false);
|
||||||
|
setSearchTerm(msisdn);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchWallets();
|
||||||
|
fetchCustomerMsisdn([{ id: 'msisdn', desc: false }], '');
|
||||||
|
|
||||||
|
const handleClickOutside = (event: any) => {
|
||||||
|
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
||||||
|
setDropdownOpen(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
document.addEventListener('mousedown', handleClickOutside);
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener('mousedown', handleClickOutside);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const filteredMsisdn = customerMsisdn
|
||||||
|
.filter((item) => item.label.toLowerCase().includes(searchTerm.toLowerCase()))
|
||||||
|
.slice(0, 10);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Helmet>
|
||||||
|
<title>TPAY | Transaction Withdraw Saldo</title>
|
||||||
|
</Helmet>
|
||||||
|
<TransactionWithdrawProvider>
|
||||||
|
<Container className="mb-7">
|
||||||
|
<h1 className="text-xl font-medium leading-none text-gray-900 mb-5">
|
||||||
|
MANAGE TRANSACTION WITHDRAW SALDO
|
||||||
|
</h1>
|
||||||
|
<Breadcrumbs sx={{ mb: 2 }}>
|
||||||
|
<Link underline="none" color="inherit" href="/">
|
||||||
|
<span className="text-sm hover:underline">Dashboard</span>
|
||||||
|
</Link>
|
||||||
|
<Link underline="none" color="inherit">
|
||||||
|
<span className="text-sm">Transaction</span>
|
||||||
|
</Link>
|
||||||
|
<Link underline="none" color="inherit">
|
||||||
|
<span className="text-sm">Withdraw Saldo</span>
|
||||||
|
</Link>
|
||||||
|
</Breadcrumbs>
|
||||||
|
{/* Wallet Section */}
|
||||||
|
<div className="mb-6">
|
||||||
|
<h2 className="text-md font-semibold text-gray-700 mb-3">Your Wallets</h2>
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-3 gap-3">
|
||||||
|
{wallets.map((wallet: any) => (
|
||||||
|
<div key={wallet.id_wallet} className="border rounded-lg p-4 bg-white">
|
||||||
|
<p className="text-sm text-gray-500">{wallet.wallet}</p>
|
||||||
|
<p className="text-lg font-semibold text-green-600">
|
||||||
|
{new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(
|
||||||
|
wallet.amount
|
||||||
|
)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Container className="flex items-center justify-center">
|
||||||
|
<div className="card max-w-[750px] w-full">
|
||||||
|
<div className="card-body p-10">
|
||||||
|
{alert.show && (
|
||||||
|
<Alert variant="danger">
|
||||||
|
<h3>{alert.message}</h3>
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
{/* form */}
|
||||||
|
<form onSubmit={handleSubmit} className="space-y-6 mt-5">
|
||||||
|
<div className="relative" ref={dropdownRef}>
|
||||||
|
<label htmlFor="msisdn">MSISDN (Phone Number)</label>
|
||||||
|
<span className="text-red-500">*</span>
|
||||||
|
<div className="relative">
|
||||||
|
<Input
|
||||||
|
id="msisdn"
|
||||||
|
type="text"
|
||||||
|
value={searchTerm}
|
||||||
|
onChange={handleMsisdnSearch}
|
||||||
|
placeholder="Search MSISDN"
|
||||||
|
onClick={() => setDropdownOpen(true)}
|
||||||
|
/>
|
||||||
|
{dropdownOpen && (
|
||||||
|
<div className="absolute z-10 w-full mt-1 bg-white border border-gray-300 rounded-md shadow-lg max-h-60 overflow-y-auto">
|
||||||
|
{filteredMsisdn.length > 0 ? (
|
||||||
|
filteredMsisdn.map((item, index) => (
|
||||||
|
<div
|
||||||
|
key={index}
|
||||||
|
className="px-4 py-2 hover:bg-gray-100 cursor-pointer"
|
||||||
|
onClick={() => handleMsisdnSelect(item.value)}
|
||||||
|
>
|
||||||
|
{item.label}
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<div className="px-4 py-2 text-gray-500">
|
||||||
|
{isLoading ? 'Loading...' : 'No results found'}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label htmlFor="amount">Amount</label>
|
||||||
|
<span className="text-red-500">*</span>
|
||||||
|
<Input
|
||||||
|
id="topupAmount"
|
||||||
|
type="number"
|
||||||
|
min={0}
|
||||||
|
value={form.amount}
|
||||||
|
onChange={(e) => {
|
||||||
|
const value = Number(e.target.value);
|
||||||
|
if (value >= 0) {
|
||||||
|
setForm({ ...form, amount: String(value) });
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label htmlFor="pin">PIN</label>
|
||||||
|
<span className="text-red-500">*</span>
|
||||||
|
<Input
|
||||||
|
id="pin"
|
||||||
|
type="password"
|
||||||
|
value={form.pin}
|
||||||
|
onChange={(e) => setForm({ ...form, pin: e.target.value })}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label htmlFor="pin">Purpose</label>
|
||||||
|
<span className="text-red-500">*</span>
|
||||||
|
<Input
|
||||||
|
id="purpose"
|
||||||
|
type="text"
|
||||||
|
value={form.purpose}
|
||||||
|
onChange={(e) => setForm({ ...form, purpose: e.target.value })}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<Button type="button" onClick={handleSubmit}>
|
||||||
|
Submit
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Container>
|
||||||
|
|
||||||
|
{showConfirmation && (
|
||||||
|
<div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">
|
||||||
|
<div className="bg-white p-6 rounded-lg shadow-lg max-w-md w-full">
|
||||||
|
<h3 className="text-lg font-semibold mb-4">Confirm Transaction</h3>
|
||||||
|
<p className="mb-6">
|
||||||
|
Are you sure you want to withdraw saldo of{' '}
|
||||||
|
<span className="font-semibold">
|
||||||
|
{new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(
|
||||||
|
Number(form.amount)
|
||||||
|
)}{' '}
|
||||||
|
</span>
|
||||||
|
?
|
||||||
|
</p>
|
||||||
|
<div className="flex justify-end space-x-3">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
onClick={handleCancelSubmit}
|
||||||
|
className="border-gray-300 text-gray-700"
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button onClick={() => doPostData(form)} disabled={isSubmitting}>
|
||||||
|
{isSubmitting ? (
|
||||||
|
<RefreshCw className="animate-spin h-8 w-8 text-white mx-3" />
|
||||||
|
) : (
|
||||||
|
'Confirm'
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Container>
|
||||||
|
</TransactionWithdrawProvider>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TransactionWithdraw;
|
||||||
61
src/pages/transaction/withdrawl-saldo/blocks/ListToolbar.tsx
Normal file
61
src/pages/transaction/withdrawl-saldo/blocks/ListToolbar.tsx
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
import { DefaultTooltip, KeenIcon, useDataGrid } from '@/components';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { useCallback, useState, useEffect } from 'react';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
|
||||||
|
const ListToolbar = () => {
|
||||||
|
const { table, reload } = useDataGrid();
|
||||||
|
|
||||||
|
// Set the initial state for trxDate
|
||||||
|
const [trxDate, settrxDate] = useState({ from: '', to: '' });
|
||||||
|
|
||||||
|
// Function to format date to YYYY-MM-DD
|
||||||
|
const formatDate = (date: Date): string => {
|
||||||
|
return date.toISOString().split('T')[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
// useEffect to set the default date values
|
||||||
|
useEffect(() => {
|
||||||
|
const today = new Date();
|
||||||
|
const nextWeek = new Date(today);
|
||||||
|
nextWeek.setDate(today.getDate() + 7);
|
||||||
|
|
||||||
|
settrxDate({
|
||||||
|
from: formatDate(today), // Set 'from' to today
|
||||||
|
to: formatDate(nextWeek), // Set 'to' to 7 days later
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleFilterData = useCallback(() => {
|
||||||
|
try {
|
||||||
|
table.getColumn('transaction_date')?.setFilterValue(trxDate);
|
||||||
|
} catch (error) {
|
||||||
|
toast.error('Error applying filter');
|
||||||
|
console.error('Error applying filter:', error);
|
||||||
|
}
|
||||||
|
}, [trxDate, table]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (trxDate.from && trxDate.to) {
|
||||||
|
handleFilterData();
|
||||||
|
}
|
||||||
|
}, [trxDate]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="card-header flex-wrap gap-2 border-b-0 px-5">
|
||||||
|
<div className="flex flex-wrap gap-2 lg:gap-5 w-full">
|
||||||
|
<div className="flex justify-between w-full items-center">
|
||||||
|
<div className="flex gap-3 items-center ml-auto">
|
||||||
|
<DefaultTooltip title={'Refresh'} placement={'top'}>
|
||||||
|
<Button variant="outline" className="h-7.5" onClick={() => reload()}>
|
||||||
|
<KeenIcon icon="arrows-circle" />
|
||||||
|
</Button>
|
||||||
|
</DefaultTooltip>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ListToolbar;
|
||||||
@ -0,0 +1,80 @@
|
|||||||
|
import { DataGridColumnHeader, DataGridProvider, KeenIcon } from '@/components';
|
||||||
|
import { Toaster } from '@/components/ui/sonner';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import { apiConfig } from '@/config/api.config';
|
||||||
|
import { ColumnDef } from '@tanstack/react-table';
|
||||||
|
import { createContext, useCallback, useMemo, useState } from 'react';
|
||||||
|
import ListToolbar from '../blocks/ListToolbar';
|
||||||
|
import { useCallApi } from '@/hooks';
|
||||||
|
import moment from 'moment';
|
||||||
|
|
||||||
|
interface TransactionWithdrawProps {
|
||||||
|
id: string;
|
||||||
|
customers_id: string;
|
||||||
|
group_id: string;
|
||||||
|
username: string;
|
||||||
|
fullname: string;
|
||||||
|
email: string;
|
||||||
|
status: string;
|
||||||
|
created_at: Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ContextProps {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const initialProps: ContextProps = {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const TransactionWithdrawContext = createContext<ContextProps>(initialProps);
|
||||||
|
const API_URL = apiConfig.service_customer;
|
||||||
|
|
||||||
|
type StatusCode = 'W' | 'Y' | 'N' | 'T';
|
||||||
|
|
||||||
|
interface StatusInfo {
|
||||||
|
label: string;
|
||||||
|
bg: string;
|
||||||
|
text: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const statusMap: Record<StatusCode, StatusInfo> = {
|
||||||
|
W: { label: 'Waiting Approval', bg: 'bg-yellow-100', text: 'text-yellow-600' },
|
||||||
|
T: { label: 'No Need', bg: 'bg-blue-100', text: 'text-blue-600' },
|
||||||
|
N: { label: 'Reject', bg: 'bg-red-100', text: 'text-red-600' },
|
||||||
|
Y: { label: 'Approve', bg: 'bg-green-100', text: 'text-green-600' },
|
||||||
|
};
|
||||||
|
|
||||||
|
export const renderStatusBadge = (statusRaw: string | null | undefined) => {
|
||||||
|
const status = statusRaw as StatusCode;
|
||||||
|
const { label, bg, text } = statusMap[status] ?? {
|
||||||
|
label: 'Unknown',
|
||||||
|
bg: 'bg-gray-100',
|
||||||
|
text: 'text-gray-600',
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<span className={`px-2 py-1 text-xs font-semibold rounded-full ${bg} ${text}`}>
|
||||||
|
{label}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// const { reload } = useDataGrid();
|
||||||
|
|
||||||
|
const TransactionWithdrawProvider = ({ children }: { children: React.ReactNode }) => {
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TransactionWithdrawContext.Provider
|
||||||
|
value={{}}
|
||||||
|
>
|
||||||
|
<Toaster expand visibleToasts={9} duration={3000} />
|
||||||
|
<div>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
</TransactionWithdrawContext.Provider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export { TransactionWithdrawProvider, TransactionWithdrawContext };
|
||||||
|
export type { TransactionWithdrawProps };
|
||||||
2
src/pages/transaction/withdrawl-saldo/hooks/index.tsx
Normal file
2
src/pages/transaction/withdrawl-saldo/hooks/index.tsx
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
export * from './TransactionWithdrawContext';
|
||||||
|
export * from './useTransactionWithdrawContext';
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
import { useContext } from 'react';
|
||||||
|
import { TransactionWithdrawContext } from './TransactionWithdrawContext';
|
||||||
|
|
||||||
|
const useTransactionWithdrawContext = () => {
|
||||||
|
const context = useContext(TransactionWithdrawContext);
|
||||||
|
|
||||||
|
if (!context) throw new Error('useTransactionWithdrawContext must be used within AuthProvider');
|
||||||
|
|
||||||
|
return context;
|
||||||
|
};
|
||||||
|
|
||||||
|
export { useTransactionWithdrawContext };
|
||||||
@ -2,7 +2,6 @@ import { apiConfig } from '@/config/api.config';
|
|||||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||||
import { useManageTransferTypeContext } from '../hooks/useManageTransferTypeContext';
|
import { useManageTransferTypeContext } from '../hooks/useManageTransferTypeContext';
|
||||||
import {
|
import {
|
||||||
Alert,
|
|
||||||
Container,
|
Container,
|
||||||
DataGridColumnHeader,
|
DataGridColumnHeader,
|
||||||
DataGridInner,
|
DataGridInner,
|
||||||
@ -65,17 +64,14 @@ const AddDialog = () => {
|
|||||||
const [customers, setCustomers] = useState<CustomerProps[]>([]);
|
const [customers, setCustomers] = useState<CustomerProps[]>([]);
|
||||||
const { reload } = useDataGrid();
|
const { reload } = useDataGrid();
|
||||||
const { PostData, PutData } = useCallApi();
|
const { PostData, PutData } = useCallApi();
|
||||||
const [alert, setAlert] = useState({
|
|
||||||
show: false,
|
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||||
message: ''
|
|
||||||
});
|
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
name: '',
|
name: '',
|
||||||
description: '',
|
description: '',
|
||||||
wallet_origin: '',
|
wallet_origin: '',
|
||||||
wallet_destination: '',
|
wallet_destination: '',
|
||||||
|
|
||||||
minimum_amount: 0,
|
minimum_amount: 0,
|
||||||
maximum_amount: 0,
|
maximum_amount: 0,
|
||||||
max_transaction_per_day: 0,
|
max_transaction_per_day: 0,
|
||||||
@ -92,38 +88,39 @@ const AddDialog = () => {
|
|||||||
|
|
||||||
const resetForm = () => {
|
const resetForm = () => {
|
||||||
setFormField(initialState);
|
setFormField(initialState);
|
||||||
|
setErrors({});
|
||||||
};
|
};
|
||||||
|
|
||||||
const parsedUser = getAuth()?.user;
|
const parsedUser = getAuth()?.user;
|
||||||
|
|
||||||
const validateForm = () => {
|
const validateForm = () => {
|
||||||
const requiredFields = [
|
const requiredFields = [
|
||||||
'name',
|
{ key: 'name', label: 'Transfer Type Name' },
|
||||||
'description',
|
{ key: 'description', label: 'Description' },
|
||||||
'wallet_origin',
|
{ key: 'wallet_origin', label: 'From Account' },
|
||||||
'wallet_destination',
|
{ key: 'wallet_destination', label: 'To Account' },
|
||||||
'status',
|
{ key: 'status', label: 'Status' },
|
||||||
'status_approval',
|
{ key: 'status_approval', label: 'Status Approval' },
|
||||||
'status_kind'
|
{ key: 'status_kind', label: 'Status Kind' }
|
||||||
];
|
];
|
||||||
|
|
||||||
const missingFields = requiredFields.filter(
|
const newErrors: Record<string, string> = {};
|
||||||
(field) =>
|
let isValid = true;
|
||||||
formField[field as keyof typeof formField] === '' ||
|
|
||||||
formField[field as keyof typeof formField] === null ||
|
|
||||||
formField[field as keyof typeof formField] === undefined
|
|
||||||
);
|
|
||||||
|
|
||||||
if (missingFields.length > 0) {
|
requiredFields.forEach(({ key, label }) => {
|
||||||
setAlert({
|
if (
|
||||||
show: true,
|
formField[key as keyof typeof formField] === '' ||
|
||||||
message: `Please fill out all required fields: ${missingFields.join(', ')}`
|
formField[key as keyof typeof formField] === null ||
|
||||||
});
|
formField[key as keyof typeof formField] === undefined
|
||||||
return false;
|
) {
|
||||||
}
|
newErrors[key] = `${label} is required`;
|
||||||
|
toast.error(`${label} is required`);
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
setAlert({ show: false, message: '' });
|
setErrors(newErrors);
|
||||||
return true;
|
return isValid;
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
||||||
@ -162,20 +159,17 @@ const AddDialog = () => {
|
|||||||
const response = await PostData(`${API_URL}/transactiontype/create`, data);
|
const response = await PostData(`${API_URL}/transactiontype/create`, data);
|
||||||
|
|
||||||
if (response?.status) {
|
if (response?.status) {
|
||||||
setAlert({ show: false, message: '' });
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
setAlert({ show: true, message: response?.message || 'Failed to create transfer type' });
|
toast.error(response?.message || 'Failed to create transfer type');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setAlert({
|
toast.error(
|
||||||
show: true,
|
error instanceof Error
|
||||||
message:
|
? error.message
|
||||||
error instanceof Error
|
: 'An error occurred while creating transfer type'
|
||||||
? error.message
|
);
|
||||||
: 'An error occurred while creating transfer type'
|
|
||||||
});
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -226,7 +220,6 @@ const AddDialog = () => {
|
|||||||
order_direction: 'ASC'
|
order_direction: 'ASC'
|
||||||
};
|
};
|
||||||
const response = await GetData(`${API_URL_MASTERDATA}/wallet/list`, params);
|
const response = await GetData(`${API_URL_MASTERDATA}/wallet/list`, params);
|
||||||
// console.log(response)
|
|
||||||
if (response?.status && response?.data) {
|
if (response?.status && response?.data) {
|
||||||
setWallets(response.data.list);
|
setWallets(response.data.list);
|
||||||
} else {
|
} else {
|
||||||
@ -238,7 +231,13 @@ const AddDialog = () => {
|
|||||||
if (!showAddDialog) return;
|
if (!showAddDialog) return;
|
||||||
fetchWallets();
|
fetchWallets();
|
||||||
}, [showAddDialog]);
|
}, [showAddDialog]);
|
||||||
// console.log(formField)
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!showAddDialog) {
|
||||||
|
resetForm();
|
||||||
|
}
|
||||||
|
}, [showAddDialog]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={showAddDialog} onOpenChange={(open) => handleAddDialog(open)}>
|
<Dialog open={showAddDialog} onOpenChange={(open) => handleAddDialog(open)}>
|
||||||
<DialogContent className="container-fixed max-w-[1080px] flex flex-col p-5 overflow-hidden [&>button]:hidden">
|
<DialogContent className="container-fixed max-w-[1080px] flex flex-col p-5 overflow-hidden [&>button]:hidden">
|
||||||
@ -256,7 +255,6 @@ const AddDialog = () => {
|
|||||||
className="cursor-pointer hover:opacity-100 opacity-50"
|
className="cursor-pointer hover:opacity-100 opacity-50"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
handleAddDialog(false);
|
handleAddDialog(false);
|
||||||
resetForm();
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<KeenIcon icon="cross" className="text-1.5xl" />
|
<KeenIcon icon="cross" className="text-1.5xl" />
|
||||||
@ -265,13 +263,6 @@ const AddDialog = () => {
|
|||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<DialogBody className="scrollable-y px-0 pb-0" ref={parentRef}>
|
<DialogBody className="scrollable-y px-0 pb-0" ref={parentRef}>
|
||||||
<div className="flex flex-col px-0">
|
<div className="flex flex-col px-0">
|
||||||
{alert.show && (
|
|
||||||
<div className="sticky top-0 z-10 bg-white p-3">
|
|
||||||
<Alert variant="danger" className="mb-3">
|
|
||||||
<h3>{alert.message}</h3>
|
|
||||||
</Alert>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<form action="" onSubmit={handleSubmit}>
|
<form action="" onSubmit={handleSubmit}>
|
||||||
<div className="card-body grid gap-5 p-0">
|
<div className="card-body grid gap-5 p-0">
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
@ -280,16 +271,20 @@ const AddDialog = () => {
|
|||||||
Transfer Type Name
|
Transfer Type Name
|
||||||
<span className="text-red-500">*</span>
|
<span className="text-red-500">*</span>
|
||||||
</label>
|
</label>
|
||||||
<div className="grow">
|
<div className="grow flex flex-col">
|
||||||
<Input
|
<Input
|
||||||
className="input"
|
className={`input ${errors.name ? 'border-red-500' : ''}`}
|
||||||
type="text"
|
type="text"
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
value={formField.name}
|
value={formField.name}
|
||||||
onChange={({ target }) =>
|
onChange={({ target }) => {
|
||||||
setFormField((prev) => ({ ...prev, name: target.value }))
|
setFormField((prev) => ({ ...prev, name: target.value }));
|
||||||
}
|
if (target.value) {
|
||||||
|
setErrors((prev) => ({ ...prev, name: '' }));
|
||||||
|
}
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
|
{errors.name && <span className="text-red-500 text-xs mt-1">{errors.name}</span>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -300,16 +295,20 @@ const AddDialog = () => {
|
|||||||
Description
|
Description
|
||||||
<span className="text-red-500">*</span>
|
<span className="text-red-500">*</span>
|
||||||
</label>
|
</label>
|
||||||
<div className="grow">
|
<div className="grow flex flex-col">
|
||||||
<Input
|
<Input
|
||||||
className="input"
|
className={`input ${errors.description ? 'border-red-500' : ''}`}
|
||||||
type="text"
|
type="text"
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
value={formField.description}
|
value={formField.description}
|
||||||
onChange={({ target }) =>
|
onChange={({ target }) => {
|
||||||
setFormField((prev) => ({ ...prev, description: target.value }))
|
setFormField((prev) => ({ ...prev, description: target.value }));
|
||||||
}
|
if (target.value) {
|
||||||
|
setErrors((prev) => ({ ...prev, description: '' }));
|
||||||
|
}
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
|
{errors.description && <span className="text-red-500 text-xs mt-1">{errors.description}</span>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -390,24 +389,26 @@ const AddDialog = () => {
|
|||||||
From Account
|
From Account
|
||||||
<span className="text-red-500">*</span>
|
<span className="text-red-500">*</span>
|
||||||
</label>
|
</label>
|
||||||
<div className="grow">
|
<div className="grow flex flex-col">
|
||||||
<Select
|
<Select
|
||||||
value={formField.wallet_origin}
|
value={formField.wallet_origin}
|
||||||
onValueChange={(wallet_origin) =>
|
onValueChange={(wallet_origin) => {
|
||||||
setFormField((prev) => ({ ...prev, wallet_origin }))
|
setFormField((prev) => ({ ...prev, wallet_origin }));
|
||||||
}
|
setErrors((prev) => ({ ...prev, wallet_origin: '' }));
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger className={errors.wallet_origin ? 'border-red-500' : ''}>
|
||||||
<SelectValue placeholder="Select Wallet" />
|
<SelectValue placeholder="Select Wallet" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
{wallets.map((wallet, idx) => (
|
{wallets.map((wallet) => (
|
||||||
<SelectItem value={wallet.id} key={wallet.name}>
|
<SelectItem value={wallet.id} key={wallet.name}>
|
||||||
{wallet.name}
|
{wallet.name}
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
))}
|
))}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
|
{errors.wallet_origin && <span className="text-red-500 text-xs mt-1">{errors.wallet_origin}</span>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -418,24 +419,26 @@ const AddDialog = () => {
|
|||||||
To Account
|
To Account
|
||||||
<span className="text-red-500">*</span>
|
<span className="text-red-500">*</span>
|
||||||
</label>
|
</label>
|
||||||
<div className="grow">
|
<div className="grow flex flex-col">
|
||||||
<Select
|
<Select
|
||||||
value={formField.wallet_destination}
|
value={formField.wallet_destination}
|
||||||
onValueChange={(wallet_destination) =>
|
onValueChange={(wallet_destination) => {
|
||||||
setFormField((prev) => ({ ...prev, wallet_destination }))
|
setFormField((prev) => ({ ...prev, wallet_destination }));
|
||||||
}
|
setErrors((prev) => ({ ...prev, wallet_destination: '' }));
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger className={errors.wallet_destination ? 'border-red-500' : ''}>
|
||||||
<SelectValue placeholder="Select Wallet" />
|
<SelectValue placeholder="Select Wallet" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
{wallets.map((wallet, idx) => (
|
{wallets.map((wallet) => (
|
||||||
<SelectItem value={wallet.id} key={wallet.id}>
|
<SelectItem value={wallet.id} key={wallet.id}>
|
||||||
{wallet.name}
|
{wallet.name}
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
))}
|
))}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
|
{errors.wallet_destination && <span className="text-red-500 text-xs mt-1">{errors.wallet_destination}</span>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -447,14 +450,15 @@ const AddDialog = () => {
|
|||||||
<span className="text-red-500"> *</span>
|
<span className="text-red-500"> *</span>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<div className="grow">
|
<div className="grow flex flex-col">
|
||||||
<Select
|
<Select
|
||||||
value={formField.type}
|
value={formField.type}
|
||||||
onValueChange={(value) =>
|
onValueChange={(value) => {
|
||||||
setFormField((prev) => ({ ...prev, type: value }))
|
setFormField((prev) => ({ ...prev, type: value }));
|
||||||
}
|
setErrors((prev) => ({ ...prev, type: '' }));
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger className={errors.type ? 'border-red-500' : ''}>
|
||||||
<SelectValue placeholder="Select" />
|
<SelectValue placeholder="Select" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
@ -480,6 +484,7 @@ const AddDialog = () => {
|
|||||||
<SelectItem value="IC">Income Merchant</SelectItem>
|
<SelectItem value="IC">Income Merchant</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
|
{errors.type && <span className="text-red-500 text-xs mt-1">{errors.type}</span>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -490,14 +495,15 @@ const AddDialog = () => {
|
|||||||
<span className="text-red-500">*</span>
|
<span className="text-red-500">*</span>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<div className="grow">
|
<div className="grow flex flex-col">
|
||||||
<Select
|
<Select
|
||||||
value={formField.status_approval}
|
value={formField.status_approval}
|
||||||
onValueChange={(value) =>
|
onValueChange={(value) => {
|
||||||
setFormField((prev) => ({ ...prev, status_approval: value }))
|
setFormField((prev) => ({ ...prev, status_approval: value }));
|
||||||
}
|
setErrors((prev) => ({ ...prev, status_approval: '' }));
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger className={errors.status_approval ? 'border-red-500' : ''}>
|
||||||
<SelectValue placeholder="Select" />
|
<SelectValue placeholder="Select" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
@ -505,6 +511,7 @@ const AddDialog = () => {
|
|||||||
<SelectItem value="N">No</SelectItem>
|
<SelectItem value="N">No</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
|
{errors.status_approval && <span className="text-red-500 text-xs mt-1">{errors.status_approval}</span>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -515,14 +522,15 @@ const AddDialog = () => {
|
|||||||
<span className="text-red-500">*</span>
|
<span className="text-red-500">*</span>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<div className="grow">
|
<div className="grow flex flex-col">
|
||||||
<Select
|
<Select
|
||||||
value={formField.status_kind}
|
value={formField.status_kind}
|
||||||
onValueChange={(value) =>
|
onValueChange={(value) => {
|
||||||
setFormField((prev) => ({ ...prev, status_kind: value }))
|
setFormField((prev) => ({ ...prev, status_kind: value }));
|
||||||
}
|
setErrors((prev) => ({ ...prev, status_kind: '' }));
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger className={errors.status_kind ? 'border-red-500' : ''}>
|
||||||
<SelectValue placeholder="Select" />
|
<SelectValue placeholder="Select" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
@ -534,6 +542,7 @@ const AddDialog = () => {
|
|||||||
<SelectItem value="N">Top Up Patner</SelectItem>
|
<SelectItem value="N">Top Up Patner</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
|
{errors.status_kind && <span className="text-red-500 text-xs mt-1">{errors.status_kind}</span>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -545,14 +554,15 @@ const AddDialog = () => {
|
|||||||
<span className="text-red-500"> *</span>
|
<span className="text-red-500"> *</span>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<div className="grow">
|
<div className="grow flex flex-col">
|
||||||
<Select
|
<Select
|
||||||
value={formField.status}
|
value={formField.status}
|
||||||
onValueChange={(value) =>
|
onValueChange={(value) => {
|
||||||
setFormField((prev) => ({ ...prev, status: value }))
|
setFormField((prev) => ({ ...prev, status: value }));
|
||||||
}
|
setErrors((prev) => ({ ...prev, status: '' }));
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger className={errors.status ? 'border-red-500' : ''}>
|
||||||
<SelectValue placeholder="Select" />
|
<SelectValue placeholder="Select" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
@ -560,6 +570,7 @@ const AddDialog = () => {
|
|||||||
<SelectItem value="N">Inactive</SelectItem>
|
<SelectItem value="N">Inactive</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
|
{errors.status && <span className="text-red-500 text-xs mt-1">{errors.status}</span>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -67,6 +67,10 @@ const EditDialog = () => {
|
|||||||
show: false,
|
show: false,
|
||||||
message: ''
|
message: ''
|
||||||
});
|
});
|
||||||
|
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||||
|
|
||||||
|
const [isLoadingWallets, setIsLoadingWallets] = useState(false);
|
||||||
|
|
||||||
|
|
||||||
const initialState: {
|
const initialState: {
|
||||||
name: string;
|
name: string;
|
||||||
@ -106,6 +110,7 @@ const EditDialog = () => {
|
|||||||
setFormField(initialState);
|
setFormField(initialState);
|
||||||
setSelectedGroups([]);
|
setSelectedGroups([]);
|
||||||
setAlert({ show: false, message: '' });
|
setAlert({ show: false, message: '' });
|
||||||
|
setErrors({});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleGroupChange = (groupId: string) => {
|
const handleGroupChange = (groupId: string) => {
|
||||||
@ -128,42 +133,33 @@ const EditDialog = () => {
|
|||||||
|
|
||||||
const validateForm = () => {
|
const validateForm = () => {
|
||||||
const requiredFields = [
|
const requiredFields = [
|
||||||
'name',
|
{ key: 'name', label: 'Transfer Type Name' },
|
||||||
'description',
|
{ key: 'description', label: 'Description' },
|
||||||
'wallet_origin',
|
{ key: 'wallet_origin', label: 'From Account' },
|
||||||
'wallet_destination',
|
{ key: 'wallet_destination', label: 'To Account' },
|
||||||
'status',
|
{ key: 'status', label: 'Status' },
|
||||||
'status_approval',
|
{ key: 'status_approval', label: 'Status Approval' },
|
||||||
'status_kind',
|
{ key: 'status_kind', label: 'Status Kind' }
|
||||||
'type'
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const missingFields = requiredFields.filter((field) => {
|
const newErrors: Record<string, string> = {};
|
||||||
return (
|
let isValid = true;
|
||||||
formField[field as keyof typeof formField] === '' ||
|
|
||||||
formField[field as keyof typeof formField] === null ||
|
requiredFields.forEach(({ key, label }) => {
|
||||||
formField[field as keyof typeof formField] === undefined
|
if (
|
||||||
);
|
formField[key as keyof typeof formField] === '' ||
|
||||||
|
formField[key as keyof typeof formField] === null ||
|
||||||
|
formField[key as keyof typeof formField] === undefined
|
||||||
|
) {
|
||||||
|
newErrors[key] = `${label} is required`;
|
||||||
|
// Show toast for each required field
|
||||||
|
toast.error(`${label} is required`);
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (missingFields.length > 0) {
|
setErrors(newErrors);
|
||||||
setAlert({
|
return isValid;
|
||||||
show: true,
|
|
||||||
message: `Please fill out all required fields: ${missingFields.join(', ')}`
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (formField.permission.length === 0) {
|
|
||||||
setAlert({
|
|
||||||
show: true,
|
|
||||||
message: 'Please select at least one group permission'
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
setAlert({ show: false, message: '' });
|
|
||||||
return true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -202,7 +198,7 @@ const EditDialog = () => {
|
|||||||
|
|
||||||
const createActivity = {
|
const createActivity = {
|
||||||
module: 'Manage Transfer Type',
|
module: 'Manage Transfer Type',
|
||||||
description: `Edit Transfer Type => ${selectedTransferType}`,
|
description: `Edit Transfer Type => ${formField.name}`,
|
||||||
action: 'U'
|
action: 'U'
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -227,17 +223,18 @@ const EditDialog = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (response?.status) {
|
if (response?.status) {
|
||||||
setAlert({ show: false, message: '' });
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
setAlert({ show: true, message: response?.message || 'Failed to update transfer type' });
|
toast.error(response?.message || 'Failed to update transfer type');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
toast.error(
|
||||||
|
error instanceof Error ? error.message : 'Failed to Update Transfer Type'
|
||||||
|
);
|
||||||
setAlert({
|
setAlert({
|
||||||
show: true,
|
show: true,
|
||||||
message:
|
message: error instanceof Error ? error.message : 'Failed to Update Transfer Type'
|
||||||
error instanceof Error ? error.message : 'An error occurred while updating transfer type'
|
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -376,6 +373,37 @@ const EditDialog = () => {
|
|||||||
resetForm();
|
resetForm();
|
||||||
}
|
}
|
||||||
}, [showEditDialog]);
|
}, [showEditDialog]);
|
||||||
|
const renderSelectWithLoading = (
|
||||||
|
value: string,
|
||||||
|
onChangeHandler: (value: string) => void,
|
||||||
|
options: { id: string; name: string }[] | null,
|
||||||
|
placeholder: string,
|
||||||
|
isLoading: boolean
|
||||||
|
) => {
|
||||||
|
return (
|
||||||
|
<Select value={value} onValueChange={onChangeHandler} disabled={isLoading}>
|
||||||
|
<SelectTrigger>
|
||||||
|
{isLoading ? (
|
||||||
|
<div className="flex items-center">
|
||||||
|
<div className="animate-pulse bg-gray-200 h-4 w-24 rounded"></div>
|
||||||
|
<span className="ml-2">Loading...</span>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<SelectValue placeholder={placeholder} />
|
||||||
|
)}
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{options &&
|
||||||
|
options.map((option) => (
|
||||||
|
<SelectItem value={option.id} key={option.id}>
|
||||||
|
{option.name}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={showEditDialog} onOpenChange={(open) => handleEditDialog(open, null)}>
|
<Dialog open={showEditDialog} onOpenChange={(open) => handleEditDialog(open, null)}>
|
||||||
@ -418,36 +446,48 @@ const EditDialog = () => {
|
|||||||
Transfer Type Name
|
Transfer Type Name
|
||||||
<span className="text-red-500">*</span>
|
<span className="text-red-500">*</span>
|
||||||
</label>
|
</label>
|
||||||
<div className="grow">
|
<div className="grow flex flex-col">
|
||||||
<Input
|
<Input
|
||||||
className="input"
|
className={`input ${errors.name ? 'border-red-500' : ''}`}
|
||||||
type="text"
|
type="text"
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
value={formField.name}
|
value={formField.name}
|
||||||
onChange={({ target }) =>
|
onChange={({ target }) => {
|
||||||
setFormField((prev) => ({ ...prev, name: target.value }))
|
setFormField((prev) => ({ ...prev, name: target.value }));
|
||||||
}
|
if (target.value) {
|
||||||
|
setErrors((prev) => ({ ...prev, name: '' }));
|
||||||
|
}
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
|
{errors.name && (
|
||||||
|
<span className="text-red-500 text-xs mt-1">{errors.name}</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||||
<label className="form-label flex items-center gap-1 max-w-56">
|
<label className="form-label flex items-center gap-1 max-w-56">
|
||||||
Description
|
Description
|
||||||
<span className="text-red-500">*</span>
|
<span className="text-red-500">*</span>
|
||||||
</label>
|
</label>
|
||||||
<div className="grow">
|
<div className="grow flex flex-col">
|
||||||
<Input
|
<Input
|
||||||
className="input"
|
className={`input ${errors.description ? 'border-red-500' : ''}`}
|
||||||
type="text"
|
type="text"
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
value={formField.description}
|
value={formField.description}
|
||||||
onChange={({ target }) =>
|
onChange={({ target }) => {
|
||||||
setFormField((prev) => ({ ...prev, description: target.value }))
|
setFormField((prev) => ({ ...prev, description: target.value }));
|
||||||
}
|
if (target.value) {
|
||||||
|
setErrors((prev) => ({ ...prev, description: '' }));
|
||||||
|
}
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
|
{errors.description && (
|
||||||
|
<span className="text-red-500 text-xs mt-1">{errors.description}</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -528,24 +568,17 @@ const EditDialog = () => {
|
|||||||
From Account
|
From Account
|
||||||
<span className="text-red-500">*</span>
|
<span className="text-red-500">*</span>
|
||||||
</label>
|
</label>
|
||||||
<div className="grow">
|
<div className="grow flex flex-col">
|
||||||
<Select
|
{renderSelectWithLoading(
|
||||||
value={formField.wallet_origin}
|
formField.wallet_origin,
|
||||||
onValueChange={(wallet_origin) =>
|
(value) => setFormField({ ...formField, wallet_origin: value }),
|
||||||
setFormField((prev) => ({ ...prev, wallet_origin }))
|
wallets,
|
||||||
}
|
'Select Wallet',
|
||||||
>
|
isLoadingWallets
|
||||||
<SelectTrigger>
|
)}
|
||||||
<SelectValue placeholder="Select Wallet" />
|
{errors.wallet_origin && (
|
||||||
</SelectTrigger>
|
<span className="text-red-500 text-xs mt-1">{errors.wallet_origin}</span>
|
||||||
<SelectContent>
|
)}
|
||||||
{wallets.map((wallet) => (
|
|
||||||
<SelectItem value={wallet.id} key={wallet.id}>
|
|
||||||
{wallet.name}
|
|
||||||
</SelectItem>
|
|
||||||
))}
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -556,14 +589,15 @@ const EditDialog = () => {
|
|||||||
To Account
|
To Account
|
||||||
<span className="text-red-500">*</span>
|
<span className="text-red-500">*</span>
|
||||||
</label>
|
</label>
|
||||||
<div className="grow">
|
<div className="grow flex flex-col">
|
||||||
<Select
|
<Select
|
||||||
value={formField.wallet_destination}
|
value={formField.wallet_destination}
|
||||||
onValueChange={(wallet_destination) =>
|
onValueChange={(wallet_destination) => {
|
||||||
setFormField((prev) => ({ ...prev, wallet_destination }))
|
setFormField((prev) => ({ ...prev, wallet_destination }));
|
||||||
}
|
setErrors((prev) => ({ ...prev, wallet_destination: '' }));
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger className={errors.wallet_destination ? 'border-red-500' : ''}>
|
||||||
<SelectValue placeholder="Select Wallet" />
|
<SelectValue placeholder="Select Wallet" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
@ -574,6 +608,9 @@ const EditDialog = () => {
|
|||||||
))}
|
))}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
|
{errors.wallet_destination && (
|
||||||
|
<span className="text-red-500 text-xs mt-1">{errors.wallet_destination}</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -584,14 +621,15 @@ const EditDialog = () => {
|
|||||||
Status Transaction Type
|
Status Transaction Type
|
||||||
<span className="text-red-500"> *</span>
|
<span className="text-red-500"> *</span>
|
||||||
</label>
|
</label>
|
||||||
<div className="grow">
|
<div className="grow flex flex-col">
|
||||||
<Select
|
<Select
|
||||||
value={formField.type}
|
value={formField.type}
|
||||||
onValueChange={(value) =>
|
onValueChange={(value) => {
|
||||||
setFormField((prev) => ({ ...prev, type: value }))
|
setFormField((prev) => ({ ...prev, type: value }));
|
||||||
}
|
setErrors((prev) => ({ ...prev, type: '' }));
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger className={errors.type ? 'border-red-500' : ''}>
|
||||||
<SelectValue placeholder="Select" />
|
<SelectValue placeholder="Select" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
@ -617,6 +655,9 @@ const EditDialog = () => {
|
|||||||
<SelectItem value="IC">Income Merchant</SelectItem>
|
<SelectItem value="IC">Income Merchant</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
|
{errors.type && (
|
||||||
|
<span className="text-red-500 text-xs mt-1">{errors.type}</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -627,14 +668,15 @@ const EditDialog = () => {
|
|||||||
Status Approval
|
Status Approval
|
||||||
<span className="text-red-500">*</span>
|
<span className="text-red-500">*</span>
|
||||||
</label>
|
</label>
|
||||||
<div className="grow">
|
<div className="grow flex flex-col">
|
||||||
<Select
|
<Select
|
||||||
value={formField.status_approval}
|
value={formField.status_approval}
|
||||||
onValueChange={(value) =>
|
onValueChange={(value) => {
|
||||||
setFormField((prev) => ({ ...prev, status_approval: value }))
|
setFormField((prev) => ({ ...prev, status_approval: value }));
|
||||||
}
|
setErrors((prev) => ({ ...prev, status_approval: '' }));
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger className={errors.status_approval ? 'border-red-500' : ''}>
|
||||||
<SelectValue placeholder="Select" />
|
<SelectValue placeholder="Select" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
@ -642,6 +684,9 @@ const EditDialog = () => {
|
|||||||
<SelectItem value="N">No</SelectItem>
|
<SelectItem value="N">No</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
|
{errors.status_approval && (
|
||||||
|
<span className="text-red-500 text-xs mt-1">{errors.status_approval}</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -652,14 +697,15 @@ const EditDialog = () => {
|
|||||||
<span className="text-red-500">*</span>
|
<span className="text-red-500">*</span>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<div className="grow">
|
<div className="grow flex flex-col">
|
||||||
<Select
|
<Select
|
||||||
value={formField.status_kind}
|
value={formField.status_kind}
|
||||||
onValueChange={(value) =>
|
onValueChange={(value) => {
|
||||||
setFormField((prev) => ({ ...prev, status_kind: value }))
|
setFormField((prev) => ({ ...prev, status_kind: value }));
|
||||||
}
|
setErrors((prev) => ({ ...prev, status_kind: '' }));
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger className={errors.status_kind ? 'border-red-500' : ''}>
|
||||||
<SelectValue placeholder="Select" />
|
<SelectValue placeholder="Select" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
@ -671,6 +717,9 @@ const EditDialog = () => {
|
|||||||
<SelectItem value="N">Top Up Patner</SelectItem>
|
<SelectItem value="N">Top Up Patner</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
|
{errors.status_kind && (
|
||||||
|
<span className="text-red-500 text-xs mt-1">{errors.status_kind}</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -680,14 +729,15 @@ const EditDialog = () => {
|
|||||||
Status
|
Status
|
||||||
<span className="text-red-500"> *</span>
|
<span className="text-red-500"> *</span>
|
||||||
</label>
|
</label>
|
||||||
<div className="grow">
|
<div className="grow flex flex-col">
|
||||||
<Select
|
<Select
|
||||||
value={formField.status}
|
value={formField.status}
|
||||||
onValueChange={(value) =>
|
onValueChange={(value) => {
|
||||||
setFormField((prev) => ({ ...prev, status: value }))
|
setFormField((prev) => ({ ...prev, status: value }));
|
||||||
}
|
setErrors((prev) => ({ ...prev, status: '' }));
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger className={errors.status ? 'border-red-500' : ''}>
|
||||||
<SelectValue placeholder="Select" />
|
<SelectValue placeholder="Select" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
@ -695,6 +745,9 @@ const EditDialog = () => {
|
|||||||
<SelectItem value="N">Inactive</SelectItem>
|
<SelectItem value="N">Inactive</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
|
{errors.status && (
|
||||||
|
<span className="text-red-500 text-xs mt-1">{errors.status}</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -738,6 +791,13 @@ const EditDialog = () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex justify-end pt-2.5 gap-5">
|
<div className="flex justify-end pt-2.5 gap-5">
|
||||||
|
<Button
|
||||||
|
variant={'outline'}
|
||||||
|
type="button"
|
||||||
|
onClick={() => resetForm()}
|
||||||
|
>
|
||||||
|
Reset
|
||||||
|
</Button>
|
||||||
<Button variant={'default'} type="submit" disabled={isSubmitting}>
|
<Button variant={'default'} type="submit" disabled={isSubmitting}>
|
||||||
{isSubmitting ? 'Saving...' : 'Save Changes'}
|
{isSubmitting ? 'Saving...' : 'Save Changes'}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@ -346,7 +346,7 @@ const ManageTransferTypeContextProvider = ({ children }: { children: React.React
|
|||||||
setSearchTerm
|
setSearchTerm
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Toaster expand visibleToasts={9} duration={3000} />
|
{/* <Toaster expand visibleToasts={9} duration={3000} /> */}
|
||||||
|
|
||||||
<div className="px-4">
|
<div className="px-4">
|
||||||
<DataGridProvider
|
<DataGridProvider
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import Transaction from '@/pages/transaction/history-transaction/Transaction';
|
|||||||
import ApprovalTransaction from '@/pages/transaction/approval-transaction/ApprovalTransaction';
|
import ApprovalTransaction from '@/pages/transaction/approval-transaction/ApprovalTransaction';
|
||||||
import TransactionTopup from '@/pages/transaction/topup/TransactionTopup';
|
import TransactionTopup from '@/pages/transaction/topup/TransactionTopup';
|
||||||
import TransactionDisbursement from '@/pages/transaction/disbursement-saldo/TransactionDisbursement';
|
import TransactionDisbursement from '@/pages/transaction/disbursement-saldo/TransactionDisbursement';
|
||||||
|
import TransactionWithdraw from '@/pages/transaction/withdrawl-saldo/TransactionWithdraw';
|
||||||
import LogActivityPage from '@/pages/settings/user/log-activity/LogActivityPage';
|
import LogActivityPage from '@/pages/settings/user/log-activity/LogActivityPage';
|
||||||
import ManagePositionPage from '@/pages/settings/user/manage-position/ManagePositionPage';
|
import ManagePositionPage from '@/pages/settings/user/manage-position/ManagePositionPage';
|
||||||
import ManageAccount from '@/pages/account/manage-account/ManageAccount';
|
import ManageAccount from '@/pages/account/manage-account/ManageAccount';
|
||||||
@ -46,6 +47,7 @@ import FeedbackMemberMaster from '@/pages/members/feedback-member/FeedbackMember
|
|||||||
|
|
||||||
// DISBURSEMENT
|
// DISBURSEMENT
|
||||||
import HistoryTransactionDisbursement from '@/pages/disbursement/history-transaction/HistoryTransaction';
|
import HistoryTransactionDisbursement from '@/pages/disbursement/history-transaction/HistoryTransaction';
|
||||||
|
|
||||||
// DISBURSEMENT
|
// DISBURSEMENT
|
||||||
|
|
||||||
const AppRoutingSetup = (): ReactElement => {
|
const AppRoutingSetup = (): ReactElement => {
|
||||||
@ -102,6 +104,7 @@ const AppRoutingSetup = (): ReactElement => {
|
|||||||
<Route path="/approval-transaction" element={<ApprovalTransaction />} />
|
<Route path="/approval-transaction" element={<ApprovalTransaction />} />
|
||||||
<Route path="/transaction/topup" element={<TransactionTopup />} />
|
<Route path="/transaction/topup" element={<TransactionTopup />} />
|
||||||
<Route path="/transaction/disbursement-saldo" element={<TransactionDisbursement />} />
|
<Route path="/transaction/disbursement-saldo" element={<TransactionDisbursement />} />
|
||||||
|
<Route path="/transaction/withdrawl-saldo" element={<TransactionWithdraw />} />
|
||||||
<Route path="/menu/menu-management" element={<ManageMenu />} />
|
<Route path="/menu/menu-management" element={<ManageMenu />} />
|
||||||
<Route path="/menu/welcome" element={<Welcome />} />
|
<Route path="/menu/welcome" element={<Welcome />} />
|
||||||
<Route path="/message/inbox" element={<Inbox />} />
|
<Route path="/message/inbox" element={<Inbox />} />
|
||||||
|
|||||||
Reference in New Issue
Block a user