fixing transactiontype and transactionfee
This commit is contained in:
@ -63,14 +63,14 @@ const AddFeeDialog = () => {
|
||||
const parentRef = useRef<any | null>(null);
|
||||
const { reload } = useDataGrid();
|
||||
const { PostData, PutData, GetData } = useCallApi();
|
||||
const {
|
||||
showAddFeeDialog,
|
||||
handleAddFeeDialog,
|
||||
handleEditFeeDialog,
|
||||
const {
|
||||
showAddFeeDialog,
|
||||
handleAddFeeDialog,
|
||||
handleEditFeeDialog,
|
||||
selectedTransferFee,
|
||||
transactionTypeId
|
||||
} = useManageTransferFeeContext();
|
||||
|
||||
|
||||
const [alert, setAlert] = useState({
|
||||
show: false,
|
||||
message: ''
|
||||
@ -80,13 +80,13 @@ const AddFeeDialog = () => {
|
||||
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,
|
||||
name: customer.username
|
||||
}));
|
||||
const initialState = {
|
||||
name: '',
|
||||
@ -125,15 +125,18 @@ const AddFeeDialog = () => {
|
||||
useEffect(() => {
|
||||
if (showAddFeeDialog && transactionTypeId) {
|
||||
setIsLoadingTransactionType(true);
|
||||
|
||||
setFormField(prev => ({
|
||||
|
||||
setFormField((prev) => ({
|
||||
...prev,
|
||||
transaction_type: transactionTypeId
|
||||
}));
|
||||
|
||||
|
||||
const getTransactionTypeDetails = async () => {
|
||||
try {
|
||||
const response = await GetData(`${API_URL}/transactiontype/getdata/${transactionTypeId}`, {});
|
||||
const response = await GetData(
|
||||
`${API_URL}/transactiontype/getdata/${transactionTypeId}`,
|
||||
{}
|
||||
);
|
||||
if (response?.status && response?.data) {
|
||||
setTransactionTypeName(response.data.name);
|
||||
}
|
||||
@ -143,17 +146,17 @@ const AddFeeDialog = () => {
|
||||
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(prev => ({
|
||||
setFormField((prev) => ({
|
||||
...prev,
|
||||
created_by: parsedUser?.username,
|
||||
created_at: formattedTime
|
||||
@ -193,7 +196,7 @@ const AddFeeDialog = () => {
|
||||
page: 1,
|
||||
with_deleted: false,
|
||||
order_field: 'Wallets.name',
|
||||
order_direction: 'ASC',
|
||||
order_direction: 'ASC'
|
||||
};
|
||||
try {
|
||||
const response = await GetData(`${API_URL_MASTER_DATA}/wallet/list`, params);
|
||||
@ -209,7 +212,7 @@ const AddFeeDialog = () => {
|
||||
setIsLoadingWallets(false);
|
||||
}
|
||||
}, [GetData]);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (!showAddFeeDialog) return;
|
||||
fetchWallets();
|
||||
@ -231,7 +234,7 @@ const AddFeeDialog = () => {
|
||||
});
|
||||
const customerList = response?.data.list || [];
|
||||
setCustomers(customerList);
|
||||
|
||||
|
||||
if (customerList.length > 0) {
|
||||
setDefaultCustomer(customerList[0].id);
|
||||
}
|
||||
@ -250,9 +253,9 @@ const AddFeeDialog = () => {
|
||||
async (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
setIsSubmitting(true);
|
||||
|
||||
|
||||
const requiredFields = [
|
||||
'name',
|
||||
'name',
|
||||
'description',
|
||||
'period_start',
|
||||
'period_end',
|
||||
@ -265,44 +268,44 @@ const AddFeeDialog = () => {
|
||||
'credit_to',
|
||||
'credit_destination_account'
|
||||
];
|
||||
|
||||
|
||||
for (const field of requiredFields) {
|
||||
if (formField[field as keyof typeof formField] === '') {
|
||||
setAlert({
|
||||
show: true,
|
||||
message: `All required fields must be filled out. Missing: ${field.replace(/_/g, ' ')}`
|
||||
setAlert({
|
||||
show: true,
|
||||
message: `All required fields must be filled out. Missing: ${field.replace(/_/g, ' ')}`
|
||||
});
|
||||
setIsSubmitting(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (formField.credit_to === 'I' && !formField.credit_destination) {
|
||||
setAlert({
|
||||
show: true,
|
||||
message: 'Credit destination is required when Input Customer is selected'
|
||||
setAlert({
|
||||
show: true,
|
||||
message: 'Credit destination is required when Input Customer is selected'
|
||||
});
|
||||
setIsSubmitting(false);
|
||||
return;
|
||||
}
|
||||
|
||||
setAlert({ show: false, message: '' });
|
||||
|
||||
|
||||
const payload = { ...formField };
|
||||
|
||||
|
||||
if (formField.credit_to !== 'I') {
|
||||
payload.credit_destination = '00000000-0000-0000-0000-000000000000';
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
const response = await PostData(`${API_URL}/transactionfees/create`, payload);
|
||||
|
||||
|
||||
if (response?.status) {
|
||||
toast.success('Successfully created transfer fee');
|
||||
reload();
|
||||
resetForm();
|
||||
handleAddFeeDialog(false);
|
||||
|
||||
|
||||
const createActivity = {
|
||||
module: 'Manage Transfer Fee',
|
||||
description: `Create Transfer Fee => ${formField.name}`,
|
||||
@ -323,18 +326,14 @@ const AddFeeDialog = () => {
|
||||
);
|
||||
|
||||
const renderSelectWithLoading = (
|
||||
value: string,
|
||||
value: string,
|
||||
onChangeHandler: (value: string) => void,
|
||||
options: {id: string, name: string}[] | null,
|
||||
options: { id: string; name: string }[] | null,
|
||||
placeholder: string,
|
||||
isLoading: boolean
|
||||
) => {
|
||||
return (
|
||||
<Select
|
||||
value={value}
|
||||
onValueChange={onChangeHandler}
|
||||
disabled={isLoading}
|
||||
>
|
||||
<Select value={value} onValueChange={onChangeHandler} disabled={isLoading}>
|
||||
<SelectTrigger>
|
||||
{isLoading ? (
|
||||
<div className="flex items-center">
|
||||
@ -346,11 +345,12 @@ const AddFeeDialog = () => {
|
||||
)}
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{options && options.map((option) => (
|
||||
<SelectItem value={option.id} key={option.id}>
|
||||
{option.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
{options &&
|
||||
options.map((option) => (
|
||||
<SelectItem value={option.id} key={option.id}>
|
||||
{option.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
);
|
||||
@ -389,7 +389,9 @@ const AddFeeDialog = () => {
|
||||
<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>
|
||||
<label className="form-label">
|
||||
Transaction Type ID <span className="text-red-500">*</span>
|
||||
</label>
|
||||
{transactionTypeId ? (
|
||||
<div className="relative">
|
||||
<Input
|
||||
@ -412,13 +414,15 @@ const AddFeeDialog = () => {
|
||||
formField.transaction_type,
|
||||
(transaction_type) => setFormField((prev) => ({ ...prev, transaction_type })),
|
||||
transactionTypes,
|
||||
"Select Transaction Type",
|
||||
'Select Transaction Type',
|
||||
isLoadingTransactionType
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Transfer Free Name <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Transfer Free Name <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Input
|
||||
className="input"
|
||||
type="text"
|
||||
@ -430,7 +434,9 @@ const AddFeeDialog = () => {
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Description <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Description <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Input
|
||||
className="input"
|
||||
type="text"
|
||||
@ -476,7 +482,9 @@ const AddFeeDialog = () => {
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Period Start <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Period Start <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Input
|
||||
className="input"
|
||||
type="date"
|
||||
@ -488,7 +496,9 @@ const AddFeeDialog = () => {
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Period End <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Period End <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Input
|
||||
className="input"
|
||||
type="date"
|
||||
@ -551,7 +561,9 @@ const AddFeeDialog = () => {
|
||||
/>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Deduct From <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Deduct From <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Select
|
||||
value={formField.deduct_from}
|
||||
onValueChange={(value) => setFormField({ ...formField, deduct_from: value })}
|
||||
@ -566,24 +578,31 @@ const AddFeeDialog = () => {
|
||||
</Select>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Deduct From Destination <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Deduct From Destination <span className="text-red-500">*</span>
|
||||
</label>
|
||||
{renderSelectWithLoading(
|
||||
formField.deduct_from_account,
|
||||
(value) => setFormField({ ...formField, deduct_from_account: value }),
|
||||
wallets,
|
||||
"Select Wallet",
|
||||
'Select Wallet',
|
||||
isLoadingWallets
|
||||
)}
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Credit To <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Credit To <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Select
|
||||
value={formField.credit_to}
|
||||
onValueChange={(value) => setFormField({
|
||||
...formField,
|
||||
credit_to: value,
|
||||
credit_destination: value === 'I' ? '' : '00000000-0000-0000-0000-000000000000'
|
||||
})}
|
||||
onValueChange={(value) =>
|
||||
setFormField({
|
||||
...formField,
|
||||
credit_to: value,
|
||||
credit_destination:
|
||||
value === 'I' ? '' : '00000000-0000-0000-0000-000000000000'
|
||||
})
|
||||
}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select Credit To" />
|
||||
@ -597,28 +616,34 @@ const AddFeeDialog = () => {
|
||||
</div>
|
||||
{formField.credit_to === 'I' && (
|
||||
<div className="w-full">
|
||||
<label className="form-label">Credit Destination <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Credit Destination <span className="text-red-500">*</span>
|
||||
</label>
|
||||
{renderSelectWithLoading(
|
||||
formField.credit_destination,
|
||||
(value) => setFormField({ ...formField, credit_destination: value }),
|
||||
customersWithNames,
|
||||
"Select Customer",
|
||||
isLoadingCustomers
|
||||
)}
|
||||
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>
|
||||
<label className="form-label">
|
||||
Credit Destination Account <span className="text-red-500">*</span>
|
||||
</label>
|
||||
{renderSelectWithLoading(
|
||||
formField.credit_destination_account,
|
||||
(value) => setFormField({ ...formField, credit_destination_account: value }),
|
||||
wallets,
|
||||
"Select Wallet",
|
||||
'Select Wallet',
|
||||
isLoadingWallets
|
||||
)}
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Status <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Status <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Select
|
||||
value={formField.status}
|
||||
onValueChange={(value) => setFormField({ ...formField, status: value })}
|
||||
@ -633,7 +658,9 @@ const AddFeeDialog = () => {
|
||||
</Select>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Status Include <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Status Include <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Select
|
||||
value={formField.status_include}
|
||||
onValueChange={(value) => setFormField({ ...formField, status_include: value })}
|
||||
@ -648,7 +675,9 @@ const AddFeeDialog = () => {
|
||||
</Select>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<label className="form-label">Priority <span className="text-red-500">*</span></label>
|
||||
<label className="form-label">
|
||||
Priority <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<Select
|
||||
value={formField.priority}
|
||||
onValueChange={(value) => setFormField({ ...formField, priority: value })}
|
||||
@ -672,10 +701,15 @@ const AddFeeDialog = () => {
|
||||
>
|
||||
Reset
|
||||
</Button>
|
||||
<Button
|
||||
variant={'default'}
|
||||
type="submit"
|
||||
disabled={isSubmitting || isLoadingTransactionType || isLoadingWallets || isLoadingCustomers}
|
||||
<Button
|
||||
variant={'default'}
|
||||
type="submit"
|
||||
disabled={
|
||||
isSubmitting ||
|
||||
isLoadingTransactionType ||
|
||||
isLoadingWallets ||
|
||||
isLoadingCustomers
|
||||
}
|
||||
>
|
||||
{isSubmitting ? 'Saving...' : 'Save Changes'}
|
||||
</Button>
|
||||
@ -689,4 +723,4 @@ const AddFeeDialog = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export default AddFeeDialog;
|
||||
export default AddFeeDialog;
|
||||
|
||||
Reference in New Issue
Block a user