From 85b14ee5e817445dee2aa0c917ee7bceea785392 Mon Sep 17 00:00:00 2001 From: Hossein Rahmani Date: Thu, 4 Jan 2024 11:21:56 +0330 Subject: [PATCH] Citizen Panel, Request Steps done + bugs fixed --- app/Account/Complaints/[id]/page.tsx | 7 + app/Account/Complaints/page.tsx | 6 + app/Account/page.tsx | 5 + app/CitizenLogin/page.tsx | 7 + app/Login/page.tsx | 12 +- .../(Citizen)/CitizenDashboard/layout.tsx | 2 - app/components/Landing.tsx | 73 +++-- components/CitizenLogin.tsx | 5 +- components/ComplainsDetails.tsx | 99 +++++-- components/FollowResult.tsx | 2 +- components/Login.tsx | 2 + components/Navbar.tsx | 55 ++-- components/NavbarSm.tsx | 15 +- components/ProfileDropDown.tsx | 86 ++++++ components/RequestResult.tsx | 32 +- components/RequestStep1.tsx | 276 ++++++++++-------- components/RequestStep2.tsx | 217 +++++++++----- components/TabController.tsx | 33 +-- components/TableController.tsx | 132 +++------ components/TopNav.tsx | 4 +- components/Verify.tsx | 61 ++-- constants/index.tsx | 2 +- hooks/useAuthentication.tsx | 0 lib/utils.ts | 11 + store/useToken.ts | 4 +- tailwind.config.js | 3 + utils/authenticateApi.ts | 15 +- utils/citizenApi.ts | 23 +- utils/commonApi.ts | 30 +- utils/complaintCategoriesApi.ts | 4 + utils/complaintOrganizationsApi.ts | 0 31 files changed, 743 insertions(+), 480 deletions(-) create mode 100644 app/Account/Complaints/[id]/page.tsx create mode 100644 app/Account/Complaints/page.tsx create mode 100644 app/Account/page.tsx create mode 100644 components/ProfileDropDown.tsx create mode 100644 hooks/useAuthentication.tsx create mode 100644 utils/complaintCategoriesApi.ts create mode 100644 utils/complaintOrganizationsApi.ts diff --git a/app/Account/Complaints/[id]/page.tsx b/app/Account/Complaints/[id]/page.tsx new file mode 100644 index 0000000..e822830 --- /dev/null +++ b/app/Account/Complaints/[id]/page.tsx @@ -0,0 +1,7 @@ +import ComplainsDetails from "@/components/ComplainsDetails"; +import React from "react"; + +export default function page({ params }: { params: any }) { + const id = params.id; + return ; +} diff --git a/app/Account/Complaints/page.tsx b/app/Account/Complaints/page.tsx new file mode 100644 index 0000000..46e561d --- /dev/null +++ b/app/Account/Complaints/page.tsx @@ -0,0 +1,6 @@ +import TabController from "@/components/TabController"; +import React from "react"; + +export default function page() { + return ; +} diff --git a/app/Account/page.tsx b/app/Account/page.tsx new file mode 100644 index 0000000..89443d9 --- /dev/null +++ b/app/Account/page.tsx @@ -0,0 +1,5 @@ +import React from "react"; + +export default function page() { + return
page
; +} diff --git a/app/CitizenLogin/page.tsx b/app/CitizenLogin/page.tsx index 09d9d8f..f7d8040 100644 --- a/app/CitizenLogin/page.tsx +++ b/app/CitizenLogin/page.tsx @@ -1,6 +1,13 @@ import CitizenLogin from "@/components/CitizenLogin"; import React from "react"; +import { redirect } from "next/navigation"; +import { cookies } from "next/headers"; export default function page() { + const cookieStore = cookies(); + const token = cookieStore.get("Sootzani_Token"); + if (token) { + redirect("/RequestStep2"); + } return ; } diff --git a/app/Login/page.tsx b/app/Login/page.tsx index ac9a555..8be9d95 100644 --- a/app/Login/page.tsx +++ b/app/Login/page.tsx @@ -1,8 +1,14 @@ +import CitizenLogin from "@/components/CitizenLogin"; import Login from "@/components/Login"; +import { cookies } from "next/headers"; +import { redirect } from "next/navigation"; import React from "react"; export default function page() { - return ( - - ); + const cookieStore = cookies(); + const token = cookieStore.get("Sootzani_Token"); + if (token) { + redirect("/"); + } + return ; } diff --git a/app/UserPanel/(Citizen)/CitizenDashboard/layout.tsx b/app/UserPanel/(Citizen)/CitizenDashboard/layout.tsx index 1c0558a..1c938e8 100644 --- a/app/UserPanel/(Citizen)/CitizenDashboard/layout.tsx +++ b/app/UserPanel/(Citizen)/CitizenDashboard/layout.tsx @@ -7,8 +7,6 @@ export default function RootLayout({ }) { return ( <> - - {children} ) diff --git a/app/components/Landing.tsx b/app/components/Landing.tsx index 48ceedd..ac46449 100644 --- a/app/components/Landing.tsx +++ b/app/components/Landing.tsx @@ -11,49 +11,48 @@ import bgimg from "../../public/img/bg.png"; import Footer from "@/components/Footer"; // Import Swiper React components -import { Swiper, SwiperSlide } from "swiper/react"; +import { Swiper, SwiperSlide } from "swiper/react"; // Import Swiper styles import "swiper/css"; import "swiper/css/pagination"; // import required modules -import { Autoplay, Pagination, Navigation} from "swiper/modules"; +import { Autoplay, Pagination, Navigation } from "swiper/modules"; import { sliderItems } from "@/constants"; export default function Landing() { return (
-
- - {sliderItems.map((item) => { - return ( - - bg - - ); - })} - -
+
+ + {sliderItems.map((item) => { + return ( + + bg + + ); + })} + +
@@ -118,14 +117,14 @@ export default function Landing() { className=" w-1/2 max-lg:w-full border rounded-lg flex flex-row shadow-md hover:shadow-none transition-all max-lg:h-[14em] max-md:h-[12em] max-sm:h-[22em] max-sm:flex-col max-sm:gap-[3px]" > -
+
picture
diff --git a/components/CitizenLogin.tsx b/components/CitizenLogin.tsx index dc17ce1..b2371b3 100644 --- a/components/CitizenLogin.tsx +++ b/components/CitizenLogin.tsx @@ -1,6 +1,6 @@ "use client"; -import React from "react"; +import React, { useEffect } from "react"; import { zodResolver } from "@hookform/resolvers/zod"; import { useForm } from "react-hook-form"; import * as z from "zod"; @@ -26,6 +26,8 @@ import { getCaptcha } from "@/utils/commonApi"; import { useRouter } from "next/navigation"; import { Oval, ThreeDots } from "react-loader-spinner"; import useData from "@/store/useData"; +import { getCookie } from "cookies-next"; +import { isAuthorized } from "@/hooks/useAuthentication"; const FormSchema = z.object({ phoneNumber: z.string().min(1, { message: "لطفا شماره موبایل خود را وارد نمایید.", @@ -83,6 +85,7 @@ export default function CitizenLogin() { ? URL.createObjectURL(CaptchaData.data) : null; + return (
(true); + const [password, setPassword] = useState(true); + const router = useRouter(); const storeData = useData((state) => state.data); let data; - const getComplaintMutation = useMutation< - any, - Error, - { trackingNumber: string; password: string } - >({ + const getComplaintMutation = useMutation({ mutationKey: ["Complaint", id], - mutationFn: - role == "Inspector" - ? (getComplaint as any) - : (postComplaintTracking as any), - onSuccess: (res) => {}, - onError: (err) => {}, + mutationFn: postComplaintTracking, + onSuccess: (res) => { + setOpen(false); + }, + onError: (err) => { + toast("رمز عبور شما صحیح نمیباشد.", { + className: "!bg-red-500 !text-white", + }); + }, }); + const handelPassword = () => { + const payload = { ...storeData, password: password }; + getComplaintMutation.mutate({ Data: payload }); + }; console.log(storeData); - useEffect(() => { - if (role == "Inspector") { - useData.persist.rehydrate(); - } + useData.persist.rehydrate(); }, []); useEffect(() => { - if (storeData && role == "Inspector") { - getComplaintMutation.mutate(storeData); - } + // if (storeData && role == "Inspector") { + // getComplaintMutation.mutate(storeData); + // } }, [storeData]); + if (getComplaintMutation.isSuccess) { data = getComplaintMutation.data; - } else if (Data) { - data = Data; } - console.log(Data); + if (open) { + return ( + + + + رمز عبور + + برای مشاهده درخواست پسورد خود را وارد نمایید. + + +
+ {/* */} + setPassword(e.target.value)} + /> +
+ + + {/* */} + + {/* */} + +
+
+ ); + } return ( <> {data ? ( -
+

گزارش شکایت

diff --git a/components/FollowResult.tsx b/components/FollowResult.tsx index d730fb4..2e8bbc6 100644 --- a/components/FollowResult.tsx +++ b/components/FollowResult.tsx @@ -195,7 +195,7 @@ export default function FollowResult() {
) : ( diff --git a/components/Login.tsx b/components/Login.tsx index 21dd7f6..7782ff6 100644 --- a/components/Login.tsx +++ b/components/Login.tsx @@ -26,6 +26,7 @@ import { getCaptcha } from "@/utils/commonApi"; import { useRouter } from "next/navigation"; import { Oval, ThreeDots } from "react-loader-spinner"; import useData from "@/store/useData"; +import useToken from "@/store/useToken"; const FormSchema = z.object({ username: z.string().min(1, { message: "لطفا نام کاربری را وارد نمایید.", @@ -44,6 +45,7 @@ export default function Login() { const router = useRouter(); const saveData = useData((state) => state.saveData); + const { data: CaptchaData, isLoading, diff --git a/components/Navbar.tsx b/components/Navbar.tsx index a402645..d59fb39 100644 --- a/components/Navbar.tsx +++ b/components/Navbar.tsx @@ -1,22 +1,33 @@ "use client"; -import React from "react"; +import React, { useEffect, useState } from "react"; 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"; -import { usePathname } from 'next/navigation' +import { usePathname } from "next/navigation"; import TopNav from "./TopNav"; - +import { isAuthorized } from "@/lib/utils"; +import useToken from "@/store/useToken"; +import { DropdownMenu } from "@radix-ui/react-dropdown-menu"; +import ProfileDropDown from "./ProfileDropDown"; export default function Navbar() { - const pathname = usePathname() - + const pathname = usePathname(); + const isAuth = useToken((state) => state.token); + const [auth, setAuth] = useState(isAuth); + useToken.persist.rehydrate(); + useEffect(() => { + setAuth(isAuth); + }, [isAuth]); return ( -
- +
@@ -35,28 +46,32 @@ export default function Navbar() {
{menuItems.map((item, index, array) => { - - if (array.length - 1 !== index){ + if (array.length - 1 !== index) { return (
{item.name}
); - }else{ - return ( - <> - ); + } else { + return <>; } - })}
- - - - + {auth ? ( + + ) : ( + + + + )}
); diff --git a/components/NavbarSm.tsx b/components/NavbarSm.tsx index c62da18..1d7f9eb 100644 --- a/components/NavbarSm.tsx +++ b/components/NavbarSm.tsx @@ -11,12 +11,19 @@ import Link from "next/link"; import { Button } from "./ui/button"; import TopNav from "./TopNav"; import { usePathname } from "next/navigation"; +import useToken from "@/store/useToken"; +import ProfileDropDown from "./ProfileDropDown"; // import { routes } from "../routes"; export default function NavbarSm() { const pathname = usePathname(); - + const isAuth = useToken((state) => state.token); + const [auth, setAuth] = useState(isAuth); + useToken.persist.rehydrate(); + useEffect(() => { + setAuth(isAuth); + }, [isAuth]); // useClickAway(ref, () => setOpen(false)); const [isOpen, setOpen] = useState(false); @@ -26,12 +33,12 @@ export default function NavbarSm() { <>
- - + + {auth && } {/* + + + + + + + مشاهده پروفایل + + + router.push("/Account/Complaints")}> + + درخواست های اخیر + + + + { + saveToken(false); + deleteCookie("Sootzani_Token"); + router.replace("/") + }} + > + + خروج + + + + ); +} diff --git a/components/RequestResult.tsx b/components/RequestResult.tsx index 81e994c..5f5e67a 100644 --- a/components/RequestResult.tsx +++ b/components/RequestResult.tsx @@ -5,42 +5,42 @@ import Image from "next/image"; import Resultimg from "../public/img/result.png"; import { useQuery, useQueryClient } from "@tanstack/react-query"; import { useRouter } from "next/navigation"; +import { Button } from "./ui/button"; export default function Result() { const trackingNumber = localStorage.getItem("trackingNumber"); const password = localStorage.getItem("password"); const router = useRouter(); - - - useEffect(() => { - localStorage.removeItem("trackingNumber") - localStorage.removeItem("password") -}, [router]); return (

+ 3xl:text-base 3xl:font-bold " + > با تشکر از شما

+ 3xl:text-base 3xl:font-bold " + > درخواست شما با کد پیگیری - - {`${trackingNumber}`} - - و رمز عبور - - {`${password}`} - + {`${trackingNumber}`}و + رمز عبور + {`${password}`} در سامانه سوت زنی ثبت شده و شما می توانید نتیجه درخواست خود را از صفحه پیگیری درخواست، با استفاده از کد رهگیری و رمز عبور مشاهده کنید.

- + {/*
+ +
*/} icon { + const parsedNumber = Number(value); + if (Number.isNaN(parsedNumber)) { + throw new Error("کد ملی معتبر نمی باشد."); + } else if ( + Number(parsedNumber) > 100000000 && + Number(parsedNumber) < 999999999 + ) { + throw new Error("کد ملی معتبر نمی باشد."); + } + return parsedNumber; + }), }); export default function RequestStep1() { - const form = useForm>({ - resolver: zodResolver(FormSchema), - defaultValues: { - firstName: "", - lastName: "", - // nationalCode: , - // phoneNumber: , - }, + const router = useRouter(); + const { + data: profileData, + isLoading, + refetch, + } = useQuery({ + queryKey: ["Profile"], + queryFn: () => getProfile(), + refetchOnWindowFocus: false, }); - function onSubmit(data: z.infer) { - toast({ - title: "You submitted the following values:", - description: ( -
-          {JSON.stringify(data, null, 2)}
-        
- ), - }); - console.log(data); - } + const editProfileMutation = useMutation({ + mutationKey: ["editProfile"], + mutationFn: editProfile, + onSuccess: (res) => { + router.push("/RequestStep2"); + localStorage.setItem("authorized", "true"); + }, + onError: (error) => {}, + }); + const form = useForm>({ + resolver: zodResolver(FormSchema), + }); + if (profileData?.firstName) { + console.log(111); + } + useEffect(() => { + if (profileData) { + form.setValue("firstName", profileData.firstName); + form.setValue("lastName", profileData.lastName); + form.setValue("nationalId", profileData.nationalId); + } + }, [profileData]); + + console.log(form.getValues()); + function onSubmit(data: z.infer) { + // toast({ + // title: "You submitted the following values:", + // description: ( + //
+    //       {JSON.stringify(data, null, 2)}
+    //     
+ // ), + // }); + const strNationalId = String(data.nationalId); + const payload = { ...data, nationalId: strNationalId }; + console.log(data); + editProfileMutation.mutate(payload); + } + return (

لطفا جهت ارسال درخواست فرم زیر را تکمیل نمایید.

-

- در صورت عدم تمایل به ثبت مشخصات شخصی می توانید به صفحه ی بعد مراجعه کنید. -

-
- -
- ( - - - نام - - - - - - - )} - /> - ( - - - نام خانوادگی - - - - - - - )} - /> - ( - - - کد ملی - - - - - - - )} - /> + {/*

+ در صورت عدم تمایل به ثبت مشخصات شخصی می توانید به صفحه ی بعد مراجعه + کنید. +

*/} + {profileData && ( + + +
+ ( + + + نام + + + + + + + )} + /> + ( + + + نام خانوادگی + + + + + + + )} + /> + ( + + + کد ملی + + + + + + + )} + /> +
- ( - - - شماره تماس - - - - - - - )} - /> -
- -
- {/* */} -
-
- +
+ +
+ + + )}
); diff --git a/components/RequestStep2.tsx b/components/RequestStep2.tsx index 1789dea..cae771e 100644 --- a/components/RequestStep2.tsx +++ b/components/RequestStep2.tsx @@ -1,5 +1,5 @@ "use client"; -import React, { useState } from "react"; +import React, { useEffect, useState } from "react"; import { zodResolver } from "@hookform/resolvers/zod"; import { useForm } from "react-hook-form"; @@ -36,9 +36,14 @@ import Image from "next/image"; import Img1 from "../public/img/logo.png"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; -import { postComplaintSubmit } from "@/utils/citizenApi"; +import { + postAuthorizedComplaintSubmit, + postComplaintSubmit, +} from "@/utils/citizenApi"; import { useRouter } from "next/navigation"; -import { getCaptcha, getCategory } from "@/utils/commonApi"; +import { getCaptcha, getCategory, getOrganizations } from "@/utils/commonApi"; +import { ThreeDots } from "react-loader-spinner"; +import useToken from "@/store/useToken"; const MAX_IMAGE_SIZE = 5242880; // 5 MB const ALLOWED_IMAGE_TYPES = [ @@ -49,22 +54,20 @@ const ALLOWED_IMAGE_TYPES = [ ]; const FormSchema = z.object({ - subject: z.string().min(2, { - message: "subject must be at least 2 characters.", + title: z.string().min(1, { + message: "لطفا موضوع شکایت را وارد نمایید.", }), - 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.", + OrganizationId: z.string({ + required_error: "لطفا دستگاه مربوطه را انتخاب نمایید.", }), + person: z.string().optional(), description: z .string() - .min(5, { - message: "description must be at least 5 characters.", + .min(1, { + message: "لطفا توضیحات خود را بنویسید.", }) - .max(200, { - message: "description must not be longer than 200 characters.", + .max(300, { + message: "تعداد کاراکترها بیشتر از حد مجاز میباشد.", }), uploadFile: z .custom((val) => val instanceof FileList, "Required") @@ -73,47 +76,59 @@ const FormSchema = z.object({ .refine( (files) => Array.from(files).every((file) => file.size <= MAX_IMAGE_SIZE), `Each file size should be less than 5 MB.` - ), - // .refine( - // (files) => - // Array.from(files).every((file) => - // ALLOWED_IMAGE_TYPES.includes(file.type) - // ), - // "Only these types are allowed .jpg, .jpeg, .png and .webp" - // ), + ) + .nullish(), + // .refine( + // (files) => + // Array.from(files).every((file) => + // ALLOWED_IMAGE_TYPES.includes(file.type) + // ), + // "Only these types are allowed .jpg, .jpeg, .png and .webp" + // ), categoryId: z.string({ - required_error: "Please select an category to display.", + required_error: "لطفا دسته بندی را انتخاب نمایید.", }), - captchaValue: z.string().min(4, { - message: "captcha must be at least 4 characters.", + captchaValue: z.string().min(1, { + message: "لطفا کد امنیتی را وارد نمایید.ئ", }), }); +interface Organization { + title: string; + description: string; + isDeleted: string; + id: string; +} + // Form Hook export default function RequestStep2() { // const [trackingComplaint, setTrackingComplaint] = useState({}); - + const isAuth = useToken((state) => state.token); const router = useRouter(); - + useEffect(() => { + useToken.persist.rehydrate(); + }, []); const complaintSubmitMutation = useMutation({ mutationKey: ["complaintSubmit"], mutationFn: postComplaintSubmit, - onSuccess: (res) => { - console.log(res); localStorage.setItem("trackingNumber", res.trackingNumber); localStorage.setItem("password", res.password); - - // alert("Success"); - console.log("Success Step2"); router.push("/RequestResult"); - // router.push("/RequestResult", { data: trackingComplaint }); - // return (res) }, - onError: (error) => { - console.log(error); - console.log(error?.message); + onError: (error) => {}, + }); + + const authorizedComplaintSubmitMutation = useMutation({ + mutationKey: ["authorizedComplaintSubmit"], + mutationFn: postAuthorizedComplaintSubmit, + onSuccess: (res) => { + localStorage.setItem("trackingNumber", res.trackingNumber); + localStorage.setItem("password", res.password); + localStorage.removeItem("authorized"); + router.push("/RequestResult"); }, + onError: (error) => {}, }); // All Category @@ -122,8 +137,17 @@ export default function RequestStep2() { queryFn: () => getCategory(), }); + const { data: organizationsData } = useQuery({ + queryKey: ["organizations"], + queryFn: () => getOrganizations(), + }); + // Captcha - const { data: CaptchaData, isLoading } = useQuery({ + const { + data: CaptchaData, + isLoading, + refetch, + } = useQuery({ queryKey: ["Captcha"], queryFn: () => getCaptcha(), }); @@ -136,8 +160,7 @@ export default function RequestStep2() { const form = useForm>({ resolver: zodResolver(FormSchema), defaultValues: { - subject: "", - organisation: "", + title: "", person: "", description: "", captchaValue: "", @@ -146,34 +169,34 @@ export default function RequestStep2() { }); function onSubmit(data: z.infer) { - // toast({ - // title: "You submitted the following values:", - // description: ( - //
-    //       {JSON.stringify(data, null, 2)}
-    //     
- // ), - // }); - const formData = new FormData(); - formData.append("Title", data.subject); + formData.append("Title", data.title); formData.append("Text", data.description); formData.append("CategoryId", data.categoryId); - formData.append("Medias", data.uploadFile[0]); + if (data?.uploadFile && data?.uploadFile?.length > 0) { + for (let i = 0; i < data.uploadFile.length; i++) { + formData.append("Medias", data.uploadFile[i]); + } + } formData.append("Captcha.Value", data.captchaValue); formData.append("Captcha.Key", CaptchaData?.headers["captcha-key"]); - - complaintSubmitMutation.mutate({ - Data: formData, - }); + formData.append("Complaining", data.person ? data.person : ""); + formData.append("OrganizationId", data.OrganizationId); + if (isAuth) { + authorizedComplaintSubmitMutation.mutate({ + Data: formData, + }); + } else { + complaintSubmitMutation.mutate({ + Data: formData, + }); + } + refetch(); resetField("Title"); resetField("Text"); resetField("Medias"); resetField("CategoryId"); resetField("Captcha.Value"); - - console.log("submited"); - console.log(data); } const { resetField } = useForm(); @@ -192,7 +215,7 @@ export default function RequestStep2() { > ( @@ -211,19 +234,41 @@ export default function RequestStep2() {
( - + *دستگاه مربوطه - - - - + + )} /> @@ -281,6 +326,7 @@ export default function RequestStep2() { - + )} /> @@ -324,7 +370,7 @@ export default function RequestStep2() { return ( - آپلود تصویر + پیوست {/* File Upload */} @@ -367,12 +413,12 @@ export default function RequestStep2() { />
{/* Captcha */} -
+
( - + *کد امنیتی @@ -387,31 +433,40 @@ export default function RequestStep2() { )} /> -
- {!isLoading && ( + {isLoading ? ( +
+ +
+ ) : ( +
icon - )} - {/* 1 */} -
+
+ )}
- {/* */} - {/* */}
diff --git a/components/TabController.tsx b/components/TabController.tsx index ce53221..d9e9659 100644 --- a/components/TabController.tsx +++ b/components/TabController.tsx @@ -21,22 +21,17 @@ import { useRouter } from "next/navigation"; import { Decrypt } from "@/lib/utils"; import useData from "@/store/useData"; import { toast } from "sonner"; +import { getComplaints } from "@/utils/citizenApi"; export default function TabController() { const saveData = useData((state) => state.saveData); const [selectedFile, setSelectedFile] = useState(null); const router = useRouter(); - const handleFileChange = (event: any) => { - const file = event.target.files[0]; - const reader = new FileReader(); - reader.onload = (e) => { - const contents = e?.target?.result; - // Process the contents of the file here - setSelectedFile(contents); - console.log(contents); - }; + const { data, isLoading } = useQuery({ + queryKey: ["CitizenList"], + queryFn: () => getComplaints(), + refetchOnWindowFocus: false, + }); - reader.readAsText(file); - }; const checkKey = (item: any) => { const dcKey = Decrypt(item.cipherKeyInspector, selectedFile); if (dcKey != false && dcKey != null) { @@ -51,11 +46,7 @@ export default function TabController() { }); } }; - const { data, isLoading, refetch } = useQuery({ - queryKey: ["ComplaintsList"], - queryFn: () => getComplaintsList(), - refetchOnWindowFocus: false, - }); + console.log(data); const newComplaints = data?.filter((item: any) => item.status == 0); const inProgressComplaints = data?.filter((item: any) => item.status == 1); @@ -70,7 +61,7 @@ export default function TabController() { return (
- + {/* - + */}
{/* Tab Title */} @@ -91,7 +82,7 @@ export default function TabController() { value="tab1" className="hover:border-b-2 border-b-blue" > - جدید (2) + ثبت شده
{/* */} - + /> */}
diff --git a/components/TableController.tsx b/components/TableController.tsx index beff4d8..f0b2b97 100644 --- a/components/TableController.tsx +++ b/components/TableController.tsx @@ -47,11 +47,12 @@ export default function TableController({ checkKey, }: { data: Complaint[]; - checkKey: (item:any) => any; + checkKey: (item: any) => any; }) { console.log(data); const saveData = useData((state) => state.saveData); const [selectedFile, setSelectedFile] = useState(null); + const [open, setOpen] = useState(false); const router = useRouter(); const handleFileChange = (event: any) => { const file = event.target.files[0]; @@ -78,97 +79,50 @@ export default function TableController({ // }; return (
- - {/* - - */} - - - {/* A list of your recent invoices. */} - - - ردیف - تاریخ - موضوع - دستگاه مربوطه - - - - {data?.map((item: Complaint, index: number) => { - return ( - checkKey(item) - // saveData({ - // trackingNumber: item.trackingNumber, - // password: Decrypt(item.cipherKeyInspector), - // }) - } - className=" hover:bg-gray-200 cursor-pointer" - key={item.id} - > - {/* + {/* A list of your recent invoices. */} + + + ردیف + تاریخ + موضوع + دستگاه مربوطه + + + + {data?.map((item: Complaint, index: number) => { + return ( + { + router.push(`/Account/Complaints/${item.id}`); + // setOpen(true); + saveData({ + trackingNumber: item.trackingNumber, + }); + }} + > + {/* */} - - {index + 1} - - - {convertDate(item.registeredAt)} - - - {item?.category ? item.category.title : "-"} - - - - {/* */} - - ); - })} - -
- {/* - - */} - - - بارگذاری کلید خصوصی - - لطفا کلید خصوصی خود را آپلود نمایید. - - -
- {/* */} - -
- - - - - -
-
+ + {index + 1} + + + {convertDate(item.registeredAt)} + + + {item?.title ? item.title : "-"} + + - + {/* */} + + ); + })} + +
); } diff --git a/components/TopNav.tsx b/components/TopNav.tsx index 6eb1042..0b0beff 100644 --- a/components/TopNav.tsx +++ b/components/TopNav.tsx @@ -15,11 +15,11 @@ export default function TopNav() { pathname === "/" ? "bg-transparent" : "bg-white" } `} > -

+

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

{/*

Current pathname: {pathname}

*/} -
+

امروز: چهارشنبه 24 آبان 1402 diff --git a/components/Verify.tsx b/components/Verify.tsx index 6d80f97..b9b664f 100644 --- a/components/Verify.tsx +++ b/components/Verify.tsx @@ -11,6 +11,7 @@ import useData from "@/store/useData"; import { JwtPayload, jwtDecode } from "jwt-decode"; import { setCookie } from "cookies-next"; import { Oval } from "react-loader-spinner"; +import useToken from "@/store/useToken"; export default function Verify() { const [otp, setOtp] = useState(""); @@ -18,29 +19,31 @@ export default function Verify() { const router = useRouter(); const userData = useData((state) => state.data); const [VerifyRole, setVerifyRole] = useState(""); - 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 saveToken = useToken((state) => state.saveToken); + // 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 CitizenVerifyMutation = useMutation({ mutationFn: verifyCitizen, onSuccess: (res) => { + saveToken(true); const decodedToken = jwtDecode(res); setCookie("Sootzani_Token", res); const userRole = @@ -48,7 +51,13 @@ export default function Verify() { "http://schemas.microsoft.com/ws/2008/06/identity/claims/role" ]; localStorage.setItem("Sootzani_Role", userRole); - router.push("/UserPanel/CitizenDashboard"); + const justLogin = localStorage.getItem("Sootzani_Login_State"); + if (justLogin) { + router.push("/"); + localStorage.removeItem("Sootzani_Login_State"); + } else { + router.push("/RequestStep1"); + } }, onError: (err: any) => {}, }); @@ -57,11 +66,7 @@ export default function Verify() { console.log(otp); const payload = { ...userData, verificationCode: otp }; console.log(userData); - if (userData?.phoneNumber) { - CitizenVerifyMutation.mutate(payload); - } else { - verifyMutation.mutate(payload); - } + CitizenVerifyMutation.mutate(payload); }; useEffect(() => { @@ -103,12 +108,12 @@ export default function Verify() {