Merge branch 'master' of https://git.shiblysolution.id/TPAY/dashboard
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { useManageTransferFeeContext } from '../hooks/useManageTransferFeeContext';
|
||||
import { NumericFormat } from 'react-number-format';
|
||||
import {
|
||||
@ -40,11 +40,7 @@ import {
|
||||
TableHeader,
|
||||
TableRow
|
||||
} from '@/components/ui/table';
|
||||
import { ManageTransferFeeContext } from '../hooks/ManageTransferFeeContext';
|
||||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import { ManageTransferFeeContextProvider } from '../../transferfee/hooks/ManageTransferFeeContext';
|
||||
import { apiConfig } from '@/config/api.config';
|
||||
import { get } from 'http';
|
||||
|
||||
interface TransactionTypeProps {
|
||||
id: string;
|
||||
@ -62,12 +58,19 @@ interface CustomerProps {
|
||||
const API_URL = apiConfig.service_transaction;
|
||||
const API_URL_MASTER_DATA = apiConfig.service_master_data;
|
||||
const API_URL_CUSTOMER = apiConfig.service_customer;
|
||||
|
||||
const AddFeeDialog = () => {
|
||||
const parentRef = useRef<any | null>(null);
|
||||
const { reload } = useDataGrid();
|
||||
const { PostData, PutData, GetData } = useCallApi();
|
||||
const { showAddFeeDialog, handleAddFeeDialog, handleEditFeeDialog, selectedTransferFee } =
|
||||
useManageTransferFeeContext();
|
||||
const {
|
||||
showAddFeeDialog,
|
||||
handleAddFeeDialog,
|
||||
handleEditFeeDialog,
|
||||
selectedTransferFee,
|
||||
transactionTypeId
|
||||
} = useManageTransferFeeContext();
|
||||
|
||||
const [alert, setAlert] = useState({
|
||||
show: false,
|
||||
message: ''
|
||||
@ -76,7 +79,15 @@ const AddFeeDialog = () => {
|
||||
const [wallets, setWallets] = useState<WalletProps[]>([]);
|
||||
const [customers, setCustomers] = useState<CustomerProps[]>([]);
|
||||
const [defaultCustomer, setDefaultCustomer] = useState('');
|
||||
const [transactionTypeName, setTransactionTypeName] = useState('');
|
||||
|
||||
const [isLoadingTransactionType, setIsLoadingTransactionType] = useState(false);
|
||||
const [isLoadingWallets, setIsLoadingWallets] = useState(false);
|
||||
const [isLoadingCustomers, setIsLoadingCustomers] = useState(false);
|
||||
const customersWithNames = customers.map((customer) => ({
|
||||
id: customer.id,
|
||||
name: customer.username,
|
||||
}));
|
||||
const initialState = {
|
||||
name: '',
|
||||
description: '',
|
||||
@ -104,54 +115,57 @@ const AddFeeDialog = () => {
|
||||
|
||||
const resetForm = () => {
|
||||
setFormField(initialState);
|
||||
setTransactionTypeName('');
|
||||
};
|
||||
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [showTransactionFeeDialog, setShowTransactionFeeDialog] = useState(false);
|
||||
const parsedUser = getAuth()?.user;
|
||||
|
||||
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
// setIsSubmitting(true);
|
||||
const payload = {
|
||||
name: formField.name,
|
||||
description: formField.description,
|
||||
period_start: formField.period_start,
|
||||
period_end: formField.period_end,
|
||||
minimum_amount: formField.minimum_amount,
|
||||
maximum_amount: formField.maximum_amount,
|
||||
deduct_amount: formField.deduct_amount,
|
||||
deduct_percentage: formField.deduct_percentage,
|
||||
fee_amount: formField.fee_amount,
|
||||
transaction_type: formField.transaction_type,
|
||||
status: formField.status,
|
||||
status_include: formField.status_include,
|
||||
priority: formField.priority,
|
||||
deduct_from: formField.deduct_from,
|
||||
deduct_from_account: formField.deduct_from_account,
|
||||
credit_to: formField.credit_to,
|
||||
credit_destination: formField.credit_destination,
|
||||
credit_destination_account: formField.credit_destination_account
|
||||
};
|
||||
useEffect(() => {
|
||||
if (showAddFeeDialog && transactionTypeId) {
|
||||
setIsLoadingTransactionType(true);
|
||||
|
||||
setFormField(prev => ({
|
||||
...prev,
|
||||
transaction_type: transactionTypeId
|
||||
}));
|
||||
|
||||
const getTransactionTypeDetails = async () => {
|
||||
try {
|
||||
const response = await GetData(`${API_URL}/transactiontype/getdata/${transactionTypeId}`, {});
|
||||
if (response?.status && response?.data) {
|
||||
setTransactionTypeName(response.data.name);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching transaction type details', error);
|
||||
} finally {
|
||||
setIsLoadingTransactionType(false);
|
||||
}
|
||||
};
|
||||
|
||||
getTransactionTypeDetails();
|
||||
}
|
||||
}, [showAddFeeDialog, transactionTypeId, GetData]);
|
||||
|
||||
useEffect(() => {
|
||||
const created_time = new Date();
|
||||
const formattedTime = created_time.toISOString().slice(0, 19).replace('T', ' ');
|
||||
|
||||
if (showAddFeeDialog) {
|
||||
setFormField({
|
||||
...formField,
|
||||
setFormField(prev => ({
|
||||
...prev,
|
||||
created_by: parsedUser?.username,
|
||||
created_at: formattedTime
|
||||
});
|
||||
}));
|
||||
}
|
||||
}, [showAddFeeDialog]);
|
||||
}, [showAddFeeDialog, parsedUser?.username]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!showAddFeeDialog) return;
|
||||
|
||||
const getTransactionTypeList = async (sorting: any) => {
|
||||
setIsLoadingTransactionType(true);
|
||||
try {
|
||||
sorting = sorting.length === 0 ? [{ id: 'name', desc: false }] : sorting;
|
||||
const response = await GetData(`${API_URL}/transactiontype/list`, {
|
||||
@ -164,13 +178,16 @@ const AddFeeDialog = () => {
|
||||
setTransactionTypes(response?.data.list || []);
|
||||
} catch (error) {
|
||||
console.error('Error fetching transaction types', error);
|
||||
} finally {
|
||||
setIsLoadingTransactionType(false);
|
||||
}
|
||||
};
|
||||
|
||||
getTransactionTypeList([{ id: 'id', desc: false }]);
|
||||
}, [showAddFeeDialog]);
|
||||
}, [showAddFeeDialog, GetData]);
|
||||
|
||||
const fetchWallets = useCallback(async () => {
|
||||
setIsLoadingWallets(true);
|
||||
const params = {
|
||||
limit: 100,
|
||||
page: 1,
|
||||
@ -188,6 +205,8 @@ const AddFeeDialog = () => {
|
||||
} catch (error) {
|
||||
console.error('Error fetching wallets', error);
|
||||
setWallets([]);
|
||||
} finally {
|
||||
setIsLoadingWallets(false);
|
||||
}
|
||||
}, [GetData]);
|
||||
|
||||
@ -199,6 +218,7 @@ const AddFeeDialog = () => {
|
||||
useEffect(() => {
|
||||
if (!showAddFeeDialog) return;
|
||||
const getCustomerList = async (sorting: any) => {
|
||||
setIsLoadingCustomers(true);
|
||||
try {
|
||||
sorting = sorting.length === 0 ? [{ id: 'name', desc: false }] : sorting;
|
||||
|
||||
@ -218,6 +238,8 @@ const AddFeeDialog = () => {
|
||||
} catch (error) {
|
||||
console.error('Error fetching customers', error);
|
||||
setCustomers([]);
|
||||
} finally {
|
||||
setIsLoadingCustomers(false);
|
||||
}
|
||||
};
|
||||
|
||||
@ -280,6 +302,13 @@ const AddFeeDialog = () => {
|
||||
reload();
|
||||
resetForm();
|
||||
handleAddFeeDialog(false);
|
||||
|
||||
const createActivity = {
|
||||
module: 'Manage Transfer Fee',
|
||||
description: `Create Transfer Fee => ${formField.name}`,
|
||||
action: 'C'
|
||||
};
|
||||
doSaveLogActivity(createActivity);
|
||||
} else {
|
||||
setAlert({ show: true, message: response?.message || 'Failed to create transfer fee' });
|
||||
}
|
||||
@ -293,6 +322,40 @@ const AddFeeDialog = () => {
|
||||
[formField, PostData, reload, handleAddFeeDialog]
|
||||
);
|
||||
|
||||
const renderSelectWithLoading = (
|
||||
value: string,
|
||||
onChangeHandler: (value: string) => void,
|
||||
options: {id: string, name: string}[] | null,
|
||||
placeholder: string,
|
||||
isLoading: boolean
|
||||
) => {
|
||||
return (
|
||||
<Select
|
||||
value={value}
|
||||
onValueChange={onChangeHandler}
|
||||
disabled={isLoading}
|
||||
>
|
||||
<SelectTrigger>
|
||||
{isLoading ? (
|
||||
<div className="flex items-center">
|
||||
<div className="animate-pulse bg-gray-200 h-4 w-24 rounded"></div>
|
||||
<span className="ml-2">Loading...</span>
|
||||
</div>
|
||||
) : (
|
||||
<SelectValue placeholder={placeholder} />
|
||||
)}
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{options && options.map((option) => (
|
||||
<SelectItem value={option.id} key={option.id}>
|
||||
{option.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={showAddFeeDialog} onOpenChange={(open) => handleAddFeeDialog(open)}>
|
||||
<DialogContent className="container-fixed max-w-[1080px] flex flex-col p-5 overflow-hidden [&>button]:hidden">
|
||||
@ -325,6 +388,35 @@ const AddFeeDialog = () => {
|
||||
<form action="" onSubmit={doCreateTransferType}>
|
||||
<div className="card flex flex-col gap-5">
|
||||
<div className="card-body grid gap-5 p-0">
|
||||
<div className="w-full">
|
||||
<label className="form-label">Transaction Type ID <span className="text-red-500">*</span></label>
|
||||
{transactionTypeId ? (
|
||||
<div className="relative">
|
||||
<Input
|
||||
className="input bg-gray-100"
|
||||
type="text"
|
||||
value={isLoadingTransactionType ? '' : transactionTypeName}
|
||||
readOnly
|
||||
/>
|
||||
{isLoadingTransactionType && (
|
||||
<div className="absolute inset-0 flex items-center justify-start bg-gray-100 px-3">
|
||||
<div className="flex items-center">
|
||||
<div className="animate-pulse bg-gray-200 h-4 w-24 rounded"></div>
|
||||
<span className="ml-2 text-gray-500">Loading transaction type...</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
renderSelectWithLoading(
|
||||
formField.transaction_type,
|
||||
(transaction_type) => setFormField((prev) => ({ ...prev, transaction_type })),
|
||||
transactionTypes,
|
||||
"Select Transaction Type",
|
||||
isLoadingTransactionType
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Transfer Free Name <span className="text-red-500">*</span></label>
|
||||
<Input
|
||||
@ -475,21 +567,13 @@ const AddFeeDialog = () => {
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Deduct From Destination <span className="text-red-500">*</span></label>
|
||||
<Select
|
||||
value={formField.deduct_from_account}
|
||||
onValueChange={(value) => setFormField({ ...formField, deduct_from_account: value })}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select Wallet" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{wallets.map((wallet) => (
|
||||
<SelectItem value={wallet.id} key={wallet.id}>
|
||||
{wallet.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{renderSelectWithLoading(
|
||||
formField.deduct_from_account,
|
||||
(value) => setFormField({ ...formField, deduct_from_account: value }),
|
||||
wallets,
|
||||
"Select Wallet",
|
||||
isLoadingWallets
|
||||
)}
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Credit To <span className="text-red-500">*</span></label>
|
||||
@ -514,60 +598,24 @@ const AddFeeDialog = () => {
|
||||
{formField.credit_to === 'I' && (
|
||||
<div className="w-full">
|
||||
<label className="form-label">Credit Destination <span className="text-red-500">*</span></label>
|
||||
<Select
|
||||
value={formField.credit_destination}
|
||||
onValueChange={(value) => setFormField({ ...formField, credit_destination: value })}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select Customer" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{customers.map((customer) => (
|
||||
<SelectItem value={customer.id} key={customer.id}>
|
||||
{customer.username} - {customer.msisdn}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{renderSelectWithLoading(
|
||||
formField.credit_destination,
|
||||
(value) => setFormField({ ...formField, credit_destination: value }),
|
||||
customersWithNames,
|
||||
"Select Customer",
|
||||
isLoadingCustomers
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<div className="w-full">
|
||||
<label className="form-label">Credit Destination Account <span className="text-red-500">*</span></label>
|
||||
<Select
|
||||
value={formField.credit_destination_account}
|
||||
onValueChange={(value) => setFormField({ ...formField, credit_destination_account: value })}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select Wallet" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{wallets.map((wallet) => (
|
||||
<SelectItem value={wallet.id} key={wallet.id}>
|
||||
{wallet.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Transaction Type ID <span className="text-red-500">*</span></label>
|
||||
<Select
|
||||
value={formField.transaction_type}
|
||||
onValueChange={(transaction_type) =>
|
||||
setFormField((prev) => ({ ...prev, transaction_type }))
|
||||
}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select Transaction Type" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{transactionTypes.map((transactiontype) => (
|
||||
<SelectItem value={transactiontype.id} key={transactiontype.id}>
|
||||
{transactiontype.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{renderSelectWithLoading(
|
||||
formField.credit_destination_account,
|
||||
(value) => setFormField({ ...formField, credit_destination_account: value }),
|
||||
wallets,
|
||||
"Select Wallet",
|
||||
isLoadingWallets
|
||||
)}
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Status <span className="text-red-500">*</span></label>
|
||||
@ -624,7 +672,11 @@ const AddFeeDialog = () => {
|
||||
>
|
||||
Reset
|
||||
</Button>
|
||||
<Button variant={'default'} type="submit" disabled={isSubmitting}>
|
||||
<Button
|
||||
variant={'default'}
|
||||
type="submit"
|
||||
disabled={isSubmitting || isLoadingTransactionType || isLoadingWallets || isLoadingCustomers}
|
||||
>
|
||||
{isSubmitting ? 'Saving...' : 'Save Changes'}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@ -167,6 +167,11 @@ const EditFeeDialog = () => {
|
||||
toast.success('Successfully updated transfer fee');
|
||||
reload();
|
||||
handleEditFeeDialog(false, null);
|
||||
const createActivity = {
|
||||
module: 'Manage Transfer Type',
|
||||
description: `Edit Transfer Type => ${selectedTransferFee}`,
|
||||
action: 'U'
|
||||
};
|
||||
} else {
|
||||
setAlert({ show: true, message: response?.message || 'Failed to update transfer fee' });
|
||||
}
|
||||
|
||||
@ -17,6 +17,8 @@ interface ContextProps {
|
||||
handleDeleteFeeDialog: (show: boolean, selected_TransferFee: string | null) => void;
|
||||
showDeleteFeeDialog: boolean;
|
||||
selectedTransferFee: string | null;
|
||||
transactionTypeId: string | null;
|
||||
|
||||
}
|
||||
|
||||
const initialProps: ContextProps = {
|
||||
@ -26,7 +28,9 @@ const initialProps: ContextProps = {
|
||||
handleAddFeeDialog: () => {},
|
||||
showDeleteFeeDialog: false,
|
||||
handleDeleteFeeDialog: () => {},
|
||||
selectedTransferFee: null
|
||||
selectedTransferFee: null,
|
||||
transactionTypeId: null,
|
||||
|
||||
};
|
||||
|
||||
interface TransferFeeProps {
|
||||
@ -47,15 +51,13 @@ interface TransferFeeProps {
|
||||
const ManageTransferFeeContext = createContext<ContextProps>(initialProps);
|
||||
const API_URL = apiConfig.service_transaction;
|
||||
|
||||
const ManageTransferFeeContextProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
const ManageTransferFeeContextProvider = ({ children, transactionTypeId = null }: { children: React.ReactNode; transactionTypeId?: string | null }) => {
|
||||
const [showEditFeeDialog, setShowEditFeeDialog] = useState(false);
|
||||
const [showAddFeeDialog, setShowAddFeeDialog] = useState(false);
|
||||
const [showDeleteFeeDialog, setShowDeleteFeeDialog] = useState(false);
|
||||
const { showAddDialog, handleAddDialog, selectedTransferType } = useManageTransferTypeContext();
|
||||
|
||||
const [selectedTransferFee, setSelectedTransferFee] = useState<string | null>(null);
|
||||
const { GetData } = useCallApi();
|
||||
|
||||
const handleEditFeeDialog = useCallback((show: boolean, selected_TransferFee: string | null) => {
|
||||
setSelectedTransferFee(show ? selected_TransferFee : null);
|
||||
setShowEditFeeDialog(show);
|
||||
@ -85,7 +87,7 @@ const ManageTransferFeeContextProvider = ({ children }: { children: React.ReactN
|
||||
try {
|
||||
const response = await GetData(`${API_URL}/transactionfees/getdatabytransactiontype/${selectedTransferType}`, {});
|
||||
|
||||
console.log('API Response:', response?.data);
|
||||
// console.log('API Response:', response?.data);
|
||||
|
||||
return {
|
||||
data: response?.data ,
|
||||
@ -362,7 +364,8 @@ const ManageTransferFeeContextProvider = ({ children }: { children: React.ReactN
|
||||
handleAddFeeDialog,
|
||||
selectedTransferFee,
|
||||
showDeleteFeeDialog,
|
||||
handleDeleteFeeDialog
|
||||
handleDeleteFeeDialog,
|
||||
transactionTypeId
|
||||
}}
|
||||
>
|
||||
<Toaster expand visibleToasts={9} duration={3000} />
|
||||
|
||||
@ -39,6 +39,7 @@ import {
|
||||
CommandItem,
|
||||
CommandList
|
||||
} from '@/components/ui/command';
|
||||
import { doSaveLogActivity } from '@/actions/GlobalActions';
|
||||
|
||||
interface WalletProps {
|
||||
id: string;
|
||||
@ -95,7 +96,6 @@ const AddDialog = () => {
|
||||
|
||||
const parsedUser = getAuth()?.user;
|
||||
|
||||
// Updated validation function to make only certain fields required
|
||||
const validateForm = () => {
|
||||
const requiredFields = [
|
||||
'name',
|
||||
@ -141,6 +141,13 @@ const AddDialog = () => {
|
||||
toast.success('Success Create Transfer Type');
|
||||
reload();
|
||||
resetForm();
|
||||
const createActivity = {
|
||||
module: 'Manage Transfer Type',
|
||||
description: `Create Transfer Type => ${formField.name}`,
|
||||
action: 'C'
|
||||
};
|
||||
|
||||
doSaveLogActivity(createActivity);
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
@ -218,7 +225,7 @@ const AddDialog = () => {
|
||||
order_direction: 'ASC',
|
||||
};
|
||||
const response = await GetData(`${API_URL_MASTERDATA}/wallet/list`, params);
|
||||
console.log(response)
|
||||
// console.log(response)
|
||||
if (response?.status && response?.data) {
|
||||
setWallets(response.data.list);
|
||||
} else {
|
||||
@ -230,7 +237,7 @@ const AddDialog = () => {
|
||||
if (!showAddDialog) return;
|
||||
fetchWallets();
|
||||
}, [showAddDialog]);
|
||||
console.log(formField)
|
||||
// console.log(formField)
|
||||
return (
|
||||
<Dialog open={showAddDialog} onOpenChange={(open) => handleAddDialog(open)}>
|
||||
<DialogContent className="container-fixed max-w-[1080px] flex flex-col p-5 overflow-hidden [&>button]:hidden">
|
||||
@ -436,7 +443,7 @@ const AddDialog = () => {
|
||||
<div className="w-full">
|
||||
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||
<label className="form-label flex items-center gap-1 max-w-56">
|
||||
TransactionType Status
|
||||
Status Transaction Type
|
||||
<span className="text-red-500"> *</span>
|
||||
</label>
|
||||
|
||||
@ -453,12 +460,15 @@ const AddDialog = () => {
|
||||
<SelectContent>
|
||||
<SelectItem value="D">Disbursement </SelectItem>
|
||||
<SelectItem value="O">Other </SelectItem>
|
||||
<SelectItem value="CA">Change Customer to Agent </SelectItem>
|
||||
<SelectItem value="AC">Change Agent to Customer </SelectItem>
|
||||
<SelectItem value="CA">Change Group Emoney Customer to Agent </SelectItem>
|
||||
<SelectItem value="AC">Change Group Emoney Agent to Customer </SelectItem>
|
||||
<SelectItem value="PA">Change Group Point Agent to Customer </SelectItem>
|
||||
<SelectItem value="PC">Change Group Point Customer to Agent</SelectItem>
|
||||
<SelectItem value="CE">Return Customer Emoney </SelectItem>
|
||||
<SelectItem value="AD">Return Agent Deposit </SelectItem>
|
||||
<SelectItem value="AM">Return Agent Merchant </SelectItem>
|
||||
<SelectItem value="AE">Return Agent Emoney </SelectItem>
|
||||
<SelectItem value="R">Reward Point </SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
@ -7,6 +7,7 @@ import { toast } from 'sonner';
|
||||
import { useCallApi } from '@/hooks';
|
||||
import { useManageTransferTypeContext } from '../hooks/useManageTransferTypeContext';
|
||||
import { DialogDescription } from '@radix-ui/react-dialog';
|
||||
import { doSaveLogActivity } from '@/actions/GlobalActions';
|
||||
|
||||
const API_URL = apiConfig.service_transaction;
|
||||
|
||||
@ -33,6 +34,12 @@ const DeleteDialog = () => {
|
||||
setAlert({ show: false, message: '' });
|
||||
handleDeleteDialog(false, null);
|
||||
reload();
|
||||
const createActivity = {
|
||||
module: 'Manage Transfer Type',
|
||||
description: `Delete Transfer Type => ${selectedTransferType}`,
|
||||
action: 'D'
|
||||
};
|
||||
doSaveLogActivity(createActivity);
|
||||
// setTimeout(() => toast.success('Success Delete Transaction Type'), 0);
|
||||
} else {
|
||||
setAlert({ show: true, message: response?.message });
|
||||
|
||||
@ -54,8 +54,7 @@ interface PermissionObject {
|
||||
|
||||
const EditDialog = () => {
|
||||
const parentRef = useRef<any | null>(null);
|
||||
const { showEditDialog, handleEditDialog, selectedTransferType } =
|
||||
useManageTransferTypeContext();
|
||||
const { showEditDialog, handleEditDialog, selectedTransferType } = useManageTransferTypeContext();
|
||||
const { reload } = useDataGrid();
|
||||
const [wallets, setWallets] = useState<WalletProps[]>([]);
|
||||
const [groups, setGroups] = useState<PermissionObject[]>([]);
|
||||
@ -112,13 +111,11 @@ const EditDialog = () => {
|
||||
const isSelected = prevState.permission.includes(groupId);
|
||||
|
||||
if (isSelected) {
|
||||
// Remove the permission if already selected
|
||||
return {
|
||||
...prevState,
|
||||
permission: prevState.permission.filter((id) => id !== groupId)
|
||||
};
|
||||
} else {
|
||||
// Add the permission if not selected
|
||||
return {
|
||||
...prevState,
|
||||
permission: [...prevState.permission, groupId]
|
||||
@ -138,13 +135,13 @@ const EditDialog = () => {
|
||||
'type'
|
||||
];
|
||||
|
||||
const missingFields = requiredFields.filter(
|
||||
(field) => {
|
||||
return formField[field as keyof typeof formField] === '' ||
|
||||
const missingFields = requiredFields.filter((field) => {
|
||||
return (
|
||||
formField[field as keyof typeof formField] === '' ||
|
||||
formField[field as keyof typeof formField] === null ||
|
||||
formField[field as keyof typeof formField] === undefined;
|
||||
}
|
||||
formField[field as keyof typeof formField] === undefined
|
||||
);
|
||||
});
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
setAlert({
|
||||
@ -154,7 +151,6 @@ const EditDialog = () => {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validate that at least one permission is selected
|
||||
if (formField.permission.length === 0) {
|
||||
setAlert({
|
||||
show: true,
|
||||
@ -217,13 +213,15 @@ const EditDialog = () => {
|
||||
|
||||
const doUpdateTransferType = useCallback(async () => {
|
||||
try {
|
||||
// Create a clean copy of the form data with properly formatted permissions
|
||||
const formDataToSend = {
|
||||
...formField,
|
||||
permission: formField.permission.filter(id => typeof id === 'string')
|
||||
permission: formField.permission.filter((id) => typeof id === 'string')
|
||||
};
|
||||
|
||||
const response = await PutData(`${API_URL}/transactiontype/update/${selectedTransferType}`, formDataToSend);
|
||||
const response = await PutData(
|
||||
`${API_URL}/transactiontype/update/${selectedTransferType}`,
|
||||
formDataToSend
|
||||
);
|
||||
|
||||
if (response?.status) {
|
||||
setAlert({ show: false, message: '' });
|
||||
@ -236,15 +234,12 @@ const EditDialog = () => {
|
||||
setAlert({
|
||||
show: true,
|
||||
message:
|
||||
error instanceof Error
|
||||
? error.message
|
||||
: 'An error occurred while updating transfer type'
|
||||
error instanceof Error ? error.message : 'An error occurred while updating transfer type'
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}, [formField, selectedTransferType, PutData]);
|
||||
|
||||
// Fetch customers
|
||||
useEffect(() => {
|
||||
if (!showEditDialog) return;
|
||||
|
||||
@ -270,7 +265,6 @@ const EditDialog = () => {
|
||||
getCustomerList();
|
||||
}, [showEditDialog, GetData]);
|
||||
|
||||
// Fetch groups
|
||||
useEffect(() => {
|
||||
if (!showEditDialog) return;
|
||||
|
||||
@ -295,7 +289,6 @@ const EditDialog = () => {
|
||||
getGroupList();
|
||||
}, [showEditDialog, GetData]);
|
||||
|
||||
// Fetch wallets
|
||||
useEffect(() => {
|
||||
if (!showEditDialog) return;
|
||||
|
||||
@ -306,7 +299,7 @@ const EditDialog = () => {
|
||||
page: 1,
|
||||
with_deleted: false,
|
||||
order_field: 'Wallets.name',
|
||||
order_direction: 'ASC',
|
||||
order_direction: 'ASC'
|
||||
});
|
||||
|
||||
if (response?.status && response?.data) {
|
||||
@ -320,21 +313,21 @@ const EditDialog = () => {
|
||||
getWalletList();
|
||||
}, [showEditDialog, GetData]);
|
||||
|
||||
// Fetch transaction type data
|
||||
useEffect(() => {
|
||||
if (!showEditDialog || !selectedTransferType) return;
|
||||
|
||||
const fetchTransactionType = async () => {
|
||||
try {
|
||||
const response = await GetData(`${API_URL}/transactiontype/getdata/${selectedTransferType}`, {});
|
||||
console.log(response);
|
||||
const response = await GetData(
|
||||
`${API_URL}/transactiontype/getdata/${selectedTransferType}`,
|
||||
{}
|
||||
);
|
||||
// console.log(response);
|
||||
if (response?.status) {
|
||||
// Process permissions to ensure they're always string IDs
|
||||
let permissionIds: string[] = [];
|
||||
|
||||
if (Array.isArray(response.data.permission)) {
|
||||
permissionIds = response.data.permission.map((perm: any) => {
|
||||
// Check if permission is an object or string
|
||||
if (typeof perm === 'object' && perm !== null) {
|
||||
return perm.id;
|
||||
}
|
||||
@ -582,7 +575,7 @@ const EditDialog = () => {
|
||||
<div className="w-full">
|
||||
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||
<label className="form-label flex items-center gap-1 max-w-56">
|
||||
Type
|
||||
Status Transaction Type
|
||||
<span className="text-red-500"> *</span>
|
||||
</label>
|
||||
<div className="grow">
|
||||
@ -598,12 +591,15 @@ const EditDialog = () => {
|
||||
<SelectContent>
|
||||
<SelectItem value="D">Disbursement </SelectItem>
|
||||
<SelectItem value="O">Other </SelectItem>
|
||||
<SelectItem value="CA">Change Customer to Agent </SelectItem>
|
||||
<SelectItem value="AC">Change Agent to Customer </SelectItem>
|
||||
<SelectItem value="CA">Change Group Emoney Customer to Agent </SelectItem>
|
||||
<SelectItem value="AC">Change Group Emoney Agent to Customer </SelectItem>
|
||||
<SelectItem value="PA">Change Group Point Agent to Customer </SelectItem>
|
||||
<SelectItem value="PC">Change Group Point Customer to Agent</SelectItem>
|
||||
<SelectItem value="CE">Return Customer Emoney </SelectItem>
|
||||
<SelectItem value="AD">Return Agent Deposit </SelectItem>
|
||||
<SelectItem value="AM">Return Agent Merchant </SelectItem>
|
||||
<SelectItem value="AE">Return Agent Emoney </SelectItem>
|
||||
<SelectItem value="R">Reward Point </SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
@ -660,7 +656,6 @@ const EditDialog = () => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Group Permission Section - Read Only Display */}
|
||||
<div className="w-full">
|
||||
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||
<label className="form-label flex items-center gap-1 max-w-56">
|
||||
@ -671,12 +666,11 @@ const EditDialog = () => {
|
||||
<Input
|
||||
type="text"
|
||||
placeholder="No groups selected"
|
||||
value={selectedPermissionNames || ""}
|
||||
value={selectedPermissionNames || ''}
|
||||
readOnly
|
||||
className="bg-gray-100 mb-2"
|
||||
/>
|
||||
|
||||
{/* Groups Selection Area */}
|
||||
<div className="border rounded-md p-3 max-h-48 overflow-y-auto">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
|
||||
{groups.map((group) => (
|
||||
@ -707,8 +701,7 @@ const EditDialog = () => {
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
{/* Transaction Fee Section */}
|
||||
<ManageTransferFeeContextProvider>
|
||||
<ManageTransferFeeContextProvider transactionTypeId={selectedTransferType}>
|
||||
<Container>
|
||||
<div className="grid gap-5 lg:gap-7.5 mt-5">
|
||||
<DataGridInner />
|
||||
|
||||
@ -147,12 +147,28 @@ const ManageTransferTypeContextProvider = ({ children }: { children: React.React
|
||||
meta: { headerClassName: 'w-[250px]' }
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.type,
|
||||
accessorFn: (row: {type: string }) => {
|
||||
const mapping: Record<string, string> = {
|
||||
D: 'Disbursement',
|
||||
O: 'Other',
|
||||
CA: 'Change Group Emoney Customer to Agent',
|
||||
AC:'Change Group Emoney Agent to Customer',
|
||||
PC: 'Change Group Point Agent to Customer',
|
||||
PA: 'Change Group Point Customer to Agent',
|
||||
CE:'Return Customer Emoney',
|
||||
AD:'Return Agent Deposit',
|
||||
AM: 'Return Agent Merchant',
|
||||
AE: 'Return Agent Emoney',
|
||||
R: 'Reward Point',
|
||||
};
|
||||
|
||||
return mapping[row.type] || 'Unknown';
|
||||
},
|
||||
id: 'type',
|
||||
header: ({ column }) => (
|
||||
<DataGridColumnHeader title="TransactionType Status" column={column} />
|
||||
<DataGridColumnHeader title="Status Transaction Type" column={column} />
|
||||
),
|
||||
enableSorting: false,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
meta: { headerClassName: 'w-[250px]' }
|
||||
},
|
||||
@ -223,7 +239,7 @@ const ManageTransferTypeContextProvider = ({ children }: { children: React.React
|
||||
order_direction: orderDirection,
|
||||
filter: JSON.stringify(filter)
|
||||
});
|
||||
console.log(response?.data.list);
|
||||
// console.log(response?.data.list);
|
||||
return { data: response?.data.list, totalCount: response?.data.total_count };
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user