From 196d5c78e9253d9c454a44aae164a31c390a431a Mon Sep 17 00:00:00 2001 From: wayanrivan Date: Wed, 26 Mar 2025 15:48:47 +0700 Subject: [PATCH 01/22] add detail history transaction --- package-lock.json | 11 ++ package.json | 1 + .../transaction/blocks/DetailTransaction.tsx | 149 ++++++++++++++++++ .../transaction/hooks/TransactionContext.tsx | 52 ++++-- yarn.lock | 13 ++ 5 files changed, 211 insertions(+), 15 deletions(-) create mode 100644 src/pages/transaction/blocks/DetailTransaction.tsx diff --git a/package-lock.json b/package-lock.json index 3c55c14..5b8929e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -71,6 +71,7 @@ "styled-components": "^6.1.13", "stylis": "^4.3.4", "stylis-plugin-rtl": "^2.1.1", + "tabs": "^0.2.0", "tailwind-merge": "^2.5.4", "tailwindcss-animate": "^1.0.7", "vite-plugin-windicss": "^1.9.3", @@ -8025,6 +8026,10 @@ "version": "5.4.3", "resolved": "https://registry.npmjs.org/react-number-format/-/react-number-format-5.4.3.tgz", "integrity": "sha512-VCY5hFg/soBighAoGcdE+GagkJq0230qN6jcS5sp8wQX1qy1fYN/RX7/BXkrs0oyzzwqR8/+eSUrqXbGeywdUQ==", +<<<<<<< Updated upstream +======= + "license": "MIT", +>>>>>>> Stashed changes "peerDependencies": { "react": "^0.14 || ^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0", "react-dom": "^0.14 || ^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" @@ -8777,6 +8782,12 @@ "url": "https://opencollective.com/unts" } }, + "node_modules/tabs": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/tabs/-/tabs-0.2.0.tgz", + "integrity": "sha512-q6mo8KWq/Zi+zGR3ZvGq6S6ckc3JNbGRGtAwIhtnp2GlS1goTqFnWX3MkyDKYSQuzwBqBAy2fYGHQI+3HMnXZQ==", + "license": "MIT" + }, "node_modules/tailwind-merge": { "version": "2.5.4", "resolved": "https://registry.npmjs.org/tailwind-merge/-/tailwind-merge-2.5.4.tgz", diff --git a/package.json b/package.json index 8121a93..4dd81d2 100644 --- a/package.json +++ b/package.json @@ -77,6 +77,7 @@ "styled-components": "^6.1.13", "stylis": "^4.3.4", "stylis-plugin-rtl": "^2.1.1", + "tabs": "^0.2.0", "tailwind-merge": "^2.5.4", "tailwindcss-animate": "^1.0.7", "vite-plugin-windicss": "^1.9.3", diff --git a/src/pages/transaction/blocks/DetailTransaction.tsx b/src/pages/transaction/blocks/DetailTransaction.tsx new file mode 100644 index 0000000..bd06276 --- /dev/null +++ b/src/pages/transaction/blocks/DetailTransaction.tsx @@ -0,0 +1,149 @@ +import { useTransactionContext } from '../hooks/useTransactionContext'; +import { useCallApi } from '@/hooks'; +import { apiConfig } from '@/config/api.config'; +import { useEffect, useState } from 'react'; +import { + Dialog, + DialogBody, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle +} from '@/components/ui/dialog'; + +const API_URL = apiConfig.transaction; + +const DetailTransaction = () => { + const { GetData } = useCallApi(); + const { + showDetailDialog, + setShowDetailDialog, + selectedTransactionId + } = useTransactionContext(); + + const [transactionDetails, setTransactionDetails] = useState(null); + + useEffect(() => { + const fetchTransactionDetails = async () => { + if (selectedTransactionId) { + try { + const response = await GetData(`${API_URL}/transaction/history/detail/${selectedTransactionId}`, { + id: selectedTransactionId + }); + // console.log(response?.data); + setTransactionDetails(response?.data); + } catch (error) { + console.error('Error fetching transaction', error); + } + } + }; + + if (showDetailDialog && selectedTransactionId) { + fetchTransactionDetails(); + } + }, [showDetailDialog, selectedTransactionId, GetData]); + + const [activeTab, setActiveTab] = useState('detail'); // 'detail', 'log', 'approve' + + return ( + + + + Transaction Details + {/* + Viewing details for transaction ID: {selectedTransactionId} + */} + + + {/* Tabs Navigation */} +
+ + + +
+ + {/* Tab Content */} +
+ {activeTab === 'detail' && ( +
+

Transaction Information

+
+
+

Transaction Date

+

2023-11-15 14:30:22

+
+
+

Amount

+

$1,250.00

+
+
+

Status

+

COMPLETED

+
+
+

Fee

+

$5.00

+
+
+
+ )} + + {activeTab === 'log' && ( +
+

Transaction Logs

+
+
+
+ Status changed to COMPLETED + 2023-11-15 14:35:22 +
+

System processed the transaction successfully

+
+
+
+ Status changed to PROCESSING + 2023-11-15 14:31:22 +
+

Transaction received by system

+
+
+
+ )} + + {activeTab === 'approve' && ( +
+

Approval Logs

+
+
+
+ Approved by Admin + 2023-11-15 14:32:22 +
+

Transaction approved automatically by system

+
+
+
+ )} +
+
+
+
+ ); +}; + +export default DetailTransaction; \ No newline at end of file diff --git a/src/pages/transaction/hooks/TransactionContext.tsx b/src/pages/transaction/hooks/TransactionContext.tsx index c8b4943..eb87702 100644 --- a/src/pages/transaction/hooks/TransactionContext.tsx +++ b/src/pages/transaction/hooks/TransactionContext.tsx @@ -8,6 +8,7 @@ import { useCallApi } from '@/hooks'; import ListToolbar from '../blocks/ListToolbar'; import { Button } from '@/components/ui/button'; import { useNavigate } from 'react-router'; +import DetailTransaction from '../blocks/DetailTransaction'; interface TransactionProps { id: number; @@ -23,16 +24,26 @@ interface ContextProps { order_direction: any, filter: any ) => Promise<{ data: TransactionProps[]; totalCount: number } | undefined>; + showDetailDialog: boolean; + setShowDetailDialog: React.Dispatch>; + selectedTransactionId: number | null; + setSelectedTransactionId: React.Dispatch>; } const initialProps: ContextProps = { - getTransactionLists: async () => ({ data: [], totalCount: 0 }) + getTransactionLists: async () => ({ data: [], totalCount: 0 }), + showDetailDialog: false, + setShowDetailDialog: () => { }, + selectedTransactionId: null, + setSelectedTransactionId: () => { } }; const ManageTransactionContext = createContext(initialProps); const API_URL = apiConfig.transaction; const TransactionProvider = ({ children }: { children: React.ReactNode }) => { + const [showDetailDialog, setShowDetailDialog] = useState(false); + const [selectedTransactionId, setSelectedTransactionId] = useState(null); const [transaction, setTransaction] = useState([]); const { GetData } = useCallApi(); const navigate = useNavigate(); @@ -97,9 +108,9 @@ const TransactionProvider = ({ children }: { children: React.ReactNode }) => { let status; if (row.status === 'C') { status = 'COMPLETE'; - } else if(row.status === 'F') { + } else if (row.status === 'F') { status = 'FAILED'; - } else if(row.status === 'O') { + } else if (row.status === 'O') { status = 'ON PROCESS'; } else { status = 'PENDING'; @@ -138,13 +149,19 @@ const TransactionProvider = ({ children }: { children: React.ReactNode }) => { enableSorting: false, enableHiding: false, cell: (data) => { - const row = data.row.original.id; + const row = data.row.original; return ( - <> - - + ); }, meta: { @@ -161,25 +178,25 @@ const TransactionProvider = ({ children }: { children: React.ReactNode }) => { let enddate; let formattedFilter; - if (filter == undefined || filter.length==0) { + if (filter == undefined || filter.length == 0) { const today = new Date(); const nextWeek = new Date(); nextWeek.setDate(today.getDate() + 7); - - startdate = today.toISOString().split('T')[0]; + + startdate = today.toISOString().split('T')[0]; enddate = nextWeek.toISOString().split('T')[0]; - }else if (filter != undefined || filter.length!=0) { + } else if (filter != undefined || filter.length != 0) { startdate = filter[0].value.from; enddate = filter[0].value.to; } formattedFilter = { "Transactions.transaction_date": { - from: startdate+" 00:00:00", - to: enddate+" 23:59:59" + from: startdate + " 00:00:00", + to: enddate + " 23:59:59" } }; - + const response = await GetData(`${API_URL}/transaction/history`, { limit, page: page + 1, @@ -199,10 +216,15 @@ const TransactionProvider = ({ children }: { children: React.ReactNode }) => { return ( + = 16.8.0", react-dom@>=16.6.0, react-dom@>=16.8, react-dom@>=16.8.0: +>>>>>>> Stashed changes version "18.3.1" resolved "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz" integrity sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw== @@ -3887,7 +3891,11 @@ react-transition-group@^4.4.5: loose-envify "^1.4.0" prop-types "^15.6.2" +<<<<<<< Updated upstream react@^18.3.1: +======= +"react@^0.14 || ^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0", "react@^16.3.0 || ^17.0.0 || ^18.0.0", "react@^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0-rc", "react@^16.6.0 || ^17.0.0 || ^18.0.0", "react@^16.6.0 || 17 || 18", "react@^16.8 || ^17 || ^18 || ^19 || ^19.0.0-rc", "react@^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", "react@^16.8.0 || ^17.0.0 || ^18.0.0", "react@^17.0.0 || ^18.0.0", "react@^17.0.0 || ^18.0.0 || ^19.0.0", "react@^18 || ^19", "react@^18 || ^19 || ^19.0.0-rc", react@^18.0.0, "react@^18.0.0 || ^19.0.0 || ^19.0.0-rc", react@^18.3.1, "react@>= 16.8.0", react@>=0.13, react@>=16.3.0, react@>=16.6.0, react@>=16.8, react@>=16.8.0, "react@16.8 - 18": +>>>>>>> Stashed changes version "18.3.1" resolved "https://registry.npmjs.org/react/-/react-18.3.1.tgz" integrity sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ== @@ -4237,6 +4245,11 @@ synckit@^0.9.1: "@pkgr/core" "^0.1.0" tslib "^2.6.2" +tabs@^0.2.0: + version "0.2.0" + resolved "https://registry.npmjs.org/tabs/-/tabs-0.2.0.tgz" + integrity sha512-q6mo8KWq/Zi+zGR3ZvGq6S6ckc3JNbGRGtAwIhtnp2GlS1goTqFnWX3MkyDKYSQuzwBqBAy2fYGHQI+3HMnXZQ== + tailwind-merge@^2.5.4: version "2.5.4" resolved "https://registry.npmjs.org/tailwind-merge/-/tailwind-merge-2.5.4.tgz" From 16ab396e55b0b9019eae332730d890a2eaa276b3 Mon Sep 17 00:00:00 2001 From: Wikzyy Date: Wed, 26 Mar 2025 16:58:21 +0700 Subject: [PATCH 02/22] fix create and update Wallet Rule - remove validation value 0 --- src/pages/master/walletRule/blocks/AddDialog.tsx | 10 +--------- src/pages/master/walletRule/blocks/EditDialog.tsx | 10 +--------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/src/pages/master/walletRule/blocks/AddDialog.tsx b/src/pages/master/walletRule/blocks/AddDialog.tsx index 885c15a..f18cd89 100644 --- a/src/pages/master/walletRule/blocks/AddDialog.tsx +++ b/src/pages/master/walletRule/blocks/AddDialog.tsx @@ -105,15 +105,7 @@ const AddDialog = () => { const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); - if ( - formField.id_group.trim() === '' || - formField.max_transaction_per_day === 0 || - formField.balance_minimum === 0 || - formField.balance_maximum === 0 || - formField.credit_limit === 0 || - formField.monthly_limit === 0 || - formField.status.trim() === '' - ) { + if (formField.id_group.trim() === '' || formField.status.trim() === '') { setAlert({ show: true, message: 'Please fill in all required fields.' }); return; } diff --git a/src/pages/master/walletRule/blocks/EditDialog.tsx b/src/pages/master/walletRule/blocks/EditDialog.tsx index 9b870c4..8529c3f 100644 --- a/src/pages/master/walletRule/blocks/EditDialog.tsx +++ b/src/pages/master/walletRule/blocks/EditDialog.tsx @@ -108,15 +108,7 @@ const EditDialog = () => { const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); - if ( - formField.id_group.trim() === '' || - formField.max_transaction_per_day === 0 || - formField.balance_minimum === 0 || - formField.balance_maximum === 0 || - formField.credit_limit === 0 || - formField.monthly_limit === 0 || - formField.status.trim() === '' - ) { + if (formField.id_group.trim() === '' || formField.status.trim() === '') { setAlert({ show: true, message: 'Please fill in all required fields.' }); return; } From d9c487f46437806cc2e5598a45ae77acea868700 Mon Sep 17 00:00:00 2001 From: Wikzyy Date: Wed, 26 Mar 2025 17:01:40 +0700 Subject: [PATCH 03/22] feat add Wallet History - update table status display on Wallet Rule and Wallet History --- .../hooks/ManageWalletHistoryContext.tsx | 211 ++++++++++++++++++ .../hooks/useManageWalletHistoryContext.tsx | 12 + src/routing/AppRoutingSetup.tsx | 3 + 3 files changed, 226 insertions(+) create mode 100644 src/pages/wallet/wallet-history/hooks/ManageWalletHistoryContext.tsx create mode 100644 src/pages/wallet/wallet-history/hooks/useManageWalletHistoryContext.tsx diff --git a/src/pages/wallet/wallet-history/hooks/ManageWalletHistoryContext.tsx b/src/pages/wallet/wallet-history/hooks/ManageWalletHistoryContext.tsx new file mode 100644 index 0000000..e4fb7f4 --- /dev/null +++ b/src/pages/wallet/wallet-history/hooks/ManageWalletHistoryContext.tsx @@ -0,0 +1,211 @@ +import { DataGridColumnHeader, DataGridProvider, KeenIcon } from '@/components'; +import { Toaster } from '@/components/ui/sonner'; +import { apiConfig } from '@/config/api.config'; +import { useCallApi } from '@/hooks'; +import { ColumnDef } from '@tanstack/react-table'; +import React, { createContext, useCallback, useMemo, useState } from 'react'; +import ListToolbar from '../blocks/ListToolbar'; + +interface WalletProps { + id: string; + name: string; + id_currency: string; + status: string; +} + +interface ContextProps { + wallets: WalletProps[]; + showAddDialog: boolean; + handleAddDialog: (show: boolean) => void; + showEditDialog: boolean; + handleEditDialog: (show: boolean, selected_wallet: WalletProps | null) => void; + showDeleteDialog: boolean; + handleDeleteDialog: (show: boolean, selected_wallet: WalletProps | null) => void; + selectedWallet: WalletProps | null; + getWalletLists: ( + limit: number, + page: number, + with_deleted: boolean, + order_field: any, + order_direction: any + ) => Promise<{ data: WalletProps[]; totalCount: number } | undefined>; +} + +const initialProps: ContextProps = { + wallets: [], + showAddDialog: false, + handleAddDialog: (show: boolean) => {}, + showEditDialog: false, + handleEditDialog: (show: boolean, selected_wallet: object | null) => {}, + showDeleteDialog: false, + handleDeleteDialog: (show: boolean, selected_wallet: object | null) => {}, + selectedWallet: null, + getWalletLists: async () => undefined +}; + +const ManageWalletContext = createContext(initialProps); +const API_URL_WALLET = apiConfig.service_wallet; + +const ManageWalletContextProvider = ({ children }: { children: React.ReactNode }) => { + const [wallets, setWallets] = useState([]); + const [showAddDialog, setShowAddDialog] = useState(false); + const [showEditDialog, setShowEditDialog] = useState(false); + const [showDeleteDialog, setShowDeleteDialog] = useState(false); + const [selectedWallet, setSelectedWallet] = useState(null); + const { GetData } = useCallApi(); + + const handleAddDialog = useCallback((show: boolean) => { + setShowAddDialog(show); + }, []); + + const handleEditDialog = useCallback((show: boolean, selected_wallet: WalletProps | null) => { + setShowEditDialog(show); + setSelectedWallet(show ? selected_wallet : null); + }, []); + + const handleDeleteDialog = useCallback((show: boolean, selected_wallet: WalletProps | null) => { + setShowDeleteDialog(show); + setSelectedWallet(show ? selected_wallet : null); + }, []); + + const columns = useMemo[]>( + () => [ + { + accessorFn: (row) => row.name, + id: 'name', + header: ({ column }) => , + enableSorting: true, + enableHiding: false, + meta: { + headerClassName: 'w-[550px]', + cellClassName: 'p-[20px]' + } + }, + { + accessorFn: (row) => row.currency.name, + id: 'currency_name', + header: ({ column }) => , + enableSorting: false, + enableHiding: false, + meta: { + headerClassName: 'w-[200px]' + } + }, + { + accessorFn: (row) => row.currency.prefix, + id: 'currency_prefix', + header: ({ column }) => , + enableSorting: false, + enableHiding: false, + meta: { + headerClassName: 'w-[200px]' + } + }, + { + accessorFn: (row) => row.status, + id: 'status', + header: ({ column }) => , + enableSorting: false, + enableHiding: false, + cell: ({ row }) => { + const isActive = row.original.status === 'Y'; + + return ( + + {isActive ? 'Active' : 'Inactive'} + + ); + }, + meta: { + headerClassName: 'w-[100px]', + cellClassName: 'text-center' + } + } + // { + // id: 'actions', + // header: ({ column }) => , + // cell: (data) => { + // const row = data.row.original; + // return ( + // <> + // + // + // + // ); + // }, + // meta: { + // headerClassName: 'w-[150px]' + // } + // } + ], + [] + ); + + const getWalletLists = async (page: number, limit: number, sorting: any, filter: any) => { + try { + sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting; + filter = filter.length == 0 ? {} : { name: filter[0].value?.toLowerCase() }; + const response = await GetData(`${API_URL_WALLET}/dashboard/wallet`, { + limit, + page: page + 1, + with_deleted: false, + order_field: sorting[0].id, + order_direction: sorting[0].desc == false ? 'ASC' : 'DESC', + // filter: JSON.stringify(filter) + }); + console.log(response?.data); + setWallets(response?.data.list); + return { data: response?.data.list, totalCount: response?.data.total_count }; + } catch (error) { + console.error('Error fetching Wallet', error); + } + }; + + return ( + + + } + layout={{ card: true }} + sorting={[{ id: 'id', desc: false }]} + serverSide={true} + onFetchData={({ pageIndex, pageSize, sorting, columnFilters }) => + getWalletLists(pageIndex, pageSize, sorting, columnFilters) + } + > + {children} + + + ); +}; + +export { ManageWalletContext, ManageWalletContextProvider }; +export type { WalletProps }; diff --git a/src/pages/wallet/wallet-history/hooks/useManageWalletHistoryContext.tsx b/src/pages/wallet/wallet-history/hooks/useManageWalletHistoryContext.tsx new file mode 100644 index 0000000..9e5f912 --- /dev/null +++ b/src/pages/wallet/wallet-history/hooks/useManageWalletHistoryContext.tsx @@ -0,0 +1,12 @@ +import { useContext } from 'react'; +import { ManageWalletContext } from './ManageWalletHistoryContext'; + +const useManageWalletContext = () => { + const context = useContext(ManageWalletContext); + if (!context) { + throw new Error('useManageWalletContext must be used within a ManageWalletContextProvider'); + } + return context; +}; + +export { useManageWalletContext }; diff --git a/src/routing/AppRoutingSetup.tsx b/src/routing/AppRoutingSetup.tsx index b46c8a4..3c7fdab 100644 --- a/src/routing/AppRoutingSetup.tsx +++ b/src/routing/AppRoutingSetup.tsx @@ -34,6 +34,7 @@ import ProductsMaster from '@/pages/master/products/ProductsMaster'; import ProviderMaster from '@/pages/master/provider/ProviderMaster'; import ConversionMaster from '@/pages/master/conversion/ConversionMaster'; import WalletRuleMaster from '@/pages/master/walletRule/WalletRuleMaster'; +import WalletHistory from '@/pages/wallet/wallet-history/WalletHistory'; const AppRoutingSetup = (): ReactElement => { return ( @@ -72,6 +73,8 @@ const AppRoutingSetup = (): ReactElement => { } /> + } /> + } /> } /> From 0f69423e96412c13bc9ec5a815e11d182c002955 Mon Sep 17 00:00:00 2001 From: Wikzyy Date: Thu, 27 Mar 2025 09:30:40 +0700 Subject: [PATCH 04/22] change display status --- .../provider/hooks/ManageProviderContext.tsx | 18 ++++++++++++++++-- .../hooks/ManageWalletRuleContext.tsx | 18 ++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/pages/master/provider/hooks/ManageProviderContext.tsx b/src/pages/master/provider/hooks/ManageProviderContext.tsx index f68d8bc..6dc7ea4 100644 --- a/src/pages/master/provider/hooks/ManageProviderContext.tsx +++ b/src/pages/master/provider/hooks/ManageProviderContext.tsx @@ -109,8 +109,22 @@ const ManageProviderContextProvider = ({ children }: { children: React.ReactNode header: ({ column }) => , enableSorting: false, enableHiding: false, + cell: ({ row }) => { + const isActive = row.original.provider_status === 'Y'; + + return ( + + {isActive ? 'Active' : 'Inactive'} + + ); + }, meta: { - headerClassName: 'w-[100px]' + headerClassName: 'w-[100px]', + cellClassName: 'text-center' } }, { @@ -158,7 +172,7 @@ const ManageProviderContextProvider = ({ children }: { children: React.ReactNode order_direction: sorting[0].desc == false ? 'ASC' : 'DESC', filter: JSON.stringify(filter) }); - // console.log(response?.data); + console.log(response?.data); setProvider(response?.data.list); return { data: response?.data.list, totalCount: response?.data.total_count }; } catch (error) { diff --git a/src/pages/master/walletRule/hooks/ManageWalletRuleContext.tsx b/src/pages/master/walletRule/hooks/ManageWalletRuleContext.tsx index bbe1798..20f699f 100644 --- a/src/pages/master/walletRule/hooks/ManageWalletRuleContext.tsx +++ b/src/pages/master/walletRule/hooks/ManageWalletRuleContext.tsx @@ -137,10 +137,24 @@ const ManageWalletRuleContextProvider = ({ children }: { children: React.ReactNo accessorFn: (row) => row.status, id: 'status', header: ({ column }) => , - enableSorting: true, + enableSorting: false, enableHiding: false, + cell: ({ row }) => { + const isActive = row.original.status === 'Y'; + + return ( + + {isActive ? 'Active' : 'Inactive'} + + ); + }, meta: { - headerClassName: 'w-[250px]' + headerClassName: 'w-[100px]', + cellClassName: 'text-center' } }, { From 938edde70415501d058d5e41963fed776448f5aa Mon Sep 17 00:00:00 2001 From: Wikzyy Date: Thu, 27 Mar 2025 09:31:05 +0700 Subject: [PATCH 05/22] add Wallet History --- .../wallet/wallet-history/WalletHistory.tsx | 32 +++++++++++ .../wallet-history/blocks/ListToolbar.tsx | 55 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 src/pages/wallet/wallet-history/WalletHistory.tsx create mode 100644 src/pages/wallet/wallet-history/blocks/ListToolbar.tsx diff --git a/src/pages/wallet/wallet-history/WalletHistory.tsx b/src/pages/wallet/wallet-history/WalletHistory.tsx new file mode 100644 index 0000000..d146a2d --- /dev/null +++ b/src/pages/wallet/wallet-history/WalletHistory.tsx @@ -0,0 +1,32 @@ +import { Container, DataGridInner } from '@/components'; +import { ManageWalletContextProvider } from './hooks/ManageWalletHistoryContext'; +import { Breadcrumbs, Link } from '@mui/material'; + +const WalletHistory = () => { + return ( + + +

Wallet History

+ + + Dashboard + + + + Wallet + + + + Wallet History + + + +
+ +
+
+
+ ); +}; + +export default WalletHistory; diff --git a/src/pages/wallet/wallet-history/blocks/ListToolbar.tsx b/src/pages/wallet/wallet-history/blocks/ListToolbar.tsx new file mode 100644 index 0000000..cc4aee9 --- /dev/null +++ b/src/pages/wallet/wallet-history/blocks/ListToolbar.tsx @@ -0,0 +1,55 @@ +import { DefaultTooltip, KeenIcon, useDataGrid } from '@/components'; +import { useManageWalletContext } from '../hooks/useManageWalletHistoryContext'; +import { Button } from '@/components/ui/button'; + +const ListToolbar = () => { + const { table, reload } = useDataGrid(); + const { handleAddDialog } = useManageWalletContext(); + + return ( +
+
+
+
+ + {/* + + */} +
+
+ + + + +
+
+
+
+ ); +}; + +export default ListToolbar; From 892b1ad8101ccaeed02361c4c7a0e6b58d6c95ed Mon Sep 17 00:00:00 2001 From: Wikzyy Date: Thu, 27 Mar 2025 09:51:42 +0700 Subject: [PATCH 06/22] update wallet history --- src/pages/wallet/wallet-history/blocks/ListToolbar.tsx | 7 ------- .../wallet-history/hooks/ManageWalletHistoryContext.tsx | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/pages/wallet/wallet-history/blocks/ListToolbar.tsx b/src/pages/wallet/wallet-history/blocks/ListToolbar.tsx index cc4aee9..9b239b2 100644 --- a/src/pages/wallet/wallet-history/blocks/ListToolbar.tsx +++ b/src/pages/wallet/wallet-history/blocks/ListToolbar.tsx @@ -33,13 +33,6 @@ const ListToolbar = () => { */}
- + +
{/* Tab Content */} -
- {activeTab === 'detail' && ( +
+ {activeTab === 'detail' && transactionDetails?.kind === 'P' && (
-

Transaction Information

+

+ Transaction Information + + Info + +

Transaction Date

-

2023-11-15 14:30:22

+

{transactionDetails?.transaction_date}

+
+
+

Full Name

+

{transactionDetails?.origin_customer.fullname}

Amount

-

$1,250.00

-
-
-

Status

-

COMPLETED

+

{new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(transactionDetails?.purchase.amount)}

Fee

-

$5.00

+

+ {transactionDetails?.kind === 'P' + ? transactionDetails?.purchase.fee_amount.toLocaleString('en-US', { style: 'currency', currency: 'USD' }) + : transactionDetails?.transfer.fee_amount.toLocaleString('en-US', { style: 'currency', currency: 'USD' })} +

+
+
+

Status

+

+ {(() => { + let status; + if (transactionDetails?.status === 'C') { + status = 'COMPLETE'; + } else if (transactionDetails?.status === 'F') { + status = 'FAILED'; + } else if (transactionDetails?.status === 'O') { + status = 'ON PROCESS'; + } else { + status = 'PENDING'; + } + return status; + })()} +

+
+
+

Transaction Type

+

+ {(() => { + let kind; + if (transactionDetails?.kind === 'T') { + kind = 'TRANSFER'; + } else if (transactionDetails?.kind === 'P') { + kind = 'PURCHASE'; + } else if (transactionDetails?.kind === 'W') { + kind = 'WITHDRAW'; + } else if (transactionDetails?.kind === 'U') { + kind = 'TOP UP'; + } else if (transactionDetails?.kind === 'R') { + kind = 'RETURN'; + } + return kind; + })()} +

+
+
+

Description

+

{transactionDetails?.description}

+
+
+

Name

+

{transactionDetails?.type.name}

+
+
+ +

+ Origin Wallet + + Wallet + +

+
+
+

Name

+

{transactionDetails?.origin_wallet.name}

+
+
+

Description

+

{transactionDetails?.origin_wallet.description}

+
+
+ +

+ Purchase + + Purchase + +

+
+
+

Amount

+

{new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(transactionDetails?.purchase.amount)}

+
+
+

Cashback

+

{new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(transactionDetails?.purchase.cashback)}

+
+
+

Cashback Point

+

{transactionDetails?.purchase.cashback_point}

+
+
+

Fee Amount

+

{new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(transactionDetails?.purchase.fee_amount)}

+
+
+
+ )} + + {activeTab === 'detail' && transactionDetails?.kind != 'P' && transactionDetails?.transfer!=null && ( +
+

+ Transaction Information + + Info + +

+
+
+

Transaction Date

+

{transactionDetails?.transaction_date}

+
+
+

Full Name

+

{transactionDetails?.origin_customer.fullname}

+
+
+

Amount

+

{new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(transactionDetails?.transfer.amount)}

+
+
+

Fee

+

+ {transactionDetails?.transfer.fee_amount.toLocaleString('en-US', { style: 'currency', currency: 'USD' })} +

+
+
+

Status

+

+ {(() => { + let status; + if (transactionDetails?.status === 'C') { + status = 'COMPLETE'; + } else if (transactionDetails?.status === 'F') { + status = 'FAILED'; + } else if (transactionDetails?.status === 'O') { + status = 'ON PROCESS'; + } else { + status = 'PENDING'; + } + return status; + })()} +

+
+
+

Transaction Type

+

+ {(() => { + let kind; + if (transactionDetails?.kind === 'T') { + kind = 'TRANSFER'; + } else if (transactionDetails?.kind === 'P') { + kind = 'PURCHASE'; + } else if (transactionDetails?.kind === 'W') { + kind = 'WITHDRAW'; + } else if (transactionDetails?.kind === 'U') { + kind = 'TOP UP'; + } else if (transactionDetails?.kind === 'R') { + kind = 'RETURN'; + } + return kind; + })()} +

+
+
+

Description

+

{transactionDetails?.description}

+
+
+

Name

+

{transactionDetails?.type.name}

+
+
+

Reference

+

{transactionDetails?.transfer.reference}

+
+
+

Destination Iban

+

{transactionDetails?.transfer.destination_iban}

+
+
+ +

+ Destination Wallet + + Wallet + +

+
+
+

Name

+

{transactionDetails?.transfer.destination_wallet.name}

+
+
+

Description

+

{transactionDetails?.transfer.destination_wallet.description}

+
+
+ +

+ Destination Customer + + Destination Customer + +

+
+
+

Name

+

{transactionDetails?.transfer.destination_customer.fullname}

+
+
+

MSISDN

+

{transactionDetails?.transfer.destination_customer.msisdn}

+
+
+

Email

+

{transactionDetails?.transfer.destination_customer.email}

+
+
+

MSISDN

+

{transactionDetails?.transfer.destination_customer.username}

+
+
+ +

+ Origin Wallet + + Wallet + +

+
+
+

Name

+

{transactionDetails?.origin_wallet.name}

+
+
+

Description

+

{transactionDetails?.origin_wallet.description}

+
+
+
+ )} + + + {activeTab === 'origincustomer' && ( +
+

Origin Customer

+
+
+

Full Name

+

{transactionDetails?.origin_customer.fullname}

+
+
+

Phone Number

+

{transactionDetails?.origin_customer.msisdn}

+
+
+

Email

+

{transactionDetails?.origin_customer.email}

+
+
+

Username

+

{transactionDetails?.origin_customer.username}

@@ -106,21 +381,53 @@ const DetailTransaction = () => { {activeTab === 'log' && (

Transaction Logs

-
-
-
- Status changed to COMPLETED - 2023-11-15 14:35:22 -
-

System processed the transaction successfully

-
-
-
- Status changed to PROCESSING - 2023-11-15 14:31:22 -
-

Transaction received by system

-
+
+ + + + + + + + + + + + + {transactionDetails?.log && transactionDetails?.log.length > 0 ? ( + transactionDetails.log.map((log: { request_endpoint: string, status: string; request_date: string; response_date: string; request_body: string; response_body: string; response_code: number }, index: number) => ( + + + + + + + + + )) + ) : ( + + + + )} + +
StatusRequest DateRequest BodyResponse BodyResponse CodeRequest End Point
+ {(() => { + let status; + if (log.status === 'P') { + status = 'PENDING'; + } else if (log.status === 'O') { + status = 'ON PROCESS'; + } else if (log.status === 'F') { + status = 'FAILED'; + } else if (log.status === 'C') { + status = 'COMPLETE'; + } + return status; + })()} + {log.request_date ?? '-'}{log.response_date ?? '-'}{log.request_body ?? '-'}{log.response_body ?? '-'}{log.request_endpoint ?? '-'}
+ No logs available +
)} @@ -128,17 +435,99 @@ const DetailTransaction = () => { {activeTab === 'approve' && (

Approval Logs

-
-
-
- Approved by Admin - 2023-11-15 14:32:22 -
-

Transaction approved automatically by system

+ {transactionDetails?.log_approve.length === 0 ? ( +

No data available

+ ) : ( +
+ + + + + + + + + + {transactionDetails?.log_approve && transactionDetails?.log_approve.length > 0 ? ( + transactionDetails.log_approve.map((log: { created_at: string; status: string; updated_at: string }, index: number) => ( + + + + + + )) + ) : ( + + + + )} + +
StatusCreated AtUpdated At
+ {(() => { + let status; + if (log.status === 'W') { + status = 'WAITING'; + } else if (log.status === 'Y') { + status = 'APPROVE'; + } else if (log.status === 'N') { + status = 'REJECT'; + } else if (log.status === 'T') { + status = 'NO NEED'; + } + return status; + })()} + {log.created_at}{log.updated_at}
+ No logs available +
-
+ )}
)} + + {activeTab === 'p24' && ( +
+

P24 Logs

+ {transactionDetails?.p24.length === 0 ? ( +

No data available

+ ) : ( +
+ + + + + + + + + + + + + {transactionDetails?.p24 && transactionDetails?.p24.length > 0 ? ( + transactionDetails.p24.map((log: { request_endpoint: string, type: string; request_date: string; response_date: string; request_body: string; response_body: string; response_code: number }, index: number) => ( + + + + + + + + + )) + ) : ( + + + + )} + +
TypeRequest DateRequest BodyResponse BodyResponse CodeRequest Endpoint
{log.type}{log.request_date}{log.response_date}{log.request_body}{log.response_body}{log.request_endpoint ?? '-'}
+ No logs available +
+
+ )} +
+ )} +
@@ -146,4 +535,4 @@ const DetailTransaction = () => { ); }; -export default DetailTransaction; \ No newline at end of file +export default DetailTransaction; diff --git a/src/pages/transaction/hooks/TransactionContext.tsx b/src/pages/transaction/hooks/TransactionContext.tsx index eb87702..158808c 100644 --- a/src/pages/transaction/hooks/TransactionContext.tsx +++ b/src/pages/transaction/hooks/TransactionContext.tsx @@ -72,8 +72,12 @@ const TransactionProvider = ({ children }: { children: React.ReactNode }) => { } }, { - accessorFn: (row) => - new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(row.purchase.amount), + accessorFn: (row) => { + const purchaseAmount = row?.purchase?.amount; + const transferAmount = row?.transfer?.amount; + + return new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(purchaseAmount ?? transferAmount ?? 0); + }, id: 'amount', header: ({ column }) => , enableSorting: false, @@ -84,19 +88,13 @@ const TransactionProvider = ({ children }: { children: React.ReactNode }) => { }, { accessorFn: (row) => { - let fee; - if (row.kind === 'P') { - fee = row.purchase.fee_amount; - } else { - fee = row.transfer.fee_amount; - } - return fee.toLocaleString('en-US', { - style: 'currency', - currency: 'USD', - }); + const purchaseAmount = row?.purchase?.fee_amount; + const transferAmount = row?.transfer?.fee_amount; + + return new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(purchaseAmount ?? transferAmount ?? 0); }, - accessorKey: 'fee', - header: ({ column }) => , + id: 'feeamount', + header: ({ column }) => , enableSorting: false, enableHiding: false, meta: { @@ -152,8 +150,8 @@ const TransactionProvider = ({ children }: { children: React.ReactNode }) => { const row = data.row.original; return (
- + */} +
+
+ + + + +
+
+
+
+ ); +}; + +export default ListToolbar; diff --git a/src/pages/master/wallet/hooks/ManageWalletContext.tsx b/src/pages/master/wallet/hooks/ManageWalletContext.tsx new file mode 100644 index 0000000..7369367 --- /dev/null +++ b/src/pages/master/wallet/hooks/ManageWalletContext.tsx @@ -0,0 +1,204 @@ +import { DataGridColumnHeader, DataGridProvider, KeenIcon } from '@/components'; +import { apiConfig } from '@/config/api.config'; +import { useCallApi } from '@/hooks'; +import { ColumnDef } from '@tanstack/react-table'; +import React, { createContext, useCallback, useMemo, useState } from 'react'; +import { Toaster } from 'sonner'; +import ListToolbar from '../blocks/ListToolbar'; + +interface WalletProps { + id: string; + name: string; + status: string; + description: string; + group: string[]; + currency_id: string; +} + +interface ContextProps { + wallet: WalletProps[]; + showAddDialog: boolean; + handleAddDialog: (show: boolean) => void; + showEditDialog: boolean; + handleEditDialog: (show: boolean, selected_wallet: WalletProps | null) => void; + showDeleteDialog: boolean; + handleDeleteDialog: (show: boolean, selected_wallet: WalletProps | null) => void; + selectedWallet: WalletProps | null; + getWalletLists: ( + limit: number, + page: number, + with_deleted: boolean, + order_field: any, + order_direction: any + ) => Promise<{ data: WalletProps[]; totalCount: number } | undefined>; +} + +const initialProps: ContextProps = { + wallet: [], + showAddDialog: false, + handleAddDialog: (show: boolean) => {}, + showEditDialog: false, + handleEditDialog: (show: boolean, selected_wallet: WalletProps | null) => {}, + showDeleteDialog: false, + handleDeleteDialog: (show: boolean, selected_wallet: WalletProps | null) => {}, + selectedWallet: null, + getWalletLists: async () => ({ data: [], totalCount: 0 }) +}; + +const ManageWalletContext = createContext(initialProps); +const API_URL_MASTER_DATA = apiConfig.service_master_data; + +const ManageWalletContextProvider = ({ children }: { children: React.ReactNode }) => { + const [wallets, setWallets] = useState([]); + const [showAddDialog, setShowAddDialog] = useState(false); + const [showEditDialog, setShowEditDialog] = useState(false); + const [showDeleteDialog, setShowDeleteDialog] = useState(false); + const [selectedWallet, setSelectedWallet] = useState(null); + const { GetData } = useCallApi(); + + const handleAddDialog = useCallback((show: boolean) => { + setShowAddDialog(show); + }, []); + + const handleEditDialog = useCallback((show: boolean, selected_wallet: WalletProps | null) => { + setShowEditDialog(show); + setSelectedWallet(show ? selected_wallet : null); + }, []); + + const handleDeleteDialog = useCallback((show: boolean, selected_wallet: WalletProps | null) => { + setShowDeleteDialog(show); + setSelectedWallet(show ? selected_wallet : null); + }, []); + + const columns = useMemo[]>( + () => [ + { + accessorFn: (row) => row.Wallet_name, + id: 'name', + header: ({ column }) => , + enableSorting: true, + enableHiding: false, + meta: { + headerClassName: 'w-[250px]' + } + }, + { + accessorFn: (row) => row.Wallet_description, + id: 'description', + header: ({ column }) => , + enableSorting: true, + enableHiding: false, + meta: { + headerClassName: 'w-[250px]' + } + }, + { + accessorFn: (row) => row.Wallet_status, + id: 'status', + header: ({ column }) => , + enableSorting: true, + enableHiding: false, + cell: ({ row }) => { + const isActive = row.original.Wallet_status === 'Y'; + + return ( + + {isActive ? 'Active' : 'Inactive'} + + ); + }, + meta: { + headerClassName: 'w-[100px]' + } + }, + { + id: 'actions', + header: ({ column }) => , + enableSorting: false, + enableHiding: false, + cell: (data) => { + const row = data.row.original; + return ( + <> + + + + ); + }, + meta: { + headerClassName: 'w-[100px]', + cellClassName: 'text-center' + } + } + ], + [] + ); + + const getWalletLists = async (page: number, limit: number, sorting: any, filter: any) => { + try { + sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting; + filter = filter.length == 0 ? {} : { any: filter[0].value?.toLowerCase() }; + const response = await GetData(`${API_URL_MASTER_DATA}/wallet/list`, { + limit, + page: page + 1, + with_deleted: false, + order_field: sorting[0].id, + order_direction: sorting[0].desc == false ? 'ASC' : 'DESC', + filter: JSON.stringify(filter) + }); + console.log(response?.data); + setWallets(response?.data.list); + return { data: response?.data.list, totalCount: response?.data.total_count }; + } catch (error) { + console.error('Error fetching Wallet', error); + } + }; + + return ( + + + } + layout={{ card: true }} + sorting={[{ id: 'id', desc: false }]} + serverSide={true} + onFetchData={({ pageIndex, pageSize, sorting, columnFilters }) => + getWalletLists(pageIndex, pageSize, sorting, columnFilters) + } + > + {children} + + + ); +}; + +export { ManageWalletContext, ManageWalletContextProvider }; +export type { WalletProps }; diff --git a/src/pages/master/wallet/hooks/useManageWalletContext.tsx b/src/pages/master/wallet/hooks/useManageWalletContext.tsx new file mode 100644 index 0000000..e6bcaec --- /dev/null +++ b/src/pages/master/wallet/hooks/useManageWalletContext.tsx @@ -0,0 +1,12 @@ +import { useContext } from 'react'; +import { ManageWalletContext } from './ManageWalletContext'; + +const useManageWalletContext = () => { + const context = useContext(ManageWalletContext); + if (!context) { + throw new Error('useManageWalletContext must be used within a ManageWalletContextProvider'); + } + return context; +}; + +export { useManageWalletContext }; diff --git a/src/routing/AppRoutingSetup.tsx b/src/routing/AppRoutingSetup.tsx index 3c7fdab..1b0896b 100644 --- a/src/routing/AppRoutingSetup.tsx +++ b/src/routing/AppRoutingSetup.tsx @@ -35,6 +35,7 @@ import ProviderMaster from '@/pages/master/provider/ProviderMaster'; import ConversionMaster from '@/pages/master/conversion/ConversionMaster'; import WalletRuleMaster from '@/pages/master/walletRule/WalletRuleMaster'; import WalletHistory from '@/pages/wallet/wallet-history/WalletHistory'; +import WalletMaster from '@/pages/master/wallet/WalletMaster'; const AppRoutingSetup = (): ReactElement => { return ( @@ -56,6 +57,9 @@ const AppRoutingSetup = (): ReactElement => { element={} /> } /> + + } /> + } /> } /> From 15ac69a620e4af7897ad5912e4cca11b0da8ea2a Mon Sep 17 00:00:00 2001 From: Wikzyy Date: Thu, 27 Mar 2025 20:37:49 +0700 Subject: [PATCH 14/22] feat: add create and delete wallet --- src/pages/master/wallet/WalletMaster.tsx | 2 + src/pages/master/wallet/blocks/AddDialog.tsx | 298 ++++++++++++++++ .../master/wallet/blocks/DeleteDialog.tsx | 78 ++++ src/pages/master/wallet/blocks/EditDialog.tsx | 334 ++++++++++++++++++ .../wallet/hooks/ManageWalletContext.tsx | 12 +- 5 files changed, 718 insertions(+), 6 deletions(-) create mode 100644 src/pages/master/wallet/blocks/AddDialog.tsx create mode 100644 src/pages/master/wallet/blocks/DeleteDialog.tsx create mode 100644 src/pages/master/wallet/blocks/EditDialog.tsx diff --git a/src/pages/master/wallet/WalletMaster.tsx b/src/pages/master/wallet/WalletMaster.tsx index 3190787..d319707 100644 --- a/src/pages/master/wallet/WalletMaster.tsx +++ b/src/pages/master/wallet/WalletMaster.tsx @@ -3,6 +3,7 @@ import { ManageWalletContextProvider } from './hooks/ManageWalletContext'; import { Breadcrumbs, Link } from '@mui/material'; import AddDialog from './blocks/AddDialog'; import EditDialog from './blocks/EditDialog'; +import DeleteDialog from './blocks/DeleteDialog'; const WalletMaster = () => { return ( @@ -27,6 +28,7 @@ const WalletMaster = () => { + ); diff --git a/src/pages/master/wallet/blocks/AddDialog.tsx b/src/pages/master/wallet/blocks/AddDialog.tsx new file mode 100644 index 0000000..b8100ba --- /dev/null +++ b/src/pages/master/wallet/blocks/AddDialog.tsx @@ -0,0 +1,298 @@ +import { useCallApi } from '@/hooks'; +import { useManageWalletContext } from '../hooks/useManageWalletContext'; +import { Alert, useDataGrid } from '@/components'; +import React, { useCallback, useEffect, useState } from 'react'; +import { apiConfig } from '@/config/api.config'; +import { toast } from 'sonner'; +import { + Dialog, + DialogBody, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle +} from '@/components/ui/dialog'; +import { Input } from '@/components/ui/input'; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue +} from '@/components/ui/select'; +import { Button } from '@/components/ui/button'; +import { Checkbox } from '@/components/ui/checkbox'; + +interface CurrencyProps { + ID: string; + code: string; + name: string; + prefix: string; + status: string; +} + +interface GroupProps { + id: string; + name: string; + description: string; + status: string; +} + +const API_URL_WALLET = apiConfig.service_wallet; +const API_URL_MASTER_DATA = apiConfig.service_master_data; + +const AddDialog = () => { + const { showAddDialog, handleAddDialog } = useManageWalletContext(); + const { GetData, PostData } = useCallApi(); + const { reload } = useDataGrid(); + const [alert, setAlert] = useState({ + show: false, + message: '' + }); + const initialState: { + name: string; + description: string; + status: string; + group: string[]; + currency_id: string; + } = { + name: '', + description: '', + status: '', + group: [], + currency_id: '' + }; + const [formField, setFormField] = useState(initialState); + const [currencies, setCurrencies] = useState([]); + const [groups, setGroups] = useState([]); + + const resetForm = () => { + setFormField(initialState); + setAlert({ show: false, message: '' }); + }; + + const handleGroupChange = (groupId: string) => { + setFormField((prevState) => { + const isSelected = prevState.group.includes(groupId); + + if (isSelected) { + // Remove the group if already selected + return { + ...prevState, + group: prevState.group.filter((id) => id !== groupId) + }; + } else { + // Add the group if not selected + return { + ...prevState, + group: [...prevState.group, groupId] + }; + } + }); + }; + + const doCreateWallet = useCallback( + async (e: React.FormEvent) => { + e.preventDefault(); + + const response = await PostData(`${API_URL_MASTER_DATA}/wallet/create`, formField); + + if (response?.status) { + handleAddDialog(false); + toast.success('Success Create Wallet'); + reload(); + } else { + toast.error('Failed Create Wallet'); + setAlert({ show: true, message: 'Failed Create Wallet' }); + } + }, + [formField] + ); + + const handleSubmit = (e: React.FormEvent) => { + e.preventDefault(); + + if ( + formField.name.trim() === '' || + formField.description.trim() === '' || + formField.status.trim() === '' || + formField.group.length === 0 || + formField.currency_id.trim() === '' + ) { + setAlert({ show: true, message: 'Please fill in all required fields.' }); + return; + } + + console.log(formField); + doCreateWallet(e); + setAlert({ show: false, message: '' }); + }; + + const getCurrencyLists = async (sorting: any) => { + try { + const response = await GetData(`${API_URL_WALLET}/dashboard/currency`, { + limit: 100, + page: 1, + with_deleted: false, + order_field: sorting[0].id, + order_direction: sorting[0].desc == false ? 'ASC' : 'DESC' + }); + // console.log('Currency: ', response?.data); + setCurrencies(response?.data.list); + } catch (error) { + console.error('Error fetching currency', error); + } + }; + + const getGroupLists = async (sorting: any) => { + try { + const response = await GetData(`${API_URL_MASTER_DATA}/groups/list`, { + limit: 100, + page: 1, + with_deleted: false, + order_field: sorting[0].id, + order_direction: sorting[0].desc == false ? 'ASC' : 'DESC' + }); + // console.log('Group: ', response?.data); + setGroups(response?.data.list); + } catch (error) { + console.error('Error fetching group', error); + } + }; + + useEffect(() => { + getCurrencyLists([{ id: 'name', desc: false }]); + getGroupLists([{ id: 'name', desc: false }]); + }, []); + + useEffect(() => { + if (showAddDialog === false) { + resetForm(); + } + }, [showAddDialog]); + + return ( + handleAddDialog(open)}> + + + Wallet - Create + + + +
+ {alert.show && ( + +

{alert.message}

+
+ )} + +
+
+
+
+ + setFormField({ ...formField, name: e.target.value })} + placeholder="Wallet Name" + /> +
+
+ +
+
+ + setFormField({ ...formField, description: e.target.value })} + placeholder="Description" + /> +
+
+ +
+
+ + +
+
+ +
+
+ + +
+
+ +
+
+ +
+ {groups.map((group) => ( + + ))} +
+
+
+ +
+ + +
+
+
+
+
+
+
+ ); +}; + +export default AddDialog; diff --git a/src/pages/master/wallet/blocks/DeleteDialog.tsx b/src/pages/master/wallet/blocks/DeleteDialog.tsx new file mode 100644 index 0000000..9166356 --- /dev/null +++ b/src/pages/master/wallet/blocks/DeleteDialog.tsx @@ -0,0 +1,78 @@ +import { useCallApi } from '@/hooks'; +import { useManageWalletContext } from '../hooks/useManageWalletContext'; +import { Alert, useDataGrid } from '@/components'; +import { useCallback, useState } from 'react'; +import { toast } from 'sonner'; +import { apiConfig } from '@/config/api.config'; +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle +} from '@/components/ui/dialog'; +import { Button } from '@/components/ui/button'; + +const API_URL = apiConfig.service_master_data; + +const DeleteDialog = () => { + const { showDeleteDialog, handleDeleteDialog, selectedWallet } = useManageWalletContext(); + const { DeleteData } = useCallApi(); + const { reload } = useDataGrid(); + const [alert, setAlert] = useState({ show: false, message: '' }); + + const doDeleteWallet = useCallback(async () => { + if (!selectedWallet) { + toast.error('No wallet selected'); + return; + } + + const response = await DeleteData( + `${API_URL}/wallet/delete/${selectedWallet.Wallet_id}/false`, + { + id: selectedWallet.Wallet_id + } + ); + + if (response?.status) { + setAlert({ show: false, message: '' }); + handleDeleteDialog(false, null); + toast.success('Success Delete Wallet'); + reload(); + } else { + setAlert({ show: true, message: response?.message }); + toast.error('Failed Delete Wallet'); + } + }, [selectedWallet, handleDeleteDialog, DeleteData, reload]); + + return ( + handleDeleteDialog(open, null)}> + + + + + +

Are you sure?

+ You will delete this data! +
+ {alert.show && ( + +

{alert.message}

+
+ )} +
+ + + + +
+
+ ); +}; + +export default DeleteDialog; diff --git a/src/pages/master/wallet/blocks/EditDialog.tsx b/src/pages/master/wallet/blocks/EditDialog.tsx new file mode 100644 index 0000000..9f8573b --- /dev/null +++ b/src/pages/master/wallet/blocks/EditDialog.tsx @@ -0,0 +1,334 @@ +import { Alert, useDataGrid } from '@/components'; +import { useManageWalletContext } from '../hooks/useManageWalletContext'; +import { useCallApi } from '@/hooks'; +import React, { useCallback, useEffect, useState } from 'react'; +import { apiConfig } from '@/config/api.config'; +import { toast } from 'sonner'; +import { + Dialog, + DialogBody, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle +} from '@/components/ui/dialog'; +import { Input } from '@/components/ui/input'; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue +} from '@/components/ui/select'; +import { Button } from '@/components/ui/button'; + +interface CurrencyProps { + ID: string; + code: string; + name: string; + prefix: string; + status: string; +} + +interface GroupProps { + id: string; + name: string; + description: string; + status: string; +} + +const API_URL_WALLET = apiConfig.service_wallet; +const API_URL_MASTER_DATA = apiConfig.service_master_data; + +const EditDialog = () => { + const { showEditDialog, handleEditDialog, selectedWallet } = useManageWalletContext(); + const { reload } = useDataGrid(); + const { GetData, PutData } = useCallApi(); + const [alert, setAlert] = useState({ + show: false, + message: '' + }); + const initialState: { + name: string; + description: string; + status: string; + group: string[]; + currency_id: string; + } = { + name: '', + description: '', + status: '', + group: [], + currency_id: '' + }; + const [formField, setFormField] = useState(initialState); + const [currencies, setCurrencies] = useState([]); + const [groups, setGroups] = useState([]); + + const resetForm = () => { + setFormField(initialState); + setAlert({ show: false, message: '' }); + }; + + const handleGroupChange = (groupId: string) => { + setFormField((prevState) => { + const isSelected = prevState.group.includes(groupId); + + if (isSelected) { + // Remove the group if already selected + return { + ...prevState, + group: prevState.group.filter((id) => id !== groupId) + }; + } else { + // Add the group if not selected + return { + ...prevState, + group: [...prevState.group, groupId] + }; + } + }); + }; + + const doUpdateWallet = useCallback( + async (e: React.FormEvent) => { + e.preventDefault(); + + const response = await PutData( + `${API_URL_MASTER_DATA}/wallet/update/${selectedWallet?.Wallet_id}`, + formField + ); + + if (response?.status) { + handleEditDialog(false, null); + toast.success('Success Update Wallet'); + reload(); + } else { + toast.error('Failed Update Wallet'); + setAlert({ show: true, message: 'Failed Update Wallet' }); + } + }, + [formField] + ); + + const handleSubmit = (e: React.FormEvent) => { + e.preventDefault(); + + if ( + formField.name.trim() === '' || + formField.description.trim() === '' || + formField.status.trim() === '' || + formField.currency_id.trim() === '' || + formField.group.length === 0 + ) { + setAlert({ show: true, message: 'Please fill in all required fields.' }); + return; + } + + console.log(formField); + doUpdateWallet(e); + setAlert({ show: false, message: '' }); + }; + + const doFetchData = useCallback(async (id: string) => { + const response = await GetData(`${API_URL_MASTER_DATA}/wallet/detail/${id}`, { + id + }); + + console.log(response); + if (response?.status) { + setFormField((prev) => ({ + ...prev, + name: response?.data.name, + description: response?.data.description, + status: response?.data.status, + currency_id: response?.data.currency_id, + groups: Array.isArray(response?.data.groups) + ? response?.data.group.map((group: any) => group.id) + : [] + })); + } + }, []); + + const getCurrencyLists = async (sorting: any) => { + try { + const response = await GetData(`${API_URL_WALLET}/dashboard/currency`, { + limit: 100, + page: 1, + with_deleted: false, + order_field: sorting[0].id, + order_direction: sorting[0].desc == false ? 'ASC' : 'DESC' + }); + // console.log('Currency: ', response?.data); + setCurrencies(response?.data.list); + } catch (error) { + console.error('Error fetching currency', error); + } + }; + + const getGroupLists = async (sorting: any) => { + try { + const response = await GetData(`${API_URL_MASTER_DATA}/groups/list`, { + limit: 100, + page: 1, + with_deleted: false, + order_field: sorting[0].id, + order_direction: sorting[0].desc == false ? 'ASC' : 'DESC' + }); + // console.log('Group: ', response?.data); + setGroups(response?.data.list); + } catch (error) { + console.error('Error fetching group', error); + } + }; + + useEffect(() => { + getCurrencyLists([{ id: 'name', desc: false }]); + getGroupLists([{ id: 'name', desc: false }]); + }, []); + + useEffect(() => { + if (selectedWallet) { + // setFormField((prev) => ({ + // ...prev, + // name: selectedWallet?.Wallet_name, + // description: selectedWallet?.Wallet_description, + // status: selectedWallet?.Wallet_status, + // currency_id: selectedWallet?.Wallet_currency_id, + // group: selectedWallet?.Wallet_group + // })); + doFetchData(selectedWallet?.Wallet_id); + } + }, [selectedWallet]); + + useEffect(() => { + if (showEditDialog === false) { + resetForm(); + } + }, [showEditDialog]); + // console.log(selectedWallet); + return ( + handleEditDialog(open, null)}> + + + Wallet - Update + + + +
+ {alert.show && ( + +

{alert.message}

+
+ )} + +
+
+
+
+ + setFormField({ ...formField, name: e.target.value })} + placeholder="Wallet Name" + /> +
+
+ +
+
+ + setFormField({ ...formField, description: e.target.value })} + placeholder="Description" + /> +
+
+ +
+
+ + +
+
+ +
+
+ + +
+
+ +
+
+ +
+ {groups.map((group) => ( + + ))} +
+
+
+ +
+ + +
+
+
+
+
+
+
+ ); +}; + +export default EditDialog; diff --git a/src/pages/master/wallet/hooks/ManageWalletContext.tsx b/src/pages/master/wallet/hooks/ManageWalletContext.tsx index 7369367..a1ea097 100644 --- a/src/pages/master/wallet/hooks/ManageWalletContext.tsx +++ b/src/pages/master/wallet/hooks/ManageWalletContext.tsx @@ -7,12 +7,12 @@ import { Toaster } from 'sonner'; import ListToolbar from '../blocks/ListToolbar'; interface WalletProps { - id: string; - name: string; - status: string; - description: string; - group: string[]; - currency_id: string; + Wallet_id: string; + Wallet_name: string; + Wallet_status: string; + Wallet_description: string; + Wallet_group: string[]; + Wallet_currency_id: string; } interface ContextProps { From 4bc3d78700a5f5caaa37a178ce666823dff2cd90 Mon Sep 17 00:00:00 2001 From: Wikzyy Date: Thu, 27 Mar 2025 22:17:36 +0700 Subject: [PATCH 15/22] fix group field to read only --- src/pages/master/wallet/blocks/EditDialog.tsx | 46 +++---------------- 1 file changed, 7 insertions(+), 39 deletions(-) diff --git a/src/pages/master/wallet/blocks/EditDialog.tsx b/src/pages/master/wallet/blocks/EditDialog.tsx index 9f8573b..a668172 100644 --- a/src/pages/master/wallet/blocks/EditDialog.tsx +++ b/src/pages/master/wallet/blocks/EditDialog.tsx @@ -52,13 +52,13 @@ const EditDialog = () => { name: string; description: string; status: string; - group: string[]; + group: string; currency_id: string; } = { name: '', description: '', status: '', - group: [], + group: '', currency_id: '' }; const [formField, setFormField] = useState(initialState); @@ -70,26 +70,6 @@ const EditDialog = () => { setAlert({ show: false, message: '' }); }; - const handleGroupChange = (groupId: string) => { - setFormField((prevState) => { - const isSelected = prevState.group.includes(groupId); - - if (isSelected) { - // Remove the group if already selected - return { - ...prevState, - group: prevState.group.filter((id) => id !== groupId) - }; - } else { - // Add the group if not selected - return { - ...prevState, - group: [...prevState.group, groupId] - }; - } - }); - }; - const doUpdateWallet = useCallback( async (e: React.FormEvent) => { e.preventDefault(); @@ -118,7 +98,7 @@ const EditDialog = () => { formField.name.trim() === '' || formField.description.trim() === '' || formField.status.trim() === '' || - formField.currency_id.trim() === '' || + formField.currency_id === '' || formField.group.length === 0 ) { setAlert({ show: true, message: 'Please fill in all required fields.' }); @@ -126,7 +106,7 @@ const EditDialog = () => { } console.log(formField); - doUpdateWallet(e); + // doUpdateWallet(e); setAlert({ show: false, message: '' }); }; @@ -143,8 +123,8 @@ const EditDialog = () => { description: response?.data.description, status: response?.data.status, currency_id: response?.data.currency_id, - groups: Array.isArray(response?.data.groups) - ? response?.data.group.map((group: any) => group.id) + group: Array.isArray(response?.data.group) + ? response?.data.group.map((target: any) => target.name) : [] })); } @@ -300,19 +280,7 @@ const EditDialog = () => { -
- {groups.map((group) => ( - - ))} -
+ From 91a23e078fe93fef9490f9127bce8b3b8f9d6898 Mon Sep 17 00:00:00 2001 From: Wikzyy Date: Thu, 27 Mar 2025 22:19:44 +0700 Subject: [PATCH 16/22] cleaning code --- src/pages/master/wallet/blocks/EditDialog.tsx | 4 ++-- src/pages/master/wallet/hooks/ManageWalletContext.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/master/wallet/blocks/EditDialog.tsx b/src/pages/master/wallet/blocks/EditDialog.tsx index a668172..f599dbe 100644 --- a/src/pages/master/wallet/blocks/EditDialog.tsx +++ b/src/pages/master/wallet/blocks/EditDialog.tsx @@ -106,7 +106,7 @@ const EditDialog = () => { } console.log(formField); - // doUpdateWallet(e); + doUpdateWallet(e); setAlert({ show: false, message: '' }); }; @@ -115,7 +115,7 @@ const EditDialog = () => { id }); - console.log(response); + // console.log(response); if (response?.status) { setFormField((prev) => ({ ...prev, diff --git a/src/pages/master/wallet/hooks/ManageWalletContext.tsx b/src/pages/master/wallet/hooks/ManageWalletContext.tsx index a1ea097..97c5c6e 100644 --- a/src/pages/master/wallet/hooks/ManageWalletContext.tsx +++ b/src/pages/master/wallet/hooks/ManageWalletContext.tsx @@ -160,7 +160,7 @@ const ManageWalletContextProvider = ({ children }: { children: React.ReactNode } order_direction: sorting[0].desc == false ? 'ASC' : 'DESC', filter: JSON.stringify(filter) }); - console.log(response?.data); + // console.log(response?.data); setWallets(response?.data.list); return { data: response?.data.list, totalCount: response?.data.total_count }; } catch (error) { From c382035330445b4c4931f295bf582cc93c77002c Mon Sep 17 00:00:00 2001 From: Wikzyy Date: Thu, 27 Mar 2025 22:34:24 +0700 Subject: [PATCH 17/22] update --- src/pages/master/wallet/blocks/EditDialog.tsx | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/pages/master/wallet/blocks/EditDialog.tsx b/src/pages/master/wallet/blocks/EditDialog.tsx index f599dbe..b4554c7 100644 --- a/src/pages/master/wallet/blocks/EditDialog.tsx +++ b/src/pages/master/wallet/blocks/EditDialog.tsx @@ -207,7 +207,7 @@ const EditDialog = () => {
{
{
{
- +
From e5844a9f2ef62fa07283abbf31c872b285fd2510 Mon Sep 17 00:00:00 2001 From: Raja Oktafrianto Date: Fri, 28 Mar 2025 10:06:57 +0700 Subject: [PATCH 18/22] fix loading page, add delete edit manage menu, search manage user --- src/components/data-grid/DataGridContext.tsx | 1 + src/components/data-grid/DataGridLoader.tsx | 4 +- .../menu/manage-menu/blocks/AddDIalog.tsx | 80 ++++++++-------- .../menu/manage-menu/blocks/DeleteDialog.tsx | 21 ++--- .../menu/manage-menu/blocks/EditDialog.tsx | 91 +++++++++++++------ .../manage-menu/hooks/ManageMenusContext.tsx | 25 ++++- .../manage-user/hooks/ManageUserContext.tsx | 11 +++ 7 files changed, 150 insertions(+), 83 deletions(-) diff --git a/src/components/data-grid/DataGridContext.tsx b/src/components/data-grid/DataGridContext.tsx index 9e95494..4b54947 100644 --- a/src/components/data-grid/DataGridContext.tsx +++ b/src/components/data-grid/DataGridContext.tsx @@ -181,6 +181,7 @@ export const DataGridProvider = (props: TDataGridProps + {loading &&
} {props.children ? props.children : } ); diff --git a/src/components/data-grid/DataGridLoader.tsx b/src/components/data-grid/DataGridLoader.tsx index 03c08ca..77e71fb 100644 --- a/src/components/data-grid/DataGridLoader.tsx +++ b/src/components/data-grid/DataGridLoader.tsx @@ -5,10 +5,10 @@ export const DataGridLoader = () => { const { props } = useDataGrid(); return ( -
+
{ - const parentRef = useRef(null); const { showAddDialog, handleAddDialog, parents } = useManageMenusContext(); const { reload } = useDataGrid(); const { PostData } = useCallApi(); + const [open, setOpen] = useState(false); const [alert, setAlert] = useState({ show: false, message: '' @@ -51,8 +57,11 @@ const AddDialog = () => { return; } + console.log('Data dikirim ke API:', formField); const response = await PostData(`${API_URL}/menus/create`, formField); + console.log('Response from API:', response); + if (response?.status) { handleAddDialog(false); resetForm(); @@ -67,7 +76,10 @@ const AddDialog = () => { }; const resetForm = () => { - setFormField(initialState); + setFormField({ + ...initialState, + status: formField.status // Pertahankan nilai status terpilih + }); setAlert({ show: false, message: '' }); }; @@ -78,7 +90,7 @@ const AddDialog = () => { Menu - Create - +
{alert.show && ( @@ -133,24 +145,21 @@ const AddDialog = () => {
- - setFormField({ ...formField, id_parent: e.target.value })} - inputProps={{ - name: 'id_parent', - id: 'uncontrolled-native', - }} - > - - { - parents ? parents.map((el: any) => ( - - )) : '' - } - - +
@@ -190,21 +199,18 @@ const AddDialog = () => { - - setFormField({ ...formField, status: e.target.value })} - inputProps={{ - name: 'status', - id: 'uncontrolled-native', - }} - > - - - - - +
diff --git a/src/pages/menu/manage-menu/blocks/DeleteDialog.tsx b/src/pages/menu/manage-menu/blocks/DeleteDialog.tsx index 4f4818c..b5250eb 100644 --- a/src/pages/menu/manage-menu/blocks/DeleteDialog.tsx +++ b/src/pages/menu/manage-menu/blocks/DeleteDialog.tsx @@ -4,7 +4,14 @@ import { Alert, useDataGrid } from '@/components'; import { useCallApi } from '@/hooks'; import { ChangeEvent, useCallback, useState } from 'react'; import { toast } from 'sonner'; -import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'; +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle +} from '@/components/ui/dialog'; import { EnforceSwitch } from '@/components/switch'; import { Button } from '@/components/ui/button'; @@ -13,14 +20,13 @@ const DeleteDialog = () => { const { showDeleteDialog, handleDeleteDialog, selectedMenu }: any = useManageMenusContext(); const { reload } = useDataGrid(); const { DeleteData } = useCallApi(); - const [enforce, setEnforce] = useState(false); const [alert, setAlert] = useState({ show: false, message: '' }); const doDeleteMenu = async () => { - const response = await DeleteData(`${API_URL}/menus/delete/${selectedMenu.id}/${enforce}`, { + const response = await DeleteData(`${API_URL}/menus/delete/${selectedMenu.id}/false`, { id: selectedMenu.id }); @@ -44,15 +50,6 @@ const DeleteDialog = () => {

Are you sure?

you will delete this data! -
- - ) => { - setEnforce(e.target.checked); - }} - /> -
{alert.show && ( diff --git a/src/pages/menu/manage-menu/blocks/EditDialog.tsx b/src/pages/menu/manage-menu/blocks/EditDialog.tsx index 78a5ea2..6a40e87 100644 --- a/src/pages/menu/manage-menu/blocks/EditDialog.tsx +++ b/src/pages/menu/manage-menu/blocks/EditDialog.tsx @@ -12,15 +12,25 @@ import { DialogHeader, DialogTitle } from '@/components/ui/dialog'; -import { FormControl,NativeSelect } from "@mui/material"; +import { FormControl, NativeSelect } from '@mui/material'; import { Input } from '@/components/ui/input'; import { Button } from '@/components/ui/button'; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue +} from '@/components/ui/select'; + const API_URL = apiConfig.service_dashboard; const EditDialog = () => { - const { showEditDialog, handleEditDialog, selectedMenu, setSelectedMenu, parents }: any = useManageMenusContext(); + const { showEditDialog, handleEditDialog, selectedMenu, setSelectedMenu, parents }: any = + useManageMenusContext(); const { reload } = useDataGrid(); const { PutData } = useCallApi(); + const [open, setOpen] = useState(false); const [alert, setAlert] = useState({ show: false, message: '' @@ -38,11 +48,12 @@ const EditDialog = () => { const handleUpdate = async (e: React.FormEvent) => { e.preventDefault(); - + if ( selectedMenu.module === '' || selectedMenu.name === '' || selectedMenu.link === '' || + selectedMenu.id_parent === '' || selectedMenu.order_number === 0 || selectedMenu.status === '' ) { @@ -51,8 +62,8 @@ const EditDialog = () => { } const updateMenu = selectedMenu; - if (updateMenu.id_parent === null) updateMenu.id_parent = ""; - delete updateMenu.parentName + if (updateMenu.id_parent === null) updateMenu.id_parent = ''; + delete updateMenu.parentName; const response = await PutData(`${API_URL}/menus/update/${selectedMenu.id}`, selectedMenu); if (response?.status) { handleEditDialog(false, null); @@ -67,7 +78,7 @@ const EditDialog = () => { }; const resetForm = () => { - setSelectedMenu(initialState) + setSelectedMenu(initialState); setAlert({ show: false, message: '' }); }; @@ -78,7 +89,7 @@ const EditDialog = () => { Menu - Update - +
{alert.show && ( @@ -132,24 +143,27 @@ const EditDialog = () => {
- - - setSelectedMenu({ ...selectedMenu, id_parent: e.target.value })} - inputProps={{ - name: 'id_parent', - id: 'uncontrolled-native', - }} - > - { - parents ? parents.map((el: any) => ( - - )) : '' - } - - + +
@@ -165,7 +179,10 @@ const EditDialog = () => { value={selectedMenu.order_number === 0 ? '' : selectedMenu.order_number} onChange={(e) => { const value = parseInt(e.target.value, 10); - setSelectedMenu({ ...selectedMenu, order_number: isNaN(value) ? 0 : value }); + setSelectedMenu({ + ...selectedMenu, + order_number: isNaN(value) ? 0 : value + }); }} />
@@ -184,6 +201,26 @@ const EditDialog = () => {
+
+ + +
+
+ + {/*
-
+
*/}
diff --git a/src/pages/menu/manage-menu/hooks/ManageMenusContext.tsx b/src/pages/menu/manage-menu/hooks/ManageMenusContext.tsx index 2d76541..3ff2f54 100644 --- a/src/pages/menu/manage-menu/hooks/ManageMenusContext.tsx +++ b/src/pages/menu/manage-menu/hooks/ManageMenusContext.tsx @@ -133,12 +133,27 @@ const ManageMenusContextProvider = ({ children }: { children: React.ReactNode }) meta: { headerClassName: 'w-[250px]' } }, { - accessorFn: (row) => row.status, - id: 'status', + accessorKey: 'status', header: ({ column }) => , enableSorting: false, enableHiding: false, - meta: { headerClassName: 'w-[100px]', cellClassName: 'text-center' } + cell: ({ row }) => { + const isActive = row.original.status === 'Y'; + + return ( + + {isActive ? 'Active' : 'Inactive'} + + ); + }, + meta: { + headerClassName: 'w-[100px]', + cellClassName: 'text-center' + } }, { id: 'actions', @@ -211,7 +226,7 @@ const ManageMenusContextProvider = ({ children }: { children: React.ReactNode }) link: child.link, id_parent: child.id_parent, status: child.status, - order_number: child.order_number + order_number: parent.order_number }; }); @@ -242,7 +257,7 @@ const ManageMenusContextProvider = ({ children }: { children: React.ReactNode }) const total_count = transformedData.length; const paginatedData = transformedData.slice(page * limit, (page + 1) * limit); - console.log(response.data); + console.log('data', paginatedData); // setMenus(transformedData); return { data: paginatedData, totalCount: total_count }; } catch (error) { diff --git a/src/pages/settings/user/manage-user/hooks/ManageUserContext.tsx b/src/pages/settings/user/manage-user/hooks/ManageUserContext.tsx index efae604..231cbc6 100644 --- a/src/pages/settings/user/manage-user/hooks/ManageUserContext.tsx +++ b/src/pages/settings/user/manage-user/hooks/ManageUserContext.tsx @@ -8,6 +8,8 @@ import { ListToolBar } from '../blocks'; import { useCallApi } from '@/hooks'; interface ContextProps { + showSearchDialog: boolean; + handleSearchDialog: (show: boolean) => void; showEditDialog: boolean; handleEditDialog: (show: boolean, selected_user: string | null) => void; showAddDialog: boolean; @@ -35,6 +37,8 @@ interface RoleListProps { } const initialProps: ContextProps = { + showSearchDialog: false, + handleSearchDialog: (show: boolean) => {}, showEditDialog: false, handleEditDialog: () => {}, showAddDialog: false, @@ -52,6 +56,7 @@ const API_URL = apiConfig.service_dashboard; const ManageUserContextProvider = ({ children }: { children: React.ReactNode }) => { /* state */ const [showEditDialog, setShowEditDialog] = useState(false); + const [showSearchDialog, setShowSearchDialog] = useState(false); const [showAddDialog, setShowAddDialog] = useState(false); const [showDeleteDialog, setShowDeleteDialog] = useState(false); const [selectedUser, setSelectedUser] = useState(null); @@ -59,6 +64,10 @@ const ManageUserContextProvider = ({ children }: { children: React.ReactNode }) const { GetData } = useCallApi(); /* action */ + const handleSearchDialog = useCallback((show: boolean) => { + setShowSearchDialog(show); + }, []); + const handleEditDialog = useCallback((show: boolean, selected_user: string | null) => { setSelectedUser(show ? selected_user : null); setShowEditDialog(show); @@ -219,6 +228,8 @@ const ManageUserContextProvider = ({ children }: { children: React.ReactNode }) return ( Date: Fri, 28 Mar 2025 11:16:11 +0700 Subject: [PATCH 19/22] fix form update manage wallet - remove validation - add .join to merge value group from response --- src/pages/master/wallet/blocks/EditDialog.tsx | 34 +++++++------------ .../wallet/hooks/ManageWalletContext.tsx | 7 ++-- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/pages/master/wallet/blocks/EditDialog.tsx b/src/pages/master/wallet/blocks/EditDialog.tsx index b4554c7..b2b8695 100644 --- a/src/pages/master/wallet/blocks/EditDialog.tsx +++ b/src/pages/master/wallet/blocks/EditDialog.tsx @@ -52,13 +52,13 @@ const EditDialog = () => { name: string; description: string; status: string; - group: string; + group: string[]; currency_id: string; } = { name: '', description: '', status: '', - group: '', + group: [], currency_id: '' }; const [formField, setFormField] = useState(initialState); @@ -94,17 +94,6 @@ const EditDialog = () => { const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); - if ( - formField.name.trim() === '' || - formField.description.trim() === '' || - formField.status.trim() === '' || - formField.currency_id === '' || - formField.group.length === 0 - ) { - setAlert({ show: true, message: 'Please fill in all required fields.' }); - return; - } - console.log(formField); doUpdateWallet(e); setAlert({ show: false, message: '' }); @@ -115,7 +104,7 @@ const EditDialog = () => { id }); - // console.log(response); + console.log(response); if (response?.status) { setFormField((prev) => ({ ...prev, @@ -124,7 +113,7 @@ const EditDialog = () => { status: response?.data.status, currency_id: response?.data.currency_id, group: Array.isArray(response?.data.group) - ? response?.data.group.map((target: any) => target.name) + ? response?.data.group.map((target: GroupProps) => target.id) : [] })); } @@ -162,6 +151,11 @@ const EditDialog = () => { } }; + const selectedGroupNames = groups + .filter((g) => formField.group.includes(g.id)) + .map((g) => g.name) + .join(', '); + useEffect(() => { getCurrencyLists([{ id: 'name', desc: false }]); getGroupLists([{ id: 'name', desc: false }]); @@ -234,9 +228,7 @@ const EditDialog = () => {
- + setFormField({ ...formField, currency_id: value })} @@ -278,7 +268,7 @@ const EditDialog = () => {
- +
diff --git a/src/pages/master/wallet/hooks/ManageWalletContext.tsx b/src/pages/master/wallet/hooks/ManageWalletContext.tsx index 97c5c6e..d92f73d 100644 --- a/src/pages/master/wallet/hooks/ManageWalletContext.tsx +++ b/src/pages/master/wallet/hooks/ManageWalletContext.tsx @@ -112,7 +112,8 @@ const ManageWalletContextProvider = ({ children }: { children: React.ReactNode } ); }, meta: { - headerClassName: 'w-[100px]' + headerClassName: 'w-[100px] text-center', + cellClassName: 'text-center' } }, { @@ -140,7 +141,7 @@ const ManageWalletContextProvider = ({ children }: { children: React.ReactNode } ); }, meta: { - headerClassName: 'w-[100px]', + headerClassName: 'w-[100px] text-center', cellClassName: 'text-center' } } @@ -185,7 +186,7 @@ const ManageWalletContextProvider = ({ children }: { children: React.ReactNode } } layout={{ card: true }} sorting={[{ id: 'id', desc: false }]} From f4b14f4d636958ad12128d6bf475ed3941747c5a Mon Sep 17 00:00:00 2001 From: bagusajisaputroo Date: Fri, 28 Mar 2025 11:26:34 +0700 Subject: [PATCH 20/22] fixing transasction type and transaction fee --- .../transfer/transferfee/blocks/AddDialog.tsx | 14 ++-- .../transferfee/blocks/DeleteDialog.tsx | 7 +- .../transferfee/blocks/EditDialog.tsx | 77 ++++++++++++------- .../hooks/ManageTransferFeeContext.tsx | 20 ++--- .../transfertype/blocks/DeleteDialog.tsx | 2 +- .../transfertype/blocks/EditDialog.tsx | 2 +- 6 files changed, 71 insertions(+), 51 deletions(-) diff --git a/src/pages/transfer/transferfee/blocks/AddDialog.tsx b/src/pages/transfer/transferfee/blocks/AddDialog.tsx index 65f032e..c7c8d64 100644 --- a/src/pages/transfer/transferfee/blocks/AddDialog.tsx +++ b/src/pages/transfer/transferfee/blocks/AddDialog.tsx @@ -150,9 +150,7 @@ const AddFeeDialog = () => { e.preventDefault(); for (const key in formField) { if ( - formField[key as keyof typeof formField] === '' || - formField[key as keyof typeof formField] === 0 - ) { + formField[key as keyof typeof formField] === '' ) { setAlert({ show: true, message: 'All fields must be filled out' }); return; } @@ -163,7 +161,7 @@ const AddFeeDialog = () => { ...formField }); if (response?.status) { - toast.success('Success Create Transfer Fee'); + // toast.success('Success Create Transfer Fee'); reload(); resetForm(); handleAddFeeDialog(false); @@ -225,7 +223,7 @@ const AddFeeDialog = () => { />
- + { />
- + { />
- + { />
- + { if (response?.status) { setAlert({ show: false, message: '' }); handleDeleteFeeDialog(false, null); - toast.success('Success Delete Product'); + // toast.success('Success Delete Transaction Fee'); reload(); } else { - toast.error('Failed Delete Product'); + // toast.error('Failed Delete Transaction Fee'); setAlert({ show: true, message: response?.message }); } }, [selectedTransferFee]); diff --git a/src/pages/transfer/transferfee/blocks/EditDialog.tsx b/src/pages/transfer/transferfee/blocks/EditDialog.tsx index 6d82790..5bcedcd 100644 --- a/src/pages/transfer/transferfee/blocks/EditDialog.tsx +++ b/src/pages/transfer/transferfee/blocks/EditDialog.tsx @@ -96,10 +96,11 @@ const EditFeeDialog = () => { async (e: React.FormEvent) => { e.preventDefault(); const response = await PutData(`${API_URL}/transactionfees/update/${selectedTransferFee}`, { - ...formField, }); + ...formField + }); if (response?.status) { handleEditFeeDialog(false, null); - toast.success('Success Update User'); + // toast.success('Success Update Transaction Fee'); reload(); } else { setAlert((prev) => ({ ...prev, show: true, message: response?.message })); @@ -252,7 +253,9 @@ const EditFeeDialog = () => {
- + { />
- + { />
- + { />
- + { />
- + { />
- + { />
- + { />
- + { />
- +
- +
- +
- - -
+ + +
{/*
diff --git a/src/pages/transfer/transferfee/hooks/ManageTransferFeeContext.tsx b/src/pages/transfer/transferfee/hooks/ManageTransferFeeContext.tsx index 8703234..2510b2d 100644 --- a/src/pages/transfer/transferfee/hooks/ManageTransferFeeContext.tsx +++ b/src/pages/transfer/transferfee/hooks/ManageTransferFeeContext.tsx @@ -10,10 +10,10 @@ import { EditFeeDialog } from '../blocks/EditDialog'; interface ContextProps { showEditFeeDialog: boolean; - handleEditFeeDialog: (show: boolean, selectedTransferFee: string | null) => void; + handleEditFeeDialog: (show: boolean, selected_TransferFee: string | null) => void; showAddFeeDialog: boolean; handleAddFeeDialog: (show: boolean) => void; - handleDeleteFeeDialog: (show: boolean, selectedTransferFee: string | null) => void; + handleDeleteFeeDialog: (show: boolean, selected_TransferFee: string | null) => void; showDeleteFeeDialog: boolean; selectedTransferFee: string | null; } @@ -39,8 +39,8 @@ const ManageTransferFeeContextProvider = ({ children }: { children: React.ReactN const [selectedTransferFee, setSelectedTransferFee] = useState(null); const { GetData } = useCallApi(); - const handleEditFeeDialog = useCallback((show: boolean, selectedTransferFee: string | null) => { - setSelectedTransferFee(show ? selectedTransferFee : null); + const handleEditFeeDialog = useCallback((show: boolean, selected_TransferFee: string | null) => { + setSelectedTransferFee(show ? selected_TransferFee : null); setShowEditFeeDialog(show); }, []); @@ -48,8 +48,8 @@ const ManageTransferFeeContextProvider = ({ children }: { children: React.ReactN setShowAddFeeDialog(show); }, []); - const handleDeleteFeeDialog = useCallback((show: boolean, selectedTransferFee: string | null) => { - setSelectedTransferFee(show ? selectedTransferFee : null); + const handleDeleteFeeDialog = useCallback((show: boolean, selected_TransferFee: string | null) => { + setSelectedTransferFee(show ? selected_TransferFee : null); setShowDeleteFeeDialog(show); }, []); const doGetTransferFeeListData = async ( @@ -62,7 +62,7 @@ const ManageTransferFeeContextProvider = ({ children }: { children: React.ReactN filter = filter.length == 0 ? {} : { any: filter[0].value.toLowerCase() }; const response = await GetData(`${API_URL}/transactionfees/list`, { limit: limit, - page: 1, + page: page+1, with_deleted: false, order_field: sorting[0].id, order_direction: sorting[0].desc ? 'ASC' : 'DESC', @@ -203,9 +203,9 @@ const ManageTransferFeeContextProvider = ({ children }: { children: React.ReactN return (
-
-

Manage Transaction Fee

-
+
+

Manage Transaction Fee

+
{ setAlert({ show: false, message: '' }); handleDeleteDialog(false, null); reload(); - setTimeout(() => toast.success('Success Delete Product'), 0); + setTimeout(() => toast.success('Success Delete Transaction Type'), 0); } else { setAlert({ show: true, message: response?.message }); setTimeout(() => toast.error('Failed Delete Product'), 0); diff --git a/src/pages/transfer/transfertype/blocks/EditDialog.tsx b/src/pages/transfer/transfertype/blocks/EditDialog.tsx index a94a4de..23236f5 100644 --- a/src/pages/transfer/transfertype/blocks/EditDialog.tsx +++ b/src/pages/transfer/transfertype/blocks/EditDialog.tsx @@ -124,7 +124,7 @@ const EditDialog = () => { }); if (response?.status) { handleEditDialog(false, null); - toast.success('Success Update User'); + toast.success('Success Update Transfer Type'); reload(); } else { setAlert((prev) => ({ ...prev, show: true, message: response?.message })); From 2dfe69f1f60b04e9ee99c319eca351c2a4449c06 Mon Sep 17 00:00:00 2001 From: bagusajisaputroo Date: Fri, 28 Mar 2025 14:33:11 +0700 Subject: [PATCH 21/22] add, edit, delete, visualize conversion on masterdata --- .../master/conversion/ConversionMaster.tsx | 10 + .../master/conversion/blocks/AddDialog.tsx | 287 +++++++++++++++++ .../master/conversion/blocks/DeleteDialog.tsx | 79 +++++ .../master/conversion/blocks/EditDialog.tsx | 299 ++++++++++++++++++ .../master/conversion/blocks/ListToolbar.tsx | 4 +- .../hooks/ManageConversionContext.tsx | 217 ++++++++----- 6 files changed, 808 insertions(+), 88 deletions(-) create mode 100644 src/pages/master/conversion/blocks/DeleteDialog.tsx create mode 100644 src/pages/master/conversion/blocks/EditDialog.tsx diff --git a/src/pages/master/conversion/ConversionMaster.tsx b/src/pages/master/conversion/ConversionMaster.tsx index 7e8725c..b33db82 100644 --- a/src/pages/master/conversion/ConversionMaster.tsx +++ b/src/pages/master/conversion/ConversionMaster.tsx @@ -1,6 +1,12 @@ import { Container, DataGridInner } from '@/components'; import { ManageConversionContextProvider } from './hooks/ManageConversionContext'; import { Breadcrumbs, Link } from '@mui/material'; +import AddDialog from './blocks/AddDialog'; +import EditDialog from './blocks/EditDialog'; +import { Delete } from 'lucide-react'; +import DeleteDialog from './blocks/DeleteDialog'; + +// import EditDialog from './blocks/EditDialog'; const ConversionMaster = () => { return ( @@ -24,6 +30,10 @@ const ConversionMaster = () => {
+ + + + ); diff --git a/src/pages/master/conversion/blocks/AddDialog.tsx b/src/pages/master/conversion/blocks/AddDialog.tsx index e69de29..b9f0e60 100644 --- a/src/pages/master/conversion/blocks/AddDialog.tsx +++ b/src/pages/master/conversion/blocks/AddDialog.tsx @@ -0,0 +1,287 @@ +import { apiConfig } from '@/config/api.config'; +import { Alert, useDataGrid } from '@/components'; +import { useCallApi } from '@/hooks'; +import { getAuth } from '@/auth'; +import React, { useCallback, useEffect, useRef, useState } from 'react'; +import { toast } from 'sonner'; +import { + Dialog, + DialogBody, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle +} from '@/components/ui/dialog'; +import { Input } from '@/components/ui/input'; +import { Button } from '@/components/ui/button'; +import { NumericFormat } from 'react-number-format'; +import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'; +import { + Command, + CommandEmpty, + CommandGroup, + CommandInput, + CommandItem, + CommandList +} from '@/components/ui/command'; +import { set } from 'date-fns'; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue +} from '@/components/ui/select'; +import { useManageConversionContext } from '../hooks/useManageConversionContext'; +interface CurrencyProps { + ID: string; + name: string; +} + +const API_URL = apiConfig.service_wallet; + +const AddDialog = () => { + const parentRef = useRef(null); + const { showAddDialog, handleAddDialog, selectedConversion } = useManageConversionContext(); + const { reload } = useDataGrid(); + const { PostData, GetData } = useCallApi(); + const parsedUser = getAuth()?.user; + const [currencies, setCurrencies] = useState([]); + const [open, setOpen] = useState(false); + const [alert, setAlert] = useState({ + show: false, + message: '' + }); + const initialState = { + status: '', + id_currency_origin: '', + id_currency_destination: '', + buy: 0, + sell: 0, + created_by: '', + created_at: '' + }; + const [formField, setFormField] = useState(initialState); + const created_time = new Date(); + const formattedTime = created_time.toISOString().slice(0, 19).replace('T', ' '); + + const resetForm = () => { + setFormField(initialState); + setAlert({ show: false, message: '' }); + }; + + const doCreateConversion = useCallback( + async (e: React.FormEvent) => { + e.preventDefault(); + + const response = await PostData(`${API_URL}/dashboard/conversion`, formField); + + if (response?.status) { + resetForm(); + handleAddDialog(false); + toast.success('Success Create Conversion'); + reload(); + } else { + toast.error('Error Create Conversion'); + setAlert({ show: true, message: 'Failed to create Conversion. Please try again.' }); + } + }, + [formField] + ); + + const doFetchCurrency = async (sorting: any) => { + try { + sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting; + const response = await GetData(`${API_URL}/dashboard/currency/`, { + limit: 1000, + page: 1, + with_deleted: false, + order_field: sorting[0].id, + order_direction: sorting[0].desc == false ? 'ASC' : 'DESC' + }); + + setCurrencies(response?.data.list); + } catch (error) { + console.error('Error fetching currency', error); + } + }; + + const handleSubmit = (e: React.FormEvent) => { + e.preventDefault(); + + if ( + formField.id_currency_origin === '' || + formField.id_currency_destination === '' || + formField.buy === 0 || + formField.sell === 0 || + formField.status === '' + ) { + setAlert({ show: true, message: 'Please fill in all required fields.' }); + return; + } + + doCreateConversion(e); + console.log(formField); + setAlert({ show: false, message: '' }); + }; + + useEffect(() => { + if (showAddDialog) { + setFormField({ + ...formField, + created_by: parsedUser.username, + created_at: formattedTime + }); + } + }, [formattedTime]); + + useEffect(() => { + doFetchCurrency([{ id: 'name', desc: false }]); + }, []); + + useEffect(() => { + if (showAddDialog === false) { + resetForm(); + } + }, [showAddDialog]); + + return ( + handleAddDialog(open)}> + + + Conversion - Create + + + +
+ {alert.show && ( + +

{alert.message}

+
+ )} + +
+
+
+ + +
+
+ + +
+
+ + { + setFormField((prev) => ({ + ...prev, + buy: values.floatValue || 0 + })); + }} + placeholder="Enter Buy" + /> +
+
+ + { + setFormField((prev) => ({ + ...prev, + sell: values.floatValue || 0 + })); + }} + placeholder="Enter Sell" + /> +
+
+ + +
+ +
+ +
+
+ + +
+
+
+
+
+
+
+ ); +}; + +export default AddDialog; diff --git a/src/pages/master/conversion/blocks/DeleteDialog.tsx b/src/pages/master/conversion/blocks/DeleteDialog.tsx new file mode 100644 index 0000000..1c84e02 --- /dev/null +++ b/src/pages/master/conversion/blocks/DeleteDialog.tsx @@ -0,0 +1,79 @@ +import { Alert, useDataGrid } from '@/components'; +import { useManageConversionContext } from '../hooks/useManageConversionContext'; +import { useCallback, useState } from 'react'; +import { apiConfig } from '@/config/api.config'; +import { useCallApi } from '@/hooks'; +import { toast } from 'sonner'; +import { + Dialog, + DialogContent, + DialogFooter, + DialogHeader, + DialogTitle +} from '@/components/ui/dialog'; +import { Button } from '@/components/ui/button'; +import { DialogDescription } from '@radix-ui/react-dialog'; + +const API_URL = apiConfig.service_wallet; + +const DeleteDialog = () => { + const { showDeleteDialog, handleDeleteDialog, selectedConversion } = useManageConversionContext(); + const { reload } = useDataGrid(); + const { DeleteData } = useCallApi(); + const [alert, setAlert] = useState({ + show: false, + message: '' + }); + + const doDeleteConversion = useCallback(async () => { + if (!selectedConversion) { + toast.error('No Conversion selected'); + return; + } + console.log(selectedConversion); + const response = await DeleteData( + `${API_URL}/dashboard/conversion/${selectedConversion}`, + { id: selectedConversion } + ); + + if (response?.status) { + setAlert({ show: false, message: '' }); + handleDeleteDialog(false, null); + toast.success('Success Delete Conversion'); + reload(); + } else { + setAlert({ show: true, message: response?.message }); + toast.error('Failed Delete Conversion'); + } + }, [selectedConversion, DeleteData, handleDeleteDialog, reload]); + console.log(selectedConversion); + return ( + handleDeleteDialog(open, null)}> + + + + + +

Are you sure?

+ You will delete this data! +
+ {alert.show && ( + +

{alert.message}

+
+ )} +
+ + + + +
+
+ ); +}; + +export default DeleteDialog; diff --git a/src/pages/master/conversion/blocks/EditDialog.tsx b/src/pages/master/conversion/blocks/EditDialog.tsx new file mode 100644 index 0000000..05f4d68 --- /dev/null +++ b/src/pages/master/conversion/blocks/EditDialog.tsx @@ -0,0 +1,299 @@ +import { apiConfig } from '@/config/api.config'; +import { Alert, useDataGrid } from '@/components'; +import { useCallApi } from '@/hooks'; +import { getAuth } from '@/auth'; +import React, { useCallback, useEffect, useRef, useState } from 'react'; +import { toast } from 'sonner'; +import { + Dialog, + DialogBody, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle +} from '@/components/ui/dialog'; +import { Input } from '@/components/ui/input'; +import { Button } from '@/components/ui/button'; +import { NumericFormat } from 'react-number-format'; +import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'; +import { + Command, + CommandEmpty, + CommandGroup, + CommandInput, + CommandItem, + CommandList +} from '@/components/ui/command'; +import { set } from 'date-fns'; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue +} from '@/components/ui/select'; +import { useManageConversionContext } from '../hooks/useManageConversionContext'; +interface CurrencyProps { + ID: string; + name: string; +} + +const API_URL = apiConfig.service_wallet; + +const EditDialog = () => { + const parentRef = useRef(null); + const { showEditDialog, handleEditDialog, selectedConversion } = useManageConversionContext(); + const { reload } = useDataGrid(); + const { PostData, GetData, PutData } = useCallApi(); + const parsedUser = getAuth()?.user; + const [currencies, setCurrencies] = useState([]); + const [open, setOpen] = useState(false); + const [alert, setAlert] = useState({ + show: false, + message: '' + }); + const initialState = { + status: '', + id_currency_origin: '', + id_currency_destination: '', + buy: 0, + sell: 0, + created_by: '', + created_at: '' + }; + const [formField, setFormField] = useState(initialState); + const updated_time = new Date(); + const formattedTime = updated_time.toISOString().slice(0, 19).replace('T', ' '); + + const resetForm = () => { + setFormField(initialState); + setAlert({ show: false, message: '' }); + }; + + const doUpdateConversion = useCallback( + async (e: React.FormEvent) => { + e.preventDefault(); + if(!showEditDialog) return; + const response = await PutData(`${API_URL}/dashboard/conversion/${selectedConversion}`,{ + ...formField + }); + + if (response?.status) { + resetForm(); + handleEditDialog(false, null); + toast.success('Success Update Conversion'); + reload(); + } else { + toast.error('Error Create Conversion'); + setAlert({ show: true, message: 'Failed to Update Conversion. Please try again.' }); + } + }, + [formField] + ); + + const doGetCurrency = async (sorting: any) => { + if (!showEditDialog)return; + try { + sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting; + const response = await GetData(`${API_URL}/dashboard/currency/`, { + limit: 1000, + page: 1, + with_deleted: false, + order_field: sorting[0].id, + order_direction: sorting[0].desc == false ? 'ASC' : 'DESC' + }); + + setCurrencies(response?.data.list); + } catch (error) { + console.error('Error fetching currency', error); + } + }; + + const doGetConversionById = useCallback(async (id: string) => { + const response = await GetData(`${API_URL}/dashboard/conversion/${id}`, { id }); + console.log('Transaction Type: ', response?.data); + if (response?.status) { + setFormField((prev) => ({ + ...prev, + status: response.data.status, + id_currency_origin: response.data.id_currency_origin, + id_currency_destination: response.data.id_currency_destination, + buy: response.data.buy, + sell: response.data.sell, + })); + } + // console.log('form fieldd Transaction Type: ', formField); + }, []); + + useEffect(() => { + if (selectedConversion) { + doGetConversionById(selectedConversion); + } + }, [selectedConversion]); + + + + + useEffect(() => { + if (showEditDialog) { + setFormField({ + ...formField, + created_by: parsedUser.username, + created_at: formattedTime + }); + } + }, [formattedTime]); + + useEffect(() => { + if (showEditDialog) { + doGetCurrency([{ id: 'name', desc: false }]); + } + }, [showEditDialog]); + + + useEffect(() => { + if (showEditDialog === false) { + resetForm(); + } + }, [showEditDialog]); + + return ( + handleEditDialog(open,null)}> + + + Conversion - Update + + + +
+ {alert.show && ( + +

{alert.message}

+
+ )} + +
+
+
+ + +
+
+ + +
+
+ + { + setFormField((prev) => ({ + ...prev, + buy: values.floatValue || 0 + })); + }} + placeholder="Enter Buy" + /> +
+
+ + { + setFormField((prev) => ({ + ...prev, + sell: values.floatValue || 0 + })); + }} + placeholder="Enter Sell" + /> +
+
+ + +
+ +
+ +
+
+ + +
+
+
+
+
+
+
+ ); +}; + +export default EditDialog; diff --git a/src/pages/master/conversion/blocks/ListToolbar.tsx b/src/pages/master/conversion/blocks/ListToolbar.tsx index 1cacece..f356e29 100644 --- a/src/pages/master/conversion/blocks/ListToolbar.tsx +++ b/src/pages/master/conversion/blocks/ListToolbar.tsx @@ -11,7 +11,7 @@ const ListToolbar = () => {
- */} {/* ); }, - meta: { - headerClassName: 'w-[100px]', - cellClassName: 'text-center' - } + meta: { headerClassName: 'w-[100px]', cellClassName: 'text-center' } } ], - [] + [handleEditDialog, handleDeleteDialog] ); - - const getConversionLists = async (page: number, limit: number, sorting: any, filter: any) => { - try { - sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting; - filter = filter.length == 0 ? {} : { any: filter[0].value?.toLowerCase() }; - const response = await GetData(`${API_URL_WALLET}/dashboard/conversion`, { - limit, - page: page + 1, - with_deleted: false, - order_field: sorting[0].id, - order_direction: sorting[0].desc == false ? 'ASC' : 'DESC', - filter: JSON.stringify(filter) - }); - console.log(response?.data); - setConversions(response?.data.list); - return { data: response?.data.list, totalCount: response?.data.total_count }; - } catch (error) { - console.error('Error fetching Conversion', error); - } + const doGetConversion = async ( + page: number, + limit: number, + sorting: any, + filter: any + ) => { + sorting = sorting.length == 0 ? [{ id: 'name', desc: true }] : sorting; + filter = filter.length == 0 ? {} : { any: filter[0].value?.toLowerCase() }; + console.log(sorting); + const response = await GetData(`${API_URL}/dashboard/conversion/`, { + limit: limit, + page: page + 1, + with_deleted: false, + order_field: sorting[0].id, + order_direction: sorting[0].desc ? 'ASC' : 'DESC', + filter: JSON.stringify(filter) + }); + console.log(response?.data); + return { data: response?.data.list, totalCount: response?.data.total_count }; }; return ( - - - } - layout={{ card: true }} - sorting={[{ id: 'id', desc: false }]} - serverSide={true} - onFetchData={({ pageIndex, pageSize, sorting, columnFilters }) => - getConversionLists(pageIndex, pageSize, sorting, columnFilters) - } +
+ - {children} - - + + +
+ } + sorting={[{ id: 'ID', desc: true }]} + serverSide={true} + onFetchData={({ pageIndex, pageSize, sorting, columnFilters }) => + doGetConversion(pageIndex, pageSize, sorting, columnFilters) + } + > + {children} + +
+ +
); }; export { ManageConversionContext, ManageConversionContextProvider }; -export type { ConversionProps }; +export type { Conversion }; From cc95b3efa7d534b6ec10aabe3926c40d38293628 Mon Sep 17 00:00:00 2001 From: Wikzyy Date: Fri, 28 Mar 2025 20:59:12 +0700 Subject: [PATCH 22/22] fix edit form on fetch data --- src/pages/master/wallet/blocks/EditDialog.tsx | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/src/pages/master/wallet/blocks/EditDialog.tsx b/src/pages/master/wallet/blocks/EditDialog.tsx index b2b8695..c5faae1 100644 --- a/src/pages/master/wallet/blocks/EditDialog.tsx +++ b/src/pages/master/wallet/blocks/EditDialog.tsx @@ -111,7 +111,7 @@ const EditDialog = () => { name: response?.data.name, description: response?.data.description, status: response?.data.status, - currency_id: response?.data.currency_id, + currency_id: response?.data.id_currency, group: Array.isArray(response?.data.group) ? response?.data.group.map((target: GroupProps) => target.id) : [] @@ -156,6 +156,8 @@ const EditDialog = () => { .map((g) => g.name) .join(', '); + const selectedCurrency = currencies.find((currency) => currency.ID === formField.currency_id); + useEffect(() => { getCurrencyLists([{ id: 'name', desc: false }]); getGroupLists([{ id: 'name', desc: false }]); @@ -247,28 +249,14 @@ const EditDialog = () => {
- +
- +