diff --git a/app/Login/page.tsx b/app/Login/page.tsx new file mode 100644 index 0000000..8cca1c9 --- /dev/null +++ b/app/Login/page.tsx @@ -0,0 +1,10 @@ +import Login from "@/components/Login"; +import React from "react"; + +export default function page() { + return ( +
+ +
+ ); +} diff --git a/app/layout.tsx b/app/layout.tsx index 2e2291b..2438630 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -1,6 +1,8 @@ import type { Metadata } from "next"; import { Inter } from "next/font/google"; import "./globals.css"; +import { Toaster } from "@/components/ui/toaster"; +import Navbar from "@/components/Navbar"; const inter = Inter({ subsets: ["latin"] }); @@ -16,7 +18,11 @@ export default function RootLayout({ }) { return ( - {children} + + {/* */} + {children} + + ); } diff --git a/components/Login.tsx b/components/Login.tsx new file mode 100644 index 0000000..534cf9a --- /dev/null +++ b/components/Login.tsx @@ -0,0 +1,109 @@ +"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 Image from "next/image"; +import LoginIcon from "../public/img/login-icon.svg"; + +const FormSchema = z.object({ + username: z.string().min(2, { + message: "Username must be at least 2 characters.", + }), + password: z.string().min(4, { + message: "Password must be at least 4 characters.", + }), +}); + +export default function Login() { + const form = useForm>({ + resolver: zodResolver(FormSchema), + defaultValues: { + username: "", + password:"", + }, + }); + + function onSubmit(data: z.infer) { + toast({ + title: "You submitted the following values:", + description: ( +
+          {JSON.stringify(data, null, 2)}
+        
+ ), + }); + console.log(data); + } + + return ( +
+
+ icon + +

+ ورود به پنل کاربری +

+ +
+ + ( + + نام کاربری + + + + {/* + This is your public display name. + */} + + + + )} + /> + + ( + + رمز عبور + + + + + + + )} + /> + +
+ + +
+ + +
+
+ ); +} diff --git a/components/Navbar.tsx b/components/Navbar.tsx index 6a97cf1..fb798fc 100644 --- a/components/Navbar.tsx +++ b/components/Navbar.tsx @@ -3,19 +3,20 @@ import { Input } from "./ui/input"; import Image from "next/image"; import { menuItems } from "@/constants"; import Link from "next/link"; +import Login from "./Login"; import { Button } from "./ui/button"; export default function Navbar() { return (
-
+

سال 1402 | مهارم تورم، رشد تولید

-
+
- + + + +
); diff --git a/components/SubmitRequest.tsx b/components/SubmitRequest.tsx index 260f57d..65ad4c7 100644 --- a/components/SubmitRequest.tsx +++ b/components/SubmitRequest.tsx @@ -10,7 +10,7 @@ import { IoArrowDown } from "react-icons/io5"; export default function SubmitRequest() { return ( -
+

درباره سامانه سوت زنی diff --git a/components/ui/form.tsx b/components/ui/form.tsx new file mode 100644 index 0000000..3f946cf --- /dev/null +++ b/components/ui/form.tsx @@ -0,0 +1,176 @@ +import * as React from "react" +import * as LabelPrimitive from "@radix-ui/react-label" +import { Slot } from "@radix-ui/react-slot" +import { + Controller, + ControllerProps, + FieldPath, + FieldValues, + FormProvider, + useFormContext, +} from "react-hook-form" + +import { cn } from "@/lib/utils" +import { Label } from "@/components/ui/label" + +const Form = FormProvider + +type FormFieldContextValue< + TFieldValues extends FieldValues = FieldValues, + TName extends FieldPath = FieldPath +> = { + name: TName +} + +const FormFieldContext = React.createContext( + {} as FormFieldContextValue +) + +const FormField = < + TFieldValues extends FieldValues = FieldValues, + TName extends FieldPath = FieldPath +>({ + ...props +}: ControllerProps) => { + return ( + + + + ) +} + +const useFormField = () => { + const fieldContext = React.useContext(FormFieldContext) + const itemContext = React.useContext(FormItemContext) + const { getFieldState, formState } = useFormContext() + + const fieldState = getFieldState(fieldContext.name, formState) + + if (!fieldContext) { + throw new Error("useFormField should be used within ") + } + + const { id } = itemContext + + return { + id, + name: fieldContext.name, + formItemId: `${id}-form-item`, + formDescriptionId: `${id}-form-item-description`, + formMessageId: `${id}-form-item-message`, + ...fieldState, + } +} + +type FormItemContextValue = { + id: string +} + +const FormItemContext = React.createContext( + {} as FormItemContextValue +) + +const FormItem = React.forwardRef< + HTMLDivElement, + React.HTMLAttributes +>(({ className, ...props }, ref) => { + const id = React.useId() + + return ( + +

+ + ) +}) +FormItem.displayName = "FormItem" + +const FormLabel = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => { + const { error, formItemId } = useFormField() + + return ( +