diff --git a/app/UserPanel/(Admin)/AdminDashboard/layout.tsx b/app/UserPanel/(Admin)/AdminDashboard/layout.tsx index 1c0558a..959f44d 100644 --- a/app/UserPanel/(Admin)/AdminDashboard/layout.tsx +++ b/app/UserPanel/(Admin)/AdminDashboard/layout.tsx @@ -1,16 +1,22 @@ 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/app/UserPanel/(Admin)/AdminDashboard/page.tsx b/app/UserPanel/(Admin)/AdminDashboard/page.tsx index 4119248..9957518 100644 --- a/app/UserPanel/(Admin)/AdminDashboard/page.tsx +++ b/app/UserPanel/(Admin)/AdminDashboard/page.tsx @@ -1,8 +1,7 @@ import AdminDashboard from "@/components/AdminDashboard"; +import ControllerDashboard from "@/components/ControllerDashboard"; import React from "react"; export default function page() { - return ( - - ); + return ; } diff --git a/app/UserPanel/(Controller)/ControllerDashboard/Complaints/[id]/page.tsx b/app/UserPanel/(Controller)/ControllerDashboard/Complaints/[id]/page.tsx index 1843f83..964edc4 100644 --- a/app/UserPanel/(Controller)/ControllerDashboard/Complaints/[id]/page.tsx +++ b/app/UserPanel/(Controller)/ControllerDashboard/Complaints/[id]/page.tsx @@ -3,16 +3,10 @@ import React from "react"; export default function page({ params }: { params: any }) { const id = params.id; - { - console.log(params); - } - { - console.log(id); - } return (
- ; +
); } diff --git a/app/UserPanel/(Controller)/ControllerDashboard/layout.tsx b/app/UserPanel/(Controller)/ControllerDashboard/layout.tsx index 29df5bc..2f29e0d 100644 --- a/app/UserPanel/(Controller)/ControllerDashboard/layout.tsx +++ b/app/UserPanel/(Controller)/ControllerDashboard/layout.tsx @@ -6,11 +6,12 @@ export default function RootLayout({ }: { children: React.ReactNode; }) { - // const cookieStore = cookies(); - // const token = cookieStore.get("Sootzani-Token"); - // if (!token.value) { - // return redirect("/"); - // } + const cookieStore = cookies(); + const token = cookieStore.get("Sootzani_Token"); + if (!token?.value) { + return redirect("/"); + } + return ( <> diff --git a/app/layout.tsx b/app/layout.tsx index aae73fd..6803ed2 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -20,9 +20,9 @@ export default function RootLayout({ }) { return ( - + - {children} + {children} diff --git a/components/AdminDashboard.tsx b/components/AdminDashboard.tsx index 066e55e..a6fae4b 100644 --- a/components/AdminDashboard.tsx +++ b/components/AdminDashboard.tsx @@ -12,12 +12,12 @@ export default function AdminDashboard() {
+ {/* - - + */}
@@ -26,7 +26,7 @@ export default function AdminDashboard() {

- + {/* */}
diff --git a/components/AdminKeysManagement.tsx b/components/AdminKeysManagement.tsx index 04a4e74..870cce7 100644 --- a/components/AdminKeysManagement.tsx +++ b/components/AdminKeysManagement.tsx @@ -36,6 +36,7 @@ import { toast } from "sonner"; import { zodResolver } from "@hookform/resolvers/zod"; import { useForm } from "react-hook-form"; import * as z from "zod"; +import { Textarea } from "./ui/textarea"; const MAX_FILE_SIZE = 5242880; // 5 MB // Edit Key Form @@ -76,8 +77,8 @@ export default function AdminKeysManagement() { const [openAdd, setOpenAdd] = React.useState(false); const [openEdit, setOpenEdit] = React.useState(false); - const inputPubRef = useRef(null); - const inputPrvRef = useRef(null); + const inputPubRef = useRef(null); + const inputPrvRef = useRef(null); // ..............Read .txt const [selectedFile, setSelectedFile] = useState(null); @@ -138,17 +139,10 @@ export default function AdminKeysManagement() { console.log("bcbcbbcbcbccc" + selectedFile); console.log("bcbcbbcbcbccccc" + data1[0]?.id); - // if (keyId) { ChangeKeyMutation.mutate({ privateKey: selectedFile, publicKeyId: keyId, - - // publicKeyId: data1?.id, }); - // } - // else{ - // console.error("keyId is undefined"); - // } } // Add Form @@ -210,6 +204,7 @@ export default function AdminKeysManagement() { error: Error1, isLoading: isListLoading, refetch: refetch1, + isSuccess: isSuccess1, } = useQuery({ queryKey: ["KeysList"], queryFn: () => GetKeys(), @@ -223,6 +218,7 @@ export default function AdminKeysManagement() { error: Error2, isLoading: isNewKeyLoading, refetch: refetch2, + isSuccess: isSuccess2, } = useQuery({ queryKey: ["GenerateKey"], queryFn: () => GenerateKeyPair(), @@ -236,6 +232,11 @@ export default function AdminKeysManagement() { refetch2(); console.log(data2); }; + useEffect(() => { + if (isSuccess2) { + formAdd.setValue("publicKey", data2?.publicKey); + } + }, [isSuccess2]); useEffect(() => { if (inputPubRef.current && inputPrvRef.current) { @@ -244,28 +245,39 @@ export default function AdminKeysManagement() { } }, [handleClickGenerate]); - - const handleClickAddKey = () => { - // refetch2(); - console.log(data1); + const saveTextFile = () => { + const textToSave = data2?.privateKey ?? ""; + const fileName = "privateKey.txt"; + + // Create a Blob containing the file data + const blob = new Blob([textToSave], { type: "text/plain" }); + + // Create a link element + const link = document.createElement("a"); + + // Set the download attribute and create a URL for the Blob + link.download = fileName; + link.href = window.URL.createObjectURL(blob); + + // Append the link to the document and trigger the click event + document.body.appendChild(link); + link.click(); + + // Remove the link from the document + document.body.removeChild(link); }; + useEffect(() => { + if (AddKeyMutation.isSuccess) { + saveTextFile(); + } + }, [AddKeyMutation.isSuccess]); return ( -
+
{/* 1 */} - - - - +

@@ -277,150 +289,79 @@ export default function AdminKeysManagement() { -

-
- ایجاد جفت کلید جدید -
- - {isNewKeyLoading ? ( -
- -
- ) : ( -
- - {isNewKeyLoading ? ( -
- -
- ) : ( -
-
-

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

- {/*

- {data2?.publicKey} -

*/} - -
-
-

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

- {/*

- {data2?.privateKey} -

*/} - -
-
- )} -
- )} - +
افزودن کلید جدید
-
- -
- ( - - - عنوان کلید - - - - - - - )} - /> - - ( - - - کلید عمومی - - - - - - - )} - /> -
- -
- -
-
- +
+
+ +
+ ( + + + عنوان کلید + + + + + + + )} + /> + + ( + + + کلید عمومی + + +