fixing Add+ delete+ managetransferfee
This commit is contained in:
@ -7,6 +7,7 @@ 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;
|
||||
@ -28,6 +29,21 @@ const initialProps: ContextProps = {
|
||||
selectedTransferFee: 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;
|
||||
|
||||
@ -35,6 +51,7 @@ const ManageTransferFeeContextProvider = ({ children }: { children: React.ReactN
|
||||
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();
|
||||
@ -58,18 +75,28 @@ const ManageTransferFeeContextProvider = ({ children }: { children: React.ReactN
|
||||
sorting: any,
|
||||
filter: any
|
||||
) => {
|
||||
sorting = sorting.length == 0 ? [{ id: 'id', desc: false }] : sorting;
|
||||
filter = filter.length == 0 ? {} : { any: filter[0].value.toLowerCase() };
|
||||
const response = await GetData(`${API_URL}/transactionfees/list`, {
|
||||
limit: limit,
|
||||
page: page+1,
|
||||
with_deleted: false,
|
||||
order_field: sorting[0].id,
|
||||
order_direction: sorting[0].desc ? 'ASC' : 'DESC',
|
||||
filter: JSON.stringify(filter)
|
||||
});
|
||||
return { data: response?.data.list, totalCount: response?.data.total_count };
|
||||
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>[]>(
|
||||
() => [
|
||||
{
|
||||
@ -105,20 +132,12 @@ const ManageTransferFeeContextProvider = ({ children }: { children: React.ReactN
|
||||
meta: { headerClassName: 'w-[150px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.period_start?.split('T')[0],
|
||||
id: 'period_start',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Period Start" column={column} />,
|
||||
accessorFn: (row) => row.fee_amount,
|
||||
id: 'fee_amount',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Fee Amount" 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]' }
|
||||
meta: { headerClassName: 'w-[150px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.deduct_amount,
|
||||
@ -136,6 +155,23 @@ const ManageTransferFeeContextProvider = ({ children }: { children: React.ReactN
|
||||
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',
|
||||
@ -144,6 +180,30 @@ const ManageTransferFeeContextProvider = ({ children }: { children: React.ReactN
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[250px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => 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) => row.deduct_from_account?.description,
|
||||
id: 'deduct_from_account',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Credit Destination Account" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[250px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => (row.priority === 'Y' ? 'Yes' : 'No'),
|
||||
id: 'priority',
|
||||
@ -230,8 +290,7 @@ const ManageTransferFeeContextProvider = ({ children }: { children: React.ReactN
|
||||
}
|
||||
>
|
||||
{children}
|
||||
<DeleteDialog />
|
||||
<EditFeeDialog />
|
||||
|
||||
</DataGridProvider>
|
||||
</ManageTransferFeeContext.Provider>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user