From b440c14ee96e906ff407ee552428b0a958bc22c1 Mon Sep 17 00:00:00 2001 From: wayanrivan Date: Wed, 21 May 2025 15:20:03 +0700 Subject: [PATCH] update --- .../dashboards/home/DashboardHomePage.tsx | 11 +- .../dashboards/home/blocks/BankSaldo.tsx | 96 +++-- .../home/blocks/ShowDetailWalletDialog.tsx | 394 ++++++++++++++++++ 3 files changed, 454 insertions(+), 47 deletions(-) create mode 100644 src/pages/dashboards/home/blocks/ShowDetailWalletDialog.tsx diff --git a/src/pages/dashboards/home/DashboardHomePage.tsx b/src/pages/dashboards/home/DashboardHomePage.tsx index a42faee..71ba39a 100644 --- a/src/pages/dashboards/home/DashboardHomePage.tsx +++ b/src/pages/dashboards/home/DashboardHomePage.tsx @@ -268,13 +268,16 @@ const DashboardHomePage = () => { ) : null}
- {bankaccount?.data && bankaccount?.data.length > 0 && getAuth()?.statusbalance=='Y' ? ( - bankaccount?.data.map((bankaccountdatas: { amount: string, creditlimit: string, monthlylimit: string; wallet: string; }, index: number) => ( + {bankaccount?.data && bankaccount?.data.length > 0 + && getAuth()?.statusbalance=='Y' + ? ( + bankaccount?.data.map((bankaccountdatas: { id_balance:string,amount: string, credit_limit: string, monthly_limit: string; wallet: string; }, index: number) => ( )) ) : ( diff --git a/src/pages/dashboards/home/blocks/BankSaldo.tsx b/src/pages/dashboards/home/blocks/BankSaldo.tsx index 928b576..93302a6 100644 --- a/src/pages/dashboards/home/blocks/BankSaldo.tsx +++ b/src/pages/dashboards/home/blocks/BankSaldo.tsx @@ -1,62 +1,72 @@ -// BankSaldo.tsx -import { Wallet } from "lucide-react"; +import React, { useState } from 'react'; +import { Wallet } from 'lucide-react'; +import { Button } from '@/components/ui/button'; +import ShowDetailWalletDialog from './ShowDetailWalletDialog'; interface AccountCardProps { title: string; balance: string; creditLimit: string; monthlyLimit: string; + idbalance: string; } -export const BankSaldo = ({ +export const BankSaldo: React.FC = ({ title, balance, creditLimit, monthlyLimit, -}: AccountCardProps) => { + idbalance, +}) => { + const [showDialog, setShowDialog] = useState(false); + return ( -
-
-
-
-

{title}

- -
-
- {new Intl.NumberFormat("en-US", { - style: "currency", - currency: "USD", - minimumFractionDigits: 2, - maximumFractionDigits: 2, - }).format(parseFloat(balance))} -
-
-
- Credit Limit: - {creditLimit} + <> +
+
+
+
+

{title}

+
-
- Monthly Limit: - {monthlyLimit} +
+ {new Intl.NumberFormat('en-US', { + style: 'currency', + currency: 'USD', + minimumFractionDigits: 2, + maximumFractionDigits: 2, + }).format(parseFloat(balance))} +
+
+
+ Credit Limit: + {creditLimit} +
+
+ Monthly Limit: + {monthlyLimit} +
+
+ +
-
+ + {showDialog && ( + setShowDialog(false)} + idbalance={idbalance} + /> + )} + ); }; - -interface AccountCardsProps { - accounts: AccountCardProps[]; -} - -export const AccountCards = ({ accounts }: AccountCardsProps) => { - return ( -
- {accounts.map((account, index) => ( - - ))} -
- ); -}; - -export default BankSaldo +export default BankSaldo; \ No newline at end of file diff --git a/src/pages/dashboards/home/blocks/ShowDetailWalletDialog.tsx b/src/pages/dashboards/home/blocks/ShowDetailWalletDialog.tsx new file mode 100644 index 0000000..8f522db --- /dev/null +++ b/src/pages/dashboards/home/blocks/ShowDetailWalletDialog.tsx @@ -0,0 +1,394 @@ +import React, { useCallback, useEffect, useState } from 'react'; +import { + Dialog, + DialogBody, + DialogContent, + DialogHeader, + DialogTitle, +} from '@/components/ui/dialog'; +import { useCallApi } from '@/hooks'; +import { apiConfig } from '@/config/api.config'; +import { DataGridColumnHeader, DataGridProvider } from '@/components'; +import { Button } from '@/components/ui/button'; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from '@/components/ui/select'; +import { DefaultTooltip, KeenIcon } from '@/components'; + +interface WalletTransaction { + ID: string; + transaction_code: string; + transaction_type: { + id: string; + name: string; + }; + type: string; + amount: number; + pre_amount: number; + post_amount: number; + category: string; + notes: string; + date: string; + msisdn_reff?: string; + purpose?: string; +} + +interface ShowDetailWalletDialogProps { + open: boolean; + onClose: () => void; + idbalance: string; +} + +interface TransferType { + id: string; + name: string; +} + +const formatDate = (date: Date) => date.toLocaleDateString('sv-SE'); +const getDefaultDateRange = () => { + const today = new Date(); + const sevenDaysAgo = new Date(today.getTime() - 7 * 24 * 60 * 60 * 1000); + return { + from: formatDate(sevenDaysAgo), + to: formatDate(today), + }; +}; + +const columns = [ + { + accessorKey: 'transaction_code', + header: ({ column }: any) => , + enableSorting: false, + meta: { headerClassName: 'min-w-[120px]' }, + }, + { + accessorKey: 'msisdn_reff', + header: ({ column }: any) => , + enableSorting: false, + meta: { headerClassName: 'min-w-[120px]' }, + }, + { + accessorKey: 'transaction_type.name', + header: ({ column }: any) => , + enableSorting: false, + meta: { headerClassName: 'min-w-[180px]' }, + }, + { + accessorKey: 'type', + header: ({ column }: any) => , + enableSorting: false, + meta: { headerClassName: 'min-w-[80px]' }, + }, + { + accessorKey: 'amount', + header: ({ column }: any) => , + enableSorting: false, + cell: (info: any) => info.getValue()?.toFixed(2), + meta: { headerClassName: 'min-w-[100px]' }, + }, + { + accessorKey: 'pre_amount', + header: ({ column }: any) => , + enableSorting: false, + cell: (info: any) => info.getValue()?.toFixed(2), + meta: { headerClassName: 'min-w-[100px]' }, + }, + { + accessorKey: 'post_amount', + header: ({ column }: any) => , + enableSorting: false, + cell: (info: any) => info.getValue()?.toFixed(2), + meta: { headerClassName: 'min-w-[100px]' }, + }, + { + accessorKey: 'category', + header: ({ column }: any) => , + enableSorting: false, + meta: { headerClassName: 'min-w-[80px]' }, + }, + { + accessorKey: 'date', + header: ({ column }: any) => , + enableSorting: false, + cell: (info: any) => { + const val = info.getValue(); + if (!val) return '-'; + return new Date(val).toLocaleString('id-ID', { + day: '2-digit', + month: 'short', + year: 'numeric', + hour: '2-digit', + minute: '2-digit', + }); + }, + meta: { headerClassName: 'min-w-[150px]' }, + }, + { + accessorKey: 'purpose', + header: ({ column }: any) => , + enableSorting: false, + cell: (info: any) => info.getValue() || '-', + meta: { headerClassName: 'min-w-[200px]' }, + }, + { + accessorKey: 'notes', + header: ({ column }: any) => , + enableSorting: false, + cell: (info: any) => info.getValue() || '-', + meta: { headerClassName: 'min-w-[200px]' }, + }, +]; + +const ShowDetailWalletDialog: React.FC = ({ + open, + onClose, + idbalance, +}) => { + const { GetData } = useCallApi(); + const [data, setData] = useState([]); + const [isLoading, setIsLoading] = useState(false); + const [dateRange, setDateRange] = useState(getDefaultDateRange()); + const [selectedTransferType, setSelectedTransferType] = useState(null); + const [selectedCategory, setSelectedCategory] = useState(null); + const [searchValue, setSearchValue] = useState(''); + const [transferType, setTransferType] = useState([]); + const [category, setCategory] = useState([]); + + const fetchTransferType = async () => { + try { + const response = await GetData(`${apiConfig.service_transaction}/transactiontype/list`, { + limit: 100, + page: 1, + with_deleted: false, + order_field: 'created_at', + order_direction: 'ASC', + }); + setTransferType(response?.data?.list || []); + } catch (error) { + console.error('Error fetching transfer types', error); + } + }; + + const getDetailList = useCallback( + async ( + limit: number, + page: number, + with_deleted: boolean, + order_field: string, + order_direction: string, + filter: any + ): Promise => { + if (!idbalance) return []; + try { + const response = await GetData( + `${apiConfig.service_wallet}/dashboard/balance/list-balance-detail/${idbalance}`, + { + limit, + page, + with_deleted, + order_field, + order_direction, + filter: JSON.stringify(filter), + } + ); + return response?.data?.list || []; + } catch (error) { + console.error('Error fetching wallet detail:', error); + return []; + } + }, + [GetData, idbalance] + ); + + const fetchData = useCallback( + async (params: { + pageIndex: number; + pageSize: number; + sorting: Array<{ id: string; desc: boolean }>; + columnFilters: any; + }): Promise<{ data: WalletTransaction[] }> => { + // setIsLoading(true); + const order_field = params.sorting.length ? params.sorting[0].id : 'date'; + const order_direction = params.sorting.length && params.sorting[0].desc ? 'DESC' : 'ASC'; + const result = await getDetailList( + params.pageSize, + params.pageIndex + 1, + false, + order_field, + order_direction, + params.columnFilters + ); + setData(result); + setIsLoading(false); + return { data: result }; + }, + [getDetailList] + ); + + // Ambil unique category dari data transaksi setelah data di-fetch + useEffect(() => { + const uniqueCategories = Array.from( + new Set(data.map((tx) => tx.category).filter((cat) => !!cat)) + ); + setCategory(uniqueCategories); + }, [data]); + + const handleTransferTypeChange = (value: string) => { + setSelectedTransferType(value === 'all' ? null : value); + }; + + const handleCategoryChange = (value: string) => { + setSelectedCategory(value === '' ? null : value); + }; + + const handleClearAllFilters = () => { + setDateRange(getDefaultDateRange()); + setSelectedTransferType(null); + setSelectedCategory(null); + setSearchValue(''); + }; + + useEffect(() => { + fetchTransferType(); + }, []); + + const handleApplyFilter = () => { + const filters = []; + + if (dateRange.from) filters.push({ id: 'date', value: { gte: dateRange.from } }); + if (dateRange.to) filters.push({ id: 'date', value: { lte: dateRange.to } }); + if (selectedTransferType) filters.push({ id: 'transaction_type.id', value: selectedTransferType }); + if (selectedCategory) filters.push({ id: 'category', value: selectedCategory }); + if (searchValue) filters.push({ id: 'transaction_code', value: searchValue }); + + console.log(filters); + + fetchData({ + pageIndex: 0, + pageSize: 10, + sorting: [{ id: 'date', desc: true }], + columnFilters: JSON.stringify(filters), + }); + }; + + + return ( + + + + Details Wallet Statement + + +
+ {/*
+
+ + + + +
+ +
+ +
+ +
+ + + + + + + + +
+
*/} + + { + return await fetchData({ + pageIndex: params.pageIndex, + pageSize: params.pageSize, + sorting: params.sorting ?? [], + columnFilters: params.columnFilters ?? [], + }); + }} + /> +
+
+
+
+ ); +}; + +export default ShowDetailWalletDialog;