From b995c36a8e8b26596823b81375881ac4b4c6678c Mon Sep 17 00:00:00 2001 From: victorAnumudu Date: Thu, 17 Oct 2024 21:00:17 +0100 Subject: [PATCH 1/2] virtual card form country and state added --- .../FamilyAcc/Tabs/wallet/Wallet.jsx | 2 +- .../walletvirtual/VirtualAddCardPopout.jsx | 137 +++++++++++------- src/services/UsersService.js | 12 ++ 3 files changed, 100 insertions(+), 51 deletions(-) diff --git a/src/components/FamilyAcc/Tabs/wallet/Wallet.jsx b/src/components/FamilyAcc/Tabs/wallet/Wallet.jsx index 3b4f50d..9e3fe60 100644 --- a/src/components/FamilyAcc/Tabs/wallet/Wallet.jsx +++ b/src/components/FamilyAcc/Tabs/wallet/Wallet.jsx @@ -53,7 +53,7 @@ function Wallet({wallet, familyData, setFamilyWalletReload}) { name="plan" // onClick={onClose} > - Plan Wallet + Add Card diff --git a/src/components/MyWallet/walletvirtual/VirtualAddCardPopout.jsx b/src/components/MyWallet/walletvirtual/VirtualAddCardPopout.jsx index 68bc0f0..187faec 100644 --- a/src/components/MyWallet/walletvirtual/VirtualAddCardPopout.jsx +++ b/src/components/MyWallet/walletvirtual/VirtualAddCardPopout.jsx @@ -37,7 +37,7 @@ const validationSchema = Yup.object().shape({ .required("Required"), zipCode: Yup.string() .min(1, "Minimum 3 characters") - .max(10, "Maximum 25 characters") + .max(8, "Maximum 8 characters") .required("Required"), }); @@ -45,15 +45,20 @@ const VirtualAddCardPopout = ({ details, onClose, situation, walletItem }) => { const { userDetails } = useSelector((state) => state.userDetails); + const countryCode = userDetails?.country + const userApi = new usersService() const [requestStatus, setRequestStatus] = useState({loading: false, status:false, message: ''}) const [allCountries, setAllCountries] = useState({loading: true, data: []}) // VARIABLE TO HOLD COUNTRY LIST + const [state, setState] = useState({loading: true, data: {}}) // VARIABLE TO HOLD STATE LIST + + let initialValues = { // initial values for formik - country: '', + country: countryCode ? countryCode : '', phone_number: '', email: userDetails?.email, firstname: userDetails?.firstname, @@ -67,6 +72,7 @@ const VirtualAddCardPopout = ({ details, onClose, situation, walletItem }) => { zipCode: '' }; + const handleSubmit = (values) => { const reqData = { name: values.firstname + ' ' + values.firstname, @@ -98,6 +104,9 @@ const VirtualAddCardPopout = ({ details, onClose, situation, walletItem }) => { if(!res?.data?.result_list){ return setAllCountries({ loading: false, data: [] }); } + // if(countryCode){ + // return setAllCountries({ loading: false, data: res?.data?.result_list?.filter(item => item?.code == countryCode) }); + // } setAllCountries({ loading: false, data: res?.data?.result_list }); }).catch(err => { setAllCountries({ loading: false, data: [] }); @@ -105,6 +114,20 @@ const VirtualAddCardPopout = ({ details, onClose, situation, walletItem }) => { }) },[]) + useEffect(()=>{ + // GET STATE API + setState({loading: true, data: {}}) + userApi.getStateFromCountry({country: countryCode, action: '649'}).then(res =>{ + if(!res?.data?.country_state){ + return setState({ loading: false, data: {} }); + } + setState({ loading: false, data: res?.data?.country_state}); + }).catch(err => { + setState({ loading: false, data: {} }); + console.log('err', err) + }) +},[initialValues.country]) + return ( { value={props.values.country} className={`input-field p-2 mt-3 rounded-full placeholder:text-base text-dark-gray w-full h-[42px] bg-slate-100 focus:ring-0 focus:outline-none border`} onChange={props.handleChange} + disabled={countryCode ? true : false} > {allCountries.loading ?