diff --git a/src/components/MyWallet/AddRecipient.jsx b/src/components/MyWallet/AddRecipient.jsx index 0064eca..fbce09b 100644 --- a/src/components/MyWallet/AddRecipient.jsx +++ b/src/components/MyWallet/AddRecipient.jsx @@ -1,8 +1,26 @@ -import React, {useState} from 'react' +import React, {useEffect, useState} from 'react' import { Link } from 'react-router-dom' import Icons from '../Helpers/Icons' +import usersService from '../../services/UsersService' function AddRecipient() { + + const apiURL = new usersService() + + let [countries, setCountries] = useState({ // STATE TO HOLD LIST OF COUNTRIES + loading: true, + data: [] + }) + + let [bankName, setBankName] = useState({ // STATE TO HOLD LIST OF BANK NAME + loading: true, + data: [] + }) + + let [accountType, setAccountType] = useState({ // STATE TO HOLD LIST ACCOUNT TYPE + loading: true, + data: [] + }) //STATE FOR CONTROLLED INPUTS let [inputs, setInputs] = useState({ @@ -28,11 +46,7 @@ function AddRecipient() { //valid inputs before submitting. Just for texting remove later - // setInputs((prev)=>{ - // for(let input in prev){ - // prev[input] = '' - // } - // }) + // RETURN INPUTS TO EMPTY STRING setInputs({ firstname: '', @@ -46,6 +60,55 @@ function AddRecipient() { city: '' }) } + + // FUNCTION TO GET COUNTRIES + const getCountry = ()=> { + apiURL.getSignupCountryData().then((res)=>{ + if(res.data.internal_return < 0){ + setCountries(prev => ({loading: false, data: []})) + return + } + setCountries(prev => ({loading: false, data:res.data.signup_country})) + }).catch((error)=>{ + setCountries(prev => ({loading: false, data: []})) + }) + } + // END OF FUNCTION TO GET COUNTRIES + + // FUNCTION TO GET COUNTRY BANK + const getCountryBank = ()=> { + apiURL.getCountryBank().then((res)=>{ + if(res.data.internal_return < 0){ + setBankName(prev => ({loading: false, data: []})) + return + } + setBankName(prev => ({loading: false, data:res.data.result_list})) + }).catch((error)=>{ + setBankName(prev => ({loading: false, data: []})) + }) + } + // END OF FUNCTION TO GET COUNTRY BANK + + // FUNCTION TO GET ACCOUNT TYPES + const getAccountTypes = ()=> { + apiURL.getAccountTypes().then((res)=>{ + if(res.data.internal_return < 0){ + setAccountType(prev => ({loading: false, data: []})) + return + } + setAccountType(prev => ({loading: false, data:res.data.result_list})) + }).catch((error)=>{ + setAccountType(prev => ({loading: false, data: []})) + }) + } + // END OF FUNCTION TO GET ACCOUNT TYPES + + useEffect(()=>{ + getCountry() // TO LOAD LIST COUNTRY + getCountryBank() // TO LOAD LIST COUNTRY BANK + getAccountTypes() // TO LOAD LIST ACCOUNT TYPES + },[]) + return (
@@ -56,7 +119,7 @@ function AddRecipient() { {/* inputs starts here */}
- - - + {countries.loading ? + + : + countries.data.length ? + <> + + {countries.data.map((item, index)=>( + + ))} + + : + + }
- + {bankName.loading ? + + : + bankName.data.length ? + <> + + {bankName.data.map((item, index)=>( + + ))} + + : + + }
- - - + {accountType.loading ? + + : + accountType.data.length ? + <> + + {accountType.data.map((item, index)=>( + + ))} + + : + + }
- -