From d75b6ee26c07db6855563994eb9b90ab29dc74cf Mon Sep 17 00:00:00 2001 From: victorAnumudu Date: Mon, 17 Jul 2023 11:03:27 +0100 Subject: [PATCH 1/2] made withdrawal a pop up --- .../MyWallet/ConfirmNairaWithdraw.jsx | 67 ++-- src/components/MyWallet/NairaWithdraw.jsx | 337 ------------------ .../MyWallet/Popup/NairaWithdraw.jsx | 322 +++++++++++++++++ src/components/MyWallet/Wallet.jsx | 112 ++---- src/components/MyWallet/WalletAction.jsx | 24 +- src/components/MyWallet/WalletBox.jsx | 2 +- 6 files changed, 396 insertions(+), 468 deletions(-) delete mode 100644 src/components/MyWallet/NairaWithdraw.jsx create mode 100644 src/components/MyWallet/Popup/NairaWithdraw.jsx diff --git a/src/components/MyWallet/ConfirmNairaWithdraw.jsx b/src/components/MyWallet/ConfirmNairaWithdraw.jsx index 30c8210..e7f8b9e 100644 --- a/src/components/MyWallet/ConfirmNairaWithdraw.jsx +++ b/src/components/MyWallet/ConfirmNairaWithdraw.jsx @@ -3,17 +3,15 @@ import { useLocation, useNavigate } from "react-router-dom"; import { toast } from "react-toastify"; import InputCom from "../Helpers/Inputs/InputCom"; import LoadingSpinner from "../Spinners/LoadingSpinner"; -import RecentActivityTable from "./WalletComponent/RecentActivityTable"; +import ModalCom from "../Helpers/ModalCom"; import usersService from "../../services/UsersService"; -function ConfirmNairaWithdraw({ payment, wallet }) { +function ConfirmNairaWithdraw({ payment, wallet, action, situation, state }) { const apiURL = new usersService(); const navigate = useNavigate(); - let { state } = useLocation(); - let [requestStatus, setRequestStatus] = useState({ message: "", loading: false, @@ -69,34 +67,16 @@ function ConfirmNairaWithdraw({ payment, wallet }) { } }, []); return ( -
- {pageLoading ? ( - - ) : ( -
+ +
+
- {wallet.loading ? ( - - ) : wallet.data.length ? ( -

- {wallet.data.map((item) => { - if (item.description == "Naira") { - return `Withdraw from Naira Wallet : ${item.symbol}${( - item.amount * 0.01 - ).toFixed(2)}`; - } - })} -

- ) : wallet.error ? ( -

- Opps! An Error Occured -

- ) : ( -

- No Wallet Information Found! -

- )} +

+ {`Withdraw from ${wallet.description} Wallet : ${wallet.symbol}${( + wallet.amount * 0.01 + ).toFixed(2)}`} +


@@ -174,13 +154,20 @@ function ConfirmNairaWithdraw({ payment, wallet }) { {requestStatus.message}

)} -
+
+ {requestStatus.loading ? ( ) : ( @@ -188,22 +175,8 @@ function ConfirmNairaWithdraw({ payment, wallet }) {
- )} - -
-
-

- Recent Activity -

- {/*

Activity Report

*/} - {payment.loading ? ( - - ) : ( - - )} -
-
+ ); } diff --git a/src/components/MyWallet/NairaWithdraw.jsx b/src/components/MyWallet/NairaWithdraw.jsx deleted file mode 100644 index b9b768c..0000000 --- a/src/components/MyWallet/NairaWithdraw.jsx +++ /dev/null @@ -1,337 +0,0 @@ -import React, { useEffect, useState } from "react"; -import { Link, useNavigate } from "react-router-dom"; -import InputCom from "../Helpers/Inputs/InputCom"; -import LoadingSpinner from "../Spinners/LoadingSpinner"; -import RecentActivityTable from "./WalletComponent/RecentActivityTable"; - -import usersService from "../../services/UsersService"; - -import { Form, Formik } from "formik"; -import * as Yup from "yup"; - -const validationSchema = Yup.object().shape({ - amount: Yup.number() - .typeError("you must specify a number") - .min(1, "Amount must be greater than 0") - .required("Amount is required"), - recipientID: Yup.string() - .min(1, "Minimum 1 characters") - .max(50, "Maximum 50 characters") - .required("Recipient is required"), -}); - -const initialValues = { - amount: "", - recipientID: "", - comment: "", -}; - -function NairaWithdraw({ payment, wallet }) { - const apiCall = new usersService(); // API CLASS CALL - - const navigate = useNavigate(); - - let [requestStatus, setRequestStatus] = useState(false); - - let [recipients, setRecipients] = useState({ - // FOR COUPON HISTORY - loading: true, - data: [], - error: false, - }); - - let [sendMoneyFee, setSendMoneyFee] = useState({ - loading: false, - fee: 0, - total: 0, - }); // HOLD THE VALUE FOR SEND MONEY FEE - - //FUNCTION TO GET RECIPIENT LIST - const getRecipients = () => { - apiCall - .getRecipient() - .then((res) => { - if (res.data.internal_return < 0) { - // success but no data - setRecipients((prev) => ({ ...prev, loading: false })); - return; - } - setRecipients((prev) => ({ - ...prev, - loading: false, - data: res.data.result_list, - })); - }) - .catch((error) => { - setRecipients((prev) => ({ ...prev, loading: false, error: true })); - }); - }; - - //FUNCTION TO GET SEND MONEY FEE - const getSendMoneyFee = ({ target: { value } }) => { - setSendMoneyFee({ loading: true, fee: 0, total: 0 }); - let amount = value; - if (Number(amount) <= 0 || amount == "" || isNaN(amount)) { - setSendMoneyFee({ loading: false, fee: 0, total: 0 }); - return; - } - apiCall - .getSendMoneyFee(Number(amount)) - .then((res) => { - setSendMoneyFee({ - loading: false, - fee: res.data.processing_fee, - total: res.data.total_amount, - }); - }) - .catch((error) => { - setSendMoneyFee({ loading: false, fee: 0, total: 0 }); - }); - }; - - //FUNCTION TO HANDLE SUBMIT - const handleSubmit = (values, helpers) => { - if(!values?.amount && !values.recipientID) return - setRequestStatus(true); - let recipientDetails = recipients.data?.filter( - (item) => item.recipient_id == values.recipientID - ); - let stateData = { - ...values, - ...sendMoneyFee, - details: { ...recipientDetails[0] }, - }; - - setTimeout(() => { - setRequestStatus(false); - navigate("confirm-withdraw-naira", { state: stateData }); - }, 1000); - }; - - useEffect(() => { - getRecipients(); - }, []); - - return ( -
-
-
- - {(props) => { - return ( -
- {wallet.loading ? ( - - ) : wallet.data.length ? ( -

- {wallet.data.map((item) => { - if (item.description == "Naira") { - return `Withdraw from Naira Wallet : ${item.symbol}${( - item.amount * 0.01 - ).toFixed(2)}`; - } - })} -

- ) : wallet.error ? ( -

- Opps! An Error Occurred -

- ) : ( -

- No Wallet Information Found! -

- )} -
-
- { - getSendMoneyFee(e); - }} - // props.handleBlur - // onMouseLeave={(e)=>{getSendMoneyFee(e)}} - /> - {props.errors.amount && props.touched.amount && ( -

- {props.errors.amount} -

- )} -
- -
- -
- -
- -
-
- -
-
-
- -
- -
- {props.errors.recipientID && - props.touched.recipientID && ( -

- {props.errors.recipientID} -

- )} - - Add New - -
-
-
-
-
- -
- -