butuh install packagee react number format
This commit is contained in:
@ -0,0 +1,236 @@
|
||||
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';
|
||||
|
||||
interface ContextProps {
|
||||
showEditFeeDialog: boolean;
|
||||
handleEditFeeDialog: (show: boolean, selectedTransferFee: string | null) => void;
|
||||
showAddFeeDialog: boolean;
|
||||
handleAddFeeDialog: (show: boolean) => void;
|
||||
handleDeleteFeeDialog: (show: boolean, selectedTransferFee: string | null) => void;
|
||||
showDeleteFeeDialog: boolean;
|
||||
selectedTransferFee: string | null;
|
||||
}
|
||||
|
||||
const initialProps: ContextProps = {
|
||||
showEditFeeDialog: false,
|
||||
handleEditFeeDialog: () => {},
|
||||
showAddFeeDialog: false,
|
||||
handleAddFeeDialog: () => {},
|
||||
showDeleteFeeDialog: false,
|
||||
handleDeleteFeeDialog: () => {},
|
||||
selectedTransferFee: null
|
||||
};
|
||||
|
||||
const ManageTransferFeeContext = createContext<ContextProps>(initialProps);
|
||||
const API_URL = apiConfig.service_transaction;
|
||||
|
||||
const ManageTransferFeeContextProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
const [showEditFeeDialog, setShowEditFeeDialog] = useState(false);
|
||||
const [showAddFeeDialog, setShowAddFeeDialog] = useState(false);
|
||||
const [showDeleteFeeDialog, setShowDeleteFeeDialog] = useState(false);
|
||||
|
||||
const [selectedTransferFee, setSelectedTransferFee] = useState<string | null>(null);
|
||||
const { GetData } = useCallApi();
|
||||
|
||||
const handleEditFeeDialog = useCallback((show: boolean, selectedTransferFee: string | null) => {
|
||||
setSelectedTransferFee(show ? selectedTransferFee : null);
|
||||
setShowEditFeeDialog(show);
|
||||
}, []);
|
||||
|
||||
const handleAddFeeDialog = useCallback((show: boolean) => {
|
||||
setShowAddFeeDialog(show);
|
||||
}, []);
|
||||
|
||||
const handleDeleteFeeDialog = useCallback((show: boolean, selectedTransferFee: string | null) => {
|
||||
setSelectedTransferFee(show ? selectedTransferFee : null);
|
||||
setShowDeleteFeeDialog(show);
|
||||
}, []);
|
||||
const doGetTransferFeeListData = async (
|
||||
page: number,
|
||||
limit: number,
|
||||
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: 1,
|
||||
with_deleted: false,
|
||||
order_field: sorting[0].id,
|
||||
order_direction: sorting[0].desc ? 'ASC' : 'DESC',
|
||||
filter: JSON.stringify(filter)
|
||||
});
|
||||
console.log('hasilnya', response?.data.list);
|
||||
console.log('transactiontype', response?.data);
|
||||
|
||||
return { data: response?.data.list, totalCount: response?.data.total_count };
|
||||
};
|
||||
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.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.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.priority,
|
||||
id: 'priority',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Priority" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[100px]' }
|
||||
},
|
||||
{
|
||||
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) => row.status_include,
|
||||
id: 'status_include',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Status Include" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[150px]' }
|
||||
},
|
||||
{
|
||||
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 mb-4">
|
||||
<h1 className="text-2xl font-semibold">Manage Transaction Fee</h1>
|
||||
</div>
|
||||
<ManageTransferFeeContext.Provider
|
||||
value={{
|
||||
showEditFeeDialog,
|
||||
handleEditFeeDialog,
|
||||
showAddFeeDialog,
|
||||
handleAddFeeDialog,
|
||||
selectedTransferFee,
|
||||
showDeleteFeeDialog,
|
||||
handleDeleteFeeDialog
|
||||
}}
|
||||
>
|
||||
<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}
|
||||
<DeleteDialog />
|
||||
<EditFeeDialog />
|
||||
</DataGridProvider>
|
||||
</ManageTransferFeeContext.Provider>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export { ManageTransferFeeContext, ManageTransferFeeContextProvider };
|
||||
@ -0,0 +1,12 @@
|
||||
import { useContext } from 'react';
|
||||
import { ManageTransferFeeContext } from './ManageTransferFeeContext';
|
||||
|
||||
const useManageTransferFeeContext = () => {
|
||||
const context = useContext(ManageTransferFeeContext);
|
||||
|
||||
if (!context) throw new Error('useManageAccessTypeContext must be used within AuthProvider');
|
||||
|
||||
return context;
|
||||
};
|
||||
|
||||
export { useManageTransferFeeContext };
|
||||
Reference in New Issue
Block a user