Sootzani/components/RequestStep2.tsx

176 lines
5.5 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 { Textarea } from "@/components/ui/textarea";
import Link from "next/link";
import RequestResult from "./RequestResult";
const FormSchema = z.object({
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 RequestStep2() {
const form = useForm<z.infer<typeof FormSchema>>({
resolver: zodResolver(FormSchema),
defaultValues: {
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-8 pt-12">
<div className="space-y-3 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>
<Form {...form}>
<form
onSubmit={form.handleSubmit(onSubmit)}
className="w-full flex flex-col mt-6"
>
<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> */}
<Link
href="/RequestResult"
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>
);
}