import React, {useEffect, useState} from 'react' import { Link, useNavigate } from 'react-router-dom' import RecentActivityTable from './WalletComponent/RecentActivityTable' import LoadingSpinner from '../Spinners/LoadingSpinner' import InputCom from '../Helpers/Inputs/InputCom' import usersService from '../../services/UsersService' import {toast} from 'react-toastify' import {Formik, Form} 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 TransferFund({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) => { 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-transfer', {state: stateData}) }, 1000) } useEffect(()=>{ getRecipients() },[]) return (
Activity Report
{payment.loading ?