From 42b792ab9dc27e32e093ae2ba4e7c305ea50630c Mon Sep 17 00:00:00 2001 From: victorAnumudu Date: Tue, 12 Sep 2023 15:24:30 +0100 Subject: [PATCH 1/4] made country auto filled if pathname contains country value --- src/components/AuthPages/SignUp/index.jsx | 41 +++++++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/src/components/AuthPages/SignUp/index.jsx b/src/components/AuthPages/SignUp/index.jsx index 02d00b1..3e4e423 100644 --- a/src/components/AuthPages/SignUp/index.jsx +++ b/src/components/AuthPages/SignUp/index.jsx @@ -6,15 +6,18 @@ import InputCom from "../../Helpers/Inputs/InputCom"; import AuthLayout from "../AuthLayout"; export default function SignUp() { + const queryParams = new URLSearchParams(location?.search); + const country = queryParams.get("cnt")?.toUpperCase(); + const [signUpLoading, setSignUpLoading] = useState(false); const [checked, setValue] = useState(false); // for the catch error const [msgError, setMsgError] = useState(""); const [showPassword, setShowPassword] = useState(false); - const [countries, setCountries] = useState([]); + const [countries, setCountries] = useState({loading:true, data:[]}); const [formData, setFormData] = useState({ - country: "", + country: country? country : "", first_name: "", last_name: "", email: "", @@ -45,9 +48,14 @@ export default function SignUp() { try { if (res.status === 200) { const { signup_country } = await res.data; - setCountries(signup_country); + // setCountries(signup_country); + if(country){ // IF LINK/PATHNAME HAS CNT QUERY VALUE + let cnt = signup_country.filter(item => item[0]==country) + return setCountries({loading: false, data: cnt.length ? signup_country.filter(item => item[0]==country) : signup_country}); + } + setCountries({loading: false, data:signup_country}); } else if (res.data.result !== 100) { - setCountries("Nothing see here!"); + setCountries({loading: false, data:[]}); } } catch (error) { throw new Error(error); @@ -352,13 +360,32 @@ const SelectOption = ({ onChange={inputHandler} value={value} > - - {data?.length > 0 && - data?.map((item, idx) => ( + {data?.data?.length > 1 ? + <> + + {data?.data?.map((item, idx) => ( ))} + + : + data?.data?.length == 1 ? + data?.data?.map((item, idx) => ( + + )) + : + data?.data?.length < 1 && data.loading ? + + : + + } From a1140f7006a3d9dc7b225f6425c1c84c51c7b4e6 Mon Sep 17 00:00:00 2001 From: victorAnumudu Date: Tue, 12 Sep 2023 20:05:22 +0100 Subject: [PATCH 2/4] modified signup page to show select country list or defaults to country passed on search param --- src/components/AuthPages/SignUp/index.jsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/components/AuthPages/SignUp/index.jsx b/src/components/AuthPages/SignUp/index.jsx index 3e4e423..f1ebc53 100644 --- a/src/components/AuthPages/SignUp/index.jsx +++ b/src/components/AuthPages/SignUp/index.jsx @@ -50,8 +50,12 @@ export default function SignUp() { const { signup_country } = await res.data; // setCountries(signup_country); if(country){ // IF LINK/PATHNAME HAS CNT QUERY VALUE - let cnt = signup_country.filter(item => item[0]==country) - return setCountries({loading: false, data: cnt.length ? signup_country.filter(item => item[0]==country) : signup_country}); + let cnt = signup_country.filter(item => item[0]==country) // test to see country passed in query param exist from list of countries supplied by API + if(!cnt.length){ // IF CNT EMPTY, SET FORMDATA COUNTRY BACK TO EMPTY STRING: RE: THIS IS BCOS WE INITAIL SET COUNTRY VALUE IN FORMDATA, IF COUNTRY PARAM IS PRESENT IN LINK + setFormData(prev => ({...prev, country: ''})) + return setCountries({loading: false, data: signup_country}); + } + return setCountries({loading: false, data: cnt}); } setCountries({loading: false, data:signup_country}); } else if (res.data.result !== 100) { @@ -64,6 +68,7 @@ export default function SignUp() { const handleSignUp = async () => { let { country, first_name, last_name, email, password } = formData; + console.log('FORMDATA', formData) try { if ( email !== "" && @@ -180,6 +185,7 @@ export default function SignUp() { name="country" value={formData.country} inputHandler={handleInputChange} + disable={country && countries?.data?.length <= 1 ? true : false} />
@@ -314,6 +320,7 @@ export default function SignUp() {