fix create update form field

- use NumericFormat from react number format
- pull data object from table not consume API get data by id
This commit is contained in:
Wikzyy
2025-03-26 11:46:04 +07:00
parent 41c1fed872
commit d1835b32bc
3 changed files with 168 additions and 89 deletions

View File

@ -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<string | null>(null);
const [selectedWalletRule, setSelectedWalletRule] = useState<WalletRuleProps | null>(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<ColumnDef<any>[]>(
() => [
@ -142,13 +154,13 @@ const ManageWalletRuleContextProvider = ({ children }: { children: React.ReactNo
<>
<button
className="btn btn-sm btn-icon btn-clear btn-light"
onClick={() => handleEditDialog(true, row.ID)}
onClick={() => handleEditDialog(true, row)}
>
<KeenIcon icon="notepad-edit" />
</button>
<button
className="btn btn-sm btn-icon btn-clear btn-light"
onClick={() => handleDeleteDialog(true, row.ID)}
onClick={() => handleDeleteDialog(true, row)}
>
<KeenIcon icon="trash" />
</button>
@ -194,7 +206,7 @@ const ManageWalletRuleContextProvider = ({ children }: { children: React.ReactNo
handleEditDialog,
showDeleteDialog,
handleDeleteDialog,
selectedWalletRule,
selectedWalletRule: selectedWalletRule,
getWalletRuleLists
}}
>