From 38c23c90639922f75368a410b028c85c0209e05a Mon Sep 17 00:00:00 2001 From: yasaman Date: Mon, 1 Jan 2024 16:43:27 +0330 Subject: [PATCH] Part of Admin panel done --- .../AdminDashboard/KeysManagement/page.tsx | 8 + .../AdminDashboard/Management/page.tsx | 8 - .../AdminDashboard/UserManagement/page.tsx | 8 + app/components/Landing.tsx | 4 +- components/AdminKeysManagement.tsx | 257 ++++++++++++++++++ ...Management.tsx => AdminUserManagement.tsx} | 2 +- components/ComplainsDetails.tsx | 12 +- components/FollowResult.tsx | 28 +- components/NavbarPanel.tsx | 4 +- components/RequestStep1.tsx | 2 +- components/RequestStep2.tsx | 18 +- constants/index.tsx | 7 +- utils/adminApi.ts | 9 +- 13 files changed, 324 insertions(+), 43 deletions(-) create mode 100644 app/UserPanel/(Admin)/AdminDashboard/KeysManagement/page.tsx delete mode 100644 app/UserPanel/(Admin)/AdminDashboard/Management/page.tsx create mode 100644 app/UserPanel/(Admin)/AdminDashboard/UserManagement/page.tsx create mode 100644 components/AdminKeysManagement.tsx rename components/{AdminManagement.tsx => AdminUserManagement.tsx} (99%) diff --git a/app/UserPanel/(Admin)/AdminDashboard/KeysManagement/page.tsx b/app/UserPanel/(Admin)/AdminDashboard/KeysManagement/page.tsx new file mode 100644 index 0000000..24aea02 --- /dev/null +++ b/app/UserPanel/(Admin)/AdminDashboard/KeysManagement/page.tsx @@ -0,0 +1,8 @@ +import AdminKeysManagement from '@/components/AdminKeysManagement' +import React from 'react' + +export default function page() { + return ( + + ) +} diff --git a/app/UserPanel/(Admin)/AdminDashboard/Management/page.tsx b/app/UserPanel/(Admin)/AdminDashboard/Management/page.tsx deleted file mode 100644 index 82e57d0..0000000 --- a/app/UserPanel/(Admin)/AdminDashboard/Management/page.tsx +++ /dev/null @@ -1,8 +0,0 @@ -import AdminManagement from '@/components/AdminManagement' -import React from 'react' - -export default function page() { - return ( - - ) -} diff --git a/app/UserPanel/(Admin)/AdminDashboard/UserManagement/page.tsx b/app/UserPanel/(Admin)/AdminDashboard/UserManagement/page.tsx new file mode 100644 index 0000000..ec7fdbb --- /dev/null +++ b/app/UserPanel/(Admin)/AdminDashboard/UserManagement/page.tsx @@ -0,0 +1,8 @@ +import AdminUserManagement from '@/components/AdminUserManagement' +import React from 'react' + +export default function page() { + return ( + + ) +} diff --git a/app/components/Landing.tsx b/app/components/Landing.tsx index 933c4e9..48ceedd 100644 --- a/app/components/Landing.tsx +++ b/app/components/Landing.tsx @@ -21,7 +21,7 @@ import { sliderItems } from "@/constants"; export default function Landing() { return ( -
+
); diff --git a/components/AdminKeysManagement.tsx b/components/AdminKeysManagement.tsx new file mode 100644 index 0000000..972cd7a --- /dev/null +++ b/components/AdminKeysManagement.tsx @@ -0,0 +1,257 @@ +"use client"; + +import React, { useState } from "react"; +import { useQuery } from "@tanstack/react-query"; +import { GenerateKeyPair, GetKeys } from "@/utils/adminApi"; + +import { + AlertDialog, + AlertDialogAction, + AlertDialogCancel, + AlertDialogContent, + AlertDialogDescription, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogTitle, + AlertDialogTrigger, +} from "@/components/ui/alert-dialog"; +import { Button } from "@/components/ui/button"; +import { ThreeDots } from "react-loader-spinner"; + +import { + Form, + FormControl, + FormDescription, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form"; +import { Input } from "@/components/ui/input"; + + +// const FormSchema = z.object({ +// title: z.string().min(2, { +// message: "trackingNumber must be at least 2 characters.", +// }), +// password: z.string().min(4, { +// message: "Password must be at least 4 characters.", +// }), +// }); + +export default function AdminKeysManagement() { + // List Keys + const { + data: data1, + error: Error1, + isLoading: isListLoading, + refetch: refetch1, + } = useQuery({ + queryKey: ["KeysList"], + queryFn: () => GetKeys(), + // refetchOnWindowFocus: false, + }); + console.log(data1); + + // GenerateKeyPair + const { + data: data2, + error: Error2, + isLoading: isNewKeyLoading, + refetch: refetch2, + } = useQuery({ + queryKey: ["GenerateKey"], + queryFn: () => GenerateKeyPair(), + enabled: false, // Disable automatic fetching + }); + const handleClick = () => { + refetch2(); + console.log(data2); + // Manually trigger the query when the button is clicked + }; + + // } + return ( +
+
+ {/* 1 */} + + + + + + + اطلاعات کلید جدید + + {isNewKeyLoading ? ( +
+ +
+ ) : ( +
+

+ کلید عمومی : +

+

+ {data2?.publicKey} +

+ +

+ کلید خصوصی : +

+

+ {data2?.privateKey} +

+
+ )} +
+
+ + بستن + {/* Continue */} + +
+
+ + {/* 1 */} + + + + + + + افزودن کلید جدید + + {isNewKeyLoading ? ( +
+ +
+ ) : ( + <> + //
+ // + //
+ // ( + // + // + // کد پیگیری + // + // + // + // + // + // + // )} + // /> + + // ( + // + // + // رمز عبور + // + // + // + // + // + // + // )} + // /> + //
+ + //
+ // + //
+ //
+ // + )} +
+
+ + بستن + {/* Continue */} + +
+
+ +
+ لیست کلیدها +
+ {/* 2 */} +
+ {data1?.map((item: any) => { + return ( +
+

+ عنوان کلید : + {item.title} +

+

+ آی دی بازرس : + + {item.inspectorId} + +

+
+ ); + })} +
+
+
+ ); +} diff --git a/components/AdminManagement.tsx b/components/AdminUserManagement.tsx similarity index 99% rename from components/AdminManagement.tsx rename to components/AdminUserManagement.tsx index 5b3f89e..827cd7d 100644 --- a/components/AdminManagement.tsx +++ b/components/AdminUserManagement.tsx @@ -22,7 +22,7 @@ import { Button } from "./ui/button"; import { AdminCardItems } from "@/constants"; import TableAdmin from "./TableAdmin"; -export default function AdminManagement() { +export default function AdminUserManagement() { return (
diff --git a/components/ComplainsDetails.tsx b/components/ComplainsDetails.tsx index 92f39a4..92ce15e 100644 --- a/components/ComplainsDetails.tsx +++ b/components/ComplainsDetails.tsx @@ -90,7 +90,7 @@ export default function ComplainsDetails({ id }: { id: number }) {
{data.contents?.map((item: any) => { return ( -
+

{item.sender == 0 ? "شهروند" : "بازرس"} @@ -110,7 +110,7 @@ export default function ComplainsDetails({ id }: { id: number }) { })} {data.contents?.map((item: any) => { return ( -

+

{item.sender == 0 ? "شهروند" : "بازرس"} @@ -130,7 +130,7 @@ export default function ComplainsDetails({ id }: { id: number }) { })} {data.contents?.map((item: any) => { return ( -

+

{item.sender == 0 ? "شهروند" : "بازرس"} @@ -150,7 +150,7 @@ export default function ComplainsDetails({ id }: { id: number }) { })} {data.contents?.map((item: any) => { return ( -

+

{item.sender == 0 ? "شهروند" : "بازرس"} @@ -170,7 +170,7 @@ export default function ComplainsDetails({ id }: { id: number }) { })} {data.contents?.map((item: any) => { return ( -

+

{item.sender == 0 ? "شهروند" : "بازرس"} @@ -190,7 +190,7 @@ export default function ComplainsDetails({ id }: { id: number }) { })} {data.contents?.map((item: any) => { return ( -

+

{item.sender == 0 ? "شهروند" : "بازرس"} diff --git a/components/FollowResult.tsx b/components/FollowResult.tsx index a955e20..1ed4fc2 100644 --- a/components/FollowResult.tsx +++ b/components/FollowResult.tsx @@ -30,20 +30,27 @@ export default function FollowResult() { const [trackingNumber, setTrackingNumber] = useState(); const [password, setPassword] = useState(); const [complaintData, setComplaintData] = useState(); + const [printStyle, setPrintStyle] = useState(true); // Print component Data const componentRef = useRef(null); const handlePrint = useReactToPrint({ - content: () => componentRef.current + content: () => componentRef.current, + // onBeforePrint() { + // setPrintStyle(!printStyle); + // }, + // onAfterPrint() { + // setPrintStyle(!printStyle) + // }, }); - - + useEffect(() => { setTrackingNumber(localStorage.getItem("trackingNumber2")); setPassword(localStorage.getItem("password2")); }, []); + const complaintPrintMutation = useMutation({ mutationKey: ["complaintPrint"], mutationFn: postComplaintTracking, @@ -70,10 +77,7 @@ export default function FollowResult() { Data: { trackingNumber: trackingNumber, password: password }, }); } - - -const printableContent = 'This is the content to be printed.'; - + return (

@@ -114,7 +118,7 @@ const printableContent = 'This is the content to be printed.'; - + {complaintPrintMutation.isPending ? (
) : ( -
+

{" "} موضوع شکایت:{" "} @@ -164,8 +170,8 @@ const printableContent = 'This is the content to be printed.'; )} - - {/* Cancel */} + + {/* Cancel */}

); diff --git a/components/RequestStep1.tsx b/components/RequestStep1.tsx index 4428591..5f99518 100644 --- a/components/RequestStep1.tsx +++ b/components/RequestStep1.tsx @@ -64,7 +64,7 @@ export default function RequestStep1() {

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

-

+

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

diff --git a/components/RequestStep2.tsx b/components/RequestStep2.tsx index d0933f1..7c496bf 100644 --- a/components/RequestStep2.tsx +++ b/components/RequestStep2.tsx @@ -68,19 +68,19 @@ const FormSchema = z.object({ }), uploadFile: z .custom((val) => val instanceof FileList, "Required") - .refine((files) => files.length > 0, `Required`) + // .refine((files) => files.length > 0, `Required`) .refine((files) => files.length <= 5, `Maximum of 5 File are allowed.`) .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" ), + // .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.", }), @@ -331,7 +331,7 @@ export default function RequestStep2() {