fix group name on wallet history

This commit is contained in:
bagusajisaputroo
2025-05-12 22:19:04 +07:00
parent 2ef9c8a4e4
commit 8dca6c875e

View File

@ -192,8 +192,7 @@ const ManageWalletContextProvider = ({ children }: { children: React.ReactNode }
}
},
{
accessorFn: (row) => row.group.name,
id: 'group_name',
accessorKey: 'group_name',
header: ({ column }) => <DataGridColumnHeader title="Group Name" column={column} />,
enableSorting: false,
enableHiding: false,
@ -253,12 +252,13 @@ const ManageWalletContextProvider = ({ children }: { children: React.ReactNode }
order_direction: sortDirection,
filter: JSON.stringify(filterParams)
});
// console.log(response);
if (!response || !response.data) {
console.warn('No data received:', response);
return { data: [], totalCount: 0 };
}
// Fetch wallets to map wallet names
const walletsResponse = await GetData(`${API_URL_WALLET}/dashboard/wallet/`, {
limit: 100,
page: 1,
@ -267,6 +267,15 @@ const ManageWalletContextProvider = ({ children }: { children: React.ReactNode }
order_direction: 'ASC'
});
// Fetch groups to map group names
const groupsResponse = await GetData(`${API_URL_WALLET}/dashboard/group/`, {
limit: 100,
page: 1,
with_deleted: false,
order_field: 'created_at',
order_direction: 'ASC'
});
const walletsMap = walletsResponse?.data?.list
? walletsResponse.data.list.reduce((acc: any, wallet: any) => {
acc[wallet.ID] = wallet.name;
@ -274,9 +283,17 @@ const ManageWalletContextProvider = ({ children }: { children: React.ReactNode }
}, {})
: {};
const groupsMap = groupsResponse?.data?.list
? groupsResponse.data.list.reduce((acc: any, group: any) => {
acc[group.ID] = group.name;
return acc;
}, {})
: {};
const enrichedData = response?.data.list.map((item: any) => ({
...item,
name: walletsMap[item.id_wallet] || 'Unknown Wallet'
name: walletsMap[item.id_wallet] || 'Unknown Wallet',
group_name: groupsMap[item.id_group] || 'Unknown Group'
}));
setWallets(enrichedData);
@ -322,4 +339,4 @@ const ManageWalletContextProvider = ({ children }: { children: React.ReactNode }
};
export { ManageWalletContext, ManageWalletContextProvider };
export type { WalletProps };
export type { WalletProps };