diff --git a/src/components/MyWallet/Popup/ConfirmNairaWithdraw.jsx b/src/components/MyWallet/Popup/ConfirmNairaWithdraw.jsx index 8f713b0..b483cfe 100644 --- a/src/components/MyWallet/Popup/ConfirmNairaWithdraw.jsx +++ b/src/components/MyWallet/Popup/ConfirmNairaWithdraw.jsx @@ -4,12 +4,10 @@ import { toast } from "react-toastify"; import InputCom from "../../Helpers/Inputs/InputCom"; import ModalCom from "../../Helpers/ModalCom"; import LoadingSpinner from "../../Spinners/LoadingSpinner"; - import usersService from "../../../services/UsersService"; function ConfirmNairaWithdraw({ payment, wallet, action, situation, state }) { const apiURL = new usersService(); - const navigate = useNavigate(); let [requestStatus, setRequestStatus] = useState({ @@ -25,19 +23,35 @@ function ConfirmNairaWithdraw({ payment, wallet, action, situation, state }) { let reqData = { amount: Number(state.amount * 100), Fee: Number(state.fee), - recipient_uid: Number(state.details?.recipient_uid), + recipient_uid: state.details?.recipient_uid, wallet_uid: wallet.wallet_uid, }; apiURL .sendMoney(reqData) .then((res) => { if (res.data.internal_return < 0) { - setRequestStatus({ - message: "Could not perform transaction", - loading: false, - status: false, - }); - return; + if (res.data?.status_message?.toLowerCase().includes("limit")) { + setRequestStatus({ + message: "You have exceeded the transfer limit", + loading: false, + status: false, + }); + } else { + setRequestStatus({ + message: "Could not perform transaction", + loading: false, + status: false, + }); + } + return setTimeout( + () => + setRequestStatus({ + message: "", + loading: false, + status: false, + }), + 1500 + ); } setRequestStatus({ message: "transfer successful", @@ -59,7 +73,7 @@ function ConfirmNairaWithdraw({ payment, wallet, action, situation, state }) { }); }; - console.log(state) + console.log(state); return ( diff --git a/src/components/MyWallet/Popup/NairaWithdraw.jsx b/src/components/MyWallet/Popup/NairaWithdraw.jsx index 49cc3f8..361fd7a 100644 --- a/src/components/MyWallet/Popup/NairaWithdraw.jsx +++ b/src/components/MyWallet/Popup/NairaWithdraw.jsx @@ -1,6 +1,7 @@ import { Form, Formik } from "formik"; import React, { useEffect, useState } from "react"; import { useNavigate } from "react-router-dom"; +import { checkAndSetError } from "../../../lib"; import usersService from "../../../services/UsersService"; import InputCom from "../../Helpers/Inputs/InputCom"; import ModalCom from "../../Helpers/ModalCom"; @@ -33,6 +34,7 @@ function NairaWithdraw({ const [tab, setTab] = useState("previous"); let [requestStatus, setRequestStatus] = useState(false); const [errorMsgs, setErrorMsgs] = useState(initialValues); + const { isNotEmpty, textCount } = checkAndSetError(); let [sendMoneyFee, setSendMoneyFee] = useState({ loading: false, @@ -210,12 +212,13 @@ function NairaWithdraw({ const stateData = { amount: values.amount, comment: values.comment, - wallet_uid: wallet.wallet_uid, + choice: "prev", + wallet_uid: wallet.wallet_uid, ...sendMoneyFee, details: { ...recipientDetails[0] }, }; - setTimeout(() => { + return setTimeout(() => { setRequestStatus(false); // navigate("confirm-withdraw-naira", { state: stateData }); action(); @@ -226,6 +229,71 @@ function NairaWithdraw({ if (tab === "new") { const { accountNumber, accountType, bank, city, country, state } = values?.newAccount; + + const isAccountNumberValid = isNotEmpty( + "accountNumber", + accountNumber, + setErrorMsgs, + "Please enter the account number" + ); + const isAccountTypeValid = isNotEmpty( + "accountType", + accountType, + setErrorMsgs, + "Please select an account type" + ); + const isBankValid = isNotEmpty( + "bank", + bank, + setErrorMsgs, + "Please enter the bank name" + ); + const isCityValid = isNotEmpty( + "city", + city, + setErrorMsgs, + "Please enter the city" + ); + const isCountryValid = isNotEmpty( + "country", + country, + setErrorMsgs, + "Please enter the country" + ); + const isStateValid = isNotEmpty( + "state", + state, + setErrorMsgs, + "Please enter the state" + ); + + if ( + !isAccountNumberValid || + !isAccountTypeValid || + !isBankValid || + !isCityValid || + !isCountryValid || + !isStateValid + ) { + return; + } + + setRequestStatus(true); + + const stateData = { + amount: values.amount, + comment: values.comment, + choice: "new", + wallet_uid: wallet.wallet_uid, + ...sendMoneyFee, + ...values?.newAccount, + }; + + return setTimeout(() => { + setRequestStatus(false); + action(); + setShowConfirmNairaWithdraw({ show: true, state: stateData }); + }, 1000); } } catch (errors) { // If validation fails, handle the validation errors @@ -301,12 +369,13 @@ function NairaWithdraw({ blurHandler={(e) => { getSendMoneyFee(e); }} + error={errorMsgs.amount && errorMsgs.amount} /> - {errorMsgs?.amount && ( + {/* {errorMsgs?.amount && (

- {errorMsgs.amount} +

- )} + )} */}
@@ -485,7 +554,7 @@ function NairaWithdraw({
-
+
)} @@ -506,9 +575,11 @@ function NairaWithdraw({ className="w-full text-base p-2 text-dark-gray dark:text-white border border-slate-300 outline-0 flex-[0.6] rounded-full h-[42px] overflow-hidden relative font-medium leading-6 bg-clip-padding" name="newAccount.country" value={props.values.newAccount?.country} - onChange={ - props.handleChange || handleBankOptions - } + onChange={(e) => { + props.handleChange(e); + handleBankOptions(e); + }} + // onBlur={(e) => handleBankOptions(e)} > {allCountries.loading ? (