From aee720312511d3049fd41e3507252ac30b98693e Mon Sep 17 00:00:00 2001 From: Wikzyy Date: Tue, 25 Feb 2025 10:41:33 +0700 Subject: [PATCH] refactor: form access type --- .../access/access-type/blocks/AddDialog.tsx | 173 ++---------------- .../hooks/ManageAccessTypeContext.tsx | 30 +-- 2 files changed, 24 insertions(+), 179 deletions(-) diff --git a/src/pages/access/access-type/blocks/AddDialog.tsx b/src/pages/access/access-type/blocks/AddDialog.tsx index 19189e0..eaa6d16 100644 --- a/src/pages/access/access-type/blocks/AddDialog.tsx +++ b/src/pages/access/access-type/blocks/AddDialog.tsx @@ -21,22 +21,11 @@ import { } from '@/components/ui/select'; import { Button } from '@/components/ui/button'; -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; -} - const API_URL = apiConfig.service_dashboard; const AddDialog = () => { const parentRef = useRef(null); - const { showAddDialog, handleAddDialog, accounts } = useManageAccessTypeContext(); + const { showAddDialog, handleAddDialog, accessTypes } = useManageAccessTypeContext(); const { reload } = useDataGrid(); const { PostData, PutData } = useCallApi(); const [alert, setAlert] = useState({ @@ -45,14 +34,9 @@ const AddDialog = () => { }); const initialState = { - transfer_type_name: '', + name: '', description: '', - from_account: '', - to_account: '', - minimal_amount: 0, - maximum_amount: 0, - otp_threshold: 0, - maximum_transaction_perDay: 0 + internal_name: '' }; const [formField, setFormField] = useState(initialState); @@ -64,17 +48,11 @@ const AddDialog = () => { 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); + console.log(formField); + }; + + const handleReset = () => { + setFormField(initialState); }; return ( @@ -84,7 +62,7 @@ const AddDialog = () => {

- Create Transfer Type + Create Access Type

@@ -110,16 +88,14 @@ const AddDialog = () => {
- + - setFormField((prev) => ({ ...prev, transfer_type_name: target.value })) + setFormField((prev) => ({ ...prev, name: target.value })) } />
@@ -142,140 +118,25 @@ const AddDialog = () => {
-
-
- - -
- -
-
-
- -
-
- - -
- -
-
-
-
- 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) - })) + setFormField((prev) => ({ ...prev, internal_name: target.value })) } />
-