From 8dca6c875eeddef69bdb52f05de7d383be46f07b Mon Sep 17 00:00:00 2001 From: bagusajisaputroo Date: Mon, 12 May 2025 22:19:04 +0700 Subject: [PATCH] fix group name on wallet history --- .../hooks/ManageWalletHistoryContext.tsx | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/pages/wallet/wallet-history/hooks/ManageWalletHistoryContext.tsx b/src/pages/wallet/wallet-history/hooks/ManageWalletHistoryContext.tsx index ccc854e..2a7a907 100644 --- a/src/pages/wallet/wallet-history/hooks/ManageWalletHistoryContext.tsx +++ b/src/pages/wallet/wallet-history/hooks/ManageWalletHistoryContext.tsx @@ -192,8 +192,7 @@ const ManageWalletContextProvider = ({ children }: { children: React.ReactNode } } }, { - accessorFn: (row) => row.group.name, - id: 'group_name', + accessorKey: 'group_name', header: ({ 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 }; \ No newline at end of file