feat: phone number validation
This commit is contained in:
11
components/VerifyPhoneForm/VerifyPhone.module.css
Normal file
11
components/VerifyPhoneForm/VerifyPhone.module.css
Normal file
@ -0,0 +1,11 @@
|
||||
.pin-input-root {
|
||||
width: 100%;
|
||||
justify-content: space-between;
|
||||
margin-top: 10px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.pin-input {
|
||||
font-size: 17px;
|
||||
border-radius: 10px;
|
||||
}
|
||||
59
components/VerifyPhoneForm/VerifyPhoneForm.tsx
Normal file
59
components/VerifyPhoneForm/VerifyPhoneForm.tsx
Normal file
@ -0,0 +1,59 @@
|
||||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import { redirect } from "next/navigation";
|
||||
import { Button, PinInput, Stack } from "@mantine/core";
|
||||
import { useForm } from "@mantine/form";
|
||||
import style from "@/components/VerifyPhoneForm/VerifyPhone.module.css";
|
||||
|
||||
type VerifyNumberForm = {
|
||||
code: string;
|
||||
};
|
||||
|
||||
const VerifyPhoneForm: FC = () => {
|
||||
const form = useForm<VerifyNumberForm>({
|
||||
initialValues: {
|
||||
code: "",
|
||||
},
|
||||
validate: {
|
||||
code: code => code.length !== 6 && "Введите весь код",
|
||||
},
|
||||
});
|
||||
|
||||
const handleSubmit = (values: VerifyNumberForm) => {
|
||||
console.log(values);
|
||||
};
|
||||
|
||||
const navigateToLogin = () => redirect("/");
|
||||
|
||||
return (
|
||||
<form onSubmit={form.onSubmit(handleSubmit)}>
|
||||
<Stack>
|
||||
<PinInput
|
||||
length={6}
|
||||
placeholder="_"
|
||||
oneTimeCode
|
||||
size={"md"}
|
||||
classNames={{
|
||||
root: style["pin-input-root"],
|
||||
input: style["pin-input"],
|
||||
}}
|
||||
{...form.getInputProps("code")}
|
||||
/>
|
||||
<Button
|
||||
variant={"filled"}
|
||||
type={"submit"}
|
||||
disabled={form.values.code.length !== 6}>
|
||||
Подтвердить
|
||||
</Button>
|
||||
<Button
|
||||
variant={"outline"}
|
||||
onClick={navigateToLogin}>
|
||||
Назад
|
||||
</Button>
|
||||
</Stack>
|
||||
</form>
|
||||
);
|
||||
};
|
||||
|
||||
export default VerifyPhoneForm;
|
||||
Reference in New Issue
Block a user