diff --git a/src/config/api.config.ts b/src/config/api.config.ts index 3087034..8896461 100644 --- a/src/config/api.config.ts +++ b/src/config/api.config.ts @@ -1,6 +1,8 @@ interface apiConfigProps { service_dashboard: string; service_master_data: string; + service_transaction: string; + service_customer: string; } const API_URL = import.meta.env.VITE_APP_API_URL; @@ -8,7 +10,9 @@ const apiConfig: apiConfigProps = { // service_dashboard: `${API_URL}${import.meta.env.VITE_ENV != 'development' ? '/d' : ''}`, service_dashboard: `${API_URL}/d`, // service_master_data: `${API_URL}/m` - service_master_data: `${API_URL}/t` + service_master_data: `${API_URL}/t`, + service_transaction: `${API_URL}/tt`, + service_customer: `${API_URL}/c`, }; export { apiConfig }; diff --git a/src/pages/transfer/TransferType.tsx b/src/pages/transfer/TransferType.tsx deleted file mode 100644 index 2e5d03e..0000000 --- a/src/pages/transfer/TransferType.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import { Container, DataGridInner } from '@/components'; -import { - ManageTransferTypeContext, - ManageTransferTypeContextProvider -} from './hooks/ManageTransferTypeContext'; -import AddDialog from './blocks/AddDialog'; - -const TransferType = () => { - return ( - - -
- -
- -
-
- ); -}; - -export default TransferType; diff --git a/src/pages/transfer/blocks/AddDialog.tsx b/src/pages/transfer/blocks/AddDialog.tsx deleted file mode 100644 index a7abdf1..0000000 --- a/src/pages/transfer/blocks/AddDialog.tsx +++ /dev/null @@ -1,398 +0,0 @@ -import { apiConfig } from '@/config/api.config'; -import { useCallback, useEffect, useRef, useState } from 'react'; -import { useManageTransferTypeContext } from '../hooks/useManageTransferTypeContext'; -import { Alert, KeenIcon, useDataGrid } from '@/components'; -import { useCallApi } from '@/hooks'; -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 TransactionFeeDialog from './TransactionFeeDialog'; -import { toast } from 'sonner'; -import { doSaveLogActivity } from '@/actions/GlobalActions'; -import { getAuth } from '@/auth'; - -interface CreateTransferTypeParams { - transfer_type_name: string; - description: string; - from_account: string; - to_account: string; - minimal_amount: number; - maximum_amount: number; - otp_threshold: number; - maximum_transaction_perDay: number; - status: string; - created_by: string; - created_at: string; -} - -const API_URL = apiConfig.service_dashboard; - -const AddDialog = () => { - const parentRef = useRef(null); - const { showAddDialog, handleAddDialog, accounts } = useManageTransferTypeContext(); - const { reload } = useDataGrid(); - const { PostData, PutData } = useCallApi(); - const [alert, setAlert] = useState({ - show: false, - message: '' - }); - - const initialState = { - transfer_type_name: '', - description: '', - from_account: '', - to_account: '', - minimal_amount: 0, - maximum_amount: 0, - otp_threshold: 0, - maximum_transaction_perDay: 0, - status: '', - created_by: '', - created_at: '' - }; - - const [formField, setFormField] = useState(initialState); - - const resetForm = () => { - setFormField(initialState); - }; - - const [isSubmitting, setIsSubmitting] = useState(false); - const [showTransactionFeeDialog, setShowTransactionFeeDialog] = useState(false); - const parsedUser = getAuth()?.user; - - const handleSubmit = (e: React.FormEvent) => { - e.preventDefault(); - // setIsSubmitting(true); - const payload = { - transfer_type_name: formField.transfer_type_name, - description: formField.description, - from_account: formField.from_account, - to_account: formField.to_account, - minimal_amount: formField.minimal_amount, - maximum_amount: formField.maximum_amount, - otp_threshold: formField.otp_threshold, - maximum_transaction_perDay: formField.maximum_transaction_perDay - }; - console.log(payload); - }; - useEffect(() => { - const created_time = new Date(); - const formattedTime = created_time.toISOString().slice(0, 19).replace('T', ' '); - - if (showAddDialog) { - setFormField({ - ...formField, - created_by: parsedUser?.username, - created_at: formattedTime - }); - } - }, [showAddDialog]); - const doCreateTransferType = useCallback( - async (e: React.FormEvent) => { - e.preventDefault(); - console.log(formField); - - for (const key in formField) { - if ( - formField[key as keyof typeof formField] === '' || - formField[key as keyof typeof formField] === 0 - ) { - setAlert({ show: true, message: 'All fields must be filled out' }); - return; - } - } - - setAlert({ show: false, message: '' }); - const response = await PostData(`${API_URL}/transactiontype/create`, formField); - - if (response?.status) { - setAlert({ show: false, message: '' }); - handleAddDialog(false); - toast.success('Success Create Transfer Type'); - reload(); - resetForm(); - - const createActivity = { - module: 'Manage Transfer Type', - description: `Create New Transfer Type => ${formField.transfer_type_name}`, - action: 'C' - }; - - doSaveLogActivity(createActivity); - } else { - setAlert({ show: true, message: response?.message || 'Failed to create transfer type' }); - } - - handleAddDialog(false); - }, - [formField] - ); - const handleTransactionFeeSubmit = (data: any) => { - // console.log('Transaction Fee Data Submitted:', data); - setShowTransactionFeeDialog(false); - }; - - return ( - handleAddDialog(open)}> - - - - -
-
-

Transfer Type

-
-
-
{ - handleAddDialog(false); - resetForm(); - }} - > - -
-
-
- -
- {alert.show && ( - -

{alert.message}

-
- )} -
-
-
-
- - - setFormField((prev) => ({ ...prev, transfer_type_name: target.value })) - } - /> -
-
- -
-
- - - setFormField((prev) => ({ ...prev, description: target.value })) - } - /> -
-
- -
-
- - -
- -
-
-
- -
-
- - -
- -
-
-
- -
-
- - - setFormField((prev) => ({ - ...prev, - minimal_amount: Number(target.value) - })) - } - /> -
-
- -
-
- - - setFormField((prev) => ({ - ...prev, - maximum_amount: Number(target.value) - })) - } - /> -
-
- -
-
- - - setFormField((prev) => ({ - ...prev, - otp_threshold: Number(target.value) - })) - } - /> -
-
- -
-
- - - setFormField((prev) => ({ - ...prev, - maximum_transaction_perDay: Number(target.value) - })) - } - /> -
-
-
-
- - -
- -
-
-
- -
- - - -
-
-
- setShowTransactionFeeDialog(false)} - onSubmit={handleTransactionFeeSubmit} - /> -
-
-
-
- ); -}; - -export default AddDialog; diff --git a/src/pages/transfer/blocks/ListToolBar.tsx b/src/pages/transfer/blocks/ListToolBar.tsx deleted file mode 100644 index a3af2c3..0000000 --- a/src/pages/transfer/blocks/ListToolBar.tsx +++ /dev/null @@ -1,49 +0,0 @@ -import { DefaultTooltip, KeenIcon, useDataGrid } from '@/components'; -import { useManageTransferTypeContext } from '../hooks/useManageTransferTypeContext'; -import { Button } from '@/components/ui/button'; - -const ListToolbar = () => { - const { table, reload } = useDataGrid(); - const { handleAddDialog, handleEditDialog } = useManageTransferTypeContext(); - - return ( -
-
-
-
- - - - -
-
- - - - -
-
-
-
- ); -}; - -export default ListToolbar; diff --git a/src/pages/transfer/blocks/TransactionFeeDialog.tsx b/src/pages/transfer/blocks/TransactionFeeDialog.tsx deleted file mode 100644 index cccf165..0000000 --- a/src/pages/transfer/blocks/TransactionFeeDialog.tsx +++ /dev/null @@ -1,281 +0,0 @@ -import { useState, useCallback, useEffect } from 'react'; -import { - Dialog, - DialogBody, - DialogContent, - DialogDescription, - DialogHeader, - DialogTitle -} from '@/components/ui/dialog'; -import { Input } from '@/components/ui/input'; -import { Button } from '@/components/ui/button'; -import Typography from '@mui/material/Typography'; -import { toast } from 'sonner'; -import { apiConfig } from '@/config/api.config'; -import { useCallApi } from '@/hooks'; -import { useManageTransferTypeContext } from '../hooks/useManageTransferTypeContext'; -import { get } from 'http'; -import { getAuth } from '@/auth'; -import { useDataGrid } from '@/components'; -import { set } from 'date-fns'; -import { doSaveLogActivity } from '@/actions/GlobalActions'; -import { - Select, - SelectTrigger, - SelectValue, - SelectContent, - SelectItem -} from '@/components/ui/select'; - -interface TransactionFeeDialogProps { - open: boolean; - onClose: () => void; - onSubmit: (data: TransactionFeeForm) => void; -} - -interface TransactionFeeForm { - name: string; - description: string; - minimum_amount: number; - maximum_amount: number; - period_start: string; - period_end: string; - deduct_amount: number; - deduct_percentage: number; - priority: string; - status: string; - transactionTypeId: string; - created_by: string; - created_at: string; -} - -const API_URL = apiConfig.service_dashboard; - -const TransactionFeeDialog: React.FC = ({ open, onClose, onSubmit }) => { - const { showAddDialog, handleAddDialog } = useManageTransferTypeContext(); - const parsedUser = getAuth()?.user; - const [formField, setFormField] = useState({ - name: '', - description: '', - minimum_amount: 0, - maximum_amount: 0, - period_start: '', - period_end: '', - deduct_amount: 0, - deduct_percentage: 0, - priority: '', - status: '', - transactionTypeId: '', - created_by: '', - created_at: '' - }); - const { PostData, PutData } = useCallApi(); - const handleChange = (e: React.ChangeEvent) => { - const { name, value } = e.target; - setFormField((prev) => ({ - ...prev, - [name]: value - })); - }; - const [isSubmitting, setIsSubmitting] = useState(false); - const { reload } = useDataGrid(); - const resetForm = () => { - setFormField(formField); - }; - const [alert, setAlert] = useState({ - show: false, - message: '' - }); - useEffect(() => { - const created_time = new Date(); - const formattedTime = created_time.toISOString().slice(0, 19).replace('T', ' '); - - if (showAddDialog) { - setFormField({ - ...formField, - created_by: parsedUser?.username, - created_at: formattedTime - }); - } - }, [showAddDialog]); - const doCreateTransactionFee = useCallback( - async (e: React.FormEvent) => { - e.preventDefault(); - console.log(formField); - const response = await PostData(`${API_URL}/transactionfees/create`, formField); - - if (response?.status) { - setAlert({ show: false, message: '' }); - handleAddDialog(false); - toast.success('Success Create Transfer Type'); - reload(); - resetForm(); - - const createActivity = { - module: 'Manage Transfer Fee', - description: `Create New Transfer Fee => ${formField.name}`, - action: 'C' - }; - - doSaveLogActivity(createActivity); - } else { - setAlert({ show: true, message: response?.message || 'Failed to create transfer fee' }); - } - - onSubmit(formField); - }, - [formField] - ); - - return ( - - - - Transaction Fee - - - -
-
-
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - { - const value = e.target.value; - if (/^\d*$/.test(value)) { - handleChange(e); - } - }} - required - type="text" - inputMode="numeric" - placeholder="Masukkan angka" - /> -
-
- - -
- -
- - -
-
-
-
-
-
- ); -}; - -export default TransactionFeeDialog; diff --git a/src/pages/transfer/hooks/ManageTransferTypeContext.tsx b/src/pages/transfer/hooks/ManageTransferTypeContext.tsx deleted file mode 100644 index 5a3d5d3..0000000 --- a/src/pages/transfer/hooks/ManageTransferTypeContext.tsx +++ /dev/null @@ -1,178 +0,0 @@ -import { DataGridColumnHeader, DataGridProvider } 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 { createContext, useCallback, useEffect, useMemo, useState } from 'react'; -import ListToolbar from '../blocks/ListToolBar'; - -interface SelectedUser { - id: string; - name: string; - internal_name: string; - description: string; -} - -interface AccountProps { - id: string; - name: string; -} - -const accounts: string[] = [ - 'eMoney Account', - 'Topup Account', - 'Merchant Account', - 'Deposit Account', - 'Cash out/in' -]; - -interface ContextProps { - showEditDialog: boolean; - handleEditDialog: (show: boolean, selected_user: string | null) => void; - showAddDialog: boolean; - handleAddDialog: (show: boolean) => void; - selectedUser: string | null; - accounts: AccountProps[]; -} - -const initialProps: ContextProps = { - showEditDialog: false, - handleEditDialog: () => {}, - showAddDialog: false, - handleAddDialog: () => {}, - selectedUser: null, - accounts: [] -}; - -const ManageTransferTypeContext = createContext(initialProps); -const API_URL = apiConfig.service_dashboard; - -const ManageTransferTypeContextProvider = ({ children }: { children: React.ReactNode }) => { - const [showEditDialog, setShowEditDialog] = useState(false); - const [showAddDialog, setShowAddDialog] = useState(false); - const [selectedUser, setSelectedUser] = useState(null); - const [accounts, setAccount] = useState([]); - const { GetData } = useCallApi(); - - useEffect(() => { - setAccount([ - { id: '1', name: 'eMoney Account' }, - { id: '2', name: 'Topup Account' }, - { id: '3', name: 'Merchant Account' }, - { id: '4', name: 'Deposit Account' }, - { id: '5', name: 'Cash in/out Account' } - ]); - }, []); - - const handleEditDialog = useCallback((show: boolean, selected_user: string | null) => { - setSelectedUser(show ? selected_user : null); - setShowEditDialog(show); - }, []); - - const handleAddDialog = useCallback((show: boolean) => { - setShowAddDialog(show); - }, []); - - const columns = useMemo[]>( - () => [ - { - accessorFn: (row) => row.id, - id: 'id', - header: ({ column }) => , - enableSorting: true, - enableHiding: false, - meta: { - headerClassName: 'w-[100px]' - } - }, - { - accessorFn: (row) => row.name, - id: 'name', - header: ({ column }) => , - enableSorting: true, - enableHiding: false, - meta: { - headerClassName: 'w-[250px]' - } - }, - { - accessorFn: (row) => row.internal_name, - id: 'internal_name', - header: ({ column }) => , - enableSorting: true, - enableHiding: false, - meta: { - headerClassName: 'w-[250px]' - } - }, - { - accessorFn: (row) => row.description, - id: 'description', - header: ({ column }) => , - enableSorting: true, - enableHiding: false, - meta: { - headerClassName: 'w-[250px]' - } - }, - { - id: 'actions', - enableSorting: false, - header: ({ column }) => , - cell: ({ row }) => { - return ( - <> - - - - ); - }, - meta: { - headerClassName: 'w-[100px]', - cellClassName: 'text-center' - } - } - ], - [handleAddDialog, handleEditDialog] - ); - - return ( -
-
-

Manage Access Type

-
- - - } - sorting={[{ id: 'id', desc: true }]} - serverSide={true} - > - {children} - - -
- ); -}; - -export { ManageTransferTypeContext, ManageTransferTypeContextProvider }; -export type { SelectedUser }; diff --git a/src/pages/transfer/hooks/useManageTransferTypeContext.tsx b/src/pages/transfer/hooks/useManageTransferTypeContext.tsx deleted file mode 100644 index b726a7c..0000000 --- a/src/pages/transfer/hooks/useManageTransferTypeContext.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import { useContext } from 'react'; -import { ManageTransferTypeContext } from './ManageTransferTypeContext'; - -const useManageTransferTypeContext = () => { - const context = useContext(ManageTransferTypeContext); - - if (!context) throw new Error('useManageAccessTypeContext must be used within AuthProvider'); - - return context; -}; - -export { useManageTransferTypeContext }; diff --git a/src/routing/AppRoutingSetup.tsx b/src/routing/AppRoutingSetup.tsx index 971fbaa..1cf83ae 100644 --- a/src/routing/AppRoutingSetup.tsx +++ b/src/routing/AppRoutingSetup.tsx @@ -24,7 +24,7 @@ import ManageMenu from '@/pages/menu/manage-menu/ManageMenu'; import Welcome from '@/pages/menu/welcome/Welcome'; import Inbox from '@/pages/message/Inbox'; import ManageWebServices from '@/pages/webservice/ManageWebServices'; -import TransferType from '@/pages/transfer/TransferType'; +import TransferType from '@/pages/transfer/transfertype/TransferType'; import MasterData from '@/pages/master/MasterData'; import PostoAdmsMaster from '@/pages/master/postoadms/PostoAdmsMaster'; import SucosMaster from '@/pages/master/sucos/SucosMaster';