fix customer

This commit is contained in:
bagusajisaputroo
2025-03-24 15:33:01 +07:00
parent 2960ed2b8e
commit 8160529dcb
4 changed files with 128 additions and 108 deletions

View File

@ -487,10 +487,13 @@ const EditFeeDialog = () => {
</Select> </Select>
</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" <Button
onClick={() => { variant={'outline'}
resetForm(); type="reset"
}}> onClick={() => {
resetForm();
}}
>
Reset Reset
</Button> </Button>
<Button variant={'default'} type="submit" disabled={isSubmitting}> <Button variant={'default'} type="submit" disabled={isSubmitting}>

View File

@ -199,7 +199,9 @@ const AddDialog = () => {
<DialogDescription></DialogDescription> <DialogDescription></DialogDescription>
<div className="flex items-center justify-between flex-wrap grow"> <div className="flex items-center justify-between flex-wrap grow">
<div className="flex flex-col justify-center"> <div className="flex flex-col justify-center">
<h1 className="text-xl font-semibold leading-none text-gray-900">Addd Transaction Type</h1> <h1 className="text-xl font-semibold leading-none text-gray-900">
Addd Transaction Type
</h1>
<div className="flex items-center gap-2 text-sm font-normal text-gray-700"></div> <div className="flex items-center gap-2 text-sm font-normal text-gray-700"></div>
</div> </div>
<div <div

View File

@ -506,10 +506,13 @@ const EditDialog = () => {
Transaction Fee Form Transaction Fee Form
</Button> */} </Button> */}
<Button variant={'outline'} type="reset" <Button
onClick={() => { variant={'outline'}
resetForm(); type="reset"
}}> onClick={() => {
resetForm();
}}
>
Reset Reset
</Button> </Button>
<Button variant={'default'} type="submit" disabled={isSubmitting}> <Button variant={'default'} type="submit" disabled={isSubmitting}>

View File

@ -1,87 +1,86 @@
import { DataGridColumnHeader, DataGridProvider, KeenIcon } from '@/components'; import { DataGridColumnHeader, DataGridProvider, KeenIcon } from '@/components';
import { Toaster } from '@/components/ui/sonner'; import { Toaster } from '@/components/ui/sonner';
import { apiConfig } from '@/config/api.config'; import { apiConfig } from '@/config/api.config';
import { useCallApi } from '@/hooks'; import { useCallApi } from '@/hooks';
import { ColumnDef } from '@tanstack/react-table'; import { ColumnDef } from '@tanstack/react-table';
import { createContext, useCallback, useEffect, useMemo, useState } from 'react'; import { createContext, useCallback, useEffect, useMemo, useState } from 'react';
import ListToolbar from '../blocks/ListToolBar'; import ListToolbar from '../blocks/ListToolBar';
interface AccountProps {
id: string;
name: string;
}
interface AccountProps { interface TransferType {
id: string; id: string;
name: string; name: string;
} minimum_amount: number;
maximum_amount: number;
max_transaction_per_day: number;
walletOriginId: string;
walletDestinationId: string;
status: string;
}
interface TransferType { interface ContextProps {
id: string; showEditDialog: boolean;
name: string; handleEditDialog: (show: boolean, selected_user: string | null) => void;
minimum_amount: number; showAddDialog: boolean;
maximum_amount: number; handleAddDialog: (show: boolean) => void;
max_transaction_per_day: number; showDeleteDialog: boolean;
walletOriginId: string; handleDeleteDialog: (show: boolean, selected_user: string | null) => void;
walletDestinationId: string; selectedTransferType: string | null;
status: string; transferType: string | null;
} accounts: AccountProps[];
}
interface ContextProps { const initialProps: ContextProps = {
showEditDialog: boolean; showEditDialog: false,
handleEditDialog: (show: boolean, selected_user: string | null) => void; handleEditDialog: () => {},
showAddDialog: boolean; showAddDialog: false,
handleAddDialog: (show: boolean) => void; handleAddDialog: () => {},
showDeleteDialog: boolean; showDeleteDialog: false,
handleDeleteDialog: (show: boolean, selected_user: string | null) => void; handleDeleteDialog: () => {},
selectedTransferType: string | null; selectedTransferType: null,
transferType: string|null; accounts: [],
accounts: AccountProps[]; transferType: null
} };
const initialProps: ContextProps = { const ManageTransferTypeContext = createContext<ContextProps>(initialProps);
showEditDialog: false, const API_URL = apiConfig.service_transaction;
handleEditDialog: () => {},
showAddDialog: false,
handleAddDialog: () => {},
showDeleteDialog: false,
handleDeleteDialog: () => {},
selectedTransferType: null,
accounts: [],
transferType: null
};
const ManageTransferTypeContext = createContext<ContextProps>(initialProps); const ManageTransferTypeContextProvider = ({ children }: { children: React.ReactNode }) => {
const API_URL = apiConfig.service_transaction; const [showEditDialog, setShowEditDialog] = useState(false);
const [showAddDialog, setShowAddDialog] = useState(false);
const [showDeleteDialog, setShowDeleteDialog] = useState(false);
const [selectedUser, setSelectedUser] = useState<string | null>(null);
const [accounts, setAccount] = useState<AccountProps[]>([]);
const { GetData } = useCallApi();
const [selectedTransferType, setSelectedTransferType] = useState<string | null>(null);
const [transferType, setTransferType] = useState<string | null>(null);
const ManageTransferTypeContextProvider = ({ children }: { children: React.ReactNode }) => { const handleEditDialog = useCallback((show: boolean, selected_transfertype: string | null) => {
const [showEditDialog, setShowEditDialog] = useState(false); setSelectedTransferType(show ? selected_transfertype : null);
const [showAddDialog, setShowAddDialog] = useState(false); setShowEditDialog(show);
const [showDeleteDialog, setShowDeleteDialog] = useState(false); }, []);
const [selectedUser, setSelectedUser] = useState<string | null>(null);
const [accounts, setAccount] = useState<AccountProps[]>([]);
const { GetData } = useCallApi();
const [selectedTransferType, setSelectedTransferType] = useState<string | null>(null);
const [transferType, setTransferType] = useState<string | null>(null);
const handleAddDialog = useCallback((show: boolean) => {
setShowAddDialog(show);
}, []);
const handleEditDialog = useCallback((show: boolean, selected_transfertype: string | null) => { const handleDeleteDialog = useCallback((show: boolean, selected_transfertype: string | null) => {
setSelectedTransferType(show ? selected_transfertype : null); setShowDeleteDialog(show);
setShowEditDialog(show); setSelectedTransferType(show ? selected_transfertype : null);
}, []); }, []);
const handleAddDialog = useCallback((show: boolean) => { const columns = useMemo<ColumnDef<any>[]>(
setShowAddDialog(show);
}, []);
const handleDeleteDialog = useCallback((show: boolean, selected_transfertype: string | null) => {
setShowDeleteDialog(show);
setSelectedTransferType(show ? selected_transfertype : null);
}, []);
const columns = useMemo<ColumnDef<any>[]>(
() => [ () => [
{ {
accessorFn: (row) => row.name, accessorFn: (row) => row.name,
id: 'name', id: 'name',
header: ({ column }) => <DataGridColumnHeader title="Transaction Type Name" column={column} />, header: ({ column }) => (
<DataGridColumnHeader title="Transaction Type Name" column={column} />
),
enableSorting: true, enableSorting: true,
enableHiding: false, enableHiding: false,
meta: { headerClassName: 'w-[250px]' } meta: { headerClassName: 'w-[250px]' }
@ -121,7 +120,9 @@
{ {
accessorFn: (row) => row.max_transaction_per_day, accessorFn: (row) => row.max_transaction_per_day,
id: 'max_transaction_per_day', id: 'max_transaction_per_day',
header: ({ column }) => <DataGridColumnHeader title="Max Transaction Per Day" column={column} />, header: ({ column }) => (
<DataGridColumnHeader title="Max Transaction Per Day" column={column} />
),
enableSorting: true, enableSorting: true,
enableHiding: false, enableHiding: false,
meta: { headerClassName: 'w-[250px]' } meta: { headerClassName: 'w-[250px]' }
@ -135,9 +136,11 @@
meta: { headerClassName: 'w-[250px]' } meta: { headerClassName: 'w-[250px]' }
}, },
{ {
accessorFn: (row) => row.wallet_fee_destination.name , accessorFn: (row) => row.wallet_fee_destination.name,
id: 'wallet_fee_destination', id: 'wallet_fee_destination',
header: ({ column }) => <DataGridColumnHeader title="Wallet Fee Destination" column={column} />, header: ({ column }) => (
<DataGridColumnHeader title="Wallet Fee Destination" column={column} />
),
enableSorting: true, enableSorting: true,
enableHiding: false, enableHiding: false,
meta: { headerClassName: 'w-[250px]' } meta: { headerClassName: 'w-[250px]' }
@ -145,7 +148,9 @@
{ {
accessorFn: (row) => row.customer_fee_destination?.username || 'N/A', accessorFn: (row) => row.customer_fee_destination?.username || 'N/A',
id: 'customer_fee_destination', id: 'customer_fee_destination',
header: ({ column }) => <DataGridColumnHeader title="Customer Fee Destination" column={column} />, header: ({ column }) => (
<DataGridColumnHeader title="Customer Fee Destination" column={column} />
),
enableSorting: true, enableSorting: true,
enableHiding: false, enableHiding: false,
meta: { headerClassName: 'w-[250px]' } meta: { headerClassName: 'w-[250px]' }
@ -165,8 +170,7 @@
enableSorting: true, enableSorting: true,
enableHiding: false, enableHiding: false,
meta: { headerClassName: 'w-[150px]' } meta: { headerClassName: 'w-[150px]' }
} },
,
{ {
id: 'actions', id: 'actions',
header: ({ column }) => <DataGridColumnHeader title="Actions" column={column} />, header: ({ column }) => <DataGridColumnHeader title="Actions" column={column} />,
@ -176,10 +180,16 @@
const row = data.row.original; const row = data.row.original;
return ( return (
<> <>
<button className="btn btn-sm btn-icon btn-clear btn-light" onClick={() => handleEditDialog(true, row.id)}> <button
className="btn btn-sm btn-icon btn-clear btn-light"
onClick={() => handleEditDialog(true, row.id)}
>
<KeenIcon icon="notepad-edit" /> <KeenIcon icon="notepad-edit" />
</button> </button>
<button className="btn btn-sm btn-icon btn-clear btn-light" onClick={() => handleDeleteDialog(true, row.id)}> <button
className="btn btn-sm btn-icon btn-clear btn-light"
onClick={() => handleDeleteDialog(true, row.id)}
>
<KeenIcon icon="trash" /> <KeenIcon icon="trash" />
</button> </button>
</> </>
@ -190,24 +200,27 @@
], ],
[handleEditDialog, handleDeleteDialog] [handleEditDialog, handleDeleteDialog]
); );
const doGetTransferTypeListData = async (page: number, limit: number, sorting: any, filter: any) => { const doGetTransferTypeListData = async (
page: number,
sorting = sorting.length == 0 ? [{ id: 'id', desc: false }] : sorting; limit: number,
filter = filter.length == 0 ? {} : { any: filter[0].value?.toLowerCase() }; sorting: any,
const response = await GetData(`${API_URL}/transactiontype/list`, { filter: any
limit: limit, ) => {
page: page + 1, sorting = sorting.length == 0 ? [{ id: 'id', desc: false }] : sorting;
with_deleted: false, filter = filter.length == 0 ? {} : { any: filter[0].value?.toLowerCase() };
order_field: sorting[0].id, const response = await GetData(`${API_URL}/transactiontype/list`, {
order_direction: sorting[0].desc ? 'ASC' : 'DESC', limit: limit,
filter: JSON.stringify(filter) page: page + 1,
}); with_deleted: false,
return { data: response?.data.list, totalCount: response?.data.total_count }; 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 };
};
return ( return (
<div className="min-h-screen"> <div className="min-h-screen">
<ManageTransferTypeContext.Provider <ManageTransferTypeContext.Provider
value={{ value={{
showEditDialog, showEditDialog,
@ -218,7 +231,7 @@
handleDeleteDialog, handleDeleteDialog,
selectedTransferType, selectedTransferType,
accounts, accounts,
transferType, transferType
}} }}
> >
<Toaster expand visibleToasts={9} duration={3000} /> <Toaster expand visibleToasts={9} duration={3000} />
@ -241,8 +254,7 @@
</ManageTransferTypeContext.Provider> </ManageTransferTypeContext.Provider>
</div> </div>
); );
};
}; export { ManageTransferTypeContext, ManageTransferTypeContextProvider };
export type { TransferType };
export { ManageTransferTypeContext, ManageTransferTypeContextProvider };
export type { TransferType };