diff --git a/src/components/AuthPages/SignUp/index.jsx b/src/components/AuthPages/SignUp/index.jsx index 02d00b1..735b69a 100644 --- a/src/components/AuthPages/SignUp/index.jsx +++ b/src/components/AuthPages/SignUp/index.jsx @@ -1,20 +1,26 @@ import React, { useCallback, useEffect, useState } from "react"; -import { Link, useNavigate } from "react-router-dom"; +import { Link, useLocation, useNavigate } from "react-router-dom"; import WrenchBoard from "../../../assets/images/wrenchboard-logo-text.png"; import usersService from "../../../services/UsersService"; 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 {pathname} = useLocation() + const currentPath = country ? `${pathname}?cnt=${country.toLowerCase()}`:pathname // Determines the new pathname is country query params exist + 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 +51,18 @@ 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) // 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) { - setCountries("Nothing see here!"); + setCountries({loading: false, data:[]}); } } catch (error) { throw new Error(error); @@ -134,7 +149,7 @@ export default function SignUp() {
- + wrenchboard
@@ -306,6 +322,7 @@ export default function SignUp() {