Bugs Fixed

Kahdooie
Hossein Rahmani 2024-01-27 00:09:46 +03:30
parent dae4ec5264
commit 08872f04b9
6 changed files with 81 additions and 49 deletions

View File

@ -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<typeof EditNewsFormSchema>;
// This can come from your database or API.
@ -361,7 +376,12 @@ const resetFormAdd = () => {
<p className="text-[#464646] text-base font-bold">
افزودن خبر
</p>
<AlertDialogCancel className="h-auto p-0 border-0" onClick={() => { resetFormAdd(); }}>
<AlertDialogCancel
className="h-auto p-0 border-0"
onClick={() => {
resetFormAdd();
}}
>
<IoMdClose />
</AlertDialogCancel>
</AlertDialogTitle>
@ -514,7 +534,12 @@ const resetFormAdd = () => {
>
افزودن
</Button>
<AlertDialogCancel className="mt-0 text-white bg-blue rounded-xl" onClick={() => { resetFormAdd(); }}>
<AlertDialogCancel
className="mt-0 text-white bg-blue rounded-xl"
onClick={() => {
resetFormAdd();
}}
>
بستن
</AlertDialogCancel>
</div>
@ -726,16 +751,10 @@ const resetFormAdd = () => {
</p>
<p className="text-sm font-normal leading-normal text-slate-500">
توضیحات:
<span className="self-end text-slate-800 line-clamp-2">
<span className="self-end text-slate-800 line-clamp-4">
{item.description}
</span>
</p>
<p className="text-sm font-normal leading-normal text-slate-500">
محتوا:
<span className="self-end text-slate-800">
{item.content}
</span>
</p>
</div>
<div className="flex items-end justify-end w-full gap-2">
<Switch

View File

@ -1,3 +1,4 @@
import { ClipboardList, EyeOff, Info, User, UserCheck } from "lucide-react";
import React from "react";
export default function BoxDashboard({
@ -7,17 +8,32 @@ export default function BoxDashboard({
value: string;
title: string;
}) {
const boxIcons = {
"درخواست ناشناس": <EyeOff className=" mb-2 mx-auto" />,
"درخواست شناس": <UserCheck className=" mb-2 mx-auto" />,
درخواست: <ClipboardList className=" mb-2 mx-auto" />,
کاربر: <User className=" mb-2 mx-auto" />,
};
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]
) : (
<Info className=" mb-2 mx-auto" />
);
return (
<div
className=" px-7 py-8 bg-zinc-100 rounded-lg shadow flex flex-col justify-end items-center text-black
className=" px-7 py-8 bg-zinc-100 rounded-lg shadow flex flex-col justify-evenly items-center text-black
transition duration-200
hover:text-white hover:bg-blue
group h-44 w-44"
>
<div className="group-hover:-translate-y-2 transition-all duration-300">
<p className="text-center text-xs font-medium">
{value}
</p>
{checkIcon ? checkIcon : <Info className=" mb-2 mx-auto" />}
{/* <EyeOff className=" mb-2 mx-auto" /> */}
<div className="group-hover:-translate-y-2 flex flex-col justify-center transition-all duration-300">
<p className="text-center text-sm font-medium">{value}</p>
<p className="text-center text-xs font-medium">{title}</p>
</div>
</div>

View File

@ -14,9 +14,6 @@ export default function ControllerDashboard() {
queryFn: () => getInfo(),
refetchOnWindowFocus: false,
});
const [decryptedMessage, errorMessage] = useDecrypt(
"gJoT9AqK7wk1MZFSD04yXXfF36fzsOL+RYtJfySrEnQeJ7VoaL7pmOU6nB3+0+PQcaxIi3hf1AHjzIB0Cn5oHgKROeoI4XslhAezZk23QhtIU4HUF1wpeOJfA+4hWyRfbh4fI9774sa/KL47VaBbrNM/rvBxk6hjlKx5mTb3hqM="
);
return (
<div className="w-[95vw] lg:w-[82vw] xl:w-[70vw] 3xl:w-[65vw] mt-12 pt-9 mx-auto px-2">

4
package-lock.json generated
View File

@ -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",

View File

@ -1,6 +1,6 @@
{
"name": "sootzani",
"version": "0.2.5",
"version": "0.2.6",
"private": true,
"scripts": {
"dev": "next dev",

View File

@ -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;
}