fixing transactiontype and transactionfee
This commit is contained in:
@ -63,14 +63,14 @@ const AddFeeDialog = () => {
|
||||
const parentRef = useRef<any | null>(null);
|
||||
const { reload } = useDataGrid();
|
||||
const { PostData, PutData, GetData } = useCallApi();
|
||||
const {
|
||||
showAddFeeDialog,
|
||||
handleAddFeeDialog,
|
||||
handleEditFeeDialog,
|
||||
const {
|
||||
showAddFeeDialog,
|
||||
handleAddFeeDialog,
|
||||
handleEditFeeDialog,
|
||||
selectedTransferFee,
|
||||
transactionTypeId
|
||||
} = useManageTransferFeeContext();
|
||||
|
||||
|
||||
const [alert, setAlert] = useState({
|
||||
show: false,
|
||||
message: ''
|
||||
@ -80,13 +80,13 @@ const AddFeeDialog = () => {
|
||||
const [customers, setCustomers] = useState<CustomerProps[]>([]);
|
||||
const [defaultCustomer, setDefaultCustomer] = useState('');
|
||||
const [transactionTypeName, setTransactionTypeName] = useState('');
|
||||
|
||||
|
||||
const [isLoadingTransactionType, setIsLoadingTransactionType] = useState(false);
|
||||
const [isLoadingWallets, setIsLoadingWallets] = useState(false);
|
||||
const [isLoadingCustomers, setIsLoadingCustomers] = useState(false);
|
||||
const customersWithNames = customers.map((customer) => ({
|
||||
id: customer.id,
|
||||
name: customer.username,
|
||||
name: customer.username
|
||||
}));
|
||||
const initialState = {
|
||||
name: '',
|
||||
@ -125,15 +125,18 @@ const AddFeeDialog = () => {
|
||||
useEffect(() => {
|
||||
if (showAddFeeDialog && transactionTypeId) {
|
||||
setIsLoadingTransactionType(true);
|
||||
|
||||
setFormField(prev => ({
|
||||
|
||||
setFormField((prev) => ({
|
||||
...prev,
|
||||
transaction_type: transactionTypeId
|
||||
}));
|
||||
|
||||
|
||||
const getTransactionTypeDetails = async () => {
|
||||
try {
|
||||
const response = await GetData(`${API_URL}/transactiontype/getdata/${transactionTypeId}`, {});
|
||||
const response = await GetData(
|
||||
`${API_URL}/transactiontype/getdata/${transactionTypeId}`,
|
||||
{}
|
||||
);
|
||||
if (response?.status && response?.data) {
|
||||
setTransactionTypeName(response.data.name);
|
||||
}
|
||||
@ -143,17 +146,17 @@ const AddFeeDialog = () => {
|
||||
setIsLoadingTransactionType(false);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
getTransactionTypeDetails();
|
||||
}
|
||||
}, [showAddFeeDialog, transactionTypeId, GetData]);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
const created_time = new Date();
|
||||
const formattedTime = created_time.toISOString().slice(0, 19).replace('T', ' ');
|
||||
|
||||
if (showAddFeeDialog) {
|
||||
setFormField(prev => ({
|
||||
setFormField((prev) => ({
|
||||
...prev,
|
||||
created_by: parsedUser?.username,
|
||||
created_at: formattedTime
|
||||
@ -193,7 +196,7 @@ const AddFeeDialog = () => {
|
||||
page: 1,
|
||||
with_deleted: false,
|
||||
order_field: 'Wallets.name',
|
||||
order_direction: 'ASC',
|
||||
order_direction: 'ASC'
|
||||
};
|
||||
try {
|
||||
const response = await GetData(`${API_URL_MASTER_DATA}/wallet/list`, params);
|
||||
@ -209,7 +212,7 @@ const AddFeeDialog = () => {
|
||||
setIsLoadingWallets(false);
|
||||
}
|
||||
}, [GetData]);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (!showAddFeeDialog) return;
|
||||
fetchWallets();
|
||||
@ -231,7 +234,7 @@ const AddFeeDialog = () => {
|
||||
});
|
||||
const customerList = response?.data.list || [];
|
||||
setCustomers(customerList);
|
||||
|
||||
|
||||
if (customerList.length > 0) {
|
||||
setDefaultCustomer(customerList[0].id);
|
||||
}
|
||||
@ -250,9 +253,9 @@ const AddFeeDialog = () => {
|
||||
async (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
setIsSubmitting(true);
|
||||
|
||||
|
||||
const requiredFields = [
|
||||
'name',
|
||||
'name',
|
||||
'description',
|
||||
'period_start',
|
||||
'period_end',
|
||||
@ -265,44 +268,44 @@ const AddFeeDialog = () => {
|
||||
'credit_to',
|
||||
'credit_destination_account'
|
||||
];
|
||||
|
||||
|
||||
for (const field of requiredFields) {
|
||||
if (formField[field as keyof typeof formField] === '') {
|
||||
setAlert({
|
||||
show: true,
|
||||
message: `All required fields must be filled out. Missing: ${field.replace(/_/g, ' ')}`
|
||||
setAlert({
|
||||
show: true,
|
||||
message: `All required fields must be filled out. Missing: ${field.replace(/_/g, ' ')}`
|
||||
});
|
||||
setIsSubmitting(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (formField.credit_to === 'I' && !formField.credit_destination) {
|
||||
setAlert({
|
||||
show: true,
|
||||
message: 'Credit destination is required when Input Customer is selected'
|
||||
setAlert({
|
||||
show: true,
|
||||
message: 'Credit destination is required when Input Customer is selected'
|
||||
});
|
||||
setIsSubmitting(false);
|
||||
return;
|
||||
}
|
||||
|
||||
setAlert({ show: false, message: '' });
|
||||
|
||||
|
||||
const payload = { ...formField };
|
||||
|
||||
|
||||
if (formField.credit_to !== 'I') {
|
||||
payload.credit_destination = '00000000-0000-0000-0000-000000000000';
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
const response = await PostData(`${API_URL}/transactionfees/create`, payload);
|
||||
|
||||
|
||||
if (response?.status) {
|
||||
toast.success('Successfully created transfer fee');
|
||||
reload();
|
||||
resetForm();
|
||||
handleAddFeeDialog(false);
|
||||
|
||||
|
||||
const createActivity = {
|
||||
module: 'Manage Transfer Fee',
|
||||
description: `Create Transfer Fee => ${formField.name}`,
|
||||
@ -323,18 +326,14 @@ const AddFeeDialog = () => {
|
||||
);
|
||||
|
||||
const renderSelectWithLoading = (
|
||||
value: string,
|
||||
value: string,
|
||||
onChangeHandler: (value: string) => void,
|
||||
options: {id: string, name: string}[] | null,
|
||||
options: { id: string; name: string }[] | null,
|
||||
placeholder: string,
|
||||
isLoading: boolean
|
||||
) => {
|
||||
return (
|
||||
<Select
|
||||
value={value}
|
||||
onValueChange={onChangeHandler}
|
||||
disabled={isLoading}
|
||||
>
|
||||
<Select value={value} onValueChange={onChangeHandler} disabled={isLoading}>
|
||||
<SelectTrigger>
|
||||
{isLoading ? (
|
||||
<div className="flex items-center">
|
||||
@ -346,11 +345,12 @@ const AddFeeDialog = () => {
|
||||
)}
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{options && options.map((option) => (
|
||||
<SelectItem value={option.id} key={option.id}>
|
||||
{option.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
{options &&
|
||||
options.map((option) => (
|
||||
<SelectItem value={option.id} key={option.id}>
|
||||
{option.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
);
|
||||
@ -389,7 +389,9 @@ const AddFeeDialog = () => {
|
||||
<div className="card flex flex-col gap-5">
|
||||
<div className="card-body grid gap-5 p-0">
|
||||
<div className="w-full">
|
||||
<label className="form-label">Transaction Type ID <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Transaction Type ID <span className="text-red-500">*</span>
|
||||
</label>
|
||||
{transactionTypeId ? (
|
||||
<div className="relative">
|
||||
<Input
|
||||
@ -412,13 +414,15 @@ const AddFeeDialog = () => {
|
||||
formField.transaction_type,
|
||||
(transaction_type) => setFormField((prev) => ({ ...prev, transaction_type })),
|
||||
transactionTypes,
|
||||
"Select Transaction Type",
|
||||
'Select Transaction Type',
|
||||
isLoadingTransactionType
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Transfer Free Name <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Transfer Free Name <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Input
|
||||
className="input"
|
||||
type="text"
|
||||
@ -430,7 +434,9 @@ const AddFeeDialog = () => {
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Description <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Description <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Input
|
||||
className="input"
|
||||
type="text"
|
||||
@ -476,7 +482,9 @@ const AddFeeDialog = () => {
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Period Start <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Period Start <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Input
|
||||
className="input"
|
||||
type="date"
|
||||
@ -488,7 +496,9 @@ const AddFeeDialog = () => {
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Period End <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Period End <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Input
|
||||
className="input"
|
||||
type="date"
|
||||
@ -551,7 +561,9 @@ const AddFeeDialog = () => {
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Deduct From <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Deduct From <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Select
|
||||
value={formField.deduct_from}
|
||||
onValueChange={(value) => setFormField({ ...formField, deduct_from: value })}
|
||||
@ -566,24 +578,31 @@ const AddFeeDialog = () => {
|
||||
</Select>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Deduct From Destination <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Deduct From Destination <span className="text-red-500">*</span>
|
||||
</label>
|
||||
{renderSelectWithLoading(
|
||||
formField.deduct_from_account,
|
||||
(value) => setFormField({ ...formField, deduct_from_account: value }),
|
||||
wallets,
|
||||
"Select Wallet",
|
||||
'Select Wallet',
|
||||
isLoadingWallets
|
||||
)}
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Credit To <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Credit To <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Select
|
||||
value={formField.credit_to}
|
||||
onValueChange={(value) => setFormField({
|
||||
...formField,
|
||||
credit_to: value,
|
||||
credit_destination: value === 'I' ? '' : '00000000-0000-0000-0000-000000000000'
|
||||
})}
|
||||
onValueChange={(value) =>
|
||||
setFormField({
|
||||
...formField,
|
||||
credit_to: value,
|
||||
credit_destination:
|
||||
value === 'I' ? '' : '00000000-0000-0000-0000-000000000000'
|
||||
})
|
||||
}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select Credit To" />
|
||||
@ -597,28 +616,34 @@ const AddFeeDialog = () => {
|
||||
</div>
|
||||
{formField.credit_to === 'I' && (
|
||||
<div className="w-full">
|
||||
<label className="form-label">Credit Destination <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Credit Destination <span className="text-red-500">*</span>
|
||||
</label>
|
||||
{renderSelectWithLoading(
|
||||
formField.credit_destination,
|
||||
(value) => setFormField({ ...formField, credit_destination: value }),
|
||||
customersWithNames,
|
||||
"Select Customer",
|
||||
isLoadingCustomers
|
||||
)}
|
||||
formField.credit_destination,
|
||||
(value) => setFormField({ ...formField, credit_destination: value }),
|
||||
customersWithNames,
|
||||
'Select Customer',
|
||||
isLoadingCustomers
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<div className="w-full">
|
||||
<label className="form-label">Credit Destination Account <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Credit Destination Account <span className="text-red-500">*</span>
|
||||
</label>
|
||||
{renderSelectWithLoading(
|
||||
formField.credit_destination_account,
|
||||
(value) => setFormField({ ...formField, credit_destination_account: value }),
|
||||
wallets,
|
||||
"Select Wallet",
|
||||
'Select Wallet',
|
||||
isLoadingWallets
|
||||
)}
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Status <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Status <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Select
|
||||
value={formField.status}
|
||||
onValueChange={(value) => setFormField({ ...formField, status: value })}
|
||||
@ -633,7 +658,9 @@ const AddFeeDialog = () => {
|
||||
</Select>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Status Include <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Status Include <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Select
|
||||
value={formField.status_include}
|
||||
onValueChange={(value) => setFormField({ ...formField, status_include: value })}
|
||||
@ -648,7 +675,9 @@ const AddFeeDialog = () => {
|
||||
</Select>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Priority <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Priority <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Select
|
||||
value={formField.priority}
|
||||
onValueChange={(value) => setFormField({ ...formField, priority: value })}
|
||||
@ -672,10 +701,15 @@ const AddFeeDialog = () => {
|
||||
>
|
||||
Reset
|
||||
</Button>
|
||||
<Button
|
||||
variant={'default'}
|
||||
type="submit"
|
||||
disabled={isSubmitting || isLoadingTransactionType || isLoadingWallets || isLoadingCustomers}
|
||||
<Button
|
||||
variant={'default'}
|
||||
type="submit"
|
||||
disabled={
|
||||
isSubmitting ||
|
||||
isLoadingTransactionType ||
|
||||
isLoadingWallets ||
|
||||
isLoadingCustomers
|
||||
}
|
||||
>
|
||||
{isSubmitting ? 'Saving...' : 'Save Changes'}
|
||||
</Button>
|
||||
@ -689,4 +723,4 @@ const AddFeeDialog = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export default AddFeeDialog;
|
||||
export default AddFeeDialog;
|
||||
|
||||
@ -1,4 +1,11 @@
|
||||
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle , DialogDescription} from '@/components/ui/dialog';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogDescription
|
||||
} from '@/components/ui/dialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Alert, useDataGrid } from '@/components';
|
||||
import { useCallback, useState } from 'react';
|
||||
@ -10,7 +17,8 @@ import { useManageTransferFeeContext } from '../hooks/useManageTransferFeeContex
|
||||
const API_URL = apiConfig.service_transaction;
|
||||
|
||||
const DeleteFeeDialog = () => {
|
||||
const { showDeleteFeeDialog, handleDeleteFeeDialog, selectedTransferFee } = useManageTransferFeeContext();
|
||||
const { showDeleteFeeDialog, handleDeleteFeeDialog, selectedTransferFee } =
|
||||
useManageTransferFeeContext();
|
||||
const { reload } = useDataGrid();
|
||||
const { DeleteData } = useCallApi();
|
||||
const [alert, setAlert] = useState({
|
||||
@ -19,9 +27,12 @@ const DeleteFeeDialog = () => {
|
||||
});
|
||||
|
||||
const doDeleteTransferFee = useCallback(async () => {
|
||||
const response = await DeleteData(`${API_URL}/transactionfees/delete/${selectedTransferFee}/false`, {
|
||||
id: selectedTransferFee
|
||||
});
|
||||
const response = await DeleteData(
|
||||
`${API_URL}/transactionfees/delete/${selectedTransferFee}/false`,
|
||||
{
|
||||
id: selectedTransferFee
|
||||
}
|
||||
);
|
||||
|
||||
if (response?.status) {
|
||||
setAlert({ show: false, message: '' });
|
||||
@ -39,7 +50,9 @@ const DeleteFeeDialog = () => {
|
||||
<DialogContent className="container-fixed max-w-md flex flex-col p-5 overflow-hidden [&>button]:hidden">
|
||||
<DialogHeader className="p-0 border-0 block">
|
||||
<DialogTitle className="text-lg">Delete Transfer Type</DialogTitle>
|
||||
<DialogDescription className="text-sm">Are you sure you want to delete this data?</DialogDescription>
|
||||
<DialogDescription className="text-sm">
|
||||
Are you sure you want to delete this data?
|
||||
</DialogDescription>
|
||||
<Alert variant="warning">
|
||||
<h3 className="text-lg">Are you sure?</h3>
|
||||
<span className="text-sm">You will delete this data!</span>
|
||||
@ -64,4 +77,3 @@ const DeleteFeeDialog = () => {
|
||||
};
|
||||
|
||||
export default DeleteFeeDialog;
|
||||
|
||||
|
||||
@ -8,7 +8,14 @@ import {
|
||||
SelectValue
|
||||
} from '@/components/ui/select';
|
||||
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
|
||||
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from '@/components/ui/command';
|
||||
import {
|
||||
Command,
|
||||
CommandEmpty,
|
||||
CommandGroup,
|
||||
CommandInput,
|
||||
CommandItem,
|
||||
CommandList
|
||||
} from '@/components/ui/command';
|
||||
import {
|
||||
Dialog,
|
||||
DialogBody,
|
||||
@ -96,7 +103,7 @@ const EditFeeDialog = () => {
|
||||
const formattedTime = updated_time.toISOString().slice(0, 19).replace('T', ' ');
|
||||
|
||||
if (showEditFeeDialog) {
|
||||
setFormField(prevState => ({
|
||||
setFormField((prevState) => ({
|
||||
...prevState,
|
||||
updated_by: parsedUser?.username,
|
||||
updated_at: formattedTime
|
||||
@ -116,9 +123,9 @@ const EditFeeDialog = () => {
|
||||
async (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
setIsSubmitting(true);
|
||||
|
||||
|
||||
const requiredFields = [
|
||||
'name',
|
||||
'name',
|
||||
'description',
|
||||
'period_start',
|
||||
'period_end',
|
||||
@ -131,38 +138,41 @@ const EditFeeDialog = () => {
|
||||
'credit_to',
|
||||
'credit_destination_account'
|
||||
];
|
||||
|
||||
|
||||
for (const field of requiredFields) {
|
||||
if (formField[field as keyof typeof formField] === '') {
|
||||
setAlert({
|
||||
show: true,
|
||||
message: `All required fields must be filled out. Missing: ${field.replace(/_/g, ' ')}`
|
||||
setAlert({
|
||||
show: true,
|
||||
message: `All required fields must be filled out. Missing: ${field.replace(/_/g, ' ')}`
|
||||
});
|
||||
setIsSubmitting(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (formField.credit_to === 'I' && !formField.credit_destination) {
|
||||
setAlert({
|
||||
show: true,
|
||||
message: 'Credit destination is required when Input Customer is selected'
|
||||
setAlert({
|
||||
show: true,
|
||||
message: 'Credit destination is required when Input Customer is selected'
|
||||
});
|
||||
setIsSubmitting(false);
|
||||
return;
|
||||
}
|
||||
|
||||
setAlert({ show: false, message: '' });
|
||||
|
||||
|
||||
const payload = { ...formField };
|
||||
|
||||
|
||||
if (formField.credit_to !== 'I') {
|
||||
payload.credit_destination = '00000000-0000-0000-0000-000000000000';
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
const response = await PutData(`${API_URL}/transactionfees/update/${selectedTransferFee}`, payload);
|
||||
|
||||
const response = await PutData(
|
||||
`${API_URL}/transactionfees/update/${selectedTransferFee}`,
|
||||
payload
|
||||
);
|
||||
|
||||
if (response?.status) {
|
||||
toast.success('Successfully updated transfer fee');
|
||||
reload();
|
||||
@ -191,7 +201,7 @@ const EditFeeDialog = () => {
|
||||
page: 1,
|
||||
with_deleted: false,
|
||||
order_field: 'Wallets.name',
|
||||
order_direction: 'ASC',
|
||||
order_direction: 'ASC'
|
||||
};
|
||||
try {
|
||||
const response = await GetData(`${API_URL_MASTER_DATA}/wallet/list`, params);
|
||||
@ -260,56 +270,58 @@ const EditFeeDialog = () => {
|
||||
return dateString.split('T')[0];
|
||||
};
|
||||
|
||||
const fetchTransactionFee = useCallback(async (id: string) => {
|
||||
try {
|
||||
const response = await GetData(`${API_URL}/transactionfees/getdata/${id}`, { });
|
||||
|
||||
if (response?.status) {
|
||||
const fetchTransactionFee = useCallback(
|
||||
async (id: string) => {
|
||||
try {
|
||||
const response = await GetData(`${API_URL}/transactionfees/getdata/${id}`, {});
|
||||
|
||||
|
||||
setFormField({
|
||||
...initialState,
|
||||
name: response.data.name || '',
|
||||
description: response.data.description || '',
|
||||
transaction_type: response.data.transaction_type?.id || '',
|
||||
minimum_amount: response.data.minimum_amount || 0,
|
||||
maximum_amount: response.data.maximum_amount || 0,
|
||||
period_start: formatDate(response.data.period_start),
|
||||
period_end: formatDate(response.data.period_end),
|
||||
deduct_amount: response.data.deduct_amount || 0,
|
||||
deduct_percentage: response.data.deduct_percentage || 0,
|
||||
fee_amount: response.data.fee_amount || 0,
|
||||
priority: response.data.priority || '',
|
||||
status: response.data.status || '',
|
||||
status_include: response.data.status_include || '',
|
||||
deduct_from: response.data.deduct_from||'',
|
||||
deduct_from_account: response.data.deduct_from_account?.id || '',
|
||||
credit_to: response.data.credit_to || '',
|
||||
credit_destination: response.data.credit_destination?.id || '00000000-0000-0000-0000-000000000000',
|
||||
credit_destination_account: response.data.credit_destination_account?.id || '',
|
||||
updated_by: parsedUser?.username,
|
||||
updated_at: new Date().toISOString().slice(0, 19).replace('T', ' ')
|
||||
});
|
||||
if (response?.status) {
|
||||
setFormField({
|
||||
...initialState,
|
||||
name: response.data.name || '',
|
||||
description: response.data.description || '',
|
||||
transaction_type: response.data.transaction_type?.id || '',
|
||||
minimum_amount: response.data.minimum_amount || 0,
|
||||
maximum_amount: response.data.maximum_amount || 0,
|
||||
period_start: formatDate(response.data.period_start),
|
||||
period_end: formatDate(response.data.period_end),
|
||||
deduct_amount: response.data.deduct_amount || 0,
|
||||
deduct_percentage: response.data.deduct_percentage || 0,
|
||||
fee_amount: response.data.fee_amount || 0,
|
||||
priority: response.data.priority || '',
|
||||
status: response.data.status || '',
|
||||
status_include: response.data.status_include || '',
|
||||
deduct_from: response.data.deduct_from || '',
|
||||
deduct_from_account: response.data.deduct_from_account?.id || '',
|
||||
credit_to: response.data.credit_to || '',
|
||||
credit_destination:
|
||||
response.data.credit_destination?.id || '00000000-0000-0000-0000-000000000000',
|
||||
credit_destination_account: response.data.credit_destination_account?.id || '',
|
||||
updated_by: parsedUser?.username,
|
||||
updated_at: new Date().toISOString().slice(0, 19).replace('T', ' ')
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching transaction fee details', error);
|
||||
setAlert({ show: true, message: 'Failed to fetch transaction fee details' });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching transaction fee details', error);
|
||||
setAlert({ show: true, message: 'Failed to fetch transaction fee details' });
|
||||
}
|
||||
}, [GetData, parsedUser?.username]);
|
||||
|
||||
},
|
||||
[GetData, parsedUser?.username]
|
||||
);
|
||||
|
||||
const hasFetchedRef = useRef(false);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedTransferFee && showEditFeeDialog && !hasFetchedRef.current) {
|
||||
fetchTransactionFee(selectedTransferFee);
|
||||
hasFetchedRef.current = true;
|
||||
}
|
||||
|
||||
|
||||
if (!showEditFeeDialog) {
|
||||
hasFetchedRef.current = false;
|
||||
}
|
||||
}, [selectedTransferFee, showEditFeeDialog, fetchTransactionFee]);
|
||||
|
||||
|
||||
const handleCloseDialog = () => {
|
||||
setFormField(initialState);
|
||||
setAlert({ show: false, message: '' });
|
||||
@ -317,11 +329,14 @@ const EditFeeDialog = () => {
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={showEditFeeDialog} onOpenChange={(open) => {
|
||||
if (!open) {
|
||||
handleCloseDialog();
|
||||
}
|
||||
}}>
|
||||
<Dialog
|
||||
open={showEditFeeDialog}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) {
|
||||
handleCloseDialog();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<DialogContent className="container-fixed max-w-[1080px] flex flex-col p-5 overflow-hidden [&>button]:hidden">
|
||||
<DialogTitle></DialogTitle>
|
||||
<DialogDescription></DialogDescription>
|
||||
@ -348,12 +363,14 @@ const EditFeeDialog = () => {
|
||||
</Alert>
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
<form action="" onSubmit={doUpdateTransferFee}>
|
||||
<div className="card flex flex-col gap-5">
|
||||
<div className="card-body grid gap-5 p-0">
|
||||
<div className="w-full">
|
||||
<label className="form-label">Transfer Fee Name <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Transfer Fee Name <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Input
|
||||
className="input"
|
||||
type="text"
|
||||
@ -364,9 +381,11 @@ const EditFeeDialog = () => {
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
<div className="w-full">
|
||||
<label className="form-label">Description <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Description <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Input
|
||||
className="input"
|
||||
type="text"
|
||||
@ -377,7 +396,7 @@ const EditFeeDialog = () => {
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
<div className="w-full">
|
||||
<label className="form-label">Minimum Amount</label>
|
||||
<NumericFormat
|
||||
@ -395,7 +414,7 @@ const EditFeeDialog = () => {
|
||||
placeholder="Enter Minimum Amount"
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
<div className="w-full">
|
||||
<label className="form-label">Maximum Amount</label>
|
||||
<NumericFormat
|
||||
@ -413,9 +432,11 @@ const EditFeeDialog = () => {
|
||||
placeholder="Enter Maximum Amount"
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
<div className="w-full">
|
||||
<label className="form-label">Period Start <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Period Start <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Input
|
||||
className="input"
|
||||
type="date"
|
||||
@ -426,9 +447,11 @@ const EditFeeDialog = () => {
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
<div className="w-full">
|
||||
<label className="form-label">Period End <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Period End <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Input
|
||||
className="input"
|
||||
type="date"
|
||||
@ -439,7 +462,7 @@ const EditFeeDialog = () => {
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
<div className="w-full">
|
||||
<label className="form-label">Deduct Amount</label>
|
||||
<NumericFormat
|
||||
@ -457,7 +480,7 @@ const EditFeeDialog = () => {
|
||||
placeholder="Enter Deduct Amount"
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
<div className="w-full">
|
||||
<label className="form-label">Deduct Percentage</label>
|
||||
<NumericFormat
|
||||
@ -475,7 +498,7 @@ const EditFeeDialog = () => {
|
||||
placeholder="Enter Deduct Percentage"
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
<div className="w-full">
|
||||
<label className="form-label">Fee Amount</label>
|
||||
<NumericFormat
|
||||
@ -493,9 +516,11 @@ const EditFeeDialog = () => {
|
||||
placeholder="Enter Fee Amount"
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
<div className="w-full">
|
||||
<label className="form-label">Deduct From <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Deduct From <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Select
|
||||
value={formField.deduct_from}
|
||||
onValueChange={(value) => setFormField({ ...formField, deduct_from: value })}
|
||||
@ -509,12 +534,16 @@ const EditFeeDialog = () => {
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
|
||||
<div className="w-full">
|
||||
<label className="form-label">Deduct From Destination <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Deduct From Destination <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Select
|
||||
value={formField.deduct_from_account}
|
||||
onValueChange={(value) => setFormField({ ...formField, deduct_from_account: value })}
|
||||
onValueChange={(value) =>
|
||||
setFormField({ ...formField, deduct_from_account: value })
|
||||
}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select Wallet" />
|
||||
@ -528,16 +557,21 @@ const EditFeeDialog = () => {
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
|
||||
<div className="w-full">
|
||||
<label className="form-label">Credit To <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Credit To <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Select
|
||||
value={formField.credit_to}
|
||||
onValueChange={(value) => setFormField({
|
||||
...formField,
|
||||
credit_to: value,
|
||||
credit_destination: value === 'I' ? '' : '00000000-0000-0000-0000-000000000000'
|
||||
})}
|
||||
onValueChange={(value) =>
|
||||
setFormField({
|
||||
...formField,
|
||||
credit_to: value,
|
||||
credit_destination:
|
||||
value === 'I' ? '' : '00000000-0000-0000-0000-000000000000'
|
||||
})
|
||||
}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select Credit To" />
|
||||
@ -549,13 +583,17 @@ const EditFeeDialog = () => {
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
|
||||
{formField.credit_to === 'I' && (
|
||||
<div className="w-full">
|
||||
<label className="form-label">Credit Destination <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Credit Destination <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Select
|
||||
value={formField.credit_destination}
|
||||
onValueChange={(value) => setFormField({ ...formField, credit_destination: value })}
|
||||
onValueChange={(value) =>
|
||||
setFormField({ ...formField, credit_destination: value })
|
||||
}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select Customer" />
|
||||
@ -570,12 +608,16 @@ const EditFeeDialog = () => {
|
||||
</Select>
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
<div className="w-full">
|
||||
<label className="form-label">Credit Destination Account <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Credit Destination Account <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Select
|
||||
value={formField.credit_destination_account}
|
||||
onValueChange={(value) => setFormField({ ...formField, credit_destination_account: value })}
|
||||
onValueChange={(value) =>
|
||||
setFormField({ ...formField, credit_destination_account: value })
|
||||
}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select Wallet" />
|
||||
@ -589,9 +631,11 @@ const EditFeeDialog = () => {
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
|
||||
<div className="w-full">
|
||||
<label className="form-label">Transaction Type ID <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Transaction Type ID <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Select
|
||||
value={formField.transaction_type}
|
||||
onValueChange={(transaction_type) =>
|
||||
@ -610,9 +654,11 @@ const EditFeeDialog = () => {
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
|
||||
<div className="w-full">
|
||||
<label className="form-label">Status <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Status <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Select
|
||||
value={formField.status}
|
||||
onValueChange={(value) => setFormField({ ...formField, status: value })}
|
||||
@ -626,9 +672,11 @@ const EditFeeDialog = () => {
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
|
||||
<div className="w-full">
|
||||
<label className="form-label">Status Include <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Status Include <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Select
|
||||
value={formField.status_include}
|
||||
onValueChange={(value) => setFormField({ ...formField, status_include: value })}
|
||||
@ -642,9 +690,11 @@ const EditFeeDialog = () => {
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
|
||||
<div className="w-full">
|
||||
<label className="form-label">Priority <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Priority <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Select
|
||||
value={formField.priority}
|
||||
onValueChange={(value) => setFormField({ ...formField, priority: value })}
|
||||
@ -658,7 +708,7 @@ const EditFeeDialog = () => {
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
|
||||
<div className="flex justify-end pt-2.5 gap-5">
|
||||
<Button variant={'default'} type="submit" disabled={isSubmitting}>
|
||||
{isSubmitting ? 'Saving...' : 'Save Changes'}
|
||||
@ -673,4 +723,4 @@ const EditFeeDialog = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export { EditFeeDialog };
|
||||
export { EditFeeDialog };
|
||||
|
||||
@ -1,391 +1,400 @@
|
||||
import { DataGridColumnHeader, DataGridProvider, KeenIcon } from '@/components';
|
||||
import { Toaster } from '@/components/ui/sonner';
|
||||
import { apiConfig } from '@/config/api.config';
|
||||
import { useCallApi } from '@/hooks';
|
||||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import { createContext, useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import ListToolbar from '../blocks/ListToolBar';
|
||||
import DeleteDialog from '../blocks/DeleteDialog';
|
||||
import { EditFeeDialog } from '../blocks/EditDialog';
|
||||
import { useManageTransferTypeContext } from '../../transfertype/hooks/useManageTransferTypeContext';
|
||||
import { DataGridColumnHeader, DataGridProvider, KeenIcon } from '@/components';
|
||||
import { Toaster } from '@/components/ui/sonner';
|
||||
import { apiConfig } from '@/config/api.config';
|
||||
import { useCallApi } from '@/hooks';
|
||||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import { createContext, useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import ListToolbar from '../blocks/ListToolBar';
|
||||
import DeleteDialog from '../blocks/DeleteDialog';
|
||||
import { EditFeeDialog } from '../blocks/EditDialog';
|
||||
import { useManageTransferTypeContext } from '../../transfertype/hooks/useManageTransferTypeContext';
|
||||
|
||||
interface ContextProps {
|
||||
showEditFeeDialog: boolean;
|
||||
handleEditFeeDialog: (show: boolean, selected_TransferFee: string | null) => void;
|
||||
showAddFeeDialog: boolean;
|
||||
handleAddFeeDialog: (show: boolean) => void;
|
||||
handleDeleteFeeDialog: (show: boolean, selected_TransferFee: string | null) => void;
|
||||
showDeleteFeeDialog: boolean;
|
||||
selectedTransferFee: string | null;
|
||||
transactionTypeId: string | null;
|
||||
interface ContextProps {
|
||||
showEditFeeDialog: boolean;
|
||||
handleEditFeeDialog: (show: boolean, selected_TransferFee: string | null) => void;
|
||||
showAddFeeDialog: boolean;
|
||||
handleAddFeeDialog: (show: boolean) => void;
|
||||
handleDeleteFeeDialog: (show: boolean, selected_TransferFee: string | null) => void;
|
||||
showDeleteFeeDialog: boolean;
|
||||
selectedTransferFee: string | null;
|
||||
transactionTypeId: string | null;
|
||||
}
|
||||
|
||||
}
|
||||
const initialProps: ContextProps = {
|
||||
showEditFeeDialog: false,
|
||||
handleEditFeeDialog: () => {},
|
||||
showAddFeeDialog: false,
|
||||
handleAddFeeDialog: () => {},
|
||||
showDeleteFeeDialog: false,
|
||||
handleDeleteFeeDialog: () => {},
|
||||
selectedTransferFee: null,
|
||||
transactionTypeId: null
|
||||
};
|
||||
|
||||
const initialProps: ContextProps = {
|
||||
showEditFeeDialog: false,
|
||||
handleEditFeeDialog: () => {},
|
||||
showAddFeeDialog: false,
|
||||
handleAddFeeDialog: () => {},
|
||||
showDeleteFeeDialog: false,
|
||||
handleDeleteFeeDialog: () => {},
|
||||
selectedTransferFee: null,
|
||||
transactionTypeId: null,
|
||||
interface TransferFeeProps {
|
||||
name: string;
|
||||
description: string;
|
||||
minimum_amount: number;
|
||||
maximum_amount: number;
|
||||
period_start: string;
|
||||
period_end: string;
|
||||
deduct_amount: number;
|
||||
deduct_percentage: number;
|
||||
transaction_type: string;
|
||||
status: string;
|
||||
status_include: string;
|
||||
fee: number;
|
||||
}
|
||||
|
||||
};
|
||||
const ManageTransferFeeContext = createContext<ContextProps>(initialProps);
|
||||
const API_URL = apiConfig.service_transaction;
|
||||
|
||||
interface TransferFeeProps {
|
||||
name: string;
|
||||
description: string;
|
||||
minimum_amount: number;
|
||||
maximum_amount:number;
|
||||
period_start:string;
|
||||
period_end:string;
|
||||
deduct_amount: number;
|
||||
deduct_percentage: number;
|
||||
transaction_type: string;
|
||||
status: string;
|
||||
status_include: string;
|
||||
fee: number;
|
||||
}
|
||||
const ManageTransferFeeContextProvider = ({
|
||||
children,
|
||||
transactionTypeId = null
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
transactionTypeId?: string | null;
|
||||
}) => {
|
||||
const [showEditFeeDialog, setShowEditFeeDialog] = useState(false);
|
||||
const [showAddFeeDialog, setShowAddFeeDialog] = useState(false);
|
||||
const [showDeleteFeeDialog, setShowDeleteFeeDialog] = useState(false);
|
||||
const { showAddDialog, handleAddDialog, selectedTransferType } = useManageTransferTypeContext();
|
||||
const [selectedTransferFee, setSelectedTransferFee] = useState<string | null>(null);
|
||||
const { GetData } = useCallApi();
|
||||
const handleEditFeeDialog = useCallback((show: boolean, selected_TransferFee: string | null) => {
|
||||
setSelectedTransferFee(show ? selected_TransferFee : null);
|
||||
setShowEditFeeDialog(show);
|
||||
}, []);
|
||||
|
||||
const ManageTransferFeeContext = createContext<ContextProps>(initialProps);
|
||||
const API_URL = apiConfig.service_transaction;
|
||||
const handleAddFeeDialog = useCallback((show: boolean) => {
|
||||
setShowAddFeeDialog(show);
|
||||
}, []);
|
||||
|
||||
const ManageTransferFeeContextProvider = ({ children, transactionTypeId = null }: { children: React.ReactNode; transactionTypeId?: string | null }) => {
|
||||
const [showEditFeeDialog, setShowEditFeeDialog] = useState(false);
|
||||
const [showAddFeeDialog, setShowAddFeeDialog] = useState(false);
|
||||
const [showDeleteFeeDialog, setShowDeleteFeeDialog] = useState(false);
|
||||
const { showAddDialog, handleAddDialog, selectedTransferType } = useManageTransferTypeContext();
|
||||
const [selectedTransferFee, setSelectedTransferFee] = useState<string | null>(null);
|
||||
const { GetData } = useCallApi();
|
||||
const handleEditFeeDialog = useCallback((show: boolean, selected_TransferFee: string | null) => {
|
||||
setSelectedTransferFee(show ? selected_TransferFee : null);
|
||||
setShowEditFeeDialog(show);
|
||||
}, []);
|
||||
|
||||
const handleAddFeeDialog = useCallback((show: boolean) => {
|
||||
setShowAddFeeDialog(show);
|
||||
}, []);
|
||||
|
||||
const handleDeleteFeeDialog = useCallback((show: boolean, selected_TransferFee: string | null) => {
|
||||
const handleDeleteFeeDialog = useCallback(
|
||||
(show: boolean, selected_TransferFee: string | null) => {
|
||||
setSelectedTransferFee(show ? selected_TransferFee : null);
|
||||
setShowDeleteFeeDialog(show);
|
||||
}, []);
|
||||
const doGetTransferFeeListData = async (
|
||||
page: number,
|
||||
limit: number,
|
||||
sorting: any,
|
||||
filter: any
|
||||
) => {
|
||||
if (!selectedTransferType) {
|
||||
return { data: [], totalCount: 0 };
|
||||
}
|
||||
|
||||
sorting = sorting.length === 0 ? [{ id: 'id', desc: false }] : sorting;
|
||||
filter = filter.length === 0 ? {} : { any: filter[0].value.toLowerCase() };
|
||||
|
||||
try {
|
||||
const response = await GetData(`${API_URL}/transactionfees/getdatabytransactiontype/${selectedTransferType}`, {});
|
||||
|
||||
// console.log('API Response:', response?.data);
|
||||
|
||||
return {
|
||||
data: response?.data ,
|
||||
totalCount: 1
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error fetching transaction fees by transaction type:", error);
|
||||
return { data: [], totalCount: 0 };
|
||||
}
|
||||
};
|
||||
|
||||
const columns = useMemo<ColumnDef<any>[]>(
|
||||
() => [
|
||||
{
|
||||
accessorFn: (row) => row.name,
|
||||
id: 'name',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Name" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[200px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.description,
|
||||
id: 'description',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Description" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[250px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.minimum_amount,
|
||||
id: 'minimum_amount',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Min Amount" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[150px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.maximum_amount,
|
||||
id: 'maximum_amount',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Max Amount" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[150px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.fee_amount,
|
||||
id: 'fee_amount',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Fee Amount" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[150px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.deduct_amount,
|
||||
id: 'deduct_amount',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Deduct Amount" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[150px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.deduct_percentage,
|
||||
id: 'deduct_percentage',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Deduct %" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[150px]' }
|
||||
},
|
||||
|
||||
{
|
||||
accessorFn: (row) => row.period_start?.split('T')[0],
|
||||
id: 'period_start',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Period Start" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[200px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.period_end?.split('T')[0],
|
||||
id: 'period_end',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Period End" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[200px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.transaction_type?.name,
|
||||
id: 'transactionTypeId',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Transaction Type" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[250px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row: { credit_to: string }) => {
|
||||
const mapping: Record<string, string> = {
|
||||
D: 'Destination Member',
|
||||
S: 'Source Member',
|
||||
I: 'Input Customer'
|
||||
};
|
||||
|
||||
return mapping[row.credit_to] || 'Unknown';
|
||||
},
|
||||
id: 'credit_to',
|
||||
header: ({ column }) => (
|
||||
<DataGridColumnHeader title="Credit To" column={column} />
|
||||
),
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[250px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => {
|
||||
if (row.credit_to === 'S' || row.credit_to === 'D' || !row.credit_destination) {
|
||||
return 'N/A';
|
||||
}
|
||||
return row.credit_destination?.fullname;
|
||||
},
|
||||
id: 'credit_destination',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Credit Destination" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[250px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.credit_destination_account?.description,
|
||||
id: 'credit_destination_account',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Credit Destination Account" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[250px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row: { deduct_from: string }) => {
|
||||
const mapping: Record<string, string> = {
|
||||
D: 'Destination Member',
|
||||
S: 'Source Member',
|
||||
};
|
||||
|
||||
return mapping[row.deduct_from];
|
||||
},
|
||||
id: 'deduct_from',
|
||||
header: ({ column }) => (
|
||||
<DataGridColumnHeader title="Deduct From" column={column} />
|
||||
),
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[250px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.deduct_from_account?.description,
|
||||
id: 'deduct_from_account',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Deduct From Account" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[250px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.priority,
|
||||
id: 'priority',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Priority" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => {
|
||||
const isActive = row.original.priority === 'Y';
|
||||
|
||||
return (
|
||||
<span
|
||||
className={`px-2 py-1 text-xs font-semibold rounded-full ${
|
||||
isActive ? 'bg-green-100 text-green-600' : 'bg-red-100 text-red-600'
|
||||
}`}
|
||||
>
|
||||
{isActive ? 'Yes' : 'No'}
|
||||
</span>
|
||||
);
|
||||
},
|
||||
meta: {
|
||||
headerClassName: 'w-[100px]',
|
||||
cellClassName: 'text-center'
|
||||
}
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.status,
|
||||
id: 'status',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Status" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => {
|
||||
const isActive = row.original.status === 'Y';
|
||||
},
|
||||
[]
|
||||
);
|
||||
const doGetTransferFeeListData = async (
|
||||
page: number,
|
||||
limit: number,
|
||||
sorting: any,
|
||||
filter: any
|
||||
) => {
|
||||
if (!selectedTransferType) {
|
||||
return { data: [], totalCount: 0 };
|
||||
}
|
||||
|
||||
return (
|
||||
<span
|
||||
className={`px-2 py-1 text-xs font-semibold rounded-full ${
|
||||
isActive ? 'bg-green-100 text-green-600' : 'bg-red-100 text-red-600'
|
||||
}`}
|
||||
>
|
||||
{isActive ? 'Active' : 'Inactive'}
|
||||
</span>
|
||||
);
|
||||
},
|
||||
meta: {
|
||||
headerClassName: 'w-[100px]',
|
||||
cellClassName: 'text-center'
|
||||
}
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.status_include,
|
||||
id: 'status_include',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Status Include" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => {
|
||||
const isActive = row.original.status_include === 'Y';
|
||||
sorting = sorting.length === 0 ? [{ id: 'id', desc: false }] : sorting;
|
||||
filter = filter.length === 0 ? {} : { any: filter[0].value.toLowerCase() };
|
||||
|
||||
return (
|
||||
<span
|
||||
className={`px-2 py-1 text-xs font-semibold rounded-full ${
|
||||
isActive ? 'bg-green-100 text-green-600' : 'bg-red-100 text-red-600'
|
||||
}`}
|
||||
>
|
||||
{isActive ? 'Yes' : 'No'}
|
||||
</span>
|
||||
);
|
||||
},
|
||||
meta: {
|
||||
headerClassName: 'w-[100px]',
|
||||
cellClassName: 'text-center'
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Actions" column={column} />,
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
cell: (data) => {
|
||||
const row = data.row.original;
|
||||
return (
|
||||
<>
|
||||
<button
|
||||
className="btn btn-sm btn-icon btn-clear btn-light"
|
||||
onClick={() => handleEditFeeDialog(true, row.id)}
|
||||
>
|
||||
<KeenIcon icon="notepad-edit" />
|
||||
</button>
|
||||
<button
|
||||
className="btn btn-sm btn-icon btn-clear btn-light"
|
||||
onClick={() => handleDeleteFeeDialog(true, row.id)}
|
||||
>
|
||||
<KeenIcon icon="trash" />
|
||||
</button>
|
||||
</>
|
||||
);
|
||||
},
|
||||
meta: {
|
||||
headerClassName: 'w-[100px]',
|
||||
cellClassName: 'text-center'
|
||||
}
|
||||
}
|
||||
],
|
||||
[handleEditFeeDialog, handleDeleteFeeDialog]
|
||||
);
|
||||
try {
|
||||
const response = await GetData(
|
||||
`${API_URL}/transactionfees/getdatabytransactiontype/${selectedTransferType}`,
|
||||
{}
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="container mx-auto py-5">
|
||||
<div className="flex justify-between items-center mt-6">
|
||||
<h1 className="text-xl font-semibold text-gray-900">Manage Transaction Fee</h1>
|
||||
</div>
|
||||
<ManageTransferFeeContext.Provider
|
||||
value={{
|
||||
showEditFeeDialog,
|
||||
handleEditFeeDialog,
|
||||
showAddFeeDialog,
|
||||
handleAddFeeDialog,
|
||||
selectedTransferFee,
|
||||
showDeleteFeeDialog,
|
||||
handleDeleteFeeDialog,
|
||||
transactionTypeId
|
||||
}}
|
||||
>
|
||||
<Toaster expand visibleToasts={9} duration={3000} />
|
||||
<DataGridProvider
|
||||
columns={columns}
|
||||
pagination={{ size: 10 }}
|
||||
layout={{ card: true }}
|
||||
toolbar={<ListToolbar />}
|
||||
sorting={[{ id: 'id', desc: true }]}
|
||||
serverSide={true}
|
||||
onFetchData={({ pageIndex, pageSize, sorting, columnFilters }) =>
|
||||
doGetTransferFeeListData(pageIndex, pageSize, sorting, columnFilters)
|
||||
}
|
||||
>
|
||||
{children}
|
||||
// console.log('API Response:', response?.data);
|
||||
|
||||
</DataGridProvider>
|
||||
</ManageTransferFeeContext.Provider>
|
||||
</div>
|
||||
);
|
||||
return {
|
||||
data: response?.data,
|
||||
totalCount: 1
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Error fetching transaction fees by transaction type:', error);
|
||||
return { data: [], totalCount: 0 };
|
||||
}
|
||||
};
|
||||
|
||||
export { ManageTransferFeeContext, ManageTransferFeeContextProvider };
|
||||
const columns = useMemo<ColumnDef<any>[]>(
|
||||
() => [
|
||||
{
|
||||
accessorFn: (row) => row.name,
|
||||
id: 'name',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Name" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[200px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.description,
|
||||
id: 'description',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Description" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[250px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.minimum_amount,
|
||||
id: 'minimum_amount',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Min Amount" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[150px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.maximum_amount,
|
||||
id: 'maximum_amount',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Max Amount" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[150px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.fee_amount,
|
||||
id: 'fee_amount',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Fee Amount" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[150px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.deduct_amount,
|
||||
id: 'deduct_amount',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Deduct Amount" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[150px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.deduct_percentage,
|
||||
id: 'deduct_percentage',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Deduct %" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[150px]' }
|
||||
},
|
||||
|
||||
{
|
||||
accessorFn: (row) => row.period_start?.split('T')[0],
|
||||
id: 'period_start',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Period Start" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[200px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.period_end?.split('T')[0],
|
||||
id: 'period_end',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Period End" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[200px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.transaction_type?.name,
|
||||
id: 'transactionTypeId',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Transaction Type" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[250px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row: { credit_to: string }) => {
|
||||
const mapping: Record<string, string> = {
|
||||
D: 'Destination Member',
|
||||
S: 'Source Member',
|
||||
I: 'Input Customer'
|
||||
};
|
||||
|
||||
return mapping[row.credit_to] || 'Unknown';
|
||||
},
|
||||
id: 'credit_to',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Credit To" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[250px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => {
|
||||
if (row.credit_to === 'S' || row.credit_to === 'D' || !row.credit_destination) {
|
||||
return 'N/A';
|
||||
}
|
||||
return row.credit_destination?.fullname;
|
||||
},
|
||||
id: 'credit_destination',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Credit Destination" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[250px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.credit_destination_account?.description,
|
||||
id: 'credit_destination_account',
|
||||
header: ({ column }) => (
|
||||
<DataGridColumnHeader title="Credit Destination Account" column={column} />
|
||||
),
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[250px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row: { deduct_from: string }) => {
|
||||
const mapping: Record<string, string> = {
|
||||
D: 'Destination Member',
|
||||
S: 'Source Member'
|
||||
};
|
||||
|
||||
return mapping[row.deduct_from];
|
||||
},
|
||||
id: 'deduct_from',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Deduct From" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[250px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.deduct_from_account?.description,
|
||||
id: 'deduct_from_account',
|
||||
header: ({ column }) => (
|
||||
<DataGridColumnHeader title="Deduct From Account" column={column} />
|
||||
),
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[250px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.priority,
|
||||
id: 'priority',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Priority" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => {
|
||||
const isActive = row.original.priority === 'Y';
|
||||
|
||||
return (
|
||||
<span
|
||||
className={`px-2 py-1 text-xs font-semibold rounded-full ${
|
||||
isActive ? 'bg-green-100 text-green-600' : 'bg-red-100 text-red-600'
|
||||
}`}
|
||||
>
|
||||
{isActive ? 'Yes' : 'No'}
|
||||
</span>
|
||||
);
|
||||
},
|
||||
meta: {
|
||||
headerClassName: 'w-[100px]',
|
||||
cellClassName: 'text-center'
|
||||
}
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.status,
|
||||
id: 'status',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Status" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => {
|
||||
const isActive = row.original.status === 'Y';
|
||||
|
||||
return (
|
||||
<span
|
||||
className={`px-2 py-1 text-xs font-semibold rounded-full ${
|
||||
isActive ? 'bg-green-100 text-green-600' : 'bg-red-100 text-red-600'
|
||||
}`}
|
||||
>
|
||||
{isActive ? 'Active' : 'Inactive'}
|
||||
</span>
|
||||
);
|
||||
},
|
||||
meta: {
|
||||
headerClassName: 'w-[100px]',
|
||||
cellClassName: 'text-center'
|
||||
}
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.status_include,
|
||||
id: 'status_include',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Status Include" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => {
|
||||
const isActive = row.original.status_include === 'Y';
|
||||
|
||||
return (
|
||||
<span
|
||||
className={`px-2 py-1 text-xs font-semibold rounded-full ${
|
||||
isActive ? 'bg-green-100 text-green-600' : 'bg-red-100 text-red-600'
|
||||
}`}
|
||||
>
|
||||
{isActive ? 'Yes' : 'No'}
|
||||
</span>
|
||||
);
|
||||
},
|
||||
meta: {
|
||||
headerClassName: 'w-[100px]',
|
||||
cellClassName: 'text-center'
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Actions" column={column} />,
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
cell: (data) => {
|
||||
const row = data.row.original;
|
||||
return (
|
||||
<>
|
||||
<button
|
||||
className="btn btn-sm btn-icon btn-clear btn-light"
|
||||
onClick={() => handleEditFeeDialog(true, row.id)}
|
||||
>
|
||||
<KeenIcon icon="notepad-edit" />
|
||||
</button>
|
||||
<button
|
||||
className="btn btn-sm btn-icon btn-clear btn-light"
|
||||
onClick={() => handleDeleteFeeDialog(true, row.id)}
|
||||
>
|
||||
<KeenIcon icon="trash" />
|
||||
</button>
|
||||
</>
|
||||
);
|
||||
},
|
||||
meta: {
|
||||
headerClassName: 'w-[100px]',
|
||||
cellClassName: 'text-center'
|
||||
}
|
||||
}
|
||||
],
|
||||
[handleEditFeeDialog, handleDeleteFeeDialog]
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="container mx-auto py-5">
|
||||
<div className="flex justify-between items-center mt-6">
|
||||
<h1 className="text-xl font-semibold text-gray-900">Manage Transaction Fee</h1>
|
||||
</div>
|
||||
<ManageTransferFeeContext.Provider
|
||||
value={{
|
||||
showEditFeeDialog,
|
||||
handleEditFeeDialog,
|
||||
showAddFeeDialog,
|
||||
handleAddFeeDialog,
|
||||
selectedTransferFee,
|
||||
showDeleteFeeDialog,
|
||||
handleDeleteFeeDialog,
|
||||
transactionTypeId
|
||||
}}
|
||||
>
|
||||
<Toaster expand visibleToasts={9} duration={3000} />
|
||||
<DataGridProvider
|
||||
columns={columns}
|
||||
pagination={{ size: 10 }}
|
||||
layout={{ card: true }}
|
||||
toolbar={<ListToolbar />}
|
||||
sorting={[{ id: 'id', desc: true }]}
|
||||
serverSide={true}
|
||||
onFetchData={({ pageIndex, pageSize, sorting, columnFilters }) =>
|
||||
doGetTransferFeeListData(pageIndex, pageSize, sorting, columnFilters)
|
||||
}
|
||||
>
|
||||
{children}
|
||||
</DataGridProvider>
|
||||
</ManageTransferFeeContext.Provider>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export { ManageTransferFeeContext, ManageTransferFeeContextProvider };
|
||||
|
||||
Reference in New Issue
Block a user