262 lines
8.6 KiB
TypeScript
262 lines
8.6 KiB
TypeScript
"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 { Textarea } from "@/components/ui/textarea";
|
||
|
||
import Image from "next/image";
|
||
import LoginIcon from "../public/img/login-icon.svg";
|
||
|
||
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.",
|
||
}),
|
||
subject: z.string().min(2, {
|
||
message: "subject must be at least 2 characters.",
|
||
}),
|
||
organisation: z.string().min(2, {
|
||
message: "organisation must be at least 2 characters.",
|
||
}),
|
||
person: z.string().min(2, {
|
||
message: "personName must be at least 2 characters.",
|
||
}),
|
||
description: z
|
||
.string()
|
||
.min(5, {
|
||
message: "description must be at least 5 characters.",
|
||
})
|
||
.max(200, {
|
||
message: "description must not be longer than 200 characters.",
|
||
}),
|
||
});
|
||
|
||
export default function Request() {
|
||
const form = useForm<z.infer<typeof FormSchema>>({
|
||
resolver: zodResolver(FormSchema),
|
||
defaultValues: {
|
||
firstName: "",
|
||
lastName: "",
|
||
// nationalCode: ,
|
||
// phoneNumber: ,
|
||
subject: "",
|
||
organisation: "",
|
||
person: "",
|
||
description: "",
|
||
},
|
||
});
|
||
|
||
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-4 ">
|
||
<div className="space-y-3 md:space-y-4 h-full flex flex-col justify-center">
|
||
<p className="text-base font-bold leading-tight tracking-tight text-blue dark:text-white">
|
||
لطفا جهت ارسال درخواست فرم زیر را تکمیل نمایید.
|
||
</p>
|
||
|
||
<Form {...form}>
|
||
<form
|
||
onSubmit={form.handleSubmit(onSubmit)}
|
||
className="w-full flex flex-col "
|
||
>
|
||
<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>
|
||
|
||
<FormField
|
||
control={form.control}
|
||
name="subject"
|
||
render={({ field }) => (
|
||
<FormItem>
|
||
<FormLabel className="text-[#7C838A] text-sm font-medium mt-7">
|
||
*موضوع شکایت
|
||
</FormLabel>
|
||
<FormControl>
|
||
<Input
|
||
placeholder="موضوع شکایت خود را بنویسید"
|
||
{...field}
|
||
/>
|
||
</FormControl>
|
||
<FormMessage />
|
||
</FormItem>
|
||
)}
|
||
/>
|
||
<div className="flex flex-row flex-wrap justify-between">
|
||
<FormField
|
||
control={form.control}
|
||
name="organisation"
|
||
render={({ field }) => (
|
||
<FormItem className="w-full sm:w-[48%]">
|
||
<FormLabel className="text-[#7C838A] text-sm font-medium mt-7">
|
||
*دستگاه مربوطه
|
||
</FormLabel>
|
||
<FormControl>
|
||
<Input
|
||
placeholder="دستگاه مربوطه را انتخاب کنید"
|
||
{...field}
|
||
/>
|
||
</FormControl>
|
||
<FormMessage />
|
||
</FormItem>
|
||
)}
|
||
/>
|
||
|
||
<FormField
|
||
control={form.control}
|
||
name="person"
|
||
render={({ field }) => (
|
||
<FormItem className=" w-full sm:w-[48%]">
|
||
<FormLabel className="text-[#7C838A] text-sm font-medium mt-7">
|
||
فرد مربوطه
|
||
</FormLabel>
|
||
<FormControl>
|
||
<Input
|
||
placeholder="نام فرد مورد نظر خود را بنویسید"
|
||
{...field}
|
||
/>
|
||
</FormControl>
|
||
<FormMessage />
|
||
</FormItem>
|
||
)}
|
||
/>
|
||
</div>
|
||
|
||
|
||
<FormField
|
||
control={form.control}
|
||
name="description"
|
||
render={({ field }) => (
|
||
<FormItem>
|
||
<FormLabel className="text-[#7C838A] text-sm font-medium mt-7">توضیحات</FormLabel>
|
||
<FormControl>
|
||
<Textarea
|
||
placeholder="متن توضیحات خود را بنویسید"
|
||
className="resize-none"
|
||
{...field}
|
||
/>
|
||
</FormControl>
|
||
<FormMessage />
|
||
</FormItem>
|
||
)}
|
||
/>
|
||
|
||
<div className="flex justify-center sm:justify-end gap-2 w-full mt-8">
|
||
<Button
|
||
type="submit"
|
||
className="w-1/2 sm:w-1/3 lg:w-1/4 bg-blue text-white p-3 rounded-xl"
|
||
>
|
||
ارسال درخواست
|
||
</Button>
|
||
</div>
|
||
</form>
|
||
</Form>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|