From 65f966081d4b0c6ad98a3a881985f448cd7a5f85 Mon Sep 17 00:00:00 2001 From: Wikzyy Date: Fri, 21 Mar 2025 09:49:09 +0700 Subject: [PATCH 1/5] fix padding --- src/pages/groups/ManageGroups.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/groups/ManageGroups.tsx b/src/pages/groups/ManageGroups.tsx index 3be46e2..819ad82 100644 --- a/src/pages/groups/ManageGroups.tsx +++ b/src/pages/groups/ManageGroups.tsx @@ -148,7 +148,7 @@ const ManageGroups = () => { return (
-
+
setDialogOpen(false)} From 90dc351393fdbf92d432333442bd6a7ac6dd5071 Mon Sep 17 00:00:00 2001 From: Wikzyy Date: Fri, 21 Mar 2025 13:29:56 +0700 Subject: [PATCH 2/5] remove filter icon --- .../master/aldeias/blocks/ListToolbar.tsx | 10 ++-- .../master/conversion/blocks/ListToolbar.tsx | 55 +++++++++++++++++++ .../master/municipios/blocks/ListToolbar.tsx | 6 +- .../master/postoadms/blocks/ListToolbar.tsx | 6 +- .../master/products/blocks/ListToolbar.tsx | 6 +- .../master/profession/blocks/ListToolbar.tsx | 6 +- .../master/provider/blocks/ListToolbar.tsx | 6 +- src/pages/master/sucos/blocks/ListToolbar.tsx | 6 +- 8 files changed, 78 insertions(+), 23 deletions(-) create mode 100644 src/pages/master/conversion/blocks/ListToolbar.tsx diff --git a/src/pages/master/aldeias/blocks/ListToolbar.tsx b/src/pages/master/aldeias/blocks/ListToolbar.tsx index 70ababf..fbf8537 100644 --- a/src/pages/master/aldeias/blocks/ListToolbar.tsx +++ b/src/pages/master/aldeias/blocks/ListToolbar.tsx @@ -20,17 +20,17 @@ const ListToolbar = () => { onChange={(event) => table.getColumn('name')?.setFilterValue(event.target.value)} /> - + {/* - + */} {/* + */} +
+
+ + + + +
+
+
+ + ); +}; + +export default ListToolbar; diff --git a/src/pages/master/municipios/blocks/ListToolbar.tsx b/src/pages/master/municipios/blocks/ListToolbar.tsx index 68dd8fe..4c5a633 100644 --- a/src/pages/master/municipios/blocks/ListToolbar.tsx +++ b/src/pages/master/municipios/blocks/ListToolbar.tsx @@ -33,17 +33,17 @@ const ListToolbar = () => { onChange={(event) => table.getColumn('name')?.setFilterValue(event.target.value)} /> - + {/* - + */} {/* - + */} {/* - + */}
- + */}
- + */}
- + */} {/*
@@ -184,8 +186,10 @@ const AddDialog = () => { setFormField({ ...formField, type: e.target.value })} + value={formField.products_type} + onChange={(e) => + setFormField({ ...formField, products_type: e.target.value }) + } /> @@ -198,8 +202,10 @@ const AddDialog = () => { setFormField({ ...formField, code: e.target.value })} + value={formField.products_code} + onChange={(e) => + setFormField({ ...formField, products_code: e.target.value }) + } /> @@ -212,8 +218,10 @@ const AddDialog = () => { setFormField({ ...formField, description: e.target.value })} + value={formField.products_description} + onChange={(e) => + setFormField({ ...formField, products_description: e.target.value }) + } /> @@ -228,10 +236,13 @@ const AddDialog = () => { type="number" min={0} step={0.01} - value={formField.price_point} + value={formField.products_price_point} onChange={(e) => { const value = parseFloat(e.target.value); - setFormField({ ...formField, price_point: isNaN(value) ? 0 : value }); + setFormField({ + ...formField, + products_price_point: isNaN(value) ? 0 : value + }); }} /> @@ -247,10 +258,13 @@ const AddDialog = () => { type="number" min={0} step={0.01} - value={formField.price_cash} + value={formField.products_price_cash} onChange={(e) => { const value = parseFloat(e.target.value); - setFormField({ ...formField, price_cash: isNaN(value) ? 0 : value }); + setFormField({ + ...formField, + products_price_cash: isNaN(value) ? 0 : value + }); }} /> @@ -266,10 +280,13 @@ const AddDialog = () => { type="number" min={0} step={0.01} - value={formField.cashback_point} + value={formField.products_cashback_point} onChange={(e) => { const value = parseFloat(e.target.value); - setFormField({ ...formField, cashback_point: isNaN(value) ? 0 : value }); + setFormField({ + ...formField, + products_cashback_point: isNaN(value) ? 0 : value + }); }} /> @@ -285,10 +302,13 @@ const AddDialog = () => { type="number" min={0} step={0.01} - value={formField.cashback_cash} + value={formField.products_cashback_cash} onChange={(e) => { const value = parseFloat(e.target.value); - setFormField({ ...formField, cashback_cash: isNaN(value) ? 0 : value }); + setFormField({ + ...formField, + products_cashback_cash: isNaN(value) ? 0 : value + }); }} /> @@ -300,8 +320,10 @@ const AddDialog = () => { Status* - setFormField({ ...formField, provider: value.toString() }) + setFormField({ ...formField, products_provider: value.toString() }) } > @@ -330,8 +352,11 @@ const AddDialog = () => { {providers.map((provider) => ( - - {provider.name} + + {provider.provider_name} ))} @@ -345,9 +370,9 @@ const AddDialog = () => { Process on Third Party* table.getColumn('name')?.setFilterValue(event.target.value)} + /> + + {/* + + */} + +
+ + + + +
+ + + + ); +}; + +export default ListToolbar; diff --git a/src/pages/master/walletRule/hooks/ManageWalletRuleContext.tsx b/src/pages/master/walletRule/hooks/ManageWalletRuleContext.tsx new file mode 100644 index 0000000..e196eaa --- /dev/null +++ b/src/pages/master/walletRule/hooks/ManageWalletRuleContext.tsx @@ -0,0 +1,240 @@ +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 React, { createContext, useCallback, useMemo, useState } from 'react'; +import ListToolbar from '../blocks/ListToolbar'; + +interface WalletRuleProps { + name: string; + id_currency: string; + status: string; +} + +interface ContextProps { + walletRules: WalletRuleProps[]; + showAddDialog: boolean; + handleAddDialog: (show: boolean) => void; + showEditDialog: boolean; + handleEditDialog: (show: boolean, selected_walletRule: string | null) => void; + showDeleteDialog: boolean; + handleDeleteDialog: (show: boolean, selected_walletRule: string | null) => void; + selectedWalletRule: string | null; + getWalletRuleLists: ( + limit: number, + page: number, + with_deleted: boolean, + order_field: any, + order_direction: any + ) => Promise<{ data: WalletRuleProps[]; totalCount: number } | undefined>; +} + +const initialProps: ContextProps = { + walletRules: [], + showAddDialog: false, + handleAddDialog: (show: boolean) => {}, + showEditDialog: false, + handleEditDialog: (show: boolean, selected_walletRule: string | null) => {}, + showDeleteDialog: false, + handleDeleteDialog: (show: boolean, selected_walletRule: string | null) => {}, + selectedWalletRule: null, + getWalletRuleLists: async () => undefined +}; + +const ManageWalletRuleContext = createContext(initialProps); +const API_URL_WALLET = apiConfig.service_wallet; + +const ManageWalletRuleContextProvider = ({ children }: { children: React.ReactNode }) => { + const [walletRules, setWalletRules] = useState([]); + const [showAddDialog, setShowAddDialog] = useState(false); + const [showEditDialog, setShowEditDialog] = useState(false); + const [showDeleteDialog, setShowDeleteDialog] = useState(false); + const [selectedWalletRule, setSelectedWalletRule] = useState(null); + const { GetData } = useCallApi(); + + const handleAddDialog = useCallback((show: boolean) => { + setShowAddDialog(show); + }, []); + + const handleEditDialog = useCallback((show: boolean, selected_walletRule: string | null) => { + setShowEditDialog(show); + setSelectedWalletRule(show ? selected_walletRule : null); + }, []); + + const handleDeleteDialog = useCallback((show: boolean, selected_walletRule: string | null) => { + setShowDeleteDialog(show); + setSelectedWalletRule(show ? selected_walletRule : null); + }, []); + + const columns = useMemo[]>( + () => [ + { + accessorFn: (row) => row.ID, + id: 'id', + header: ({ column }) => , + enableSorting: true, + enableHiding: false, + meta: { + headerClassName: 'w-[100px]' + } + }, + { + accessorFn: (row) => row.IDWallet, + id: 'name', + header: ({ column }) => , + enableSorting: true, + enableHiding: false, + meta: { + headerClassName: 'w-[250px]' + } + }, + { + accessorFn: (row) => row.balance_minimum, + id: 'balance_minimum', + header: ({ column }) => , + enableSorting: true, + enableHiding: false, + meta: { + headerClassName: 'w-[250px]' + } + }, + { + accessorFn: (row) => row.balance_maximum, + id: 'balance_maximum', + header: ({ column }) => , + enableSorting: true, + enableHiding: false, + meta: { + headerClassName: 'w-[250px]' + } + }, + { + accessorFn: (row) => row.credit_limit, + id: 'credit_limit', + header: ({ column }) => , + enableSorting: true, + enableHiding: false, + meta: { + headerClassName: 'w-[250px]' + } + }, + { + accessorFn: (row) => row.max_transaction_per_day, + id: 'max_transaction_per_day', + header: ({ column }) => ( + + ), + enableSorting: true, + enableHiding: false, + meta: { + headerClassName: 'w-[250px]' + } + }, + { + accessorFn: (row) => row.monthly_limit, + id: 'monthly_limit', + header: ({ column }) => , + enableSorting: true, + enableHiding: false, + meta: { + headerClassName: 'w-[250px]' + } + }, + { + accessorFn: (row) => row.status, + id: 'status', + header: ({ column }) => , + enableSorting: true, + enableHiding: false, + meta: { + headerClassName: 'w-[250px]' + } + }, + { + id: 'actions', + header: ({ column }) => , + enableSorting: false, + enableHiding: false, + cell: (data) => { + const row = data.row.original; + return ( + <> + + + + ); + }, + meta: { + headerClassName: 'w-[100px]', + cellClassName: 'text-center' + } + } + ], + [] + ); + + const getWalletRuleLists = 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_WALLET}/dashboard/wallet_rule`, { + 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); + setWalletRules(response?.data.list); + return { data: response?.data.list, totalCount: response?.data.total_count }; + } catch (error) { + console.error('Error fetching Wallet Rule', error); + } + }; + + return ( + + + } + layout={{ card: true }} + sorting={[{ id: 'id', desc: false }]} + serverSide={true} + onFetchData={({ pageIndex, pageSize, sorting, columnFilters }) => + getWalletRuleLists(pageIndex, pageSize, sorting, columnFilters) + } + > + {children} + + + ); +}; + +export { ManageWalletRuleContext, ManageWalletRuleContextProvider }; +export type { WalletRuleProps }; diff --git a/src/pages/master/walletRule/hooks/useManageWalletRuleContext.tsx b/src/pages/master/walletRule/hooks/useManageWalletRuleContext.tsx new file mode 100644 index 0000000..5d1c3a7 --- /dev/null +++ b/src/pages/master/walletRule/hooks/useManageWalletRuleContext.tsx @@ -0,0 +1,16 @@ +import { useContext } from 'react'; +import { ManageWalletRuleContext } from './ManageWalletRuleContext'; + +const useManageWalletRuleContext = () => { + const context = useContext(ManageWalletRuleContext); + + if (!context) { + throw new Error( + 'useManageWalletRuleContext must be used within a ManageWalletRuleContextProvider' + ); + } + + return context; +}; + +export { useManageWalletRuleContext }; diff --git a/src/routing/AppRoutingSetup.tsx b/src/routing/AppRoutingSetup.tsx index faa26c7..ace6ab8 100644 --- a/src/routing/AppRoutingSetup.tsx +++ b/src/routing/AppRoutingSetup.tsx @@ -35,6 +35,7 @@ import ProductsMaster from '@/pages/master/products/ProductsMaster'; import ProviderMaster from '@/pages/master/provider/ProviderMaster'; import Transaction from '@/pages/transaction/transaction'; import ConversionMaster from '@/pages/master/conversion/ConversionMaster'; +import WalletRuleMaster from '@/pages/master/walletRule/WalletRuleMaster'; const AppRoutingSetup = (): ReactElement => { return ( @@ -56,6 +57,7 @@ const AppRoutingSetup = (): ReactElement => { element={} /> } /> + } /> } />