From 791f2dc9add44f6a1e58fdbb820f71629a0d352d Mon Sep 17 00:00:00 2001 From: bagusajisaputroo Date: Tue, 13 May 2025 22:21:17 +0700 Subject: [PATCH] add group name filter on wallet history --- .../wallet-history/blocks/ListToolbar.tsx | 51 ++++++++++++++++++- .../hooks/ManageWalletHistoryContext.tsx | 26 ++++------ 2 files changed, 58 insertions(+), 19 deletions(-) diff --git a/src/pages/wallet/wallet-history/blocks/ListToolbar.tsx b/src/pages/wallet/wallet-history/blocks/ListToolbar.tsx index 2cacce6..6eb8298 100644 --- a/src/pages/wallet/wallet-history/blocks/ListToolbar.tsx +++ b/src/pages/wallet/wallet-history/blocks/ListToolbar.tsx @@ -19,6 +19,11 @@ interface WalletProps { name: string; } +interface GroupProps { + ID: string; + name: string; +} + const getOneMonthsAgo = () => { const today = new Date(); return new Date(today.getFullYear(), today.getMonth() - 1, today.getDate()); @@ -37,7 +42,11 @@ const ListToolbar = () => { const [walletId, setWalletId] = useState( (table.getColumn('id_wallet')?.getFilterValue() as string) ?? '' ); + const [groupId, setGroupId] = useState( + (table.getColumn('id_group')?.getFilterValue() as string) ?? '' + ); const [wallets, setWallets] = useState([]); + const [groups, setGroups] = useState([]); useEffect(() => { const today = new Date(); @@ -67,6 +76,11 @@ const ListToolbar = () => { table.setPageIndex(0); }, [walletId, table]); + useEffect(() => { + table.getColumn('id_group')?.setFilterValue(groupId); + table.setPageIndex(0); + }, [groupId, table]); + useEffect(() => { if (dateRange.from && dateRange.to) { handleFilterByDate(); @@ -83,14 +97,29 @@ const ListToolbar = () => { order_direction: 'ASC' }); setWallets(response?.data.list || []); - // console.log('Wallets: ', response?.data); } catch (error) { console.error('Error fetching wallets', error); } }; + const fetchGroups = async () => { + try { + const response = await GetData(`${API_URL_WALLET}/dashboard/group/`, { + limit: 100, + page: 1, + with_deleted: false, + order_field: 'created_at', + order_direction: 'ASC' + }); + setGroups(response?.data.list || []); + } catch (error) { + console.error('Error fetching groups', error); + } + }; + useEffect(() => { fetchWallets(); + fetchGroups(); }, []); const handleClearAllFilters = () => { @@ -103,10 +132,12 @@ const ListToolbar = () => { setSearchValue(''); setWalletId(''); + setGroupId(''); setDateRange(resetDateRange); table.getColumn('msisdn')?.setFilterValue(''); table.getColumn('id_wallet')?.setFilterValue(''); + table.getColumn('id_group')?.setFilterValue(''); table.getColumn('CreatedAt')?.setFilterValue(resetDateRange); setTimeout(() => { @@ -115,7 +146,6 @@ const ListToolbar = () => { }, 0); }; - const handleRefresh = () => { const today = new Date(); const threeMonthsAgo = getOneMonthsAgo(); @@ -126,6 +156,7 @@ const ListToolbar = () => { setSearchValue(''); setWalletId(''); + setGroupId(''); setDateRange(resetDateRange); table.setColumnFilters([{ id: 'CreatedAt', value: resetDateRange }]); @@ -181,6 +212,22 @@ const ListToolbar = () => { + +
+ +
+