Sootzani/components/RequestStep1.tsx

167 lines
5.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

"use client";
import React from "react";
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
import * as z from "zod";
import { Button } from "@/components/ui/button";
import {
Form,
FormControl,
FormDescription,
FormField,
FormItem,
FormLabel,
FormMessage,
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { toast } from "@/components/ui/use-toast";
import Link from "next/link";
import RequestStep2 from "./RequestStep2";
const FormSchema = z.object({
firstName: z.string().min(2, {
message: "firstName must be at least 2 characters.",
}),
lastName: z.string().min(2, {
message: "lastName must be at least 2 characters.",
}),
nationalCode: z.number().min(10, {
message: "nationalCode must be at least 10 characters.",
}),
phoneNumber: z.number().min(11, {
message: "phoneNumber must be at least 11 characters.",
}),
});
export default function RequestStep1() {
const form = useForm<z.infer<typeof FormSchema>>({
resolver: zodResolver(FormSchema),
defaultValues: {
firstName: "",
lastName: "",
// nationalCode: ,
// phoneNumber: ,
},
});
function onSubmit(data: z.infer<typeof FormSchema>) {
toast({
title: "You submitted the following values:",
description: (
<pre className="mt-2 w-[340px] rounded-md bg-slate-950 p-4">
<code className="text-white">{JSON.stringify(data, null, 2)}</code>
</pre>
),
});
console.log(data);
}
return (
<div className="w-full h-full sm:w-2/3 md:w-2/4 max-sm:p-8 pt-12">
<div className="space-y-4 md:space-y-4 h-full flex flex-col justify-center">
<p className="text-sm md:text-base font-bold leading-tight tracking-tight text-blue dark:text-white">
لطفا جهت ارسال درخواست فرم زیر را تکمیل نمایید.
</p>
<p className="text-sm md:text-base font-bold leading-tight tracking-tight text-red-800 dark:text-white">
در صورت عدم تمایل به ثبت مشخصات شخصی می توانید به صفحه ی بعد مراجعه کنید.
</p>
<Form {...form}>
<form
onSubmit={form.handleSubmit(onSubmit)}
className="w-full flex flex-col mt-6 "
>
<div className="flex flex-row flex-wrap justify-between">
<FormField
control={form.control}
name="firstName"
render={({ field }) => (
<FormItem className="w-full sm:w-[48%]">
<FormLabel className="text-[#7C838A] text-sm font-medium">
نام
</FormLabel>
<FormControl>
<Input placeholder="نام خود را وارد نمایید" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="lastName"
render={({ field }) => (
<FormItem className="w-full sm:w-[48%] ">
<FormLabel className="text-[#7C838A] text-sm font-medium">
نام خانوادگی
</FormLabel>
<FormControl>
<Input
placeholder="نام خانوادگی خود را وارد نمایید"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="nationalCode"
render={({ field }) => (
<FormItem className="w-full sm:w-[48%]">
<FormLabel className="text-[#7C838A] text-sm font-medium mt-7">
کد ملی
</FormLabel>
<FormControl>
<Input
type="number"
placeholder="کد ملی خود را وارد نمایید "
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="phoneNumber"
render={({ field }) => (
<FormItem className=" w-full sm:w-[48%]">
<FormLabel className="text-[#7C838A] text-sm font-medium mt-7">
شماره تماس
</FormLabel>
<FormControl>
<Input
type="number"
placeholder="شماره تماس خود را وارد نمایید "
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
<div className="flex justify-center sm:justify-end gap-2 w-full mt-8">
{/* <Button> */}
<Link
href="/RequestStep2"
type="submit"
className="w-1/2 sm:w-1/3 lg:w-1/4 bg-blue text-white p-2 rounded-xl text-center"
>
صفحه ی بعد
</Link>
{/* </Button> */}
</div>
</form>
</Form>
</div>
</div>
);
}