diff --git a/src/pages/master/wallet/WalletMaster.tsx b/src/pages/master/wallet/WalletMaster.tsx new file mode 100644 index 0000000..3190787 --- /dev/null +++ b/src/pages/master/wallet/WalletMaster.tsx @@ -0,0 +1,35 @@ +import { Container, DataGridInner } from '@/components'; +import { ManageWalletContextProvider } from './hooks/ManageWalletContext'; +import { Breadcrumbs, Link } from '@mui/material'; +import AddDialog from './blocks/AddDialog'; +import EditDialog from './blocks/EditDialog'; + +const WalletMaster = () => { + return ( + + +

Manage Wallet

+ + + Dashboard + + + + Master Data + + + + Manage Wallet + + +
+ +
+ + +
+
+ ); +}; + +export default WalletMaster; diff --git a/src/pages/master/wallet/blocks/ListToolbar.tsx b/src/pages/master/wallet/blocks/ListToolbar.tsx new file mode 100644 index 0000000..0d2a427 --- /dev/null +++ b/src/pages/master/wallet/blocks/ListToolbar.tsx @@ -0,0 +1,55 @@ +import { DefaultTooltip, KeenIcon, useDataGrid } from '@/components'; +import { Button } from '@/components/ui/button'; +import { useManageWalletContext } from '../hooks/useManageWalletContext'; + +const ListToolbar = () => { + const { reload, table } = useDataGrid(); + const { handleAddDialog } = useManageWalletContext(); + + return ( +
+
+
+
+ + {/* + + */} +
+
+ + + + +
+
+
+
+ ); +}; + +export default ListToolbar; diff --git a/src/pages/master/wallet/hooks/ManageWalletContext.tsx b/src/pages/master/wallet/hooks/ManageWalletContext.tsx new file mode 100644 index 0000000..7369367 --- /dev/null +++ b/src/pages/master/wallet/hooks/ManageWalletContext.tsx @@ -0,0 +1,204 @@ +import { DataGridColumnHeader, DataGridProvider, KeenIcon } from '@/components'; +import { apiConfig } from '@/config/api.config'; +import { useCallApi } from '@/hooks'; +import { ColumnDef } from '@tanstack/react-table'; +import React, { createContext, useCallback, useMemo, useState } from 'react'; +import { Toaster } from 'sonner'; +import ListToolbar from '../blocks/ListToolbar'; + +interface WalletProps { + id: string; + name: string; + status: string; + description: string; + group: string[]; + currency_id: string; +} + +interface ContextProps { + wallet: WalletProps[]; + showAddDialog: boolean; + handleAddDialog: (show: boolean) => void; + showEditDialog: boolean; + handleEditDialog: (show: boolean, selected_wallet: WalletProps | null) => void; + showDeleteDialog: boolean; + handleDeleteDialog: (show: boolean, selected_wallet: WalletProps | null) => void; + selectedWallet: WalletProps | null; + getWalletLists: ( + limit: number, + page: number, + with_deleted: boolean, + order_field: any, + order_direction: any + ) => Promise<{ data: WalletProps[]; totalCount: number } | undefined>; +} + +const initialProps: ContextProps = { + wallet: [], + showAddDialog: false, + handleAddDialog: (show: boolean) => {}, + showEditDialog: false, + handleEditDialog: (show: boolean, selected_wallet: WalletProps | null) => {}, + showDeleteDialog: false, + handleDeleteDialog: (show: boolean, selected_wallet: WalletProps | null) => {}, + selectedWallet: null, + getWalletLists: async () => ({ data: [], totalCount: 0 }) +}; + +const ManageWalletContext = createContext(initialProps); +const API_URL_MASTER_DATA = apiConfig.service_master_data; + +const ManageWalletContextProvider = ({ children }: { children: React.ReactNode }) => { + const [wallets, setWallets] = useState([]); + const [showAddDialog, setShowAddDialog] = useState(false); + const [showEditDialog, setShowEditDialog] = useState(false); + const [showDeleteDialog, setShowDeleteDialog] = useState(false); + const [selectedWallet, setSelectedWallet] = useState(null); + const { GetData } = useCallApi(); + + const handleAddDialog = useCallback((show: boolean) => { + setShowAddDialog(show); + }, []); + + const handleEditDialog = useCallback((show: boolean, selected_wallet: WalletProps | null) => { + setShowEditDialog(show); + setSelectedWallet(show ? selected_wallet : null); + }, []); + + const handleDeleteDialog = useCallback((show: boolean, selected_wallet: WalletProps | null) => { + setShowDeleteDialog(show); + setSelectedWallet(show ? selected_wallet : null); + }, []); + + const columns = useMemo[]>( + () => [ + { + accessorFn: (row) => row.Wallet_name, + id: 'name', + header: ({ column }) => , + enableSorting: true, + enableHiding: false, + meta: { + headerClassName: 'w-[250px]' + } + }, + { + accessorFn: (row) => row.Wallet_description, + id: 'description', + header: ({ column }) => , + enableSorting: true, + enableHiding: false, + meta: { + headerClassName: 'w-[250px]' + } + }, + { + accessorFn: (row) => row.Wallet_status, + id: 'status', + header: ({ column }) => , + enableSorting: true, + enableHiding: false, + cell: ({ row }) => { + const isActive = row.original.Wallet_status === 'Y'; + + return ( + + {isActive ? 'Active' : 'Inactive'} + + ); + }, + meta: { + headerClassName: 'w-[100px]' + } + }, + { + id: 'actions', + header: ({ column }) => , + enableSorting: false, + enableHiding: false, + cell: (data) => { + const row = data.row.original; + return ( + <> + + + + ); + }, + meta: { + headerClassName: 'w-[100px]', + cellClassName: 'text-center' + } + } + ], + [] + ); + + const getWalletLists = async (page: number, limit: number, sorting: any, filter: any) => { + try { + sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting; + filter = filter.length == 0 ? {} : { any: filter[0].value?.toLowerCase() }; + const response = await GetData(`${API_URL_MASTER_DATA}/wallet/list`, { + limit, + page: page + 1, + with_deleted: false, + order_field: sorting[0].id, + order_direction: sorting[0].desc == false ? 'ASC' : 'DESC', + filter: JSON.stringify(filter) + }); + console.log(response?.data); + setWallets(response?.data.list); + return { data: response?.data.list, totalCount: response?.data.total_count }; + } catch (error) { + console.error('Error fetching Wallet', error); + } + }; + + return ( + + + } + layout={{ card: true }} + sorting={[{ id: 'id', desc: false }]} + serverSide={true} + onFetchData={({ pageIndex, pageSize, sorting, columnFilters }) => + getWalletLists(pageIndex, pageSize, sorting, columnFilters) + } + > + {children} + + + ); +}; + +export { ManageWalletContext, ManageWalletContextProvider }; +export type { WalletProps }; diff --git a/src/pages/master/wallet/hooks/useManageWalletContext.tsx b/src/pages/master/wallet/hooks/useManageWalletContext.tsx new file mode 100644 index 0000000..e6bcaec --- /dev/null +++ b/src/pages/master/wallet/hooks/useManageWalletContext.tsx @@ -0,0 +1,12 @@ +import { useContext } from 'react'; +import { ManageWalletContext } from './ManageWalletContext'; + +const useManageWalletContext = () => { + const context = useContext(ManageWalletContext); + if (!context) { + throw new Error('useManageWalletContext must be used within a ManageWalletContextProvider'); + } + return context; +}; + +export { useManageWalletContext }; diff --git a/src/routing/AppRoutingSetup.tsx b/src/routing/AppRoutingSetup.tsx index 3c7fdab..1b0896b 100644 --- a/src/routing/AppRoutingSetup.tsx +++ b/src/routing/AppRoutingSetup.tsx @@ -35,6 +35,7 @@ import ProviderMaster from '@/pages/master/provider/ProviderMaster'; import ConversionMaster from '@/pages/master/conversion/ConversionMaster'; import WalletRuleMaster from '@/pages/master/walletRule/WalletRuleMaster'; import WalletHistory from '@/pages/wallet/wallet-history/WalletHistory'; +import WalletMaster from '@/pages/master/wallet/WalletMaster'; const AppRoutingSetup = (): ReactElement => { return ( @@ -56,6 +57,9 @@ const AppRoutingSetup = (): ReactElement => { element={} /> } /> + + } /> + } /> } />