diff --git a/src/components/data-grid/DataGridContext.tsx b/src/components/data-grid/DataGridContext.tsx index 4b54947..000d41c 100644 --- a/src/components/data-grid/DataGridContext.tsx +++ b/src/components/data-grid/DataGridContext.tsx @@ -152,7 +152,7 @@ export const DataGridProvider = (props: TDataGridProps !loading && setSorting(newSorting), onColumnFiltersChange: (newFilters) => { - console.log('New Filters:', newFilters); // Debugging + // console.log('New Filters:', newFilters); // Debugging !loading && setColumnFilters(newFilters); }, onColumnVisibilityChange: setColumnVisibility, diff --git a/src/pages/groups/ManageGroups.tsx b/src/pages/groups/ManageGroups.tsx index 819ad82..08b145f 100644 --- a/src/pages/groups/ManageGroups.tsx +++ b/src/pages/groups/ManageGroups.tsx @@ -22,6 +22,7 @@ import { useState, useEffect } from 'react'; import CloseIcon from '@mui/icons-material/Close'; import Divider from '@mui/material/Divider'; import ConfirmDialog from '@/components/confirm'; +import { toast } from 'sonner'; // import { DialogHeader } from '@/components/ui/dialog'; // import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; const BASE_URL = apiConfig.service_customer; @@ -125,24 +126,29 @@ const ManageGroups = () => { await axios.post(`${BASE_URL}/groups/create`, { name: formData.groupName, status: formData.status, + description: formData.description, created_at: new Date() }); + toast.success(`Success create group`) } else if (dialogType === 'update') { await axios.put(`${BASE_URL}/groups/update/${formData.id}`, { name: formData.groupName, status: formData.status, + description: formData.description, updated_at: new Date() }); + toast.success(`Success update group`) } else if (dialogType === 'delete') { await axios.delete(`${BASE_URL}/groups/delete/${formData.id}/true`); + toast.success(`Success delete group`) } - await fetchGroups(); - closeDialog(); - setDialogOpen(false); - } catch (error) { + } catch (error: any) { console.log(error); - closeDialog(); + toast.error(error.message) + } finally { + await fetchGroups(); setDialogOpen(false); + closeDialog(); } }; @@ -179,7 +185,7 @@ const ManageGroups = () => { columns={columns} createData={createGroup} onUpdate={handleUpdate} - onDelete={handleDelete} + onDelete={null} /> diff --git a/src/pages/master/aldeias/blocks/AddDialog.tsx b/src/pages/master/aldeias/blocks/AddDialog.tsx index f678f33..38e4c1b 100644 --- a/src/pages/master/aldeias/blocks/AddDialog.tsx +++ b/src/pages/master/aldeias/blocks/AddDialog.tsx @@ -24,6 +24,7 @@ import { CommandItem, CommandList } from '@/components/ui/command'; +import { doSaveLogActivity } from '@/actions/GlobalActions'; interface SucosProps { sucos_id: number; @@ -34,7 +35,7 @@ const API_URL = apiConfig.service_master_data; const AddDialog = () => { const parentRef = useRef(null); - const { showAddDialog, handleAddDialog } = useManageAldeiasContext(); + const { showAddDialog, handleAddDialog, selectedAldeias } = useManageAldeiasContext(); const { reload } = useDataGrid(); const { PostData, GetData } = useCallApi(); const parsedUser = getAuth()?.user; @@ -70,6 +71,13 @@ const AddDialog = () => { handleAddDialog(false); toast.success('Success Create Aldeias'); reload(); + const createActivity = { + module: 'Manage Aldeias', + description: `Create Aldeia => ${formField.name}`, + action: 'C' + }; + + doSaveLogActivity(createActivity); } else { toast.error('Error Create Aldeias'); setAlert({ show: true, message: 'Failed to create Aldeias. Please try again.' }); diff --git a/src/pages/master/aldeias/blocks/DeleteDialog.tsx b/src/pages/master/aldeias/blocks/DeleteDialog.tsx index 17c4954..92e570e 100644 --- a/src/pages/master/aldeias/blocks/DeleteDialog.tsx +++ b/src/pages/master/aldeias/blocks/DeleteDialog.tsx @@ -6,6 +6,7 @@ import { useCallback, useState } from 'react'; import { toast } from 'sonner'; import { Dialog, DialogContent, DialogFooter, DialogHeader } from '@/components/ui/dialog'; import { Button } from '@/components/ui/button'; +import { doSaveLogActivity } from '@/actions/GlobalActions'; const API_URL = apiConfig.service_master_data; @@ -33,6 +34,14 @@ const DeleteDialog = () => { handleDeleteDialog(false, null); toast.success('Success Delete Aldeias'); reload(); + + const createActivity = { + module: 'Manage Aldeias', + description: `Delete Aldeia => ${selectedAldeias}`, + action: 'D' + }; + + doSaveLogActivity(createActivity); } else { setAlert({ show: true, message: response?.message }); toast.error('Failed Delete Aldeias'); diff --git a/src/pages/master/aldeias/blocks/EditDialog.tsx b/src/pages/master/aldeias/blocks/EditDialog.tsx index 449197d..79eb0ce 100644 --- a/src/pages/master/aldeias/blocks/EditDialog.tsx +++ b/src/pages/master/aldeias/blocks/EditDialog.tsx @@ -24,6 +24,7 @@ import { CommandItem, CommandList } from '@/components/ui/command'; +import { doSaveLogActivity } from '@/actions/GlobalActions'; interface SucosProps { sucos_id: number; @@ -69,6 +70,13 @@ const EditDialog = () => { handleEditDialog(false, null); toast.success('Success Update Aldeias'); reload(); + const createActivity = { + module: 'Manage Aldeias', + description: `Edit Aldeia => ${selectedAldeias}`, + action: 'U' + }; + + doSaveLogActivity(createActivity); } else { toast.error('Error Update Aldeias'); setAlert({ show: true, message: 'Error Update Aldeias' }); diff --git a/src/pages/master/conversion/blocks/AddDialog.tsx b/src/pages/master/conversion/blocks/AddDialog.tsx index 5cca7f8..96270b1 100644 --- a/src/pages/master/conversion/blocks/AddDialog.tsx +++ b/src/pages/master/conversion/blocks/AddDialog.tsx @@ -33,6 +33,7 @@ import { SelectValue } from '@/components/ui/select'; import { useManageConversionContext } from '../hooks/useManageConversionContext'; +import { doSaveLogActivity } from '@/actions/GlobalActions'; interface CurrencyProps { ID: string; name: string; @@ -80,6 +81,13 @@ const AddDialog = () => { resetForm(); handleAddDialog(false); toast.success('Success Create Conversion'); + const createActivity = { + module: 'Manage Conversion', + description: `Create Conversion => ${formField.id_currency_origin} => ${formField.id_currency_destination}`, + action: 'C' + }; + + doSaveLogActivity(createActivity); reload(); } else { toast.error('Error Create Conversion'); @@ -246,28 +254,27 @@ const AddDialog = () => { />
- - -
- -
+ +
+ +
@@ -189,9 +196,7 @@ const AddDialog = () => { className="input" type="text" value={formField.type} - onChange={(e) => - setFormField({ ...formField, type: e.target.value }) - } + onChange={(e) => setFormField({ ...formField, type: e.target.value })} /> @@ -205,9 +210,7 @@ const AddDialog = () => { className="input" type="text" value={formField.code} - onChange={(e) => - setFormField({ ...formField, code: e.target.value }) - } + onChange={(e) => setFormField({ ...formField, code: e.target.value })} /> @@ -221,9 +224,7 @@ const AddDialog = () => { className="input" type="text" value={formField.description} - onChange={(e) => - setFormField({ ...formField, description: e.target.value }) - } + onChange={(e) => setFormField({ ...formField, description: e.target.value })} /> @@ -323,9 +324,7 @@ const AddDialog = () => { table.getColumn('name')?.setFilterValue(event.target.value)} + value={(table.getColumn('provider_name')?.getFilterValue() as string) ?? ''} + onChange={(event) => + table.getColumn('provider_name')?.setFilterValue(event.target.value) + } /> {/* diff --git a/src/pages/master/provider/hooks/ManageProviderContext.tsx b/src/pages/master/provider/hooks/ManageProviderContext.tsx index 6dc7ea4..7d7bb5f 100644 --- a/src/pages/master/provider/hooks/ManageProviderContext.tsx +++ b/src/pages/master/provider/hooks/ManageProviderContext.tsx @@ -75,7 +75,7 @@ const ManageProviderContextProvider = ({ children }: { children: React.ReactNode () => [ { accessorFn: (row) => row.provider_name, - id: 'name', + id: 'provider_name', header: ({ column }) => , enableSorting: true, enableHiding: false, @@ -162,8 +162,9 @@ const ManageProviderContextProvider = ({ children }: { children: React.ReactNode const getProviderLists = async (page: number, limit: number, sorting: any, filter: any) => { try { + const field = 'Provider.name'; sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting; - filter = filter.length == 0 ? {} : { any: filter[0].value?.toLowerCase() }; + filter = filter.length == 0 ? {} : { [field]: filter[0].value?.toLowerCase() }; const response = await GetData(`${API_URL}/provider/list`, { limit, page: page + 1, @@ -172,7 +173,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/sucos/blocks/AddDialog.tsx b/src/pages/master/sucos/blocks/AddDialog.tsx index 4436fd1..b8213cf 100644 --- a/src/pages/master/sucos/blocks/AddDialog.tsx +++ b/src/pages/master/sucos/blocks/AddDialog.tsx @@ -24,6 +24,7 @@ import { CommandItem, CommandList } from '@/components/ui/command'; +import { doSaveLogActivity } from '@/actions/GlobalActions'; interface PostoAdmsProps { PostoAdms_id: number; @@ -33,7 +34,7 @@ const API_URL = apiConfig.service_master_data; const AddDialog = () => { const parentRef = useRef(null); - const { showAddDialog, handleAddDialog } = useManageSucosContext(); + const { showAddDialog, handleAddDialog, selectedSucos } = useManageSucosContext(); const { reload } = useDataGrid(); const { PostData, GetData } = useCallApi(); const parsedUser = getAuth()?.user; @@ -69,6 +70,13 @@ const AddDialog = () => { handleAddDialog(false); reload(); toast.success('Sucos created successfully!'); + const createActivity = { + module: 'Manage Sucos', + description: `Create Suco => ${formField.name}`, + action: 'C' + }; + + doSaveLogActivity(createActivity); } else { toast.error('Failed to create Sucos Please try again.'); setAlert({ show: true, message: 'Failed to create Sucos Please try again.' }); diff --git a/src/pages/master/sucos/blocks/DeleteDialog.tsx b/src/pages/master/sucos/blocks/DeleteDialog.tsx index 440ee6a..9d50258 100644 --- a/src/pages/master/sucos/blocks/DeleteDialog.tsx +++ b/src/pages/master/sucos/blocks/DeleteDialog.tsx @@ -4,8 +4,16 @@ import { useCallback, useState } from 'react'; import { useCallApi } from '@/hooks'; import { Alert, useDataGrid } from '@/components'; 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 { Button } from '@/components/ui/button'; +import { doSaveLogActivity } from '@/actions/GlobalActions'; const API_URL = apiConfig.service_master_data; @@ -31,6 +39,13 @@ const DeleteDialog = () => { handleDeleteDialog(false, null); toast.success('Success Delete Sucos'); reload(); + const createActivity = { + module: 'Manage Sucos', + description: `Delete Suco => ${selectedSucos}`, + action: 'D' + }; + + doSaveLogActivity(createActivity); } else { setAlert({ show: true, message: response?.message }); toast.error('Failed Delete Sucos'); diff --git a/src/pages/master/sucos/blocks/EditDialog.tsx b/src/pages/master/sucos/blocks/EditDialog.tsx index 1ff451b..136ad9b 100644 --- a/src/pages/master/sucos/blocks/EditDialog.tsx +++ b/src/pages/master/sucos/blocks/EditDialog.tsx @@ -24,6 +24,7 @@ import { CommandItem, CommandList } from '@/components/ui/command'; +import { doSaveLogActivity } from '@/actions/GlobalActions'; interface PostoAdmsProps { PostoAdms_id: number; // Ubah ke PostoAdms_id @@ -76,6 +77,13 @@ const EditDialog = () => { handleEditDialog(false, null); toast.success('Success Update Sucos'); reload(); + const createActivity = { + module: 'Manage Sucos', + description: `Edit Suco => ${selectedSucos}`, + action: 'U' + }; + + doSaveLogActivity(createActivity); } else { toast.error('Failed Update Sucos'); setAlert({ show: true, message: 'Failed Update Sucos. Please try again' }); diff --git a/src/pages/master/sucos/hooks/ManageSucosContext.tsx b/src/pages/master/sucos/hooks/ManageSucosContext.tsx index 81e38a6..6a888b1 100644 --- a/src/pages/master/sucos/hooks/ManageSucosContext.tsx +++ b/src/pages/master/sucos/hooks/ManageSucosContext.tsx @@ -153,7 +153,7 @@ const ManageSucosContextProvider = ({ children }: { children: React.ReactNode }) const response = await GetData(`${API_URL}/sucos/list`, { limit: limit, page: page + 1, - with_deleted: true, + with_deleted: false, order_field: sorting[0].id, order_direction: sorting[0].desc == false ? 'ASC' : 'DESC', filter: JSON.stringify(filter) diff --git a/src/pages/master/wallet/blocks/AddDialog.tsx b/src/pages/master/wallet/blocks/AddDialog.tsx index b8100ba..ce8a07a 100644 --- a/src/pages/master/wallet/blocks/AddDialog.tsx +++ b/src/pages/master/wallet/blocks/AddDialog.tsx @@ -22,6 +22,7 @@ import { } from '@/components/ui/select'; import { Button } from '@/components/ui/button'; import { Checkbox } from '@/components/ui/checkbox'; +import { doSaveLogActivity } from '@/actions/GlobalActions'; interface CurrencyProps { ID: string; @@ -42,7 +43,7 @@ const API_URL_WALLET = apiConfig.service_wallet; const API_URL_MASTER_DATA = apiConfig.service_master_data; const AddDialog = () => { - const { showAddDialog, handleAddDialog } = useManageWalletContext(); + const { showAddDialog, handleAddDialog, selectedWallet } = useManageWalletContext(); const { GetData, PostData } = useCallApi(); const { reload } = useDataGrid(); const [alert, setAlert] = useState({ @@ -101,6 +102,14 @@ const AddDialog = () => { handleAddDialog(false); toast.success('Success Create Wallet'); reload(); + + const createActivity = { + module: 'Manage Wallet', + description: `Create Wallet => ${selectedWallet?.Wallet_id} - ${selectedWallet?.Wallet_name}`, + action: 'C' + }; + + doSaveLogActivity(createActivity); } else { toast.error('Failed Create Wallet'); setAlert({ show: true, message: 'Failed Create Wallet' }); diff --git a/src/pages/master/wallet/blocks/EditDialog.tsx b/src/pages/master/wallet/blocks/EditDialog.tsx index c5faae1..adce821 100644 --- a/src/pages/master/wallet/blocks/EditDialog.tsx +++ b/src/pages/master/wallet/blocks/EditDialog.tsx @@ -21,6 +21,7 @@ import { SelectValue } from '@/components/ui/select'; import { Button } from '@/components/ui/button'; +import { doSaveLogActivity } from '@/actions/GlobalActions'; interface CurrencyProps { ID: string; @@ -53,13 +54,11 @@ const EditDialog = () => { description: string; status: string; group: string[]; - currency_id: string; } = { name: '', description: '', status: '', - group: [], - currency_id: '' + group: [] }; const [formField, setFormField] = useState(initialState); const [currencies, setCurrencies] = useState([]); @@ -71,18 +70,26 @@ const EditDialog = () => { }; const doUpdateWallet = useCallback( - async (e: React.FormEvent) => { - e.preventDefault(); + async (payload: { name: string; description: string; status: string }) => { + // e.preventDefault(); const response = await PutData( `${API_URL_MASTER_DATA}/wallet/update/${selectedWallet?.Wallet_id}`, - formField + payload ); if (response?.status) { handleEditDialog(false, null); toast.success('Success Update Wallet'); reload(); + + const createActivity = { + module: 'Manage Wallet', + description: `Edit Wallet => ${selectedWallet?.Wallet_id} - ${selectedWallet?.Wallet_name}`, + action: 'U' + }; + + doSaveLogActivity(createActivity); } else { toast.error('Failed Update Wallet'); setAlert({ show: true, message: 'Failed Update Wallet' }); @@ -94,8 +101,14 @@ const EditDialog = () => { const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); - console.log(formField); - doUpdateWallet(e); + // const { name, description, status } = formField; + const payload = { + name: formField.name, + description: formField.description, + status: formField.status + }; + // console.log(payload); + doUpdateWallet(payload); setAlert({ show: false, message: '' }); }; @@ -156,8 +169,6 @@ 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 }]); @@ -182,7 +193,7 @@ const EditDialog = () => { resetForm(); } }, [showEditDialog]); - // console.log(selectedWallet); + return ( handleEditDialog(open, null)}> @@ -246,25 +257,25 @@ const EditDialog = () => { -
-
- - -
-
-
- +
+ +
- -
diff --git a/src/pages/master/wallet/blocks/ListToolbar.tsx b/src/pages/master/wallet/blocks/ListToolbar.tsx index 0d2a427..11b5767 100644 --- a/src/pages/master/wallet/blocks/ListToolbar.tsx +++ b/src/pages/master/wallet/blocks/ListToolbar.tsx @@ -15,7 +15,7 @@ const ListToolbar = () => { table.getColumn('name')?.setFilterValue(event.target.value)} /> diff --git a/src/pages/master/wallet/hooks/ManageWalletContext.tsx b/src/pages/master/wallet/hooks/ManageWalletContext.tsx index 78bc048..57ae4f0 100644 --- a/src/pages/master/wallet/hooks/ManageWalletContext.tsx +++ b/src/pages/master/wallet/hooks/ManageWalletContext.tsx @@ -146,7 +146,7 @@ const ManageWalletContextProvider = ({ children }: { children: React.ReactNode } 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() }; + filter = filter.length == 0 ? {} : { name: filter[0].value?.toLowerCase() }; const response = await GetData(`${API_URL_MASTER_DATA}/wallet/list`, { limit, page: page + 1, @@ -183,7 +183,7 @@ const ManageWalletContextProvider = ({ children }: { children: React.ReactNode } pagination={{ size: 25 }} toolbar={} layout={{ card: true }} - sorting={[{ id: 'id', desc: false }]} + sorting={[{ id: 'created_at', desc: true }]} serverSide={true} onFetchData={({ pageIndex, pageSize, sorting, columnFilters }) => getWalletLists(pageIndex, pageSize, sorting, columnFilters) diff --git a/src/pages/master/walletRule/blocks/AddDialog.tsx b/src/pages/master/walletRule/blocks/AddDialog.tsx index f18cd89..6bdd088 100644 --- a/src/pages/master/walletRule/blocks/AddDialog.tsx +++ b/src/pages/master/walletRule/blocks/AddDialog.tsx @@ -31,6 +31,7 @@ import { CommandList } from '@/components/ui/command'; import { NumericFormat } from 'react-number-format'; +import { doSaveLogActivity } from '@/actions/GlobalActions'; interface GroupProps { ID: string; @@ -48,7 +49,7 @@ interface WalletProps { const API_URL_WALLET = apiConfig.service_wallet; const AddDialog = () => { - const { showAddDialog, handleAddDialog } = useManageWalletRuleContext(); + const { showAddDialog, handleAddDialog, selectedWalletRule } = useManageWalletRuleContext(); const { reload } = useDataGrid(); const { PostData, GetData } = useCallApi(); const [open, setOpen] = useState(false); @@ -94,6 +95,14 @@ const AddDialog = () => { handleAddDialog(false); toast.success('Success Create Wallet Rule'); reload(); + + const createActivity = { + module: 'Manage Wallet Rule', + description: `Create Wallet Rule => ${selectedWalletRule?.ID}`, + action: 'C' + }; + + doSaveLogActivity(createActivity); } else { toast.error('Failed Create Wallet Rule'); setAlert({ show: true, message: 'Failed Create Wallet Rule' }); diff --git a/src/pages/master/walletRule/blocks/DeleteDialog.tsx b/src/pages/master/walletRule/blocks/DeleteDialog.tsx index 97f3e0c..518201d 100644 --- a/src/pages/master/walletRule/blocks/DeleteDialog.tsx +++ b/src/pages/master/walletRule/blocks/DeleteDialog.tsx @@ -13,6 +13,7 @@ import { DialogTitle } from '@/components/ui/dialog'; import { Button } from '@/components/ui/button'; +import { doSaveLogActivity } from '@/actions/GlobalActions'; const API_URL_WALLET = apiConfig.service_wallet; @@ -37,6 +38,13 @@ const DeleteDialog = () => { toast.success('Wallet rule deleted successfully'); handleDeleteDialog(false, null); reload(); + const createActivity = { + module: 'Manage Wallet Rule', + description: `Delete Wallet Rule', => ${selectedWalletRule.ID}`, + action: 'D' + }; + + doSaveLogActivity(createActivity); setAlert({ show: false, message: '' }); } else { toast.error('Failed to delete wallet rule'); diff --git a/src/pages/master/walletRule/blocks/EditDialog.tsx b/src/pages/master/walletRule/blocks/EditDialog.tsx index 8529c3f..b555d06 100644 --- a/src/pages/master/walletRule/blocks/EditDialog.tsx +++ b/src/pages/master/walletRule/blocks/EditDialog.tsx @@ -31,6 +31,7 @@ import { import { Input } from '@/components/ui/input'; import { Button } from '@/components/ui/button'; import { NumericFormat } from 'react-number-format'; +import { doSaveLogActivity } from '@/actions/GlobalActions'; interface GroupProps { ID: string; @@ -97,6 +98,14 @@ const EditDialog = () => { handleEditDialog(false, null); toast.success('Success Update Wallet Rule'); reload(); + + const createActivity = { + module: 'Manage Wallet Rule', + description: `Edit Wallet Rule => ${selectedWalletRule?.ID}`, + action: 'U' + }; + + doSaveLogActivity(createActivity); } else { toast.error('Failed Update Wallet Rule'); setAlert({ show: true, message: 'Failed Update Wallet Rule' }); diff --git a/src/pages/members/manage-members/CustomerDetailModal.tsx b/src/pages/members/manage-members/CustomerDetailModal.tsx index a14815c..dc1711a 100644 --- a/src/pages/members/manage-members/CustomerDetailModal.tsx +++ b/src/pages/members/manage-members/CustomerDetailModal.tsx @@ -12,13 +12,18 @@ import { toast } from 'sonner'; const BASE_URL_MASTER_DATA = apiConfig.service_master_data; const BASE_URL_CUSTOMER = apiConfig.service_customer; -const CustomerDialog = ({ open, handleClose, handleSubmit, initialData, viewStats, handleReject, page }: any) => { +const CustomerDialog = ({ open, handleClose, handleSubmit, initialData, viewStats, handleReject, page, fetchCustomers }: any) => { const [formData, setFormData] = useState(initialData || initialMember); const [viewOnly, setViewOnly] = useState(viewStats || false); const [municipios, setMunicipios] = useState([]); const [aldeias, setAldeias] = useState([]); const [postoAdm, setPostoAdm] = useState([]); const [sucos, setSucos] = useState([]); + const [groupData] = useState({ + reguler: `This fill can not be empty!`, + premium: `This field required only for Premium or Agent`, + agent: `This field required only for Agent` + }) useEffect(() => { setFormData(initialData || {}); // Sync formData when initialData changes @@ -154,18 +159,20 @@ const CustomerDialog = ({ open, handleClose, handleSubmit, initialData, viewStat ) : ('') } - - - + + {/* {groupData.reguler} */} + + {fileTextFile("Photo", formData.photouser, "photouser", handleChange)} - - - - - - + + + + + + + Gender - Male Female @@ -181,7 +188,7 @@ const CustomerDialog = ({ open, handleClose, handleSubmit, initialData, viewStat {/* AGENT & PREMIUM DATA */} - + {fileTextFile("File Selfie", formData.file_selfie, "file_selfie", handleChange)} {"file_selfie"} @@ -262,18 +269,22 @@ const CustomerDialog = ({ open, handleClose, handleSubmit, initialData, viewStat - {getAdmAccess(page, formData)} + {/* {getAdmAccess(page, formData, handleClose, fetchCustomers)} */} { page === 'kyc' ? ( <> Approval - ) : ('') + ) : (<>{getAdmAccess(page, formData, handleClose, fetchCustomers, viewOnly, setViewOnly)}) }
- + { + page === 'kyc' ? ( + + ) : ('') + } { formData.isneedapproval == 1 && page === 'kyc' ? ( @@ -327,9 +338,35 @@ function fileTextFile(label: string, value: any, name: string, handleChange: any ) } -function getAdmAccess(page: string, data: any) { +function getAdmAccess(page: string, data: any, handleClose: any, fetchCustomers: any, viewOnly: any, setViewOnly: any) { const [dialogOpen, setDialogOpen] = useState(false); const [dialogType, setDialogType] = useState(''); + const [changeGroup, setChangeGroup] = useState(''); + const [changeGroupD, setChangeGroupD] = useState(false); + const [groups, setGroups] = useState([]); + + useEffect(() => { + fetchGroups() + }, []); + + const fetchGroups = async () =>{ + try { + let getGroups = await axios.get(`${BASE_URL_CUSTOMER}/groups/list`, { + params: { + limit: 50, + page: 1, + with_deleted: false, + order_field: 'name', + order_direction: 'ASC', + } + }); + setGroups(getGroups.data.data.list); + } catch (error: any) { + console.error(error.message); + toast.error(error.message) + } + } + const handleYes = async () => { try { if (dialogType === "update status") { @@ -347,6 +384,7 @@ function getAdmAccess(page: string, data: any) { toast.error(error.message) } finally { setDialogOpen(false) + handleClose() } } @@ -360,6 +398,31 @@ function getAdmAccess(page: string, data: any) { setDialogOpen(true) } + async function buttonChangeGroup() { + try { + let dataObj = { + customerid: data.id, + destination_group: changeGroup + } + if (data.group_id === changeGroup) return toast.warning(`You update same group as the exist customer group`) + if (dataObj.customerid && dataObj.destination_group) { + await axios.post(`${BASE_URL_CUSTOMER}/customer/change-group`, dataObj) + } + await fetchCustomers() + toast.success('Success Change group') + } catch (error: any) { + toast.error(error.message) + } finally { + setChangeGroupD(false) + handleClose() + } + } + + function openChangeGroupDialog() { + setChangeGroup(data.group_id); + setChangeGroupD(true) + } + if (page !== "kyc") { return ( @@ -378,14 +441,40 @@ function getAdmAccess(page: string, data: any) { Change Group - + Edit Member - + {/* */} + + + setChangeGroupD(false)} fullWidth> + + Are you sure to change customer Group? + + Destination Group + + + + + + + + + setDialogOpen(false)} @@ -427,4 +516,8 @@ function getPinStatus(status: string) { btn: 'No status found', res: null } +} + +function showCustomerWallet() { + } \ No newline at end of file diff --git a/src/pages/members/manage-members/ManageMembers.tsx b/src/pages/members/manage-members/ManageMembers.tsx index 1132b87..a258539 100644 --- a/src/pages/members/manage-members/ManageMembers.tsx +++ b/src/pages/members/manage-members/ManageMembers.tsx @@ -24,15 +24,15 @@ const ManageMembers = () => { useEffect(() => { setLoading(true); - fetchGroups(); + fetchCustomers(); setLoading(false); }, []); - async function fetchGroups() { + async function fetchCustomers() { try { let groups = await axios.get(`${BASE_URL}/customer/list`, { params: { - limit: 10, + limit: 20, page: 1, with_deleted: false, order_field: 'fullname', @@ -96,16 +96,16 @@ const ManageMembers = () => { delete updateData.group_updated_at; delete updateData.group_deleted_by; delete updateData.group_deleted_at; + delete updateData.updated_at; try { if (dialogType === 'update') await axios.put(`${BASE_URL}/customer/update/${selectedMember}`, updateData); // if (dialogType === 'create') await axios.post(`${BASE_URL}/customers/create`, member) - await fetchGroups(); + await fetchCustomers(); setDialogOpen(false); setIsDialogOpen(false); toast.success('Success Update Member'); } catch (error: any) { - alert(error.message); setDialogOpen(false); setIsDialogOpen(false); toast.error(error.message); @@ -130,6 +130,7 @@ const ManageMembers = () => { handleClose={closeDialog} handleSubmit={handleSubmit} initialData={member} + fetchCustomers={fetchCustomers} />

Manage Members

diff --git a/src/pages/menu/manage-menu/blocks/AddDIalog.tsx b/src/pages/menu/manage-menu/blocks/AddDIalog.tsx index beb6cc4..d7c2f2f 100644 --- a/src/pages/menu/manage-menu/blocks/AddDIalog.tsx +++ b/src/pages/menu/manage-menu/blocks/AddDIalog.tsx @@ -21,10 +21,11 @@ import { SelectTrigger, SelectValue } from '@/components/ui/select'; +import { doSaveLogActivity } from '@/actions/GlobalActions'; const API_URL = apiConfig.service_dashboard; const AddDialog = () => { - const { showAddDialog, handleAddDialog, parents } = useManageMenusContext(); + const { showAddDialog, handleAddDialog, parents, selectedMenu } = useManageMenusContext(); const { reload } = useDataGrid(); const { PostData } = useCallApi(); const [open, setOpen] = useState(false); @@ -57,21 +58,28 @@ const AddDialog = () => { return; } - console.log('Data dikirim ke API:', formField); + // console.log('Data dikirim ke API:', formField); const response = await PostData(`${API_URL}/menus/create`, formField); - console.log('Response from API:', response); + // console.log('Response from API:', response); if (response?.status) { handleAddDialog(false); resetForm(); toast.success('Success Create Menu'); + const createActivity = { + module: 'Manage Menu', + description: `Create Menu => ${selectedMenu}`, + action: 'C' + }; + + doSaveLogActivity(createActivity); reload(); } else { toast.error('Failed Create Menu'); setAlert({ show: true, message: 'Failed Create Menu' }); } - console.log(formField); + // console.log(formField); setAlert({ show: false, message: '' }); }; diff --git a/src/pages/menu/manage-menu/blocks/DeleteDialog.tsx b/src/pages/menu/manage-menu/blocks/DeleteDialog.tsx index b5250eb..a1ddb07 100644 --- a/src/pages/menu/manage-menu/blocks/DeleteDialog.tsx +++ b/src/pages/menu/manage-menu/blocks/DeleteDialog.tsx @@ -14,6 +14,7 @@ import { } from '@/components/ui/dialog'; import { EnforceSwitch } from '@/components/switch'; import { Button } from '@/components/ui/button'; +import { doSaveLogActivity } from '@/actions/GlobalActions'; const API_URL = apiConfig.service_dashboard; const DeleteDialog = () => { @@ -34,6 +35,13 @@ const DeleteDialog = () => { setAlert((prev) => ({ ...prev, show: false, message: '' })); handleDeleteDialog(false, null); toast.success('Success Delete Menu'); + const createActivity = { + module: 'Manage Menu', + description: `DeleteMenu => ${selectedMenu}`, + action: 'D' + }; + + doSaveLogActivity(createActivity); reload(); } else { toast.error('Failed Delete Menu'); diff --git a/src/pages/menu/manage-menu/blocks/EditDialog.tsx b/src/pages/menu/manage-menu/blocks/EditDialog.tsx index 6a40e87..e55c6bc 100644 --- a/src/pages/menu/manage-menu/blocks/EditDialog.tsx +++ b/src/pages/menu/manage-menu/blocks/EditDialog.tsx @@ -22,6 +22,7 @@ import { SelectTrigger, SelectValue } from '@/components/ui/select'; +import { doSaveLogActivity } from '@/actions/GlobalActions'; const API_URL = apiConfig.service_dashboard; @@ -69,6 +70,13 @@ const EditDialog = () => { handleEditDialog(false, null); resetForm(); toast.success('Success Update Menu'); + const createActivity = { + module: 'Manage Menu', + description: `Update Menu => ${selectedMenu.name}`, + action: 'U' + }; + + doSaveLogActivity(createActivity); reload(); } else { toast.error('Failed Update Menu'); diff --git a/src/pages/transaction/approval-transaction/ApprovalTransaction.tsx b/src/pages/transaction/approval-transaction/ApprovalTransaction.tsx new file mode 100644 index 0000000..e6aa68b --- /dev/null +++ b/src/pages/transaction/approval-transaction/ApprovalTransaction.tsx @@ -0,0 +1,31 @@ +import { Container, DataGridInner } from '@/components'; +import { ApprovalTransactionProvider } from './hooks/ApprovalTransactionContext'; +import { Breadcrumbs, Link } from '@mui/material'; + +const ApprovalTransaction = () => { + return ( + + +

TRANSACTION

+ + + Dashboard + + + + Transaction + + + + Approval Transaction + + +
+ +
+
+
+ ); +}; + +export default ApprovalTransaction; diff --git a/src/pages/transaction/approval-transaction/blocks/DetailApprovalTransaction.tsx b/src/pages/transaction/approval-transaction/blocks/DetailApprovalTransaction.tsx new file mode 100644 index 0000000..e0d0ecc --- /dev/null +++ b/src/pages/transaction/approval-transaction/blocks/DetailApprovalTransaction.tsx @@ -0,0 +1,538 @@ +import { useTransactionContext } from '../hooks/useApprovalTransactionContext'; +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 DetailApprovalTransaction = () => { + 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 + + + {/* Tabs Navigation */} +
+ + + + + +
+ + {/* Tab Content */} +
+ {activeTab === 'detail' && transactionDetails?.kind === 'P' && ( +
+

+ 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?.purchase.amount)}

+
+
+

Fee

+

+ {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}

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

Transaction Logs

+
+ + + + + + + + + + + + + {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 +
+
+
+ )} + + {activeTab === 'approve' && ( +
+

Approval Logs

+ {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 +
+
+ )} +
+ )} + +
+
+
+
+ ); +}; + +export default DetailApprovalTransaction; diff --git a/src/pages/transaction/approval-transaction/blocks/ListToolbar.tsx b/src/pages/transaction/approval-transaction/blocks/ListToolbar.tsx new file mode 100644 index 0000000..3247955 --- /dev/null +++ b/src/pages/transaction/approval-transaction/blocks/ListToolbar.tsx @@ -0,0 +1,82 @@ +import { DefaultTooltip, KeenIcon, useDataGrid } from '@/components'; +import { useTransactionContext } from '../hooks/useApprovalTransactionContext'; +import { Button } from '@/components/ui/button'; +import { useCallback, useState, useEffect } from 'react'; +import { toast } from 'sonner'; + +const ListToolbar = () => { + const { table, reload } = useDataGrid(); + + // Set the initial state for trxDate + const [trxDate, settrxDate] = useState({ from: '', to: '' }); + + // Function to format date to YYYY-MM-DD + const formatDate = (date: Date): string => { + return date.toISOString().split('T')[0]; + }; + + // useEffect to set the default date values + useEffect(() => { + const today = new Date(); + const nextWeek = new Date(today); + nextWeek.setDate(today.getDate() + 7); + + settrxDate({ + from: formatDate(today), // Set 'from' to today + to: formatDate(nextWeek), // Set 'to' to 7 days later + }); + }, []); + + const handleFilterData = useCallback(() => { + try { + table.getColumn('transaction_date')?.setFilterValue(trxDate); + } catch (error) { + toast.error('Error applying filter'); + console.error('Error applying filter:', error); + } + }, [trxDate, table]); + + useEffect(() => { + if (trxDate.from && trxDate.to) { + handleFilterData(); + } + }, [trxDate]); + + return ( +
+
+
+
+ + + +
+
+
+
+ ); +}; + +export default ListToolbar; diff --git a/src/pages/transaction/approval-transaction/hooks/ApprovalTransactionContext.tsx b/src/pages/transaction/approval-transaction/hooks/ApprovalTransactionContext.tsx new file mode 100644 index 0000000..91c87c2 --- /dev/null +++ b/src/pages/transaction/approval-transaction/hooks/ApprovalTransactionContext.tsx @@ -0,0 +1,268 @@ +import { DataGridColumnHeader, DataGridProvider, KeenIcon } from '@/components'; +import { Toaster } from '@/components/ui/sonner'; +import { apiConfig } from '@/config/api.config'; +import { ColumnDef } from '@tanstack/react-table'; +import axios from 'axios'; +import React, { createContext, useCallback, useEffect, useMemo, useState } from 'react'; +import { useCallApi } from '@/hooks'; +import ListToolbar from '../blocks/ListToolbar'; +import { Button } from '@/components/ui/button'; +import { useNavigate } from 'react-router'; +import DetailApprovalTransaction from '../blocks/DetailApprovalTransaction'; + +interface ApprovalTransactionProps { + id: number; + name: string; +} + +interface ContextProps { + getTransactionLists: ( + limit: number, + page: number, + with_deleted: boolean, + order_field: any, + order_direction: any, + filter: any + ) => Promise<{ data: ApprovalTransactionProps[]; totalCount: number } | undefined>; + showDetailDialog: boolean; + setShowDetailDialog: React.Dispatch>; + selectedTransactionId: number | null; + setSelectedTransactionId: React.Dispatch>; +} + +const initialProps: ContextProps = { + getTransactionLists: async () => ({ data: [], totalCount: 0 }), + showDetailDialog: false, + setShowDetailDialog: () => { }, + selectedTransactionId: null, + setSelectedTransactionId: () => { } +}; + +const ManageApprovalTransactionContext = createContext(initialProps); +const API_URL = apiConfig.transaction; + +const ApprovalTransactionProvider = ({ children }: { children: React.ReactNode }) => { + const [showDetailDialog, setShowDetailDialog] = useState(false); + const [selectedTransactionId, setSelectedTransactionId] = useState(null); + const [transaction, setTransaction] = useState([]); + const { GetData } = useCallApi(); + const navigate = useNavigate(); + const handleNavigate = (path: string) => { + const url = navigate(`${API_URL}/transaction/history/${path}`); + }; + + const columns = useMemo[]>( + () => [ + // { + // accessorKey: 'transaction_date', + // header: ({ column }) => , + // enableSorting: false, + // enableHiding: false, + // meta: { + // headerClassName: 'w-[250px]' + // } + // }, + { + accessorKey: 'transaction_date', + header: ({ column }) => , + enableSorting: false, + enableHiding: false, + meta: { + headerClassName: 'w-[250px]' + }, + cell: ({ row }) => { + // Memformat tanggal dan waktu dari ISO ke format biasa (DD-MM-YYYY HH:MM:SS) + const transactionDate = new Date(row.original.transaction_date); + const formattedDateTime = transactionDate.toLocaleString('en-GB', { + day: '2-digit', + month: '2-digit', + year: 'numeric', + hour: '2-digit', + minute: '2-digit', + second: '2-digit', + hour12: false // Gunakan format 24 jam + }); + return formattedDateTime; // Format DD-MM-YYYY HH:MM:SS (menggunakan waktu yang sudah ada) + } + }, + { + accessorKey: 'origin_customer.fullname', + header: ({ column }) => , + enableSorting: false, + enableHiding: false, + meta: { + headerClassName: 'w-[250px]' + } + }, + { + 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, + enableHiding: false, + meta: { + headerClassName: 'w-[250px]', + }, + }, + { + accessorFn: (row) => { + 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); + }, + id: 'feeamount', + header: ({ column }) => , + enableSorting: false, + enableHiding: false, + meta: { + headerClassName: 'w-[250px]', + }, + }, + { + accessorFn: (row) => { + let status; + if (row.status === 'C') { + status = 'COMPLETE'; + } else if (row.status === 'F') { + status = 'FAILED'; + } else if (row.status === 'O') { + status = 'ON PROCESS'; + } else { + status = 'PENDING'; + } + return status; + }, + accessorKey: 'status', + header: ({ column }) => , + enableSorting: false, + enableHiding: false, + meta: { + headerClassName: 'w-[250px]', + }, + }, + { + accessorKey: 'description', + header: ({ column }) => , + enableSorting: false, + enableHiding: false, + meta: { + headerClassName: 'w-[250px]' + } + }, + { + accessorKey: 'type.name', + header: ({ column }) => , + enableSorting: false, + enableHiding: false, + meta: { + headerClassName: 'w-[250px]' + } + }, + { + id: 'actions', + header: ({ column }) => , + enableSorting: false, + enableHiding: false, + cell: (data) => { + const row = data.row.original; + return ( +
+ +
+ ); + }, + meta: { + headerClassName: 'w-[100px]', + cellClassName: 'text-center' + } + } + ], + []); + + const getTransactionLists = async (page: number, limit: number, sorting: any, filter: any) => { + try { + let startdate; + let enddate; + let formattedFilter; + + 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]; + enddate = nextWeek.toISOString().split('T')[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" + } + }; + + const response = await GetData(`${API_URL}/transaction/history`, { + limit, + page: page + 1, + with_deleted: false, + order_field: "Transactions.created_at", + order_direction: 'DESC', + filter: JSON.stringify(formattedFilter) + }); + + setTransaction(response?.data.list); + return { data: response?.data.list, totalCount: response?.data.total_count }; + } catch (error) { + console.error('Error fetching transaction', error); + } + }; + + return ( + + + + + } + layout={{ card: true }} + sorting={[{ id: 'id', desc: false }]} + serverSide={true} + onFetchData={({ pageIndex, pageSize, sorting, columnFilters }) => + getTransactionLists(pageIndex, pageSize, sorting, columnFilters) + } + > + {children} + + + ); +}; + +export { ApprovalTransactionProvider, ManageApprovalTransactionContext }; +export type { ApprovalTransactionProps }; diff --git a/src/pages/transaction/approval-transaction/hooks/useApprovalTransactionContext.tsx b/src/pages/transaction/approval-transaction/hooks/useApprovalTransactionContext.tsx new file mode 100644 index 0000000..3f93690 --- /dev/null +++ b/src/pages/transaction/approval-transaction/hooks/useApprovalTransactionContext.tsx @@ -0,0 +1,12 @@ +import { useContext } from 'react'; +import { ManageApprovalTransactionContext } from './ApprovalTransactionContext'; + +const useTransactionContext = () => { + const context = useContext(ManageApprovalTransactionContext); + + if (!context) throw new Error('useTransactionContext must be used within AuthProvider'); + + return context; +}; + +export { useTransactionContext }; diff --git a/src/pages/transaction/Transaction.tsx b/src/pages/transaction/history-transaction/Transaction.tsx similarity index 93% rename from src/pages/transaction/Transaction.tsx rename to src/pages/transaction/history-transaction/Transaction.tsx index 9456873..3afcc68 100644 --- a/src/pages/transaction/Transaction.tsx +++ b/src/pages/transaction/history-transaction/Transaction.tsx @@ -17,7 +17,7 @@ const Transaction = () => { - Transaction + History Transaction
diff --git a/src/pages/transaction/blocks/DetailTransaction.tsx b/src/pages/transaction/history-transaction/blocks/DetailTransaction.tsx similarity index 93% rename from src/pages/transaction/blocks/DetailTransaction.tsx rename to src/pages/transaction/history-transaction/blocks/DetailTransaction.tsx index ec5dd9f..5f3ad0d 100644 --- a/src/pages/transaction/blocks/DetailTransaction.tsx +++ b/src/pages/transaction/history-transaction/blocks/DetailTransaction.tsx @@ -208,8 +208,44 @@ const DetailTransaction = () => {
)} + {activeTab === 'detail' && transactionDetails?.kind === 'P' && ( +
+

+ Product Information + + Product Info + +

+
+
+

Product Name

+

{transactionDetails?.purchase.product.name}

+
+
+

Price Cash

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

Price Point

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

Product Type

+

{transactionDetails?.purchase.product.type}

+
+
+

Provider Name

+

{transactionDetails?.purchase.product.provider.description}

+
+
+

Provider Type

+

{transactionDetails?.purchase.product.provider.type}

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

Transaction Information diff --git a/src/pages/transaction/blocks/ListToolbar.tsx b/src/pages/transaction/history-transaction/blocks/ListToolbar.tsx similarity index 100% rename from src/pages/transaction/blocks/ListToolbar.tsx rename to src/pages/transaction/history-transaction/blocks/ListToolbar.tsx diff --git a/src/pages/transaction/hooks/TransactionContext.tsx b/src/pages/transaction/history-transaction/hooks/TransactionContext.tsx similarity index 100% rename from src/pages/transaction/hooks/TransactionContext.tsx rename to src/pages/transaction/history-transaction/hooks/TransactionContext.tsx diff --git a/src/pages/transaction/hooks/useTransactionContext.tsx b/src/pages/transaction/history-transaction/hooks/useTransactionContext.tsx similarity index 100% rename from src/pages/transaction/hooks/useTransactionContext.tsx rename to src/pages/transaction/history-transaction/hooks/useTransactionContext.tsx diff --git a/src/pages/wallet/wallet-history/blocks/ListToolbar.tsx b/src/pages/wallet/wallet-history/blocks/ListToolbar.tsx index 9b239b2..546a14a 100644 --- a/src/pages/wallet/wallet-history/blocks/ListToolbar.tsx +++ b/src/pages/wallet/wallet-history/blocks/ListToolbar.tsx @@ -11,15 +11,15 @@ const ListToolbar = () => {
- */} {/* - // - // - // ); - // }, - // 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`, { + const response = await GetData(`${API_URL_WALLET}/dashboard/balance/`, { limit, page: page + 1, with_deleted: false, @@ -167,7 +193,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) { @@ -192,7 +218,7 @@ const ManageWalletContextProvider = ({ children }: { children: React.ReactNode } } layout={{ card: true }} sorting={[{ id: 'id', desc: false }]} diff --git a/src/routing/AppRoutingSetup.tsx b/src/routing/AppRoutingSetup.tsx index b0331d0..f507a0a 100644 --- a/src/routing/AppRoutingSetup.tsx +++ b/src/routing/AppRoutingSetup.tsx @@ -8,7 +8,8 @@ import { ErrorsRouting } from '@/errors'; import DashboardHomePage from '@/pages/dashboards/home/DashboardHomePage'; import ManageUserPage from '@/pages/settings/user/manage-user/ManageUserPage'; -import Transaction from '@/pages/transaction/Transaction'; +import Transaction from '@/pages/transaction/history-transaction/Transaction'; +import ApprovalTransaction from '@/pages/transaction/approval-transaction/ApprovalTransaction'; import LogActivityPage from '@/pages/settings/user/log-activity/LogActivityPage'; import ManagePositionPage from '@/pages/settings/user/manage-position/ManagePositionPage'; import ManageAccount from '@/pages/account/manage-account/ManageAccount'; @@ -88,6 +89,7 @@ const AppRoutingSetup = (): ReactElement => { } /> } /> + } /> } /> } /> } />