@ -1,18 +1,17 @@
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 { 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' ;
interface AccountProps {
interface AccountProps {
id : string ;
name : string ;
}
}
interface TransferType {
interface TransferType {
id : string ;
name : string ;
minimum_amount : number ;
@ -21,9 +20,9 @@
walletOriginId : string ;
walletDestinationId : string ;
status : string ;
}
}
interface ContextProps {
interface ContextProps {
showEditDialog : boolean ;
handleEditDialog : ( show : boolean , selected_user : string | null ) = > void ;
showAddDialog : boolean ;
@ -31,11 +30,11 @@
showDeleteDialog : boolean ;
handleDeleteDialog : ( show : boolean , selected_user : string | null ) = > void ;
selectedTransferType : string | null ;
transferType : string | null ;
transferType : string | null ;
accounts : AccountProps [ ] ;
}
}
const initialProps : ContextProps = {
const initialProps : ContextProps = {
showEditDialog : false ,
handleEditDialog : ( ) = > { } ,
showAddDialog : false ,
@ -45,12 +44,12 @@
selectedTransferType : null ,
accounts : [ ] ,
transferType : null
} ;
} ;
const ManageTransferTypeContext = createContext < ContextProps > ( initialProps ) ;
const API_URL = apiConfig . service_transaction ;
const ManageTransferTypeContext = createContext < ContextProps > ( initialProps ) ;
const API_URL = apiConfig . service_transaction ;
const ManageTransferTypeContextProvider = ( { children } : { children : React.ReactNode } ) = > {
const ManageTransferTypeContextProvider = ( { children } : { children : React.ReactNode } ) = > {
const [ showEditDialog , setShowEditDialog ] = useState ( false ) ;
const [ showAddDialog , setShowAddDialog ] = useState ( false ) ;
const [ showDeleteDialog , setShowDeleteDialog ] = useState ( false ) ;
@ -60,7 +59,6 @@
const [ selectedTransferType , setSelectedTransferType ] = useState < string | null > ( null ) ;
const [ transferType , setTransferType ] = useState < string | null > ( null ) ;
const handleEditDialog = useCallback ( ( show : boolean , selected_transfertype : string | null ) = > {
setSelectedTransferType ( show ? selected_transfertype : null ) ;
setShowEditDialog ( show ) ;
@ -77,11 +75,12 @@
const columns = useMemo < ColumnDef < any > [ ] > (
( ) = > [
{
accessorFn : ( row ) = > row . name ,
id : 'name' ,
header : ( { column } ) = > < DataGridColumnHeader title = "Transaction Type Name" column = { column } / > ,
header : ( { column } ) = > (
< DataGridColumnHeader title = "Transaction Type Name" column = { column } / >
) ,
enableSorting : true ,
enableHiding : false ,
meta : { headerClassName : 'w-[250px]' }
@ -121,7 +120,9 @@
{
accessorFn : ( row ) = > row . 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 ,
enableHiding : false ,
meta : { headerClassName : 'w-[250px]' }
@ -135,9 +136,11 @@
meta : { headerClassName : 'w-[250px]' }
} ,
{
accessorFn : ( row ) = > row . wallet_fee_destination . name ,
accessorFn : ( row ) = > row . wallet_fee_destination . name ,
id : 'wallet_fee_destination' ,
header : ( { column } ) = > < DataGridColumnHeader title = "Wallet Fee Destination" column = { column } / > ,
header : ( { column } ) = > (
< DataGridColumnHeader title = "Wallet Fee Destination" column = { column } / >
) ,
enableSorting : true ,
enableHiding : false ,
meta : { headerClassName : 'w-[250px]' }
@ -145,7 +148,9 @@
{
accessorFn : ( row ) = > row . customer_fee_destination ? . username || 'N/A' ,
id : 'customer_fee_destination' ,
header : ( { column } ) = > < DataGridColumnHeader title = "Customer Fee Destination" column = { column } / > ,
header : ( { column } ) = > (
< DataGridColumnHeader title = "Customer Fee Destination" column = { column } / >
) ,
enableSorting : true ,
enableHiding : false ,
meta : { headerClassName : 'w-[250px]' }
@ -165,8 +170,7 @@
enableSorting : true ,
enableHiding : false ,
meta : { headerClassName : 'w-[150px]' }
}
,
} ,
{
id : 'actions' ,
header : ( { column } ) = > < DataGridColumnHeader title = "Actions" column = { column } / > ,
@ -176,10 +180,16 @@
const row = data . row . original ;
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" / >
< / 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" / >
< / button >
< / >
@ -190,8 +200,12 @@
] ,
[ handleEditDialog , handleDeleteDialog ]
) ;
const doGetTransferTypeListData = async ( page : number , limit : number , sorting : any , filter : any ) = > {
const doGetTransferTypeListData = 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 } /transactiontype/list ` , {
@ -203,11 +217,10 @@
filter : JSON.stringify ( filter )
} ) ;
return { data : response?.data.list , totalCount : response?.data.total_count } ;
} ;
} ;
return (
< div className = "min-h-screen" >
< ManageTransferTypeContext.Provider
value = { {
showEditDialog ,
@ -218,7 +231,7 @@
handleDeleteDialog ,
selectedTransferType ,
accounts ,
transferType ,
transferType
} }
>
< Toaster expand visibleToasts = { 9 } duration = { 3000 } / >
@ -241,8 +254,7 @@
< / ManageTransferTypeContext.Provider >
< / div >
) ;
} ;
} ;
export { ManageTransferTypeContext , ManageTransferTypeContextProvider } ;
export type { TransferType } ;
export { ManageTransferTypeContext , ManageTransferTypeContextProvider } ;
export type { TransferType } ;