fix field Wallet and Wallet Rule

- sync form field with response field
- sync group with wallet on create Wallet Rule
This commit is contained in:
Wikzyy
2025-04-10 13:55:00 +07:00
parent 07dfcf6074
commit 0c049086e9
3 changed files with 39 additions and 19 deletions

View File

@ -40,14 +40,24 @@ interface GroupProps {
status: string;
}
interface WalletProps {
ID: string;
interface WalletGroupProps {
id: string;
name: string;
id_currency: string;
description: string;
status: string;
}
interface WalletProps {
id: string;
name: string;
id_currency: string;
status: string;
group: WalletGroupProps[];
}
const API_URL_WALLET = apiConfig.service_wallet;
const API_URL_MASTERDATA = apiConfig.service_master_data;
const AddDialog = () => {
const { showAddDialog, handleAddDialog, selectedWalletRule } = useManageWalletRuleContext();
const { reload } = useDataGrid();
@ -143,7 +153,7 @@ const AddDialog = () => {
const getWalletLists = async (sorting: any) => {
try {
const response = await GetData(`${API_URL_WALLET}/dashboard/wallet`, {
const response = await GetData(`${API_URL_MASTERDATA}/wallet/list`, {
limit: 100,
page: 1,
with_deleted: false,
@ -158,8 +168,11 @@ const AddDialog = () => {
}
};
const selectedWallet = wallets.find((wallet) => wallet.id === formField.id_wallet);
const filteredGroups = selectedWallet ? selectedWallet.group : [];
useEffect(() => {
getWalletLists([{ id: 'name', desc: false }]);
getWalletLists([{ id: 'wallets.name', desc: false }]);
getGroupLists([{ id: 'name', desc: false }]);
}, []);
@ -193,14 +206,16 @@ const AddDialog = () => {
</label>
<Select
value={formField.id_wallet}
onValueChange={(value) => setFormField({ ...formField, id_wallet: value })}
onValueChange={(value) =>
setFormField({ ...formField, id_wallet: value, id_group: '' })
}
>
<SelectTrigger>
<SelectValue placeholder="Select Wallet Type" />
</SelectTrigger>
<SelectContent>
{wallets.map((wallet) => (
<SelectItem key={wallet.ID} value={wallet.ID}>
<SelectItem key={wallet.id} value={wallet.id}>
{wallet.name}
</SelectItem>
))}
@ -217,16 +232,21 @@ const AddDialog = () => {
<Select
value={formField.id_group}
onValueChange={(value) => setFormField({ ...formField, id_group: value })}
disabled={filteredGroups.length === 0}
>
<SelectTrigger>
<SelectValue placeholder="Select Group Type" />
</SelectTrigger>
<SelectContent>
{groups.map((group) => (
<SelectItem key={group.ID} value={group.ID}>
{group.name}
</SelectItem>
))}
{filteredGroups.length > 0 ? (
filteredGroups.map((group) => (
<SelectItem key={group.id} value={group.id}>
{group.name}
</SelectItem>
))
) : (
<SelectItem value="empty">No groups available</SelectItem>
)}
</SelectContent>
</Select>
</div>