add resetform + change customer title

This commit is contained in:
bagusajisaputroo
2025-03-24 15:27:02 +07:00
parent 6fc67b0b2d
commit 2960ed2b8e
7 changed files with 62 additions and 45 deletions

View File

@ -109,7 +109,6 @@ const AddFeeDialog = () => {
status: formField.status,
status_include: formField.status_include
};
console.log(payload);
};
useEffect(() => {
const created_time = new Date();
@ -137,8 +136,6 @@ const AddFeeDialog = () => {
order_field: sorting[0].id,
order_direction: sorting[0].desc ? 'DESC' : 'ASC'
});
console.log('TRANSACTION TYPE LIST: ', response?.data?.list);
setTransactionTypes(response?.data.list || []);
} catch (error) {
console.error('Error fetching customer', error);
@ -151,7 +148,6 @@ const AddFeeDialog = () => {
const doCreateTransferType = useCallback(
async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
console.log(formField);
for (const key in formField) {
if (
formField[key as keyof typeof formField] === '' ||
@ -167,7 +163,6 @@ const AddFeeDialog = () => {
...formField,
priority: formField.priority ? 'Y' : 'N'
});
// console.log("coba coba:",response);
if (response?.status) {
toast.success('Success Create Transfer Fee');
@ -177,7 +172,6 @@ const AddFeeDialog = () => {
} else {
setAlert({ show: true, message: response?.message || 'Failed to create transfer fee' });
}
console.log(response);
},
[formField]
);
@ -190,7 +184,7 @@ const AddFeeDialog = () => {
<DialogHeader className="p-5 border-0">
<div className="flex items-center justify-between flex-wrap grow">
<div className="flex flex-col justify-center">
<h1 className="text-xl font-semibold leading-none text-gray-900">AddTransfer Fee</h1>
<h1 className="text-xl font-semibold leading-none text-gray-900">Add Transfer Fee</h1>
</div>
<div
className="cursor-pointer hover:opacity-100 opacity-50"
@ -392,7 +386,13 @@ const AddFeeDialog = () => {
</Select>
</div>
<div className="flex justify-end pt-2.5 gap-5">
<Button variant={'outline'} type="reset">
<Button
variant={'outline'}
type="reset"
onClick={() => {
resetForm();
}}
>
Reset
</Button>
<Button variant={'default'} type="submit" disabled={isSubmitting}>

View File

@ -26,7 +26,6 @@ const DeleteDialog = () => {
});
const doDeleteTransferFee = useCallback(async () => {
console.log("Selected Transfer Fee:", selectedTransferFee, "Type:", typeof selectedTransferFee);
const response = await DeleteData(`${API_URL}/transactionfees/delete/${selectedTransferFee}/${enforce}`, {
id: selectedTransferFee
});
@ -42,7 +41,6 @@ const DeleteDialog = () => {
}
}, [selectedTransferFee, enforce]);
// console.log(selectedTransferFee);
return (
<Dialog open={showDeleteFeeDialog} onOpenChange={(open) => handleDeleteFeeDialog(open, null)}>

View File

@ -105,7 +105,6 @@ const EditFeeDialog = () => {
} else {
setAlert((prev) => ({ ...prev, show: true, message: response?.message }));
}
console.log(formField);
},
[formField, selectedTransferFee]
);
@ -145,10 +144,6 @@ const EditFeeDialog = () => {
order_field: sorting[0].id,
order_direction: sorting[0].desc ? 'DESC' : 'ASC'
});
// 🟡 Log daftar pelanggan saja (kalau respons pakai struktur {data: {list: [...]}})
console.log('CUSTOMER LIST: ', response?.data?.list);
setCustomers(response?.data.list || []);
} catch (error) {
console.error('Error fetching customer', error);
@ -170,10 +165,6 @@ const EditFeeDialog = () => {
order_field: sorting[0].id,
order_direction: sorting[0].desc ? 'DESC' : 'ASC'
});
// 🟡 Log daftar pelanggan saja (kalau respons pakai struktur {data: {list: [...]}})
console.log('TRANSACTION TYPE LIST: ', response?.data?.list);
setTransactionTypes(response?.data.list || []);
} catch (error) {
console.error('Error fetching customer', error);
@ -185,7 +176,6 @@ const EditFeeDialog = () => {
const fetchTransactionFee = useCallback(async (id: string) => {
const response = await GetData(`${API_URL}/transactionfees/getdata/${id}`, { id });
// console.log("API Response:", response);
if (response?.status) {
setFormField((prev) => ({
@ -230,6 +220,24 @@ const EditFeeDialog = () => {
fetchTransactionFee(selectedTransferFee);
}
}, [selectedTransferFee]);
const resetForm = () => {
setFormField({
name: '',
description: '',
minimum_amount: 0,
maximum_amount: 0,
period_start: '',
period_end: '',
deduct_amount: 0,
deduct_percentage: 0,
priority: '',
status: '',
status_include: '',
transaction_type: '',
updated_by: '',
updated_at: ''
});
};
return (
<Dialog open={showEditFeeDialog} onOpenChange={(open) => handleEditFeeDialog(open, null)}>
@ -479,7 +487,10 @@ const EditFeeDialog = () => {
</Select>
</div> */}
<div className="flex justify-end pt-2.5 gap-5">
<Button variant={'outline'} type="reset">
<Button variant={'outline'} type="reset"
onClick={() => {
resetForm();
}}>
Reset
</Button>
<Button variant={'default'} type="submit" disabled={isSubmitting}>

View File

@ -68,9 +68,6 @@ const ManageTransferFeeContextProvider = ({ children }: { children: React.ReactN
order_direction: sorting[0].desc ? 'ASC' : 'DESC',
filter: JSON.stringify(filter)
});
console.log('hasilnya', response?.data.list);
console.log('transactiontype', response?.data);
return { data: response?.data.list, totalCount: response?.data.total_count };
};
const columns = useMemo<ColumnDef<any>[]>(

View File

@ -127,8 +127,6 @@ const AddDialog = () => {
order_field: sorting[0].id,
order_direction: sorting[0].desc ? 'DESC' : 'ASC'
});
console.log('CUSTOMER LIST: ', response?.data?.list);
setCustomers(response?.data.list || []);
} catch (error) {
console.error('Error fetching customer', error);
@ -155,7 +153,6 @@ const AddDialog = () => {
} else {
setWallets([]);
}
console.log('WALLET LIST: ', response?.data?.list);
}, []);
useEffect(() => {
@ -166,7 +163,6 @@ const AddDialog = () => {
const doCreateTransferType = useCallback(
async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
console.log(formField);
for (const key in formField) {
if (
formField[key as keyof typeof formField] === '' ||
@ -187,8 +183,6 @@ const AddDialog = () => {
toast.success('Success Create Transfer Type');
reload();
resetForm();
console.log('Berhasil nih, isinya gini:', formField);
} else {
setAlert({ show: true, message: response?.message || 'Failed to create transfer type' });
}
@ -205,7 +199,7 @@ const AddDialog = () => {
<DialogDescription></DialogDescription>
<div className="flex items-center justify-between flex-wrap grow">
<div className="flex flex-col justify-center">
<h1 className="text-xl font-semibold leading-none text-gray-900">Transaction Type</h1>
<h1 className="text-xl font-semibold leading-none text-gray-900">Addd Transaction Type</h1>
<div className="flex items-center gap-2 text-sm font-normal text-gray-700"></div>
</div>
<div
@ -401,7 +395,7 @@ const AddDialog = () => {
</div>
<div className="w-full">
<div className="flex items-center flex-wrap gap-2.5">
<label className="form-label max-w-56">Customer Fee Destination</label>
<label className="form-label max-w-56">Customer</label>
<div className="grow">
<Select
value={formField.customer_fee_destination}
@ -410,7 +404,7 @@ const AddDialog = () => {
}
>
<SelectTrigger>
<SelectValue placeholder="Select Wallet" />
<SelectValue placeholder="Select Customer" />
</SelectTrigger>
<SelectContent>
{customers.map((customer, idx) => (
@ -471,7 +465,13 @@ const AddDialog = () => {
</div>
<div className="flex justify-end pt-2.5 gap-5">
<Button variant={'outline'} type="reset">
<Button
variant={'outline'}
type="reset"
onClick={() => {
resetForm();
}}
>
Reset
</Button>
<Button variant={'default'} type="submit" disabled={isSubmitting}>

View File

@ -47,7 +47,6 @@ const DeleteDialog = () => {
}
}, [selectedTransferType, enforce, DeleteData, handleDeleteDialog, reload]);
// console.log(selectedTransferType);
return (
<Dialog open={showDeleteDialog} onOpenChange={(open) => handleDeleteDialog(open, null)}>

View File

@ -72,7 +72,21 @@ const EditDialog = () => {
message: ''
});
const resetForm = () => {
setFormField(formField);
setFormField({
name: '',
description: '',
wallet_origin: '',
wallet_destination: '',
wallet_fee_destination: '',
customer_fee_destination: '',
minimum_amount: 0,
maximum_amount: 0,
max_transaction_per_day: 0,
status_approval: '',
status: '',
updated_by: '',
updated_at: ''
});
};
const [formField, setFormField] = useState({
name: '',
@ -115,7 +129,6 @@ const EditDialog = () => {
} else {
setAlert((prev) => ({ ...prev, show: true, message: response?.message }));
}
// console.log(formField);
},
[formField, selectedTransferType]
);
@ -130,7 +143,6 @@ const EditDialog = () => {
order_field: sorting[0].id,
order_direction: sorting[0].desc ? 'DESC' : 'ASC'
});
// console.log('CUSTOMER LIST: ', response?.data?.list);
setCustomers(response?.data.list || []);
} catch (error) {
@ -165,11 +177,9 @@ const EditDialog = () => {
const fetchTransactionType = useCallback(async (id: string) => {
const response = await GetData(`${API_URL}/transactiontype/getdata/${id}`, { id });
// console.log("API Response:", response);
if (response?.status) {
const data = response.data;
console.log('Fetched customer_fee_destination:', response.data);
setFormField((prev) => ({
...prev,
name: response.data.name,
@ -209,8 +219,7 @@ const EditDialog = () => {
fetchTransactionType(selectedTransferType);
}
}, [selectedTransferType]);
// console.log('Form Field Data: ', formField);
// console.log('customer list:', customers);
return (
<Dialog open={showEditDialog} onOpenChange={(open) => handleEditDialog(open, null)}>
<DialogContent className="container-fixed max-w-[1080px] flex flex-col p-5 overflow-hidden [&>button]:hidden">
@ -417,7 +426,7 @@ const EditDialog = () => {
</div>
<div className="w-full">
<div className="flex items-center flex-wrap gap-2.5">
<label className="form-label max-w-56">Customer Fee Destination</label>
<label className="form-label max-w-56">Select Customer</label>
<div className="grow">
<Select
value={formField.customer_fee_destination}
@ -426,7 +435,7 @@ const EditDialog = () => {
}
>
<SelectTrigger>
<SelectValue placeholder="Select Wallet" />
<SelectValue placeholder="Select" />
</SelectTrigger>
<SelectContent>
{customers.map((customer, idx) => (
@ -497,7 +506,10 @@ const EditDialog = () => {
Transaction Fee Form
</Button> */}
<Button variant={'outline'} type="reset">
<Button variant={'outline'} type="reset"
onClick={() => {
resetForm();
}}>
Reset
</Button>
<Button variant={'default'} type="submit" disabled={isSubmitting}>