feat: phone number validation
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import { FC, useState } from "react";
|
||||
import { redirect } from "next/navigation";
|
||||
import { Button, Stack } from "@mantine/core";
|
||||
import { useForm } from "@mantine/form";
|
||||
@ -15,14 +15,23 @@ type Props = {
|
||||
};
|
||||
|
||||
const LoginForm: FC<Props> = ({ isCreatingId = false }) => {
|
||||
const [phoneMask, setPhoneMask] = useState<string>("");
|
||||
const form = useForm<LoginForm>({
|
||||
initialValues: {
|
||||
phoneNumber: "",
|
||||
},
|
||||
validate: {
|
||||
phoneNumber: phoneNumber =>
|
||||
phoneNumber.length !== phoneMask.length &&
|
||||
"Введите корректный номер",
|
||||
},
|
||||
});
|
||||
|
||||
const handleSubmit = (values: LoginForm) => {
|
||||
console.log(values);
|
||||
console.log(phoneMask);
|
||||
|
||||
redirect("/verify-phone");
|
||||
};
|
||||
|
||||
const navigateToCreateId = () => redirect("/create-id");
|
||||
@ -32,7 +41,10 @@ const LoginForm: FC<Props> = ({ isCreatingId = false }) => {
|
||||
return (
|
||||
<form onSubmit={form.onSubmit(handleSubmit)}>
|
||||
<Stack>
|
||||
<PhoneInput {...form.getInputProps("phoneNumber")} />
|
||||
<PhoneInput
|
||||
{...form.getInputProps("phoneNumber")}
|
||||
setPhoneMask={setPhoneMask}
|
||||
/>
|
||||
{isCreatingId ? (
|
||||
<>
|
||||
<Button
|
||||
|
||||
Reference in New Issue
Block a user