From 0f5d190c9e122128d4ea9220f32444d5bbbb6a64 Mon Sep 17 00:00:00 2001 From: Wikzyy Date: Wed, 26 Mar 2025 00:49:21 +0700 Subject: [PATCH 01/11] feat create wallet rule --- .../master/walletRule/WalletRuleMaster.tsx | 3 + .../master/walletRule/blocks/AddDialog.tsx | 362 ++++++++++++++++++ .../master/walletRule/blocks/ListToolbar.tsx | 8 +- 3 files changed, 369 insertions(+), 4 deletions(-) create mode 100644 src/pages/master/walletRule/blocks/AddDialog.tsx diff --git a/src/pages/master/walletRule/WalletRuleMaster.tsx b/src/pages/master/walletRule/WalletRuleMaster.tsx index c98a242..a580dae 100644 --- a/src/pages/master/walletRule/WalletRuleMaster.tsx +++ b/src/pages/master/walletRule/WalletRuleMaster.tsx @@ -1,6 +1,7 @@ import { Container, DataGridInner } from '@/components'; import { ManageWalletRuleContextProvider } from './hooks/ManageWalletRuleContext'; import { Breadcrumbs, Link } from '@mui/material'; +import AddDialog from './blocks/AddDialog'; const WalletRuleMaster = () => { return ( @@ -24,6 +25,8 @@ const WalletRuleMaster = () => {
+ + ); diff --git a/src/pages/master/walletRule/blocks/AddDialog.tsx b/src/pages/master/walletRule/blocks/AddDialog.tsx new file mode 100644 index 0000000..52317f7 --- /dev/null +++ b/src/pages/master/walletRule/blocks/AddDialog.tsx @@ -0,0 +1,362 @@ +import { apiConfig } from '@/config/api.config'; +import { useManageWalletRuleContext } from '../hooks/useManageWalletRuleContext'; +import { Alert, useDataGrid } from '@/components'; +import { useCallApi } from '@/hooks'; +import { useCallback, useEffect, useState } from 'react'; +import { toast } from 'sonner'; +import { + Dialog, + DialogBody, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle +} from '@/components/ui/dialog'; +import { Input } from '@/components/ui/input'; +import { Button } from '@/components/ui/button'; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue +} from '@/components/ui/select'; +import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'; +import { + Command, + CommandEmpty, + CommandGroup, + CommandInput, + CommandItem, + CommandList +} from '@/components/ui/command'; + +interface GroupProps { + ID: string; + is_bank: string; + name: string; + status: string; +} + +interface WalletProps { + ID: string; + name: string; + id_currency: string; + status: string; +} + +const API_URL_WALLET = apiConfig.service_wallet; +const AddDialog = () => { + const { showAddDialog, handleAddDialog } = useManageWalletRuleContext(); + const { reload } = useDataGrid(); + const { PostData, GetData } = useCallApi(); + const [open, setOpen] = useState(false); + const [alert, setAlert] = useState({ + show: false, + message: '' + }); + const initialState = { + id_wallet: '', + id_group: '', + max_transaction_per_day: null, + balance_minimum: null, + balance_maximum: null, + credit_limit: null, + monthly_limit: null, + status: '' + }; + const [formField, setFormField] = useState(initialState); + const [groups, setGroups] = useState([]); + const [wallets, setWallets] = useState([]); + + const resetForm = () => { + setFormField(initialState); + setAlert({ show: false, message: '' }); + }; + + const doCreateWalletRule = useCallback( + async (e: React.FormEvent) => { + e.preventDefault(); + + const response = await PostData(`${API_URL_WALLET}/dashboard/wallet_rule`, formField); + + if (response?.status) { + handleAddDialog(false); + toast.success('Success Create Wallet Rule'); + reload(); + } else { + toast.error('Failed Create Wallet Rule'); + setAlert({ show: true, message: 'Failed Create Wallet Rule' }); + } + }, + [formField] + ); + + const handleSubmit = (e: React.FormEvent) => { + e.preventDefault(); + + if ( + formField.id_group.trim() === '' || + formField.max_transaction_per_day === 0 || + formField.balance_minimum === 0 || + formField.balance_maximum === 0 || + formField.credit_limit === 0 || + formField.monthly_limit === 0 || + formField.status.trim() === '' + ) { + setAlert({ show: true, message: 'Please fill in all required fields.' }); + return; + } + + console.log(formField); + doCreateWalletRule(e); + setAlert({ show: false, message: '' }); + }; + + const getGroupLists = async (sorting: any) => { + try { + const response = await GetData(`${API_URL_WALLET}/dashboard/group`, { + limit: 100, + page: 1, + with_deleted: false, + order_field: sorting[0].id, + order_direction: sorting[0].desc == false ? 'ASC' : 'DESC' + }); + + console.log('GROUPS: ', response?.data); + setGroups(response?.data.list); + } catch (error) { + console.error('Error fetching groups', error); + } + }; + + const getWalletLists = async (sorting: any) => { + try { + const response = await GetData(`${API_URL_WALLET}/dashboard/wallet`, { + limit: 100, + page: 1, + with_deleted: false, + order_field: sorting[0].id, + order_direction: sorting[0].desc == false ? 'ASC' : 'DESC' + }); + + console.log('WALLET: ', response?.data); + setWallets(response?.data.list); + } catch (error) { + console.error('Error fetching wallet', error); + } + }; + + useEffect(() => { + getWalletLists([{ id: 'name', desc: false }]); + getGroupLists([{ id: 'name', desc: false }]); + }, []); + + useEffect(() => { + if (showAddDialog === false) { + resetForm(); + } + }, [showAddDialog]); + + return ( + handleAddDialog(open)}> + + + Wallet Rule - Create + + + +
+ {alert.show && ( + +

{alert.message}

+
+ )} + +
+
+
+
+ + +
+
+ +
+
+ + + + + + + + + + No Group found. + + {groups.map((group) => ( + { + setFormField({ + ...formField, + id_group: group.ID + }); + setOpen(false); + }} + > + {group.name} + + ))} + + + + + +
+
+ +
+
+ + + setFormField({ + ...formField, + max_transaction_per_day: parseInt(e.target.value) + }) + } + /> +
+
+ +
+
+ + + setFormField({ ...formField, balance_minimum: parseInt(e.target.value) }) + } + /> +
+
+ +
+
+ + + setFormField({ ...formField, balance_maximum: parseInt(e.target.value) }) + } + /> +
+
+ +
+
+ + + setFormField({ ...formField, credit_limit: parseInt(e.target.value) }) + } + /> +
+
+ +
+
+ + + setFormField({ ...formField, monthly_limit: parseInt(e.target.value) }) + } + /> +
+
+ +
+
+ + +
+
+ +
+ + +
+
+
+
+
+
+
+ ); +}; + +export default AddDialog; diff --git a/src/pages/master/walletRule/blocks/ListToolbar.tsx b/src/pages/master/walletRule/blocks/ListToolbar.tsx index 2a2df4f..b607532 100644 --- a/src/pages/master/walletRule/blocks/ListToolbar.tsx +++ b/src/pages/master/walletRule/blocks/ListToolbar.tsx @@ -1,17 +1,17 @@ import { DefaultTooltip, KeenIcon, useDataGrid } from '@/components'; import { Button } from '@/components/ui/button'; -import { useManageProductsContext } from '../../products/hooks/useManageProductsContext'; +import { useManageWalletRuleContext } from '../hooks/useManageWalletRuleContext'; const ListToolbar = () => { const { table, reload } = useDataGrid(); - const { handleAddDialog } = useManageProductsContext(); + const { handleAddDialog } = useManageWalletRuleContext(); return (
- */} {/* + + + + + + No Group found. + + {groups.map((group) => ( + { + setFormField({ + ...formField, + id_group: group.ID + }); + setOpen(false); + }} + > + {group.name} + + ))} + + + + + +
+
+ +
+
+ + + setFormField({ + ...formField, + max_transaction_per_day: parseInt(e.target.value) + }) + } + /> +
+
+ +
+
+ + + setFormField({ ...formField, balance_minimum: parseInt(e.target.value) }) + } + /> +
+
+ +
+
+ + + setFormField({ ...formField, balance_maximum: parseInt(e.target.value) }) + } + /> +
+
+ +
+
+ + + setFormField({ ...formField, credit_limit: parseInt(e.target.value) }) + } + /> +
+
+ +
+
+ + + setFormField({ ...formField, monthly_limit: parseInt(e.target.value) }) + } + /> +
+
+ +
+
+ + +
+
+ +
+ + +
+
+ +
+ + + + ); +}; + +export default EditDialog; diff --git a/src/pages/master/walletRule/hooks/ManageWalletRuleContext.tsx b/src/pages/master/walletRule/hooks/ManageWalletRuleContext.tsx index b71f086..51d0e07 100644 --- a/src/pages/master/walletRule/hooks/ManageWalletRuleContext.tsx +++ b/src/pages/master/walletRule/hooks/ManageWalletRuleContext.tsx @@ -142,13 +142,13 @@ const ManageWalletRuleContextProvider = ({ children }: { children: React.ReactNo <> @@ -176,7 +176,7 @@ const ManageWalletRuleContextProvider = ({ children }: { children: React.ReactNo order_direction: sorting[0].desc == false ? 'ASC' : 'DESC', filter: JSON.stringify(filter) }); - console.log(response?.data); + // console.log(response?.data); setWalletRules(response?.data.list); return { data: response?.data.list, totalCount: response?.data.total_count }; } catch (error) { From 43bc6f06f7c9a282f9309143b523aafa42700cad Mon Sep 17 00:00:00 2001 From: Wikzyy Date: Wed, 26 Mar 2025 10:55:26 +0700 Subject: [PATCH 05/11] feat add delete --- .../master/walletRule/WalletRuleMaster.tsx | 2 + .../master/walletRule/blocks/DeleteDialog.tsx | 76 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 src/pages/master/walletRule/blocks/DeleteDialog.tsx diff --git a/src/pages/master/walletRule/WalletRuleMaster.tsx b/src/pages/master/walletRule/WalletRuleMaster.tsx index 23fde29..08e56d2 100644 --- a/src/pages/master/walletRule/WalletRuleMaster.tsx +++ b/src/pages/master/walletRule/WalletRuleMaster.tsx @@ -3,6 +3,7 @@ import { ManageWalletRuleContextProvider } from './hooks/ManageWalletRuleContext import { Breadcrumbs, Link } from '@mui/material'; import AddDialog from './blocks/AddDialog'; import EditDialog from './blocks/EditDialog'; +import DeleteDialog from './blocks/DeleteDialog'; const WalletRuleMaster = () => { return ( @@ -29,6 +30,7 @@ const WalletRuleMaster = () => { + ); diff --git a/src/pages/master/walletRule/blocks/DeleteDialog.tsx b/src/pages/master/walletRule/blocks/DeleteDialog.tsx new file mode 100644 index 0000000..2f72635 --- /dev/null +++ b/src/pages/master/walletRule/blocks/DeleteDialog.tsx @@ -0,0 +1,76 @@ +import { useCallApi } from '@/hooks'; +import { useManageWalletRuleContext } from '../hooks/useManageWalletRuleContext'; +import { Alert, useDataGrid } from '@/components'; +import { useCallback, useState } from 'react'; +import { toast } from 'sonner'; +import { apiConfig } from '@/config/api.config'; +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle +} from '@/components/ui/dialog'; +import { Button } from '@/components/ui/button'; + +const API_URL_WALLET = apiConfig.service_wallet; + +const DeleteDialog = () => { + const { showDeleteDialog, handleDeleteDialog, selectedWalletRule } = useManageWalletRuleContext(); + const { DeleteData } = useCallApi(); + const { reload } = useDataGrid(); + const [alert, setAlert] = useState({ show: false, message: '' }); + + const doDeleteWalletRule = useCallback(async () => { + if (!selectedWalletRule) { + toast.error('No wallet rule selected'); + return; + } + + const response = await DeleteData( + `${API_URL_WALLET}/dashboard/wallet_rule/${selectedWalletRule}`, + { id: selectedWalletRule } + ); + + if (response?.status) { + toast.success('Wallet rule deleted successfully'); + handleDeleteDialog(false, null); + reload(); + setAlert({ show: false, message: '' }); + } else { + toast.error('Failed to delete wallet rule'); + setAlert({ show: true, message: response?.message }); + } + }, [selectedWalletRule]); + + return ( + handleDeleteDialog(open, null)}> + + + + + +

Are you sure?

+ You will delete this data! +
+ {alert.show && ( + +

{alert.message}

+
+ )} +
+ + + + +
+
+ ); +}; + +export default DeleteDialog; From 301b4a4424e94fe0a9ce1d544db2e222dfd2185d Mon Sep 17 00:00:00 2001 From: Wikzyy Date: Wed, 26 Mar 2025 10:56:02 +0700 Subject: [PATCH 06/11] fix dropdown groups on create wallet rule --- .../master/walletRule/blocks/AddDialog.tsx | 50 ++++++------------- 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/src/pages/master/walletRule/blocks/AddDialog.tsx b/src/pages/master/walletRule/blocks/AddDialog.tsx index 7ff2241..9228226 100644 --- a/src/pages/master/walletRule/blocks/AddDialog.tsx +++ b/src/pages/master/walletRule/blocks/AddDialog.tsx @@ -194,7 +194,7 @@ const AddDialog = () => { onValueChange={(value) => setFormField({ ...formField, id_wallet: value })} > - + {wallets.map((wallet) => ( @@ -212,39 +212,21 @@ const AddDialog = () => { - - - - - - - - - No Group found. - - {groups.map((group) => ( - { - setFormField({ - ...formField, - id_group: group.ID - }); - setOpen(false); - }} - > - {group.name} - - ))} - - - - - + From f7f6b128e1b393032923067d2639d8e949add0ec Mon Sep 17 00:00:00 2001 From: Wikzyy Date: Wed, 26 Mar 2025 11:00:21 +0700 Subject: [PATCH 07/11] fix dropdown groups on update wallet rule --- .../master/walletRule/blocks/EditDialog.tsx | 50 ++++++------------- 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/src/pages/master/walletRule/blocks/EditDialog.tsx b/src/pages/master/walletRule/blocks/EditDialog.tsx index 02c9435..127df2a 100644 --- a/src/pages/master/walletRule/blocks/EditDialog.tsx +++ b/src/pages/master/walletRule/blocks/EditDialog.tsx @@ -223,7 +223,7 @@ const EditDialog = () => { onValueChange={(value) => setFormField({ ...formField, id_wallet: value })} > - + {wallets.map((wallet) => ( @@ -241,39 +241,21 @@ const EditDialog = () => { - - - - - - - - - No Group found. - - {groups.map((group) => ( - { - setFormField({ - ...formField, - id_group: group.ID - }); - setOpen(false); - }} - > - {group.name} - - ))} - - - - - + From 41c1fed872692d6d7cc6b0e7ae3390fa43268530 Mon Sep 17 00:00:00 2001 From: bagusajisaputroo Date: Wed, 26 Mar 2025 11:23:40 +0700 Subject: [PATCH 08/11] fix transactionfee + give "*" on update form --- .../transfer/transferfee/blocks/AddDialog.tsx | 11 ++--- .../transferfee/blocks/EditDialog.tsx | 40 +++++++++---------- .../hooks/ManageTransferFeeContext.tsx | 2 +- .../transfertype/blocks/EditDialog.tsx | 23 ++++++++--- 4 files changed, 40 insertions(+), 36 deletions(-) diff --git a/src/pages/transfer/transferfee/blocks/AddDialog.tsx b/src/pages/transfer/transferfee/blocks/AddDialog.tsx index e626f5e..65f032e 100644 --- a/src/pages/transfer/transferfee/blocks/AddDialog.tsx +++ b/src/pages/transfer/transferfee/blocks/AddDialog.tsx @@ -75,7 +75,7 @@ const AddFeeDialog = () => { period_end: '', deduct_amount: 0, deduct_percentage: 0, - priority: false, + priority: '', status: '', status_include: '', created_by: '', @@ -107,7 +107,7 @@ const AddFeeDialog = () => { transaction_type: formField.transaction_type, status: formField.status, status_include: formField.status_include, - priority: formField.priority ? 'Y' : 'N' + priority: formField.priority }; }; useEffect(() => { @@ -162,7 +162,6 @@ const AddFeeDialog = () => { const response = await PostData(`${API_URL}/transactionfees/create`, { ...formField }); - // console.log(response); if (response?.status) { toast.success('Success Create Transfer Fee'); reload(); @@ -370,10 +369,8 @@ const AddFeeDialog = () => {
- - -
+ + + {/*
diff --git a/src/pages/transfer/transferfee/hooks/ManageTransferFeeContext.tsx b/src/pages/transfer/transferfee/hooks/ManageTransferFeeContext.tsx index 8188d4d..8703234 100644 --- a/src/pages/transfer/transferfee/hooks/ManageTransferFeeContext.tsx +++ b/src/pages/transfer/transferfee/hooks/ManageTransferFeeContext.tsx @@ -153,7 +153,7 @@ const ManageTransferFeeContextProvider = ({ children }: { children: React.ReactN meta: { headerClassName: 'w-[100px]' } }, { - accessorFn: (row) => (row.status === 'Y' ? 'Active' : 'Inactieve'), + accessorFn: (row) => (row.status === 'Y' ? 'Active' : 'Inactive'), id: 'status', header: ({ column }) => , enableSorting: true, diff --git a/src/pages/transfer/transfertype/blocks/EditDialog.tsx b/src/pages/transfer/transfertype/blocks/EditDialog.tsx index 54bf485..0061789 100644 --- a/src/pages/transfer/transfertype/blocks/EditDialog.tsx +++ b/src/pages/transfer/transfertype/blocks/EditDialog.tsx @@ -240,6 +240,7 @@ const EditDialog = () => {
{
{
{
{
{
- +
{
- +
{
- +
Date: Wed, 26 Mar 2025 11:46:04 +0700 Subject: [PATCH 09/11] fix create update form field - use NumericFormat from react number format - pull data object from table not consume API get data by id --- .../master/walletRule/blocks/AddDialog.tsx | 95 +++++++++------ .../master/walletRule/blocks/EditDialog.tsx | 112 ++++++++++++------ .../hooks/ManageWalletRuleContext.tsx | 50 +++++--- 3 files changed, 168 insertions(+), 89 deletions(-) diff --git a/src/pages/master/walletRule/blocks/AddDialog.tsx b/src/pages/master/walletRule/blocks/AddDialog.tsx index 9228226..885c15a 100644 --- a/src/pages/master/walletRule/blocks/AddDialog.tsx +++ b/src/pages/master/walletRule/blocks/AddDialog.tsx @@ -30,6 +30,7 @@ import { CommandItem, CommandList } from '@/components/ui/command'; +import { NumericFormat } from 'react-number-format'; interface GroupProps { ID: string; @@ -58,11 +59,11 @@ const AddDialog = () => { const initialState: { id_wallet: string; id_group: string; - max_transaction_per_day: number | null; - balance_minimum: number | null; - balance_maximum: number | null; - credit_limit: number | null; - monthly_limit: number | null; + max_transaction_per_day: string | number | null; + balance_minimum: string | number | null; + balance_maximum: string | number | null; + credit_limit: string | number | null; + monthly_limit: string | number | null; status: string; } = { id_wallet: '', @@ -235,16 +236,20 @@ const AddDialog = () => { - - setFormField({ - ...formField, - max_transaction_per_day: parseInt(e.target.value) - }) - } + thousandSeparator="." + decimalSeparator="," + allowNegative={false} + onValueChange={(values) => { + setFormField((prev) => ({ + ...prev, + max_transaction_per_day: + values.floatValue !== undefined ? values.floatValue : '' + })); + }} + placeholder="Enter Max Transaction Per Day" />
@@ -254,13 +259,19 @@ const AddDialog = () => { - - setFormField({ ...formField, balance_minimum: parseInt(e.target.value) }) - } + thousandSeparator="." + decimalSeparator="," + allowNegative={false} + onValueChange={(values) => { + setFormField((prev) => ({ + ...prev, + balance_minimum: values.floatValue !== undefined ? values.floatValue : '' + })); + }} + placeholder="Enter Balance Minimum" />
@@ -270,13 +281,19 @@ const AddDialog = () => { - - setFormField({ ...formField, balance_maximum: parseInt(e.target.value) }) - } + thousandSeparator="." + decimalSeparator="," + allowNegative={false} + onValueChange={(values) => { + setFormField((prev) => ({ + ...prev, + balance_maximum: values.floatValue !== undefined ? values.floatValue : '' + })); + }} + placeholder="Enter Balance Maximum" />
@@ -286,13 +303,19 @@ const AddDialog = () => { - - setFormField({ ...formField, credit_limit: parseInt(e.target.value) }) - } + thousandSeparator="." + decimalSeparator="," + allowNegative={false} + onValueChange={(values) => { + setFormField((prev) => ({ + ...prev, + credit_limit: values.floatValue !== undefined ? values.floatValue : '' + })); + }} + placeholder="Enter Credit Limit" />
@@ -302,13 +325,19 @@ const AddDialog = () => { - - setFormField({ ...formField, monthly_limit: parseInt(e.target.value) }) - } + thousandSeparator="." + decimalSeparator="," + allowNegative={false} + onValueChange={(values) => { + setFormField((prev) => ({ + ...prev, + monthly_limit: values.floatValue !== undefined ? values.floatValue : '' + })); + }} + placeholder="Enter Monthly Limit" />
diff --git a/src/pages/master/walletRule/blocks/EditDialog.tsx b/src/pages/master/walletRule/blocks/EditDialog.tsx index 127df2a..de2d497 100644 --- a/src/pages/master/walletRule/blocks/EditDialog.tsx +++ b/src/pages/master/walletRule/blocks/EditDialog.tsx @@ -30,6 +30,7 @@ import { } from '@/components/ui/command'; import { Input } from '@/components/ui/input'; import { Button } from '@/components/ui/button'; +import { NumericFormat } from 'react-number-format'; interface GroupProps { ID: string; @@ -51,7 +52,6 @@ const EditDialog = () => { const { showEditDialog, handleEditDialog, selectedWalletRule } = useManageWalletRuleContext(); const { GetData, PutData } = useCallApi(); const { reload } = useDataGrid(); - const [open, setOpen] = useState(false); const [alert, setAlert] = useState({ show: false, message: '' @@ -59,11 +59,11 @@ const EditDialog = () => { const initialState: { id_wallet: string; id_group: string; - max_transaction_per_day: number | null; - balance_minimum: number | null; - balance_maximum: number | null; - credit_limit: number | null; - monthly_limit: number | null; + max_transaction_per_day: string | number | null; + balance_minimum: string | number | null; + balance_maximum: string | number | null; + credit_limit: string | number | null; + monthly_limit: string | number | null; status: string; } = { id_wallet: '', @@ -89,7 +89,7 @@ const EditDialog = () => { e.preventDefault(); const response = await PutData( - `${API_URL_WALLET}/dashboard/wallet_rule/${selectedWalletRule}`, + `${API_URL_WALLET}/dashboard/wallet_rule/${selectedWalletRule?.ID}`, formField ); @@ -192,10 +192,20 @@ const EditDialog = () => { useEffect(() => { if (selectedWalletRule) { - doFetchData(selectedWalletRule); + setFormField((prev) => ({ + ...prev, + id_wallet: selectedWalletRule?.id_wallet, + id_group: selectedWalletRule?.id_group, + max_transaction_per_day: selectedWalletRule?.max_transaction_per_day, + balance_minimum: selectedWalletRule?.balance_minimum, + balance_maximum: selectedWalletRule?.balance_maximum, + credit_limit: selectedWalletRule?.credit_limit, + monthly_limit: selectedWalletRule?.monthly_limit, + status: selectedWalletRule?.status + })); } }, [selectedWalletRule]); -// console.log(selectedWalletRule); + // console.log(selectedWalletRule); return ( handleEditDialog(open, null)}> @@ -264,16 +274,20 @@ const EditDialog = () => { - - setFormField({ - ...formField, - max_transaction_per_day: parseInt(e.target.value) - }) - } + thousandSeparator="." + decimalSeparator="," + allowNegative={false} + onValueChange={(values) => { + setFormField((prev) => ({ + ...prev, + max_transaction_per_day: + values.floatValue !== undefined ? values.floatValue : '' + })); + }} + placeholder="Enter Max Transaction Per Day" />
@@ -283,13 +297,19 @@ const EditDialog = () => { - - setFormField({ ...formField, balance_minimum: parseInt(e.target.value) }) - } + thousandSeparator="." + decimalSeparator="," + allowNegative={false} + onValueChange={(values) => { + setFormField((prev) => ({ + ...prev, + balance_minimum: values.floatValue !== undefined ? values.floatValue : '' + })); + }} + placeholder="Enter Balance Minimum" /> @@ -299,13 +319,19 @@ const EditDialog = () => { - - setFormField({ ...formField, balance_maximum: parseInt(e.target.value) }) - } + thousandSeparator="." + decimalSeparator="," + allowNegative={false} + onValueChange={(values) => { + setFormField((prev) => ({ + ...prev, + balance_maximum: values.floatValue !== undefined ? values.floatValue : '' + })); + }} + placeholder="Enter Balance Maximum" /> @@ -315,13 +341,19 @@ const EditDialog = () => { - - setFormField({ ...formField, credit_limit: parseInt(e.target.value) }) - } + thousandSeparator="." + decimalSeparator="," + allowNegative={false} + onValueChange={(values) => { + setFormField((prev) => ({ + ...prev, + credit_limit: values.floatValue !== undefined ? values.floatValue : '' + })); + }} + placeholder="Enter Credit Limit" /> @@ -331,13 +363,19 @@ const EditDialog = () => { - - setFormField({ ...formField, monthly_limit: parseInt(e.target.value) }) - } + thousandSeparator="." + decimalSeparator="," + allowNegative={false} + onValueChange={(values) => { + setFormField((prev) => ({ + ...prev, + monthly_limit: values.floatValue !== undefined ? values.floatValue : '' + })); + }} + placeholder="Enter Monthly Limit" /> diff --git a/src/pages/master/walletRule/hooks/ManageWalletRuleContext.tsx b/src/pages/master/walletRule/hooks/ManageWalletRuleContext.tsx index 51d0e07..bbe1798 100644 --- a/src/pages/master/walletRule/hooks/ManageWalletRuleContext.tsx +++ b/src/pages/master/walletRule/hooks/ManageWalletRuleContext.tsx @@ -7,8 +7,14 @@ import React, { createContext, useCallback, useMemo, useState } from 'react'; import ListToolbar from '../blocks/ListToolbar'; interface WalletRuleProps { - name: string; - id_currency: string; + ID: string; + id_wallet: string; + id_group: string; + max_transaction_per_day: number | null; + balance_minimum: number | null; + balance_maximum: number | null; + credit_limit: number | null; + monthly_limit: number | null; status: string; } @@ -17,10 +23,10 @@ interface ContextProps { showAddDialog: boolean; handleAddDialog: (show: boolean) => void; showEditDialog: boolean; - handleEditDialog: (show: boolean, selected_walletRule: string | null) => void; + handleEditDialog: (show: boolean, selected_walletRule: WalletRuleProps | null) => void; showDeleteDialog: boolean; - handleDeleteDialog: (show: boolean, selected_walletRule: string | null) => void; - selectedWalletRule: string | null; + handleDeleteDialog: (show: boolean, selected_walletRule: WalletRuleProps | null) => void; + selectedWalletRule: WalletRuleProps | null; getWalletRuleLists: ( limit: number, page: number, @@ -35,9 +41,9 @@ const initialProps: ContextProps = { showAddDialog: false, handleAddDialog: (show: boolean) => {}, showEditDialog: false, - handleEditDialog: (show: boolean, selected_walletRule: string | null) => {}, + handleEditDialog: (show: boolean, selected_walletRule: object | null) => {}, showDeleteDialog: false, - handleDeleteDialog: (show: boolean, selected_walletRule: string | null) => {}, + handleDeleteDialog: (show: boolean, selected_walletRule: object | null) => {}, selectedWalletRule: null, getWalletRuleLists: async () => undefined }; @@ -50,22 +56,28 @@ const ManageWalletRuleContextProvider = ({ children }: { children: React.ReactNo const [showAddDialog, setShowAddDialog] = useState(false); const [showEditDialog, setShowEditDialog] = useState(false); const [showDeleteDialog, setShowDeleteDialog] = useState(false); - const [selectedWalletRule, setSelectedWalletRule] = useState(null); + 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 handleEditDialog = useCallback( + (show: boolean, selected_walletRule: WalletRuleProps | 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 handleDeleteDialog = useCallback( + (show: boolean, selected_walletRule: WalletRuleProps | null) => { + setShowDeleteDialog(show); + setSelectedWalletRule(show ? selected_walletRule : null); + }, + [] + ); const columns = useMemo[]>( () => [ @@ -142,13 +154,13 @@ const ManageWalletRuleContextProvider = ({ children }: { children: React.ReactNo <> @@ -194,7 +206,7 @@ const ManageWalletRuleContextProvider = ({ children }: { children: React.ReactNo handleEditDialog, showDeleteDialog, handleDeleteDialog, - selectedWalletRule, + selectedWalletRule: selectedWalletRule, getWalletRuleLists }} > From cfe12f84055e4f85e67642c1d6aec0e1029dd413 Mon Sep 17 00:00:00 2001 From: Wikzyy Date: Wed, 26 Mar 2025 11:52:31 +0700 Subject: [PATCH 10/11] fix delete --- src/pages/master/walletRule/blocks/DeleteDialog.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/master/walletRule/blocks/DeleteDialog.tsx b/src/pages/master/walletRule/blocks/DeleteDialog.tsx index 2f72635..97f3e0c 100644 --- a/src/pages/master/walletRule/blocks/DeleteDialog.tsx +++ b/src/pages/master/walletRule/blocks/DeleteDialog.tsx @@ -29,8 +29,8 @@ const DeleteDialog = () => { } const response = await DeleteData( - `${API_URL_WALLET}/dashboard/wallet_rule/${selectedWalletRule}`, - { id: selectedWalletRule } + `${API_URL_WALLET}/dashboard/wallet_rule/${selectedWalletRule.ID}`, + { id: selectedWalletRule.ID } ); if (response?.status) { From 5fa98dd0b2b60dd262643d9efdf5c29df2db548f Mon Sep 17 00:00:00 2001 From: Wikzyy Date: Wed, 26 Mar 2025 13:13:15 +0700 Subject: [PATCH 11/11] fix button edit Wallet Rule --- src/pages/master/walletRule/blocks/EditDialog.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/master/walletRule/blocks/EditDialog.tsx b/src/pages/master/walletRule/blocks/EditDialog.tsx index de2d497..9b870c4 100644 --- a/src/pages/master/walletRule/blocks/EditDialog.tsx +++ b/src/pages/master/walletRule/blocks/EditDialog.tsx @@ -404,7 +404,7 @@ const EditDialog = () => { - +