diff --git a/app/UserPanel/(Controller)/ControllerDashboard/layout.tsx b/app/UserPanel/(Controller)/ControllerDashboard/layout.tsx
index 1e3d64f..26a0c2b 100644
--- a/app/UserPanel/(Controller)/ControllerDashboard/layout.tsx
+++ b/app/UserPanel/(Controller)/ControllerDashboard/layout.tsx
@@ -1,15 +1,21 @@
import NavbarPanel from "@/components/NavbarPanel";
-
-export default function RootLayout({
- children,
- }: {
- children: React.ReactNode;
- }) {
- return (
- <>
-
- {children}
- >
- )
+import { cookies } from "next/headers";
+import { redirect } from "next/navigation";
-}
\ No newline at end of file
+export default function RootLayout({
+ children,
+}: {
+ children: React.ReactNode;
+}) {
+ // const cookieStore = cookies();
+ // const token = cookieStore.get("Sootzani-Token");
+ // if (!token.value) {
+ // return redirect("/");
+ // }
+ return (
+ <>
+
+ {children}
+ >
+ );
+}
diff --git a/components/ControllerDashboard.tsx b/components/ControllerDashboard.tsx
index 8f50353..69ee524 100644
--- a/components/ControllerDashboard.tsx
+++ b/components/ControllerDashboard.tsx
@@ -1,9 +1,22 @@
+"use client"
import React from "react";
import BoxDashboard from "./BoxDashboard";
import LineChart from "./LineChart";
import { HorizontalChart } from "./HorizontalChart";
+import { getComplaintsList } from "@/utils/inspectorApi";
+import { useQuery } from "@tanstack/react-query";
export default function ControllerDashboard() {
+ const {
+ data,
+ isLoading,
+ refetch,
+ } = useQuery({
+ queryKey: ["ComplaintsList"],
+ queryFn: () => getComplaintsList(),
+ refetchOnWindowFocus: false,
+ });
+ console.log(data);
return (
{/* Lg Show */}
diff --git a/components/Login.tsx b/components/Login.tsx
index df2b2f6..21dd7f6 100644
--- a/components/Login.tsx
+++ b/components/Login.tsx
@@ -24,22 +24,26 @@ import { useMutation, useQuery } from "@tanstack/react-query";
import { loginStaff } from "@/utils/authenticateApi";
import { getCaptcha } from "@/utils/commonApi";
import { useRouter } from "next/navigation";
-
+import { Oval, ThreeDots } from "react-loader-spinner";
+import useData from "@/store/useData";
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.",
- }),
- captcha: z.string().min(4, {
- message: "Password must",
+ username: z.string().min(1, {
+ message: "لطفا نام کاربری را وارد نمایید.",
}),
+ password: z
+ .string({ required_error: "لطفا رمز عبور را وارد نمایید." })
+ .min(1, {
+ message: "لطفا رمز عبور را وارد نمایید.",
+ }),
+ captcha: z
+ .string({ required_error: "لطفا کد امنیتی را وارد نمایید." })
+ .length(5, { message: "لطفا کد امنیتی را به طور کامل وارد نمایید." }),
});
export default function Login() {
const router = useRouter();
-
+ const saveData = useData((state) => state.saveData);
+
const {
data: CaptchaData,
isLoading,
@@ -47,23 +51,15 @@ export default function Login() {
} = useQuery({
queryKey: ["Captcha"],
queryFn: () => getCaptcha(),
+ refetchOnWindowFocus: false,
});
- console.log(CaptchaData);
const loginMutation = useMutation({
mutationFn: loginStaff,
- onSuccess: (res) => {
- console.log(res);
- // localStorage.setItem("roles", res.roles[0]);
- // setCookie("token", res.token);
- // if (res.roles[0] == "Operator") {
- // router.push("/MainPage/Prescriptions");
- // } else {
- // router.push("/MainPage");
- // }
- },
+ onSuccess: (res) => {},
onError: (err: any) => {
if (err.response.status == 428) {
+ console.log(useData);
router.push("/Verify");
}
},
@@ -71,22 +67,9 @@ 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(CaptchaData?.headers["captcha-key"]);
const payload = {
username: data.username,
password: data.password,
@@ -95,23 +78,23 @@ export default function Login() {
value: data.captcha,
},
};
- console.log(payload);
loginMutation.mutate(payload);
+ saveData({
+ username: data.username,
+ password: data.password,
+ });
}
- // if (data) {
- // const base64ImageData = btoa(data);
- // }
+
const srcForImage = CaptchaData
? URL.createObjectURL(CaptchaData.data)
: null;
- // const base64ImageData = btoa(data.blob());
return (
-
+
diff --git a/components/NavbarPanel.tsx b/components/NavbarPanel.tsx
index c2574cb..0b9042b 100644
--- a/components/NavbarPanel.tsx
+++ b/components/NavbarPanel.tsx
@@ -1,54 +1,75 @@
"use client";
-import React from "react";
+import React, { useEffect, useState } from "react";
import Link from "next/link";
import { AdminMenuItems, ControllerMenuItems } from "@/constants";
import { usePathname } from "next/navigation";
export default function NavbarPanel() {
const pathname = usePathname();
+ const [role, setRole] = useState
("");
+ useEffect(() => {
+ const userRole = localStorage.getItem("Sootzani_Role");
+ setRole(userRole);
+ }, []);
+ console.log(role);
+ const menus = {
+ Admin: AdminMenuItems,
+ Inspector: ControllerMenuItems,
+ };
+ const selectedMenu = menus[role as keyof typeof menus];
return (
-
-
-
-
-
- پنل کاربری |
-
+ "
+ >
+
+
+ پنل کاربری |
+
-
-
- {/* {ControllerMenuItems.map((item) => {
- return (
-
-
+ {role && (
+ <>
+ {selectedMenu.map(
+ (item: { id: number; name: string; href: string }) => {
+ return (
+
+
{item.name}
-
- );
- })} */}
+ animate-out duration-300 "
+ >
+ {item.name}
+
+
+ );
+ }
+ )}
+ >
+ )}
- {AdminMenuItems.map((item) => {
- return (
-
-
{item.name}
-
- );
- })}
-
-
+ animate-out duration-300 "
+ >
+ {item.name}
+
+
+ );
+ })} */}
-
+
نام و نام خانوادگی (بازرس)
-
);
}
diff --git a/components/Search.tsx b/components/Search.tsx
index 51e646d..5c9cbb5 100644
--- a/components/Search.tsx
+++ b/components/Search.tsx
@@ -17,13 +17,15 @@ import {
AlertDialogTrigger,
} from "@/components/ui/alert-dialog";
import { IoMdClose } from "react-icons/io";
-
+import { useMediaQuery } from "react-responsive";
export default function Search({ mode }: { mode: string }) {
-
+ // useEffect(() => {
+ // const isMobile = useMediaQuery({ query: "(max-width: 768px)" });
+ // }, []);
return (
- {mode === "controller" || mode === "admin" || mode == "landing" ? (
-
+ {mode === "controller" || mode === "admin" ? (
+
) : (
-
-
-
-
-
+ <>
+
+
+
+
+
+
+
+
+
+
+
+ >
)}
);
diff --git a/components/Verify.tsx b/components/Verify.tsx
index 1e5f786..ea7c975 100644
--- a/components/Verify.tsx
+++ b/components/Verify.tsx
@@ -1,8 +1,54 @@
"use client";
import Image from "next/image";
-import React from "react";
+import React, { useEffect, useState } from "react";
import LoginIcon from "../public/img/login-icon.svg";
+import OtpInput from "react-otp-input";
+import { Button } from "./ui/button";
+import { verifyStaff } from "@/utils/authenticateApi";
+import { useMutation } from "@tanstack/react-query";
+import { useRouter } from "next/navigation";
+import useData from "@/store/useData";
+import { JwtPayload, jwtDecode } from "jwt-decode";
+import { setCookie } from "cookies-next";
+import { Oval } from "react-loader-spinner";
+
export default function Verify() {
+ const [otp, setOtp] = useState("");
+ const space = "\xa0";
+ const router = useRouter();
+ const userData = useData((state) => state.data);
+
+ const verifyMutation = useMutation({
+ mutationFn: verifyStaff,
+ onSuccess: (res) => {
+ const decodedToken = jwtDecode
(res);
+ setCookie("Sootzani_Token", res);
+ const userRole =
+ decodedToken[
+ "http://schemas.microsoft.com/ws/2008/06/identity/claims/role"
+ ];
+ localStorage.setItem("Sootzani_Role", userRole);
+ if (userRole == "Inspector") {
+ router.push("/UserPanel/ControllerDashboard");
+ } else if (userRole == "Admin") {
+ router.push("/UserPanel/AdminDashboard");
+ } else {
+ router.push("/UserPanel/CitizenDashboard");
+ }
+ },
+ onError: (err: any) => {},
+ });
+
+ const handelVerify = () => {
+ console.log(otp);
+ const payload = { ...userData, verificationCode: otp };
+ verifyMutation.mutate(payload);
+ };
+
+ useEffect(() => {
+ useData.persist.rehydrate();
+ }, []);
+
return (
-
تایید کد
-
+
+ {space}}
+ renderInput={(props, idx) => (
+
+ )}
+ containerStyle=" flex justify-center"
+ inputStyle=" !w-10 rounded-md h-10 bg-[#F5F5F5] border border-blue/30 text-black"
+ />
+
+
+
+
+
{/*