made country auto filled if pathname contains country value
This commit was merged in pull request #415.
This commit is contained in:
@@ -6,15 +6,18 @@ import InputCom from "../../Helpers/Inputs/InputCom";
|
|||||||
import AuthLayout from "../AuthLayout";
|
import AuthLayout from "../AuthLayout";
|
||||||
|
|
||||||
export default function SignUp() {
|
export default function SignUp() {
|
||||||
|
const queryParams = new URLSearchParams(location?.search);
|
||||||
|
const country = queryParams.get("cnt")?.toUpperCase();
|
||||||
|
|
||||||
const [signUpLoading, setSignUpLoading] = useState(false);
|
const [signUpLoading, setSignUpLoading] = useState(false);
|
||||||
const [checked, setValue] = useState(false);
|
const [checked, setValue] = useState(false);
|
||||||
// for the catch error
|
// for the catch error
|
||||||
const [msgError, setMsgError] = useState("");
|
const [msgError, setMsgError] = useState("");
|
||||||
const [showPassword, setShowPassword] = useState(false);
|
const [showPassword, setShowPassword] = useState(false);
|
||||||
const [countries, setCountries] = useState([]);
|
const [countries, setCountries] = useState({loading:true, data:[]});
|
||||||
|
|
||||||
const [formData, setFormData] = useState({
|
const [formData, setFormData] = useState({
|
||||||
country: "",
|
country: country? country : "",
|
||||||
first_name: "",
|
first_name: "",
|
||||||
last_name: "",
|
last_name: "",
|
||||||
email: "",
|
email: "",
|
||||||
@@ -45,9 +48,14 @@ export default function SignUp() {
|
|||||||
try {
|
try {
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
const { signup_country } = await res.data;
|
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) {
|
} else if (res.data.result !== 100) {
|
||||||
setCountries("Nothing see here!");
|
setCountries({loading: false, data:[]});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(error);
|
throw new Error(error);
|
||||||
@@ -352,13 +360,32 @@ const SelectOption = ({
|
|||||||
onChange={inputHandler}
|
onChange={inputHandler}
|
||||||
value={value}
|
value={value}
|
||||||
>
|
>
|
||||||
<option value={""}>Select your Country</option>
|
{data?.data?.length > 1 ?
|
||||||
{data?.length > 0 &&
|
<>
|
||||||
data?.map((item, idx) => (
|
<option value={""}>Select your Country</option>
|
||||||
|
{data?.data?.map((item, idx) => (
|
||||||
<option value={item[0]} key={idx}>
|
<option value={item[0]} key={idx}>
|
||||||
{item[1]}
|
{item[1]}
|
||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
|
</>
|
||||||
|
:
|
||||||
|
data?.data?.length == 1 ?
|
||||||
|
data?.data?.map((item, idx) => (
|
||||||
|
<option value={item[0]} key={idx}>
|
||||||
|
{item[1]}
|
||||||
|
</option>
|
||||||
|
))
|
||||||
|
:
|
||||||
|
data?.data?.length < 1 && data.loading ?
|
||||||
|
<option value=''>
|
||||||
|
Loading...
|
||||||
|
</option>
|
||||||
|
:
|
||||||
|
<option value=''>
|
||||||
|
No Country Found!
|
||||||
|
</option>
|
||||||
|
}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user