Turned the code in the register optional

This commit is contained in:
Tiago Ribeiro
2023-11-26 13:59:14 +00:00
parent fa544bf4e8
commit a9bbbe8b52
9 changed files with 111 additions and 20 deletions

View File

@@ -1,4 +1,5 @@
import Button from "@/components/Low/Button";
import Checkbox from "@/components/Low/Checkbox";
import Input from "@/components/Low/Input";
import {User} from "@/interfaces/user";
import {sendEmailVerification} from "@/utils/email";
@@ -21,6 +22,7 @@ export default function RegisterIndividual({queryCode, isLoading, setIsLoading,
const [password, setPassword] = useState("");
const [confirmPassword, setConfirmPassword] = useState("");
const [code, setCode] = useState(queryCode || "");
const [hasCode, setHasCode] = useState<boolean>(!!queryCode);
const onSuccess = () => toast.success("An e-mail has been sent, please make sure to check your spam folder!");
@@ -88,12 +90,27 @@ export default function RegisterIndividual({queryCode, isLoading, setIsLoading,
defaultValue={confirmPassword}
required
/>
<Input type="text" name="code" onChange={(e) => setCode(e)} placeholder="Enter your registration code" defaultValue={code} required />
{/** TODO: Add a checkbox to disable code */}
<div className="flex flex-col gap-4 w-full items-start">
<Checkbox isChecked={hasCode} onChange={setHasCode}>
I have a code
</Checkbox>
{hasCode && (
<Input
type="text"
name="code"
onChange={(e) => setCode(e)}
placeholder="Enter your registration code (optional)"
defaultValue={code}
/>
)}
</div>
<Button
className="lg:mt-8 w-full"
color="purple"
disabled={isLoading || !email || !name || !password || !confirmPassword || password !== confirmPassword || !code}>
disabled={isLoading || !email || !name || !password || !confirmPassword || password !== confirmPassword || (hasCode ? !code : false)}>
Create account
</Button>
</form>