diff --git a/components/AdminNews.tsx b/components/AdminNews.tsx index 305fb4c..a1e04bd 100644 --- a/components/AdminNews.tsx +++ b/components/AdminNews.tsx @@ -1,18 +1,18 @@ "use client"; import React, { useState, useRef, useEffect } from "react"; -import { useMutation, useQuery, RefetchOptions } from "@tanstack/react-query"; +import { + useMutation, + useQuery, + RefetchOptions, + useQueryClient, +} from "@tanstack/react-query"; import { GetAllNews, GetSingleNews, SubmitNews, UpdateNews, DeleteNews, - GetAllOrganizations, - GetSingleOrganization, - SubmitOrganization, - UpdateOrganization, - DeleteOrganization, } from "@/utils/adminApi"; import { FaRegEdit } from "react-icons/fa"; import { IoMdClose } from "react-icons/io"; @@ -132,7 +132,7 @@ export default function AdminNews() { const [openEdit, setOpenEdit] = React.useState(false); const [delOrg, setDelOrg] = React.useState(false); - + const queryClient = useQueryClient(); // List News const { data: data1, @@ -145,10 +145,18 @@ export default function AdminNews() { GetAllNews({ PageNumber: page, }), - // queryFn: () => GetAllOrganizations(), - // refetchOnWindowFocus: false, }); - console.log(data1); + + const { + data: data2, + error: Error2, + isLoading: isLoading2, + refetch: refetch2, + } = useQuery({ + queryKey: ["News", keyId], + queryFn: () => GetSingleNews(keyId), + enabled: false, + }); // Edit const handleClickEdit = ( @@ -160,23 +168,30 @@ export default function AdminNews() { image: string ) => { // Set state variables + console.log(id); setKeyId(id); setTitleNews(title); setDescNews(description); setUrlNews(url); setContentNews(content); setImageNews(image); - // Reset the form with new default values - formEdit.reset({ - titleNews: title, - description: description, - urlNews: url, - content: content, - // uploadImg:image - }); }; - + useEffect(() => { + if (keyId) { + refetch2(); + } + }, [keyId]); + useEffect(() => { + if (data2) { + formEdit.reset({ + titleNews: data2.title, + description: data2.description, + urlNews: data2.url, + content: data2.content, + }); + } + }, [data2]); // Form Edit type EditNewsFormValues = z.infer; // This can come from your database or API. @@ -324,15 +339,15 @@ export default function AdminNews() { setPage(headersData.CurrentPage); } }, [data1]); - -const resetFormAdd = () => { - formAdd.reset({ - titleNews: "", - urlNews: "", - content: "", - description: "", - }); -}; + + const resetFormAdd = () => { + formAdd.reset({ + titleNews: "", + urlNews: "", + content: "", + description: "", + }); + }; return (
@@ -361,7 +376,12 @@ const resetFormAdd = () => {

افزودن خبر

- { resetFormAdd(); }}> + { + resetFormAdd(); + }} + > @@ -514,7 +534,12 @@ const resetFormAdd = () => { > افزودن - { resetFormAdd(); }}> + { + resetFormAdd(); + }} + > بستن
@@ -726,16 +751,10 @@ const resetFormAdd = () => {

توضیحات: - + {item.description}

-

- محتوا: - - {item.content} - -

, + "درخواست شناس": , + درخواست: , + کاربر: , + }; + const handelIcon = (item: keyof typeof boxIcons) => { + const icon = boxIcons[item]; + return icon; + }; + const checkIcon = boxIcons[title as keyof typeof boxIcons] ? ( + boxIcons[title as keyof typeof boxIcons] + ) : ( + + ); return (
-
-

- {value} -

+ {checkIcon ? checkIcon : } + {/* */} +
+

{value}

{title}

diff --git a/components/ControllerDashboard.tsx b/components/ControllerDashboard.tsx index 052de69..f5790c0 100644 --- a/components/ControllerDashboard.tsx +++ b/components/ControllerDashboard.tsx @@ -14,9 +14,6 @@ export default function ControllerDashboard() { queryFn: () => getInfo(), refetchOnWindowFocus: false, }); - const [decryptedMessage, errorMessage] = useDecrypt( - "gJoT9AqK7wk1MZFSD04yXXfF36fzsOL+RYtJfySrEnQeJ7VoaL7pmOU6nB3+0+PQcaxIi3hf1AHjzIB0Cn5oHgKROeoI4XslhAezZk23QhtIU4HUF1wpeOJfA+4hWyRfbh4fI9774sa/KL47VaBbrNM/rvBxk6hjlKx5mTb3hqM=" - ); return (
diff --git a/package-lock.json b/package-lock.json index 1dea1a9..d733db0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "sootzani", - "version": "0.2.5", + "version": "0.2.6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "sootzani", - "version": "0.2.5", + "version": "0.2.6", "dependencies": { "@hookform/resolvers": "^3.3.2", "@radix-ui/react-alert-dialog": "^1.0.5", diff --git a/package.json b/package.json index c0cddf7..cedd801 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sootzani", - "version": "0.2.5", + "version": "0.2.6", "private": true, "scripts": { "dev": "next dev", diff --git a/utils/adminApi.ts b/utils/adminApi.ts index 3a001ce..4dbb895 100644 --- a/utils/adminApi.ts +++ b/utils/adminApi.ts @@ -173,7 +173,7 @@ export async function GetAllNews({ return data; } -export async function GetSingleNews({ id }: { id: string }) { +export async function GetSingleNews(id: string) { const data = await axios.get(`api/News/${id}`); return data.data; }