From c75f36f3ff2b480d81a4a733010b4b803d3e531d Mon Sep 17 00:00:00 2001 From: Wikzyy Date: Tue, 9 Sep 2025 18:12:36 +0700 Subject: [PATCH] update: add field transaction_type on products and remove on provider --- .../master/products/blocks/AddDialog.tsx | 141 +++- .../master/products/blocks/EditDialog.tsx | 758 ++++++++++-------- .../master/provider/blocks/AddDialog.tsx | 103 +-- .../master/provider/blocks/EditDialog.tsx | 110 +-- 4 files changed, 570 insertions(+), 542 deletions(-) diff --git a/src/pages/master/products/blocks/AddDialog.tsx b/src/pages/master/products/blocks/AddDialog.tsx index 12c53c2..18141db 100644 --- a/src/pages/master/products/blocks/AddDialog.tsx +++ b/src/pages/master/products/blocks/AddDialog.tsx @@ -31,7 +31,14 @@ interface ProviderProps { provider_name: string; } +interface TransactionProps { + id: string; + name: string; +} + const API_URL = apiConfig.service_master_data; +const API_URL_TRANSACTION = apiConfig.service_transaction; + const AddDialog = () => { const parentRef = useRef(null); const parsedUser = getAuth()?.user; @@ -53,6 +60,7 @@ const AddDialog = () => { cashback_cash: string | number | null; status: string; provider: string; + transaction_type: string; process_on_third_party: string; created_by: string; created_at: string; @@ -67,20 +75,24 @@ const AddDialog = () => { cashback_cash: null, status: '', provider: '', + transaction_type: '', process_on_third_party: '', created_by: '', created_at: '' }; const [formField, setFormField] = useState(initialState); const [providers, setProviders] = useState([]); + const [transactions, setTransactions] = useState([]); const [isSubmitting, setIsSubmitting] = useState(false); const created_time = new Date(); const formattedTime = created_time.toISOString().slice(0, 19).replace('T', ' '); const [errors, setErrors] = useState>({}); + const resetForm = () => { setFormField(initialState); setErrors({}); }; + const validateForm = () => { const requiredFields = [ { key: 'name', label: 'Name' }, @@ -93,6 +105,7 @@ const AddDialog = () => { { key: 'cashback_cash', label: 'Cashback Cash' }, { key: 'status', label: 'Status' }, { key: 'provider', label: 'Provider' }, + { key: 'transaction_type', label: 'Transaction Type' }, { key: 'process_on_third_party', label: 'Process On Third Party' } ]; const newErrors: Record = {}; @@ -146,6 +159,22 @@ const AddDialog = () => { [formField] ); + const getTransactionTypeList = async (sorting: any) => { + try { + const response = await GetData(`${API_URL_TRANSACTION}/transactiontype/list`, { + limit: 100, + page: 1, + with_deleted: false, + order_field: sorting[0].id, + order_direction: sorting[0].desc == false ? 'ASC' : 'DESC' + }); + + setTransactions(response?.data.list); + } catch (error) { + console.error('Error fetching transaction type', error); + } + }; + const doFetchProvider = useCallback(async (sorting: any) => { try { const response = await GetData(`${API_URL}/provider/list`, { @@ -178,8 +207,11 @@ const AddDialog = () => { }; useEffect(() => { - doFetchProvider([{ id: 'id', desc: false }]); - }, []); + if (showAddDialog) { + doFetchProvider([{ id: 'id', desc: false }]); + getTransactionTypeList([{ id: 'name', desc: false }]); + } + }, [showAddDialog]); useEffect(() => { if (showAddDialog) { @@ -199,7 +231,7 @@ const AddDialog = () => { return ( handleAddDialog(open)}> - + Product - Create @@ -215,13 +247,13 @@ const AddDialog = () => { )}
-
+
-