+
-
-
ورود به پنل کاربری
-
-
-
فراموشی رمز عبور
-
+
+
+
+
+
+
+
ورود به پنل کاربری
+
+
+
فراموشی رمز عبور
+
+
);
}
+
+const LoginLogo = ({ className }: { className: string }) => {
+ return (
+
+ );
+};
diff --git a/components/LoginForm.tsx b/components/LoginForm.tsx
index ccbb45e..5ad8949 100644
--- a/components/LoginForm.tsx
+++ b/components/LoginForm.tsx
@@ -16,18 +16,20 @@ import {
} 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 { useMutation, useQuery } from "@tanstack/react-query";
+import { LoginStaff, getCaptcha } from "@/lib/api/Authenticate";
import { Oval, ThreeDots } from "react-loader-spinner";
import Image from "next/image";
import { useState } from "react";
+import { useRouter } from "next/navigation";
+import { login } from "@/lib/authActions";
const FormSchema = z.object({
- username: z.string().min(2, {
- message: "Username must be at least 2 characters.",
+ username: z.string().min(1, {
+ message: "لطفا نام کاربری خود را وارد نمایید.",
}),
- password: z.string().min(2, {
- message: "Username must be at least 2 characters.",
+ password: z.string().min(1, {
+ message: "لطفا رمز عبور خود را وارد نمایید.",
}),
captcha: z
.string({ required_error: "لطفا کد امنیتی را وارد نمایید." })
@@ -36,7 +38,9 @@ const FormSchema = z.object({
export default function LoginForm() {
const [showPassword, setShowPassword] = useState(false);
+ const router = useRouter();
+ //Queries
const {
data: CaptchaData,
isLoading,
@@ -47,6 +51,20 @@ export default function LoginForm() {
refetchOnWindowFocus: false,
});
+ const loginMutation = useMutation({
+ mutationKey: ["loginStaff"],
+ mutationFn: LoginStaff,
+ onSuccess: (res) => {
+ console.log(res.data.authToken);
+
+ login(JSON.stringify(res.data.authToken), "");
+ // router.push("/Dashboard");
+ },
+ onError: (err) => {
+ refetch();
+ },
+ });
+ //
const form = useForm
>({
resolver: zodResolver(FormSchema),
defaultValues: {
@@ -56,13 +74,23 @@ export default function LoginForm() {
function onSubmit(data: z.infer) {
console.log("🚀 ~ onSubmit ~ data:", data);
+ console.log(CaptchaData);
+ loginMutation.mutate({
+ username: data.username,
+ password: data.password,
+ captcha: {
+ key: CaptchaData?.headers["captcha-key"],
+ value: data.captcha,
+ },
+ });
}
- console.log(CaptchaData);
- const srcForImage = CaptchaData ? URL.createObjectURL(CaptchaData) : null;
+ const srcForImage = CaptchaData
+ ? URL.createObjectURL(CaptchaData.data)
+ : null;
return (
-