fixing transactionfee
This commit is contained in:
@ -7,7 +7,8 @@ import {
|
|||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
SelectValue
|
SelectValue
|
||||||
} from '@/components/ui/select';
|
} from '@/components/ui/select';
|
||||||
|
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
|
||||||
|
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from '@/components/ui/command';
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogBody,
|
DialogBody,
|
||||||
@ -59,6 +60,7 @@ const EditFeeDialog = () => {
|
|||||||
const [transactionTypes, setTransactionTypes] = useState<TransactionTypeProps[]>([]);
|
const [transactionTypes, setTransactionTypes] = useState<TransactionTypeProps[]>([]);
|
||||||
const parsedUser = getAuth()?.user;
|
const parsedUser = getAuth()?.user;
|
||||||
const [customers, setCustomers] = useState<CustomerProps[]>([]);
|
const [customers, setCustomers] = useState<CustomerProps[]>([]);
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
const [alert, setAlert] = useState({
|
const [alert, setAlert] = useState({
|
||||||
show: false,
|
show: false,
|
||||||
message: ''
|
message: ''
|
||||||
@ -94,24 +96,22 @@ const EditFeeDialog = () => {
|
|||||||
const formattedTime = updated_time.toISOString().slice(0, 19).replace('T', ' ');
|
const formattedTime = updated_time.toISOString().slice(0, 19).replace('T', ' ');
|
||||||
|
|
||||||
if (showEditFeeDialog) {
|
if (showEditFeeDialog) {
|
||||||
setFormField({
|
setFormField(prevState => ({
|
||||||
...formField,
|
...prevState,
|
||||||
updated_by: parsedUser?.username,
|
updated_by: parsedUser?.username,
|
||||||
updated_at: formattedTime
|
updated_at: formattedTime
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
}, [showEditFeeDialog]);
|
}, [showEditFeeDialog]);
|
||||||
|
|
||||||
const resetForm = () => {
|
const resetForm = () => {
|
||||||
if (selectedTransferFee) {
|
if (selectedTransferFee) {
|
||||||
// Re-fetch the current data to reset the form to original values
|
|
||||||
fetchTransactionFee(selectedTransferFee);
|
fetchTransactionFee(selectedTransferFee);
|
||||||
} else {
|
} else {
|
||||||
setFormField(initialState);
|
setFormField(initialState);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* actions */
|
|
||||||
const doUpdateTransferFee = useCallback(
|
const doUpdateTransferFee = useCallback(
|
||||||
async (e: React.FormEvent<HTMLFormElement>) => {
|
async (e: React.FormEvent<HTMLFormElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@ -257,15 +257,10 @@ const EditFeeDialog = () => {
|
|||||||
|
|
||||||
const fetchTransactionFee = useCallback(async (id: string) => {
|
const fetchTransactionFee = useCallback(async (id: string) => {
|
||||||
try {
|
try {
|
||||||
const response = await GetData(`${API_URL}/transactionfees/getdata/${id}`, { id });
|
const response = await GetData(`${API_URL}/transactionfees/getdata/${id}`, { });
|
||||||
|
|
||||||
if (response?.status) {
|
if (response?.status) {
|
||||||
let creditTo = '';
|
|
||||||
if (response.data.credit_destination?.id === '00000000-0000-0000-0000-000000000000') {
|
|
||||||
creditTo = 'D';
|
|
||||||
} else {
|
|
||||||
creditTo = 'I';
|
|
||||||
}
|
|
||||||
|
|
||||||
setFormField({
|
setFormField({
|
||||||
...initialState,
|
...initialState,
|
||||||
@ -282,23 +277,21 @@ const EditFeeDialog = () => {
|
|||||||
priority: response.data.priority || '',
|
priority: response.data.priority || '',
|
||||||
status: response.data.status || '',
|
status: response.data.status || '',
|
||||||
status_include: response.data.status_include || '',
|
status_include: response.data.status_include || '',
|
||||||
deduct_from: 'S',
|
deduct_from: response.data.deduct_from||'',
|
||||||
deduct_from_account: response.data.deduct_from_account?.id || '',
|
deduct_from_account: response.data.deduct_from_account?.id || '',
|
||||||
credit_to: creditTo,
|
credit_to: response.data.credit_to || '',
|
||||||
credit_destination: response.data.credit_destination?.id || '00000000-0000-0000-0000-000000000000',
|
credit_destination: response.data.credit_destination?.id || '00000000-0000-0000-0000-000000000000',
|
||||||
credit_destination_account: response.data.credit_destination_account?.id || '',
|
credit_destination_account: response.data.credit_destination_account?.id || '',
|
||||||
updated_by: parsedUser?.username,
|
updated_by: parsedUser?.username,
|
||||||
updated_at: new Date().toISOString().slice(0, 19).replace('T', ' ')
|
updated_at: new Date().toISOString().slice(0, 19).replace('T', ' ')
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.log(response)
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching transaction fee details', error);
|
console.error('Error fetching transaction fee details', error);
|
||||||
setAlert({ show: true, message: 'Failed to fetch transaction fee details' });
|
setAlert({ show: true, message: 'Failed to fetch transaction fee details' });
|
||||||
}
|
}
|
||||||
}, [GetData, parsedUser?.username]); // only use username if that's all you need
|
}, [GetData, parsedUser?.username]);
|
||||||
|
|
||||||
// This flag ensures it only fetches once per open
|
|
||||||
const hasFetchedRef = useRef(false);
|
const hasFetchedRef = useRef(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -307,15 +300,23 @@ const EditFeeDialog = () => {
|
|||||||
hasFetchedRef.current = true;
|
hasFetchedRef.current = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset fetch flag if dialog is closed
|
|
||||||
if (!showEditFeeDialog) {
|
if (!showEditFeeDialog) {
|
||||||
hasFetchedRef.current = false;
|
hasFetchedRef.current = false;
|
||||||
}
|
}
|
||||||
}, [selectedTransferFee, showEditFeeDialog, fetchTransactionFee]);
|
}, [selectedTransferFee, showEditFeeDialog, fetchTransactionFee]);
|
||||||
|
|
||||||
|
const handleCloseDialog = () => {
|
||||||
|
setFormField(initialState);
|
||||||
|
setAlert({ show: false, message: '' });
|
||||||
|
handleEditFeeDialog(false, null);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={showEditFeeDialog} onOpenChange={(open) => handleEditFeeDialog(open, null)}>
|
<Dialog open={showEditFeeDialog} onOpenChange={(open) => {
|
||||||
|
if (!open) {
|
||||||
|
handleCloseDialog();
|
||||||
|
}
|
||||||
|
}}>
|
||||||
<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">
|
||||||
<DialogTitle></DialogTitle>
|
<DialogTitle></DialogTitle>
|
||||||
<DialogDescription></DialogDescription>
|
<DialogDescription></DialogDescription>
|
||||||
@ -328,7 +329,7 @@ const EditFeeDialog = () => {
|
|||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className="cursor-pointer hover:opacity-100 opacity-50"
|
className="cursor-pointer hover:opacity-100 opacity-50"
|
||||||
onClick={() => handleEditFeeDialog(false, null)}
|
onClick={handleCloseDialog}
|
||||||
>
|
>
|
||||||
<KeenIcon icon="cross" className="text-1.5xl" />
|
<KeenIcon icon="cross" className="text-1.5xl" />
|
||||||
</div>
|
</div>
|
||||||
@ -654,13 +655,6 @@ const EditFeeDialog = () => {
|
|||||||
</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>
|
||||||
|
|||||||
@ -181,7 +181,30 @@ const ManageTransferFeeContextProvider = ({ children }: { children: React.ReactN
|
|||||||
meta: { headerClassName: 'w-[250px]' }
|
meta: { headerClassName: 'w-[250px]' }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorFn: (row) => row.credit_destination?.fullname,
|
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',
|
id: 'credit_destination',
|
||||||
header: ({ column }) => <DataGridColumnHeader title="Credit Destination" column={column} />,
|
header: ({ column }) => <DataGridColumnHeader title="Credit Destination" column={column} />,
|
||||||
enableSorting: true,
|
enableSorting: true,
|
||||||
@ -196,37 +219,102 @@ const ManageTransferFeeContextProvider = ({ children }: { children: React.ReactN
|
|||||||
enableHiding: false,
|
enableHiding: false,
|
||||||
meta: { headerClassName: 'w-[250px]' }
|
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,
|
accessorFn: (row) => row.deduct_from_account?.description,
|
||||||
id: 'deduct_from_account',
|
id: 'deduct_from_account',
|
||||||
header: ({ column }) => <DataGridColumnHeader title="Credit Destination Account" column={column} />,
|
header: ({ column }) => <DataGridColumnHeader title="Deduct From Account" column={column} />,
|
||||||
enableSorting: true,
|
enableSorting: true,
|
||||||
enableHiding: false,
|
enableHiding: false,
|
||||||
meta: { headerClassName: 'w-[250px]' }
|
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.priority === 'Y' ? 'Yes' : 'No'),
|
accessorFn: (row) => row.status,
|
||||||
id: 'priority',
|
|
||||||
header: ({ column }) => <DataGridColumnHeader title="Priority" column={column} />,
|
|
||||||
enableSorting: true,
|
|
||||||
enableHiding: false,
|
|
||||||
meta: { headerClassName: 'w-[100px]' }
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorFn: (row) => (row.status === 'Y' ? 'Active' : 'Inactive'),
|
|
||||||
id: 'status',
|
id: 'status',
|
||||||
header: ({ column }) => <DataGridColumnHeader title="Status" column={column} />,
|
header: ({ column }) => <DataGridColumnHeader title="Status" column={column} />,
|
||||||
enableSorting: true,
|
enableSorting: true,
|
||||||
enableHiding: false,
|
enableHiding: false,
|
||||||
meta: { headerClassName: 'w-[150px]' }
|
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 === 'Y' ? 'Yes' : 'No'),
|
accessorFn: (row) => row.status_include,
|
||||||
id: 'status_include',
|
id: 'status_include',
|
||||||
header: ({ column }) => <DataGridColumnHeader title="Status Include" column={column} />,
|
header: ({ column }) => <DataGridColumnHeader title="Status Include" column={column} />,
|
||||||
enableSorting: true,
|
enableSorting: true,
|
||||||
enableHiding: false,
|
enableHiding: false,
|
||||||
meta: { headerClassName: 'w-[150px]' }
|
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',
|
id: 'actions',
|
||||||
|
|||||||
@ -701,15 +701,6 @@ 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="reset"
|
|
||||||
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>
|
||||||
@ -724,7 +715,7 @@ const EditDialog = () => {
|
|||||||
</div>
|
</div>
|
||||||
<AddFeeDialog />
|
<AddFeeDialog />
|
||||||
<DeleteFeeDialog />
|
<DeleteFeeDialog />
|
||||||
{/* <EditFeeDialog /> */}
|
<EditFeeDialog />
|
||||||
</Container>
|
</Container>
|
||||||
</ManageTransferFeeContextProvider>
|
</ManageTransferFeeContextProvider>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user