diff --git a/app/globals.css b/app/globals.css index b0e6fff..37336b9 100644 --- a/app/globals.css +++ b/app/globals.css @@ -1,76 +1,94 @@ @tailwind base; - @tailwind components; - @tailwind utilities; +@tailwind components; +@tailwind utilities; - @layer base { - :root { - --background: 0 0% 100%; - --foreground: 222.2 84% 4.9%; +@layer base { + :root { + --background: 0 0% 100%; + --foreground: 0 0% 5%; - --card: 0 0% 100%; - --card-foreground: 222.2 84% 4.9%; + --card: 0 0% 100%; + --card-foreground: 0 0% 5%; - --popover: 0 0% 100%; - --popover-foreground: 222.2 84% 4.9%; + --popover: 0 0% 100%; + --popover-foreground: 0 0% 5%; - --primary: 222.2 47.4% 11.2%; - --primary-foreground: 210 40% 98%; + --primary: 213 74% 30%; + --primary-foreground: 0 0% 98%; - --secondary: 210 40% 96.1%; - --secondary-foreground: 222.2 47.4% 11.2%; + --secondary: 0 0% 96%; + --secondary-foreground: 0 0% 5%; - --muted: 210 40% 96.1%; - --muted-foreground: 215.4 16.3% 46.9%; + --muted: 0 0% 96%; + --muted-foreground: 0 0% 45%; - --accent: 210 40% 96.1%; - --accent-foreground: 222.2 47.4% 11.2%; + --accent: 0 0% 96%; + --accent-foreground: 0 0% 5%; - --destructive: 0 84.2% 60.2%; - --destructive-foreground: 210 40% 98%; + --destructive: 0 84% 60%; + --destructive-foreground: 0 0% 98%; - --border: 214.3 31.8% 91.4%; - --input: 214.3 31.8% 91.4%; - --ring: 222.2 84% 4.9%; + --border: 0 0% 92%; + --input: 0 0% 85%; + --ring: 0 0% 76%; - --radius: 0.5rem; - } - - .dark { - --background: 222.2 84% 4.9%; - --foreground: 210 40% 98%; - - --card: 222.2 84% 4.9%; - --card-foreground: 210 40% 98%; - - --popover: 222.2 84% 4.9%; - --popover-foreground: 210 40% 98%; - - --primary: 210 40% 98%; - --primary-foreground: 222.2 47.4% 11.2%; - - --secondary: 217.2 32.6% 17.5%; - --secondary-foreground: 210 40% 98%; - - --muted: 217.2 32.6% 17.5%; - --muted-foreground: 215 20.2% 65.1%; - - --accent: 217.2 32.6% 17.5%; - --accent-foreground: 210 40% 98%; - - --destructive: 0 62.8% 30.6%; - --destructive-foreground: 210 40% 98%; - - --border: 217.2 32.6% 17.5%; - --input: 217.2 32.6% 17.5%; - --ring: 212.7 26.8% 83.9%; - } + --radius: 0.5rem; } + + .dark { + --background: 240 3% 6%; + --foreground: 0 0% 98%; - @layer base { - * { - @apply border-border; - } - body { - @apply bg-background text-foreground; - } - } \ No newline at end of file + --card: 210 6% 7%; + --card-foreground: 0 0% 98%; + + --popover: 210 6% 7%; + --popover-foreground: 0 0% 98%; + + --primary: 213 74% 30%; + --primary-foreground: 0 0% 98%; + + --secondary: 210 5% 15%; + --secondary-foreground: 0 0% 98%; + + --muted: 210 5% 22%; + --muted-foreground: 215 5% 49%; + + --accent: 213 45% 14%; + --accent-foreground: 0 0% 98%; + + --destructive: 0 84% 60%; + --destructive-foreground: 0 0% 98%; + + --border: 220 5% 12%; + --input: 210 4% 18%; + --ring: 213 75% 40%; + } +} + +@layer base { + * { + @apply border-border; + } + body { + @apply bg-background text-foreground; + } +} + +@font-face { + font-family: "yekan"; + src: url(../public/fonts/iranyekanwebregularfanum.ttf); +} + +@font-face { + font-family: "yekan-m"; + src: url(../public/fonts/iranyekanwebmediumfanum.ttf); +} + +/* Change the white to any color */ +input:-webkit-autofill, +input:-webkit-autofill:hover, +input:-webkit-autofill:focus, +input:-webkit-autofill:active{ + -webkit-box-shadow: 0 0 0 30px white inset !important; +} \ No newline at end of file diff --git a/app/layout.tsx b/app/layout.tsx index dd96ff5..5d5dc6f 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -17,10 +17,12 @@ export default function RootLayout({ children: React.ReactNode; }>) { return ( - - + + -
{children}
+
+ {children} +
diff --git a/app/page.tsx b/app/page.tsx index af61af6..04de88b 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,7 +1,6 @@ +import Login from "@/components/Login"; import Image from "next/image"; export default function Home() { - return ( -
- ); + return ; } diff --git a/components/Login.tsx b/components/Login.tsx new file mode 100644 index 0000000..af53c76 --- /dev/null +++ b/components/Login.tsx @@ -0,0 +1,37 @@ +import Image from "next/image"; +import React from "react"; +import LoginForm from "./LoginForm"; +import Link from "next/link"; + +export default function Login() { + return ( +
+ ostandari + +
+ ostandari +
+

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

+ + +

فراموشی رمز عبور

+ +
+
+
+ ); +} diff --git a/components/LoginForm.tsx b/components/LoginForm.tsx new file mode 100644 index 0000000..ccbb45e --- /dev/null +++ b/components/LoginForm.tsx @@ -0,0 +1,198 @@ +"use client"; + +import { zodResolver } from "@hookform/resolvers/zod"; +import { useForm } from "react-hook-form"; +import { 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 { Eye, EyeOff, Lock, RefreshCcw, Shield, UserRound } from "lucide-react"; +import { useQuery } from "@tanstack/react-query"; +import { getCaptcha } from "@/lib/api/Authenticate"; +import { Oval, ThreeDots } from "react-loader-spinner"; +import Image from "next/image"; +import { useState } from "react"; + +const FormSchema = z.object({ + username: z.string().min(2, { + message: "Username must be at least 2 characters.", + }), + password: z.string().min(2, { + message: "Username must be at least 2 characters.", + }), + captcha: z + .string({ required_error: "لطفا کد امنیتی را وارد نمایید." }) + .length(5, { message: "لطفا کد امنیتی را به طور کامل وارد نمایید." }), +}); + +export default function LoginForm() { + const [showPassword, setShowPassword] = useState(false); + + const { + data: CaptchaData, + isLoading, + refetch, + } = useQuery({ + queryKey: ["Captcha"], + queryFn: () => getCaptcha(), + refetchOnWindowFocus: false, + }); + + const form = useForm>({ + resolver: zodResolver(FormSchema), + defaultValues: { + username: "", + }, + }); + + function onSubmit(data: z.infer) { + console.log("🚀 ~ onSubmit ~ data:", data); + } + + console.log(CaptchaData); + const srcForImage = CaptchaData ? URL.createObjectURL(CaptchaData) : null; + + return ( +
+
+ + ( + + نام کاربری + +
+
+ +
+ +
+
+ +
+ )} + /> + + ( + + رمز عبور + +
+
+ +
+ +
+ {showPassword ? ( + setShowPassword(false)} + size={20} + className=" cursor-pointer" + strokeWidth={1.5} + /> + ) : ( + setShowPassword(true)} + size={20} + strokeWidth={1.5} + /> + )} +
+
+
+ +
+ )} + /> +
+ ( + + کد امنیتی + +
+
+ +
+ +
+
+ +
+ )} + /> + + {isLoading ? ( +
+ +
+ ) : ( +
+ icon + refetch()} + size={23} + color="#003778" + /> +
+ )} +
+ + + + +
+ ); +} diff --git a/components/ui/button.tsx b/components/ui/button.tsx new file mode 100644 index 0000000..0ba4277 --- /dev/null +++ b/components/ui/button.tsx @@ -0,0 +1,56 @@ +import * as React from "react" +import { Slot } from "@radix-ui/react-slot" +import { cva, type VariantProps } from "class-variance-authority" + +import { cn } from "@/lib/utils" + +const buttonVariants = cva( + "inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50", + { + variants: { + variant: { + default: "bg-primary text-primary-foreground hover:bg-primary/90", + destructive: + "bg-destructive text-destructive-foreground hover:bg-destructive/90", + outline: + "border border-input bg-background hover:bg-accent hover:text-accent-foreground", + secondary: + "bg-secondary text-secondary-foreground hover:bg-secondary/80", + ghost: "hover:bg-accent hover:text-accent-foreground", + link: "text-primary underline-offset-4 hover:underline", + }, + size: { + default: "h-10 px-4 py-2", + sm: "h-9 rounded-md px-3", + lg: "h-11 rounded-md px-8", + icon: "h-10 w-10", + }, + }, + defaultVariants: { + variant: "default", + size: "default", + }, + } +) + +export interface ButtonProps + extends React.ButtonHTMLAttributes, + VariantProps { + asChild?: boolean +} + +const Button = React.forwardRef( + ({ className, variant, size, asChild = false, ...props }, ref) => { + const Comp = asChild ? Slot : "button" + return ( + + ) + } +) +Button.displayName = "Button" + +export { Button, buttonVariants } diff --git a/components/ui/form.tsx b/components/ui/form.tsx new file mode 100644 index 0000000..4603f8b --- /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 ( +