diff --git a/src/pages/dashboards/home/DashboardHomePage.tsx b/src/pages/dashboards/home/DashboardHomePage.tsx index 71ba39a..369149c 100644 --- a/src/pages/dashboards/home/DashboardHomePage.tsx +++ b/src/pages/dashboards/home/DashboardHomePage.tsx @@ -269,7 +269,7 @@ const DashboardHomePage = () => {
{bankaccount?.data && bankaccount?.data.length > 0 - && getAuth()?.statusbalance=='Y' + // && getAuth()?.statusbalance=='Y' ? ( bankaccount?.data.map((bankaccountdatas: { id_balance:string,amount: string, credit_limit: string, monthly_limit: string; wallet: string; }, index: number) => ( void; @@ -58,107 +41,23 @@ const getDefaultDateRange = () => { }; }; -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 [transferType, setTransferType] = useState([]); const [selectedCategory, setSelectedCategory] = useState(null); const [searchValue, setSearchValue] = useState(''); - const [transferType, setTransferType] = useState([]); const [category, setCategory] = useState([]); + const [transaction, setTransaction] = useState([]); + const [filters, setFilters] = useState({}); - const fetchTransferType = async () => { + const fetchTransferType = useCallback(async () => { try { const response = await GetData(`${apiConfig.service_transaction}/transactiontype/list`, { limit: 100, @@ -171,71 +70,18 @@ const ShowDetailWalletDialog: React.FC = ({ } catch (error) { console.error('Error fetching transfer types', error); } - }; + }, [GetData]); - 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] - ); + useEffect(() => { + fetchTransferType(); + }, [fetchTransferType]); - 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)) + new Set(transaction.map((tx) => tx.category).filter((cat) => !!cat)) ); setCategory(uniqueCategories); - }, [data]); + }, [transaction]); const handleTransferTypeChange = (value: string) => { setSelectedTransferType(value === 'all' ? null : value); @@ -250,30 +96,136 @@ const ShowDetailWalletDialog: React.FC = ({ setSelectedTransferType(null); setSelectedCategory(null); setSearchValue(''); + setFilters({}); }; - useEffect(() => { - fetchTransferType(); - }, []); + const handleApplyFilters = () => { + const appliedFilters: any = {}; - useEffect(() => { - if (!open) return; + if (dateRange.from) appliedFilters.date_from = dateRange.from+" 00:00:00"; + if (dateRange.to) appliedFilters.date_to = dateRange.to+" 23:59:59"; + if (selectedTransferType) appliedFilters.transaction_type_id = selectedTransferType; + if (selectedCategory) appliedFilters.category = selectedCategory; + if (searchValue) appliedFilters.transaction_code = searchValue; - const filters = []; + setFilters(appliedFilters); + }; - 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 }); - fetchData({ - pageIndex: 0, - pageSize: 10, - sorting: [{ id: 'date', desc: true }], - columnFilters: filters, - }); - }, [dateRange, selectedTransferType, selectedCategory, searchValue, open]); + 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 getTransactionLists = useCallback( + async (page: number, limit: number, sorting: any, _columnFilters: any) => { + // console.log(idbalance); + try { + const response = await GetData(`${apiConfig.service_wallet}/dashboard/balance/list-balance-detail/${idbalance}`, { + limit, + page: page + 1, + with_deleted: false, + order_field: "created_at", + order_direction: 'DESC', + filter: filters + }); + + // console.log(filters); + + if (!response || !response.data) { + console.warn('No data received:', response); + return { data: [], totalCount: 0 }; + } + + setTransaction(response.data.list); + return { data: response.data.list, totalCount: response.data.total_count }; + } catch (error) { + console.error('Error fetching transaction', error); + return { data: [], totalCount: 0 }; + } + }, + [GetData, idbalance, filters] + ); return ( @@ -281,98 +233,98 @@ const ShowDetailWalletDialog: React.FC = ({ Details Wallet Statement + + -
- {/*
-
- +
+
+ - + -
- -
- -
- -
- - - - - - +
+
-
*/} +
+ +
+ + + + + + + + +
+
+ +
{ - return await fetchData({ - pageIndex: params.pageIndex, - pageSize: params.pageSize, - sorting: params.sorting ?? [], - columnFilters: params.columnFilters ?? [], - }); - }} + sorting={[{ id: 'id', desc: false }]} + serverSide={true} + onFetchData={({ pageIndex, pageSize, sorting, columnFilters }) => + getTransactionLists(pageIndex, pageSize, sorting, columnFilters) + } />
@@ -381,4 +333,4 @@ const ShowDetailWalletDialog: React.FC = ({ ); }; -export default ShowDetailWalletDialog; \ No newline at end of file +export default ShowDetailWalletDialog;