|
@ -1,6 +1,6 @@ |
|
|
"use client"; |
|
|
"use client"; |
|
|
|
|
|
|
|
|
import React, { FC, useContext, useState } from "react"; |
|
|
|
|
|
|
|
|
import React, { FC, useState, useEffect } from "react"; |
|
|
import Input from "@/shared/Input"; |
|
|
import Input from "@/shared/Input"; |
|
|
import ButtonPrimary from "@/shared/ButtonPrimary"; |
|
|
import ButtonPrimary from "@/shared/ButtonPrimary"; |
|
|
import Link from "next/link"; |
|
|
import Link from "next/link"; |
|
@ -13,27 +13,28 @@ export interface PageSignUpProps {} |
|
|
|
|
|
|
|
|
const PageSignUp: FC<PageSignUpProps> = () => { |
|
|
const PageSignUp: FC<PageSignUpProps> = () => { |
|
|
const router = useRouter(); |
|
|
const router = useRouter(); |
|
|
const {user} = useUserContext() |
|
|
|
|
|
|
|
|
const { user, setForm, setMethod } = useUserContext(); |
|
|
|
|
|
|
|
|
if (Object.keys(user).length) { |
|
|
|
|
|
router.replace("/"); |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Redirect if user is already logged in
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
if (Object.keys(user).length) { |
|
|
|
|
|
router.replace("/"); |
|
|
|
|
|
} |
|
|
|
|
|
}, [user, router]); |
|
|
|
|
|
|
|
|
const { setForm, setMethod } = useUserContext(); |
|
|
|
|
|
|
|
|
|
|
|
const [name, setName] = useState(""); |
|
|
|
|
|
const [countryCode, setCountryCode] = useState(""); |
|
|
|
|
|
const [phoneNumber, setPhoneNumber] = useState(""); |
|
|
|
|
|
const [password, setPassword] = useState(""); |
|
|
|
|
|
const [confirmPassword, setConfirmPassword] = useState(""); |
|
|
|
|
|
const [loading, setLoading] = useState(false); |
|
|
|
|
|
|
|
|
|
|
|
const [failed , setFailed ] =useState("") |
|
|
|
|
|
|
|
|
const [name, setName] = useState<string>(""); |
|
|
|
|
|
const [countryCode, setCountryCode] = useState<string>(""); |
|
|
|
|
|
const [phoneNumber, setPhoneNumber] = useState<string>(""); |
|
|
|
|
|
const [password, setPassword] = useState<string>(""); |
|
|
|
|
|
const [confirmPassword, setConfirmPassword] = useState<string>(""); |
|
|
|
|
|
const [loading, setLoading] = useState<boolean>(false); |
|
|
|
|
|
const [failed, setFailed] = useState<string>(""); |
|
|
|
|
|
|
|
|
const { errors, validateForm } = useFormValidation(); |
|
|
const { errors, validateForm } = useFormValidation(); |
|
|
|
|
|
|
|
|
const countryCodeHandler = (e) => { |
|
|
|
|
|
|
|
|
const countryCodeHandler = (e: React.ChangeEvent<HTMLInputElement>) => { |
|
|
if (e.target.value.length <= 3) { |
|
|
if (e.target.value.length <= 3) { |
|
|
setCountryCode(e.target.value); |
|
|
setCountryCode(e.target.value); |
|
|
} |
|
|
} |
|
@ -46,7 +47,7 @@ const PageSignUp: FC<PageSignUpProps> = () => { |
|
|
phoneNumber, |
|
|
phoneNumber, |
|
|
password, |
|
|
password, |
|
|
confirmPassword, |
|
|
confirmPassword, |
|
|
verification_methodes : "" , |
|
|
|
|
|
|
|
|
verification_methodes: "", |
|
|
method: "register", |
|
|
method: "register", |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@ -57,18 +58,16 @@ const PageSignUp: FC<PageSignUpProps> = () => { |
|
|
const response = await axiosInstance.get( |
|
|
const response = await axiosInstance.get( |
|
|
`/api/account/verfication/?range_phone=${countryCode}&phone_number=${phoneNumber}` |
|
|
`/api/account/verfication/?range_phone=${countryCode}&phone_number=${phoneNumber}` |
|
|
); |
|
|
); |
|
|
form.verification_methodes = response.data.verification_method ; |
|
|
|
|
|
|
|
|
form.verification_methodes = response.data.verification_method; |
|
|
router.push("/signup/methodes"); |
|
|
router.push("/signup/methodes"); |
|
|
} catch (error) { |
|
|
|
|
|
|
|
|
} catch (error: any) { |
|
|
console.error("Error fetching data:", error); |
|
|
console.error("Error fetching data:", error); |
|
|
setFailed(error.message) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setFailed(error.message || "An error occurred."); |
|
|
} finally { |
|
|
} finally { |
|
|
setLoading(false); |
|
|
setLoading(false); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
console.log("Form has errors:", errors); |
|
|
console.log("Form has errors:", errors); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@ -92,7 +91,7 @@ const PageSignUp: FC<PageSignUpProps> = () => { |
|
|
{errors.name && <p className="text-xs text-red-600">{errors.name}</p>} |
|
|
{errors.name && <p className="text-xs text-red-600">{errors.name}</p>} |
|
|
</label> |
|
|
</label> |
|
|
<label className="block"> |
|
|
<label className="block"> |
|
|
<span className=" text-neutral-800 dark:text-neutral-200">Phone Number</span> |
|
|
|
|
|
|
|
|
<span className="text-neutral-800 dark:text-neutral-200">Phone Number</span> |
|
|
<div className="flex items-center mt-1 rounded-2xl border border-neutral-200 bg-white dark:border-neutral-700 dark:bg-neutral-900 focus-within:ring-0"> |
|
|
<div className="flex items-center mt-1 rounded-2xl border border-neutral-200 bg-white dark:border-neutral-700 dark:bg-neutral-900 focus-within:ring-0"> |
|
|
<span className="px-2 mr-[-15px] text-neutral-800 dark:text-neutral-200">+</span> |
|
|
<span className="px-2 mr-[-15px] text-neutral-800 dark:text-neutral-200">+</span> |
|
|
<input |
|
|
<input |
|
@ -108,7 +107,6 @@ const PageSignUp: FC<PageSignUpProps> = () => { |
|
|
value={phoneNumber} |
|
|
value={phoneNumber} |
|
|
onChange={(e) => setPhoneNumber(e.target.value)} |
|
|
onChange={(e) => setPhoneNumber(e.target.value)} |
|
|
type="text" |
|
|
type="text" |
|
|
placeholder="" |
|
|
|
|
|
className="flex-1 p-2 no-border-on-focus border-none outline-none bg-transparent text-neutral-800 dark:text-neutral-200" |
|
|
className="flex-1 p-2 no-border-on-focus border-none outline-none bg-transparent text-neutral-800 dark:text-neutral-200" |
|
|
/> |
|
|
/> |
|
|
</div> |
|
|
</div> |
|
@ -122,9 +120,8 @@ const PageSignUp: FC<PageSignUpProps> = () => { |
|
|
<Input |
|
|
<Input |
|
|
value={password} |
|
|
value={password} |
|
|
onChange={(e) => setPassword(e.target.value)} |
|
|
onChange={(e) => setPassword(e.target.value)} |
|
|
type="password" // Changed to password type for security
|
|
|
|
|
|
|
|
|
type="password" |
|
|
className="secure-input mt-1" |
|
|
className="secure-input mt-1" |
|
|
onCopy={(e) => e.preventDefault()} |
|
|
|
|
|
/> |
|
|
/> |
|
|
{errors.password && <p className="text-xs text-red-600">{errors.password}</p>} |
|
|
{errors.password && <p className="text-xs text-red-600">{errors.password}</p>} |
|
|
</label> |
|
|
</label> |
|
@ -135,16 +132,14 @@ const PageSignUp: FC<PageSignUpProps> = () => { |
|
|
<Input |
|
|
<Input |
|
|
value={confirmPassword} |
|
|
value={confirmPassword} |
|
|
onChange={(e) => setConfirmPassword(e.target.value)} |
|
|
onChange={(e) => setConfirmPassword(e.target.value)} |
|
|
placeholder="Password" |
|
|
|
|
|
type="password" // Changed to password type for security
|
|
|
|
|
|
|
|
|
type="password" |
|
|
className="secure-input mt-1" |
|
|
className="secure-input mt-1" |
|
|
onCopy={(e) => e.preventDefault()} |
|
|
|
|
|
/> |
|
|
/> |
|
|
{errors.confirmPassword && ( |
|
|
{errors.confirmPassword && ( |
|
|
<p className="text-xs text-red-600">{errors.confirmPassword}</p> |
|
|
<p className="text-xs text-red-600">{errors.confirmPassword}</p> |
|
|
)} |
|
|
)} |
|
|
</label> |
|
|
</label> |
|
|
{failed && (<p><p className="text-xs text-red-600">{failed}</p></p>)} |
|
|
|
|
|
|
|
|
{failed && <p className="text-xs text-red-600">{failed}</p>} |
|
|
<ButtonPrimary |
|
|
<ButtonPrimary |
|
|
loading={loading} |
|
|
loading={loading} |
|
|
onClick={submitHandler} |
|
|
onClick={submitHandler} |
|
|