diff --git a/src/pages/transfer/transferfee/blocks/AddDialog.tsx b/src/pages/transfer/transferfee/blocks/AddDialog.tsx index f6a736e..13469dc 100644 --- a/src/pages/transfer/transferfee/blocks/AddDialog.tsx +++ b/src/pages/transfer/transferfee/blocks/AddDialog.tsx @@ -90,6 +90,10 @@ const AddFeeDialog = () => { id: customer.id, name: customer.username })); + + const [openDeductOrigin, setOpenDeductOrigin] = useState(false); + const [openCreditDestination, setOpenCreditDestination] = useState(false); + const [errors, setErrors] = useState>({}); const initialState = { name: '', @@ -120,6 +124,16 @@ const AddFeeDialog = () => { setTransactionTypeName(''); }; + const handleCloseDialog = () => { + setFormField(initialState); + setAlert({ show: false, message: '' }); + setCustomerSearchTerm(''); + setOpenCreditDestination(false); + setOpenDeductOrigin(false); + setOpen(false); + handleEditFeeDialog(false, null); + }; + const [isSubmitting, setIsSubmitting] = useState(false); const [showTransactionFeeDialog, setShowTransactionFeeDialog] = useState(false); const parsedUser = getAuth()?.user; @@ -376,7 +390,15 @@ const AddFeeDialog = () => { }; return ( - handleAddFeeDialog(open)}> + { + if (!open) { + handleAddFeeDialog(open); + handleCloseDialog(); + } + }} + > @@ -595,16 +617,15 @@ const AddFeeDialog = () => {
setOpen(!open)} + onClick={() => setOpenDeductOrigin(!openDeductOrigin)} > {customers.find((customer) => customer.id === formField.deduct_origin) ?.username || 'Search customer...'} -
- {open && ( + {openDeductOrigin && (
{ key={customer.id} className="cursor-pointer px-3 py-1.5 text-sm hover:bg-gray-100" onClick={() => { - setFormField({ - ...formField, - deduct_origin: customer.id - }); - setOpen(false); + setFormField({ ...formField, deduct_origin: customer.id }); + setOpenDeductOrigin(false); }} > {customer.username} @@ -706,17 +724,16 @@ const AddFeeDialog = () => {
setOpen(!open)} + onClick={() => setOpenCreditDestination(!openCreditDestination)} > {customers.find( (customer) => customer.id === formField.credit_destination )?.username || 'Search customer...'} -
- {open && ( + {openCreditDestination && (
{ ...formField, credit_destination: customer.id }); - setOpen(false); + setOpenCreditDestination(false); }} > {customer.username} diff --git a/src/pages/transfer/transferfee/blocks/EditDialog.tsx b/src/pages/transfer/transferfee/blocks/EditDialog.tsx index 1999404..eef2dca 100644 --- a/src/pages/transfer/transferfee/blocks/EditDialog.tsx +++ b/src/pages/transfer/transferfee/blocks/EditDialog.tsx @@ -1,4 +1,3 @@ - import { useCallback, useEffect, useRef, useState } from 'react'; import { NumericFormat } from 'react-number-format'; import { @@ -62,6 +61,8 @@ const EditFeeDialog = () => { const { reload } = useDataGrid(); const { GetData, PutData } = useCallApi(); const parsedUser = getAuth()?.user; + const [openDeductOrigin, setOpenDeductOrigin] = useState(false); + const [openCreditDestination, setOpenCreditDestination] = useState(false); const [wallets, setWallets] = useState([]); const [customers, setCustomers] = useState([]); @@ -326,7 +327,8 @@ const EditFeeDialog = () => { status_include: response.data.status_include || '', deduct_from: response.data.deduct_from || '', deduct_from_account: response.data.deduct_from_account?.id || '', - deduct_origin: response.data.deduct_origin?.id || '00000000-0000-0000-0000-000000000000', + deduct_origin: + response.data.deduct_origin?.id || '00000000-0000-0000-0000-000000000000', credit_to: response.data.credit_to || '', credit_destination: response.data.credit_destination?.id || '00000000-0000-0000-0000-000000000000', @@ -361,22 +363,24 @@ const EditFeeDialog = () => { hasFetchedRef.current = false; } }, [selectedTransferFee, showEditFeeDialog, fetchTransactionFee]); - + const handleCloseDialog = () => { setFormField(initialState); setAlert({ show: false, message: '' }); setCustomerSearchTerm(''); + setOpenCreditDestination(false); + setOpenDeductOrigin(false); setOpen(false); handleEditFeeDialog(false, null); }; - + useEffect(() => { if (!showEditFeeDialog) { setCustomerSearchTerm(''); setOpen(false); } }, [showEditFeeDialog]); - + const renderSelectWithLoading = ( value: string, onChangeHandler: (value: string) => void, @@ -645,78 +649,68 @@ const EditFeeDialog = () => {
- {formField.deduct_from === 'I' && ( -
- -
-
setOpen(!open)} - > - - {customers.find((customer) => customer.id === formField.deduct_origin) - ?.username || 'Search customer...'} - - -
+{formField.deduct_from === 'I' && ( +
+ +
+
setOpenDeductOrigin(!openDeductOrigin)} + > + + {customers.find((customer) => customer.id === formField.deduct_origin)?.username || 'Search customer...'} + +
+ + {openDeductOrigin && ( +
+
+ setCustomerSearchTerm(e.target.value)} + autoComplete="off" + onClick={(e) => e.stopPropagation()} + autoFocus + /> +
+
+ {customers + .filter( + (customer) => + customer.username.toLowerCase().includes(customerSearchTerm.toLowerCase()) || + customer.msisdn.includes(customerSearchTerm) + ) + .map((customer) => ( +
{ + setFormField({ ...formField, deduct_origin: customer.id }); + setOpenDeductOrigin(false); + }} + > + {customer.username} +
+ ))} + {customers.filter( + (customer) => + customer.username.toLowerCase().includes(customerSearchTerm.toLowerCase()) || + customer.msisdn.includes(customerSearchTerm) + ).length === 0 && ( +
No customer found
+ )} +
+
+ )} +
+
+)} - {open && ( -
-
- setCustomerSearchTerm(e.target.value)} - autoComplete="off" - onClick={(e) => e.stopPropagation()} - autoFocus - /> -
-
- {customers - .filter( - (customer) => - customer.username - .toLowerCase() - .includes(customerSearchTerm.toLowerCase()) || - customer.msisdn.includes(customerSearchTerm) - ) - .map((customer) => ( -
{ - setFormField({ - ...formField, - deduct_origin: customer.id - }); - setOpen(false); - }} - > - {customer.username} -
- ))} - {customers.filter( - (customer) => - customer.username - .toLowerCase() - .includes(customerSearchTerm.toLowerCase()) || - customer.msisdn.includes(customerSearchTerm) - ).length === 0 && ( -
- No customer found -
- )} -
-
- )} -
-
- )}
- {formField.credit_to === 'I' && ( -
- -
-
setOpen(!open)} - > - - {customers.find( - (customer) => customer.id === formField.credit_destination - )?.username || 'Search customer...'} - - -
+{formField.credit_to === 'I' && ( +
+ +
+
setOpenCreditDestination(!openCreditDestination)} + > + + {customers.find((customer) => customer.id === formField.credit_destination) + ?.username || 'Search customer...'} + +
+ + {openCreditDestination && ( +
+
+ setCustomerSearchTerm(e.target.value)} + autoComplete="off" + onClick={(e) => e.stopPropagation()} + autoFocus + /> +
+
+ {customers + .filter( + (customer) => + customer.username + .toLowerCase() + .includes(customerSearchTerm.toLowerCase()) || + customer.msisdn.includes(customerSearchTerm) + ) + .map((customer) => ( +
{ + setFormField({ + ...formField, + credit_destination: customer.id + }); + setOpenCreditDestination(false); + }} + > + {customer.username} +
+ ))} + {customers.filter( + (customer) => + customer.username + .toLowerCase() + .includes(customerSearchTerm.toLowerCase()) || + customer.msisdn.includes(customerSearchTerm) + ).length === 0 && ( +
No customer found
+ )} +
+
+ )} +
+
+)} - {open && ( -
-
- setCustomerSearchTerm(e.target.value)} - autoComplete="off" - onClick={(e) => e.stopPropagation()} - autoFocus - /> -
-
- {customers - .filter( - (customer) => - customer.username - .toLowerCase() - .includes(customerSearchTerm.toLowerCase()) || - customer.msisdn.includes(customerSearchTerm) - ) - .map((customer) => ( -
{ - setFormField({ - ...formField, - credit_destination: customer.id - }); - setOpen(false); - }} - > - {customer.username} -
- ))} - {customers.filter( - (customer) => - customer.username - .toLowerCase() - .includes(customerSearchTerm.toLowerCase()) || - customer.msisdn.includes(customerSearchTerm) - ).length === 0 && ( -
- No customer found -
- )} -
-
- )} -
-
- )}