From cd8c85a6a251b25c25c4b4c89a160760c4fa3df2 Mon Sep 17 00:00:00 2001 From: Hossein Rahmani Date: Mon, 1 Jan 2024 23:30:45 +0330 Subject: [PATCH] Part of Inspector & Citizen Operations done --- app/CitizenLogin/page.tsx | 6 + .../Complaints/[id]/page.tsx | 23 +- components/CitizenLogin.tsx | 199 +++++++++++++ components/ComplainsDetails.tsx | 171 +++++------ components/FollowResult.tsx | 266 ++++++++++-------- components/InspectorOperations.tsx | 230 ++++++++++++--- components/RequestStep2.tsx | 10 +- components/Search.tsx | 2 +- components/TabController.tsx | 17 +- components/Verify.tsx | 27 +- components/ui/select.tsx | 4 +- constants/index.tsx | 46 ++- lib/utils.ts | 1 - utils/authenticateApi.ts | 8 +- utils/citizenApi.ts | 39 +-- utils/inspectorApi.ts | 9 +- 16 files changed, 711 insertions(+), 347 deletions(-) create mode 100644 app/CitizenLogin/page.tsx create mode 100644 components/CitizenLogin.tsx diff --git a/app/CitizenLogin/page.tsx b/app/CitizenLogin/page.tsx new file mode 100644 index 0000000..09d9d8f --- /dev/null +++ b/app/CitizenLogin/page.tsx @@ -0,0 +1,6 @@ +import CitizenLogin from "@/components/CitizenLogin"; +import React from "react"; + +export default function page() { + return ; +} diff --git a/app/UserPanel/(Controller)/ControllerDashboard/Complaints/[id]/page.tsx b/app/UserPanel/(Controller)/ControllerDashboard/Complaints/[id]/page.tsx index c431267..1843f83 100644 --- a/app/UserPanel/(Controller)/ControllerDashboard/Complaints/[id]/page.tsx +++ b/app/UserPanel/(Controller)/ControllerDashboard/Complaints/[id]/page.tsx @@ -1,13 +1,18 @@ -import ComplainsDetails from '@/components/ComplainsDetails' -import React from 'react' - -export default function page({params}:{params:any}) { +import ComplainsDetails from "@/components/ComplainsDetails"; +import React from "react"; +export default function page({ params }: { params: any }) { const id = params.id; - { console.log(params);} - { console.log(id);} - + { + console.log(params); + } + { + console.log(id); + } + return ( - - ) +
+ ; +
+ ); } diff --git a/components/CitizenLogin.tsx b/components/CitizenLogin.tsx new file mode 100644 index 0000000..dc17ce1 --- /dev/null +++ b/components/CitizenLogin.tsx @@ -0,0 +1,199 @@ +"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"; +import { useMutation, useQuery } from "@tanstack/react-query"; +import { loginStaff, logisterCitizen } 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({ + phoneNumber: z.string().min(1, { + message: "لطفا شماره موبایل خود را وارد نمایید.", + }), + captcha: z + .string({ required_error: "لطفا کد امنیتی را وارد نمایید." }) + .length(5, { message: "لطفا کد امنیتی را به طور کامل وارد نمایید." }), +}); + +export default function CitizenLogin() { + const router = useRouter(); + const saveData = useData((state) => state.saveData); + + const { + data: CaptchaData, + isLoading, + refetch, + } = useQuery({ + queryKey: ["Captcha"], + queryFn: () => getCaptcha(), + refetchOnWindowFocus: false, + }); + + const loginMutation = useMutation({ + mutationFn: logisterCitizen, + onSuccess: (res) => {}, + onError: (err: any) => { + if (err.response.status == 428) { + console.log(useData); + router.push("/Verify"); + localStorage.setItem("VerifyRole", "citizen"); + } + }, + }); + + const form = useForm>({ + resolver: zodResolver(FormSchema), + }); + + function onSubmit(data: z.infer) { + const payload = { + phoneNumber: data.phoneNumber, + captcha: { + key: CaptchaData?.headers["captcha-key"], + value: data.captcha, + }, + }; + loginMutation.mutate(payload); + saveData({ + phoneNumber: data.phoneNumber, + }); + } + + const srcForImage = CaptchaData + ? URL.createObjectURL(CaptchaData.data) + : null; + + return ( +
+
+ icon + +

+ احراز هویت +

+ +
+ + ( + + + شماره موبایل + + + + + {/* + This is your public display name. + */} + + + )} + /> +
+ ( + + {/* + رمز عبور + */} + + + + + + )} + /> + {isLoading ? ( +
+ +
+ ) : ( +
+ icon +
+ )} +
+
+ +
+ + +
+
+ ); +} diff --git a/components/ComplainsDetails.tsx b/components/ComplainsDetails.tsx index 92f39a4..2f3dc93 100644 --- a/components/ComplainsDetails.tsx +++ b/components/ComplainsDetails.tsx @@ -5,40 +5,62 @@ import blueIcon from "../public/img/bluepoint.svg"; import Image from "next/image"; import { ComplainDetailsItems } from "@/constants"; import { useMutation } from "@tanstack/react-query"; -import { getComplaint } from "@/utils/inspectorApi"; +import { OperateByInspector, getComplaint } from "@/utils/inspectorApi"; import useData from "@/store/useData"; import { convertDate } from "@/lib/utils"; import { Badge } from "./ui/badge"; import InspectorOperations from "./InspectorOperations"; +import { postComplaintTracking } from "@/utils/citizenApi"; -export default function ComplainsDetails({ id }: { id: number }) { - const complainData = useData((state) => state.data); - const getComplaintMutation = useMutation({ +export default function ComplainsDetails({ + id, + role, + Data, +}: { + id?: number; + role: string; + Data?: any; +}) { + const storeData = useData((state) => state.data); + let data; + + const getComplaintMutation = useMutation< + any, + Error, + { trackingNumber: string; password: string } + >({ mutationKey: ["Complaint", id], - mutationFn: getComplaint, + mutationFn: + role == "Inspector" + ? (getComplaint as any) + : (postComplaintTracking as any), onSuccess: (res) => {}, onError: (err) => {}, }); - console.log(complainData); + + console.log(storeData); + useEffect(() => { - useData.persist.rehydrate(); + if (role == "Inspector") { + useData.persist.rehydrate(); + } }, []); useEffect(() => { - if (complainData) { - getComplaintMutation.mutate(complainData); + if (storeData && role == "Inspector") { + getComplaintMutation.mutate(storeData); } - }, [complainData]); - let data; + }, [storeData]); if (getComplaintMutation.isSuccess) { - console.log(getComplaintMutation.data); data = getComplaintMutation.data; - console.log(data); + } else if (Data) { + data = Data; } + console.log(Data); return ( -
+ <> {data ? ( -
-
+
+

گزارش شکایت

@@ -80,12 +102,18 @@ export default function ComplainsDetails({ id }: { id: number }) { 0353286545 جهت پشتیبانی تماس حاصل کنید.{" "}

*/}
-
-

انجام عملیات

- +
+

+ انجام عملیات +

+ getComplaintMutation.mutate(storeData)} + role={role} + complaintData={data} + />
-
+

روند شکایت

{data.contents?.map((item: any) => { @@ -102,13 +130,16 @@ export default function ComplainsDetails({ id }: { id: number }) {

-
- متن: {item.text ? item.text : "-"} +
+ متن:{" "} + + {item.text ? item.text : "-"} +
); })} - {data.contents?.map((item: any) => { + {/* {data.contents?.map((item: any) => { return (
@@ -127,89 +158,19 @@ export default function ComplainsDetails({ id }: { id: number }) {
); - })} - {data.contents?.map((item: any) => { - return ( -
-
-

- {item.sender == 0 ? "شهروند" : "بازرس"} -

-

- تاریخ : - - {convertDate(item.dateTime)} - -

-
-
- متن: {item.text ? item.text : "-"} -
-
- ); - })} - {data.contents?.map((item: any) => { - return ( -
-
-

- {item.sender == 0 ? "شهروند" : "بازرس"} -

-

- تاریخ : - - {convertDate(item.dateTime)} - -

-
-
- متن: {item.text ? item.text : "-"} -
-
- ); - })} - {data.contents?.map((item: any) => { - return ( -
-
-

- {item.sender == 0 ? "شهروند" : "بازرس"} -

-

- تاریخ : - - {convertDate(item.dateTime)} - -

-
-
- متن: {item.text ? item.text : "-"} -
-
- ); - })} - {data.contents?.map((item: any) => { - return ( -
-
-

- {item.sender == 0 ? "شهروند" : "بازرس"} -

-

- تاریخ : - - {convertDate(item.dateTime)} - -

-
-
- متن: {item.text ? item.text : "-"} -
-
- ); - })} + })} */}
+
+

+ انجام عملیات +

+ getComplaintMutation.mutate(storeData)} + role={role} + complaintData={data} + /> +
{/* Left */} {/*

@@ -253,6 +214,6 @@ export default function ComplainsDetails({ id }: { id: number }) { ) : ( "" )} -

+ ); } diff --git a/components/FollowResult.tsx b/components/FollowResult.tsx index a955e20..d552cf7 100644 --- a/components/FollowResult.tsx +++ b/components/FollowResult.tsx @@ -23,39 +23,39 @@ import { postComplaintTracking } from "@/utils/citizenApi"; import { useMutation } from "@tanstack/react-query"; import { useReactToPrint } from "react-to-print"; -import '../app/print-styles.css'; +import "../app/print-styles.css"; +import ComplainsDetails from "./ComplainsDetails"; export default function FollowResult() { const router = useRouter(); const [trackingNumber, setTrackingNumber] = useState(); const [password, setPassword] = useState(); - const [complaintData, setComplaintData] = useState(); - + const [complaintData, setComplaintData] = useState(); - // Print component Data + // Print component Data const componentRef = useRef(null); const handlePrint = useReactToPrint({ - content: () => componentRef.current + content: () => componentRef.current, }); - useEffect(() => { setTrackingNumber(localStorage.getItem("trackingNumber2")); setPassword(localStorage.getItem("password2")); }, []); + useEffect(() => { + if (trackingNumber && password) { + complaintPrintMutation.mutate({ + Data: { trackingNumber: trackingNumber, password: password }, + }); + } + }, [trackingNumber, password]); + const complaintPrintMutation = useMutation({ mutationKey: ["complaintPrint"], mutationFn: postComplaintTracking, - onSuccess: (res) => { - console.log(res); - // alert("SuccessPrint"); - console.log("Success Folllow Result"); - console.log(res); - setComplaintData(res); - console.log(complaintData); }, onError: (error) => { console.log(error); @@ -66,124 +66,142 @@ export default function FollowResult() { function onSubmit() { console.log("SuccessPrinttttttttttt"); - complaintPrintMutation.mutate({ - Data: { trackingNumber: trackingNumber, password: password }, - }); + // complaintPrintMutation.mutate({ + // Data: { trackingNumber: trackingNumber, password: password }, + // }); } + // const possibleOperations = complaintPrintMutation.data?.possibleOperations; + // const selectOptions = Operations.filter((item, index) => + // possibleOperations.includes(index) + // ); - -const printableContent = 'This is the content to be printed.'; - + const printableContent = "This is the content to be printed."; + console.log(complaintPrintMutation?.data); return ( -
-
-

+ {/*

*/} + {/*

- درخواست شما با کد رهگیری - {`${trackingNumber}`}و - رمز عبور - {`${password}`} - در دست بررسی و اقدام می باشد. در صورت تمایل می توانید با شماره تلفن - 0353286545 جهت پشتیبانی تماس حاصل کنید. -

+ > + درخواست شما با کد رهگیری + {`${trackingNumber}`}و + رمز عبور + {`${password}`} + در دست بررسی و اقدام می باشد. در صورت تمایل می توانید با شماره تلفن + 0353286545 جهت پشتیبانی تماس حاصل کنید. +

*/} + {complaintPrintMutation?.data ? ( + <> +
+ + + + -
- - - - - - - - -

- گزارش شکایات -

- - - - -
- - - {complaintPrintMutation.isPending ? ( -
- -
- ) : ( -
-

- {" "} - موضوع شکایت:{" "} - - {`${complaintData?.title}`} - + + + +

+ گزارش شکایات

-

- {" "} - متن شکایت:{" "} - - {`${complaintData?.contents[0]?.text}`} - -

-
-

- {" "} - جزئیات شکایت: -

-
-

- درخواست شما با کد رهگیری - {`${trackingNumber}`} - و رمز عبور - {`${password}`} - در دست بررسی و اقدام می باشد. در صورت تمایل می توانید با - شماره تلفن 0353286545 جهت پشتیبانی تماس حاصل کنید. -

- -
- )} -
-
- - {/* Cancel */} - - - -
-
-
- - icon + + + + + + + {complaintPrintMutation.isPending ? ( +
+ +
+ ) : ( +
+

+ {" "} + موضوع شکایت:{" "} + + {`${complaintData?.title}`} + +

+

+ {" "} + متن شکایت:{" "} + + {`${complaintData?.contents[0]?.text}`} + +

+
+ +

+ {" "} + جزئیات شکایت: +

+
+

+ درخواست شما با کد رهگیری + {`${trackingNumber}`} + و رمز عبور + {`${password}`} + در دست بررسی و اقدام می باشد. در صورت تمایل می + توانید با شماره تلفن 0353286545 جهت پشتیبانی تماس + حاصل کنید. +

+
+ )} +
+ + + {/* Cancel */} + + + +
+
+ + + ) : ( + "" + )} + + {/* icon */} + {/*
*/}
-
+ ); } diff --git a/components/InspectorOperations.tsx b/components/InspectorOperations.tsx index d5072b5..0b5feee 100644 --- a/components/InspectorOperations.tsx +++ b/components/InspectorOperations.tsx @@ -15,36 +15,103 @@ import { FormMessage, } from "@/components/ui/form"; import { Textarea } from "@/components/ui/textarea"; -import { toast } from "@/components/ui/use-toast"; import { Label } from "./ui/label"; import { Input } from "./ui/input"; import { RadioGroup, RadioGroupItem } from "./ui/radio-group"; +import { + Select, + SelectContent, + SelectGroup, + SelectItem, + SelectLabel, + SelectTrigger, + SelectValue, +} from "@/components/ui/select"; +import { Operations } from "@/constants"; +import useData from "@/store/useData"; +import { useMutation } from "@tanstack/react-query"; +import { OperateByInspector } from "@/utils/inspectorApi"; +import { toast } from "sonner"; +import { postComplaintsDetails } from "@/utils/citizenApi"; -const FormSchema = z.object({ - bio: z - .string() - .min(10, { - message: "Bio must be at least 10 characters.", - }) - .max(160, { - message: "Bio must not be longer than 30 characters.", +export default function InspectorOperations({ + complaintData, + role, + updateData, +}: { + complaintData: any; + role: string; + updateData: () => any; +}) { + const FormSchema = z.object({ + text: z + .string({ required_error: "لطفا متن خود را وارد نمایید." }) + .min(8, { + message: "Bio must be at least 8 characters.", + }) + .max(260, { + message: "Bio must not be longer than 30 characters.", + }), + ...(role == "Inspector" && { + type: z.enum(["private", "public"], { + required_error: "لطفا وضعیت عملیات را انتخاب نمایید.", + }), }), -}); + operation: z.string({ + required_error: "Please select an email to display.", + }), + media: z + .custom((val) => val instanceof FileList, "Required") + // .refine((files) => files.length > 0, `Required`) + .refine((files) => files.length <= 5, `Maximum of 5 File are allowed.`) + .nullish(), + }); + const password = useData((state) => state.data.password); + const possibleOperations = complaintData?.possibleOperations; + const selectOptions = Operations.filter((item, index) => + possibleOperations.includes(index) + ); -export default function InspectorOperations() { const form = useForm>({ resolver: zodResolver(FormSchema), + defaultValues: { + operation: + selectOptions.length == 1 ? String(selectOptions[0].value) : undefined, + }, + }); + + const OperationMutation = useMutation({ + mutationKey: ["Operation"], + mutationFn: + role == "Inspector" ? OperateByInspector : postComplaintsDetails, + onSuccess: (res) => { + toast("عملیات شما با موفقیت انجام شد. ", { + className: "!bg-green-500 !text-white", + }); + }, + onError: (err) => {}, }); function onSubmit(data: z.infer) { - toast({ - title: "You submitted the following values:", - description: ( -
-          {JSON.stringify(data, null, 2)}
-        
- ), - }); + console.log(data); + const formData = new FormData(); + formData.append("text", data.text); + formData.append("trackingNumber", complaintData.trackingNumber); + formData.append("Operation", data.operation); + if (data.type) { + formData.append("IsPublic", data.type == "public" ? "true" : "false"); + } + if (role == "Inspector") { + formData.append("EncodedKey", password); + } else { + formData.append("password", localStorage.getItem("password2") as string); + } + if (data?.media && data?.media?.length > 0) { + for (let i = 0; i < data.media.length; i++) { + formData.append("Medias", data.media[i]); + } + } + OperationMutation.mutate(formData); } return ( @@ -52,13 +119,13 @@ export default function InspectorOperations() {
( متن