Compare commits

..

No commits in common. "1d36e37376f283de1c4bd89b4e45fda8ff32440e" and "ebebcbd684b87d942918f180c04bb1eb40ce889c" have entirely different histories.

23 changed files with 188 additions and 2323 deletions

View File

@ -1,8 +0,0 @@
import AdminNews from '@/components/AdminNews'
import React from 'react'
export default function page() {
return (
<AdminNews />
)
}

View File

@ -1,8 +0,0 @@
import AdminSlider from '@/components/AdminSlider'
import React from 'react'
export default function page() {
return (
<AdminSlider />
)
}

View File

@ -1,9 +0,0 @@
import AdminWebContents from '@/components/AdminWebContents'
import React from 'react'
export default function page() {
return (
<AdminWebContents />
)
}

View File

@ -102,7 +102,3 @@
}
.ql-container.ql-snow{
border: none !important;
height: 11em;
}

View File

@ -7,7 +7,6 @@ import NavbarSm from "@/components/NavbarSm";
import Provider from "../utils/Provider";
import { Toaster as SonnerToaster } from "@/components/ui/sonner";
const inter = Inter({ subsets: ["latin"] });
import { Suspense } from "react";
export const metadata: Metadata = {
title: "عیون",
@ -23,7 +22,6 @@ export default function RootLayout({
<html lang="fa" dir="rtl">
<body className="font-[yekan] bg-white">
<Provider>
{/* <Suspense fallback={<Loading />}>{children}</Suspense> */}
{children}
<Toaster />
<SonnerToaster />

View File

@ -1,19 +0,0 @@
"use client";
import { Triangle } from "react-loader-spinner";
export default function Loading() {
// You can add any UI inside Loading, including a Skeleton.
return (
<div className="w-full h-full flex justify-center items-center">
<Triangle
visible={true}
height="80"
width="80"
color="#003778"
ariaLabel="triangle-loading"
wrapperStyle={{}}
wrapperClass=""
/>
</div>
);
}

View File

@ -344,7 +344,7 @@ export default function AdminCategories() {
<AlertDialogHeader>
<AlertDialogTitle>
<p className="text-[#464646] text-base font-bold">
تغییر دسته بندی
تغییر کلید
</p>
<AlertDialogCancel className="p-0 border-0 h-auto">
<IoMdClose />

View File

@ -1,766 +0,0 @@
"use client";
import React, { useState, useRef, useEffect } from "react";
import { useMutation, useQuery, RefetchOptions } 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";
import { RiDeleteBin6Line } from "react-icons/ri";
import { useRouter } from "next/navigation";
import { ThreeDots } from "react-loader-spinner";
import { Button } from "@/components/ui/button";
import { toast } from "sonner";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog";
import {
Form,
FormControl,
FormDescription,
FormField,
FormItem,
FormLabel,
FormMessage,
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
import * as z from "zod";
import { Textarea } from "./ui/textarea";
import { Switch } from "@/components/ui/switch";
import Image from "next/image";
const MAX_IMAGE_SIZE = 5242880; // 5 MB
const ALLOWED_IMAGE_TYPES = [
"image/jpeg",
"image/png",
"image/webp",
"image/jpg",
];
// Form Validation
const EditNewsFormSchema = z.object({
titleNews: z
.string()
.min(2, {
message: "عنوان باید حداقل 2 کاراکتر باشد.",
})
.max(30, {
message: "عنوان نباید بیشتر از 30 کاراکتر باشد.",
}),
uploadImg: z
.custom<File>((val) => val instanceof File, "Required")
.refine(
(file) => file.size <= MAX_IMAGE_SIZE,
`File size should be less than ${MAX_IMAGE_SIZE / (1024 * 1024)} MB.`
)
.refine(
(file) => ALLOWED_IMAGE_TYPES.includes(file.type),
"Only these types are allowed .jpg, .jpeg, .png and .webp"
)
.nullish(),
urlNews: z.string(),
description: z.string().max(2000),
content: z.string(),
});
// Add Key Form
const AddNewsFormSchema = z.object({
titleNews: z
.string()
.min(2, {
message: "عنوان باید حداقل 2 کاراکتر باشد.",
})
.max(30, {
message: "عنوان نباید بیشتر از 30 کاراکتر باشد.",
}),
uploadImg: z
.custom<File>((val) => val instanceof File, "Required")
.refine(
(file) => file.size <= MAX_IMAGE_SIZE,
`File size should be less than ${MAX_IMAGE_SIZE / (1024 * 1024)} MB.`
)
.refine(
(file) => ALLOWED_IMAGE_TYPES.includes(file.type),
"Only these types are allowed .jpg, .jpeg, .png and .webp"
)
.nullish(),
urlNews: z.string(),
description: z.string().max(2000),
content: z.string(),
});
export default function AdminNews() {
const router = useRouter();
const [keyId, setKeyId] = useState("");
const [titleNews, setTitleNews] = useState("");
const [descNews, setDescNews] = useState("");
const [urlNews, setUrlNews] = useState("");
const [contentNews, setContentNews] = useState("");
const [imageNews, setImageNews] = useState("");
const [keyIdDel, setKeyIdDel] = useState("");
const [openAdd, setOpenAdd] = React.useState(false);
const [openEdit, setOpenEdit] = React.useState(false);
const [delOrg, setDelOrg] = React.useState(false);
// List News
const {
data: data1,
error: Error1,
isLoading: isListLoading,
refetch: refetch1,
} = useQuery({
queryKey: ["NewsList"],
queryFn: () => GetAllNews(),
// queryFn: () => GetAllOrganizations(),
// refetchOnWindowFocus: false,
});
console.log(data1);
// Edit
const handleClickEdit = (
id: string,
title: string,
description: string,
url: string,
content: string,
image: string
) => {
// Set state variables
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
});
};
// Form Edit
type EditNewsFormValues = z.infer<typeof EditNewsFormSchema>;
// This can come from your database or API.
const defaultValuesEdit: Partial<EditNewsFormValues> = {
titleNews: "",
description: "",
urlNews: "",
content: "",
};
const formEdit = useForm<EditNewsFormValues>({
resolver: zodResolver(EditNewsFormSchema),
defaultValues: defaultValuesEdit,
mode: "onChange",
});
// Form Add
type AddNewsFormValues = z.infer<typeof AddNewsFormSchema>;
// This can come from your database or API.
const defaultValuesAdd: Partial<AddNewsFormValues> = {
titleNews: "",
description: "",
urlNews: "",
content: "",
};
const formAdd = useForm<AddNewsFormValues>({
resolver: zodResolver(AddNewsFormSchema),
defaultValues: defaultValuesAdd,
mode: "onChange",
});
// Edit Submit
// ............'Mutation' Change News Submit
const ChangeNewsMutation = useMutation({
mutationKey: ["ChangeNews"],
mutationFn: UpdateNews,
onSuccess: (res) => {
console.log(res);
console.log("Success Change News");
setOpenEdit(false);
refetch1();
toast("عملیات شما با موفقیت انجام شد. ", {
className: "!bg-green-500 !text-white",
});
},
onError: (error) => {
console.log(error);
console.log(error?.message);
setOpenEdit(false);
toast(error?.message, {
className: "!bg-red-500 !text-black",
});
},
});
//Delete
const DeleteNewsMutation = useMutation({
mutationKey: ["DeleteNews"],
mutationFn: DeleteNews,
onSuccess: (res) => {
console.log(res);
console.log("Success Change News");
setOpenEdit(false);
refetch1();
toast("عملیات شما با موفقیت انجام شد. ", {
className: "!bg-green-500 !text-white",
});
},
onError: (error) => {
console.log(error);
console.log(error?.message);
toast(error?.message, {
className: "!bg-red-500 !text-black",
});
},
});
// Add
// ............'Mutation' Add News Submit
const AddNewsMutation = useMutation({
mutationKey: ["AddNews"],
mutationFn: SubmitNews,
onSuccess: (res) => {
console.log(res);
console.log("Success Change News");
setOpenAdd(false);
refetch1();
toast("عملیات شما با موفقیت انجام شد. ", {
className: "!bg-green-500 !text-white",
});
},
onError: (error) => {
console.log(error);
console.log(error?.message);
setOpenAdd(false);
toast(error?.message, {
className: "!bg-red-500 !text-black",
});
},
});
function onSubmitEdit(data: EditNewsFormValues) {
const formData = new FormData();
formData.append("Title", data.titleNews);
if (data?.uploadImg instanceof File) {
formData.append("Image", data.uploadImg);
}
formData.append("Url", data.urlNews);
formData.append("Description", data.description);
formData.append("Content", data.content);
// if (data?.media && data?.media?.length > 0) {
// for (let i = 0; i < data.media.length; i++) {
// formData.append("Medias", data.media[i]);
// }
// }
ChangeNewsMutation.mutate({ id: keyId, payload: formData });
refetch1();
resetField("Title");
resetField("Image");
resetField("Url");
resetField("Description");
resetField("Content");
console.log(data);
}
const { resetField } = useForm();
function onSubmitAdd(data: AddNewsFormValues) {
const formData = new FormData();
formData.append("Title", data.titleNews);
formData.append("Url", data.urlNews);
formData.append("Description", data.description);
formData.append("Content", data.content);
if (data?.uploadImg instanceof File) {
formData.append("Image", data.uploadImg);
}
AddNewsMutation.mutate(formData);
console.log(data);
}
return (
<div className="w-full min-h-[85vh] flex justify-center">
<div className="w-[95vw] lg:w-[85vw] 3xl:w-[70vw] mt-8 max-sm:mt-16 pt-9 ">
<div className="flex w-full justify-between flex-row ">
{/* 1 */}
<div className="w-full text-right text-neutral-600 text-lg font-bold my-4">
لیست خبر ها
</div>
{/* 2 */}
{/* 1 */}
<AlertDialog open={openAdd} onOpenChange={setOpenAdd}>
<AlertDialogTrigger asChild>
<Button
variant="outline"
// onClick={handleClickAddCat}
className="bg-orange-500 text-white"
// disabled={isNewKeyLoading}
>
افزودن خبر
</Button>
</AlertDialogTrigger>
<AlertDialogContent className=" w-full max-w-3xl h-full lg:max-h-[28em] max-h-screen sm:max-h-[27em]">
<AlertDialogHeader>
<AlertDialogTitle>
<p className="text-[#464646] text-base font-bold">
افزودن خبر
</p>
<AlertDialogCancel className="p-0 border-0 h-auto">
<IoMdClose />
</AlertDialogCancel>
</AlertDialogTitle>
<AlertDialogDescription>
<div className="w-full ">
<Form {...formAdd}>
<form
onSubmit={formAdd.handleSubmit(onSubmitAdd)}
className="w-full flex flex-col "
>
<div className="flex flex-row flex-wrap justify-between">
<FormField
control={formAdd.control}
name="titleNews"
render={({ field }) => (
<FormItem className=" w-full ">
<FormLabel> عنوان خبر</FormLabel>
<FormControl>
<Input
placeholder="عنوان خبر را وارد نمایید"
{...field}
className=" bg-white"
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={formAdd.control}
name="uploadImg"
render={({ field: { onChange }, ...field }) => {
// Get current uploadFile value (always watched updated)
const uploadImg = formAdd.watch("uploadImg");
var filename: string | undefined = undefined;
if (uploadImg) {
const file: File | null = uploadImg || null;
if (file) {
// Check if the file is an image
const allowedImageTypes = [
"image/jpeg",
"image/png",
"image/webp",
"image/jpg",
];
if (allowedImageTypes.includes(file.type)) {
// Valid image file type
filename = file.name;
} else {
// Invalid file type
// You may want to display an error message or take appropriate action
console.error(
"Invalid file type. Only images (JPEG, PNG, GIF) are allowed."
);
}
}
}
return (
<FormItem className="w-full sm:w-[48%]">
<FormLabel className="text-[#7C838A] text-sm font-medium mt-7">
پیوست
</FormLabel>
{/* File Upload */}
<FormControl>
<Input
type="file"
className="mb-3 bg-white"
accept="image/*"
multiple={false} // Allow only one file
disabled={formAdd.formState.isSubmitting}
{...field}
onChange={(event) => {
const newFile = event.target.files?.[0];
onChange(newFile);
}}
/>
</FormControl>
{/* Show File Name */}
{/* <FormDescription>{filename}</FormDescription> */}
<FormMessage />
</FormItem>
);
}}
/>
<FormField
control={formAdd.control}
name="urlNews"
render={({ field }) => (
<FormItem className="w-full sm:w-[48%]">
<FormLabel>لینک</FormLabel>
<FormControl>
<Input
placeholder="لینک"
{...field}
className=" bg-white"
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={formAdd.control}
name="description"
render={({ field }) => (
<FormItem className="w-full sm:w-[48%]">
<FormLabel>توضیحات</FormLabel>
<FormControl>
<Textarea
placeholder="توضیحات"
className="resize-none bg-white 3xl:min-h-[110px]"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={formAdd.control}
name="content"
render={({ field }) => (
<FormItem className="w-full sm:w-[48%]">
<FormLabel>محتوا</FormLabel>
<FormControl>
<Textarea
placeholder="محتوا"
className="resize-none bg-white 3xl:min-h-[110px]"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
<div className="flex justify-center sm:justify-end gap-2 w-full mt-8">
<Button
type="submit"
className="bg-blue text-white min-w-max rounded-xl text-center hover:bg-white hover:text-slate-800"
>
افزودن
</Button>
<AlertDialogCancel className="bg-blue text-white rounded-xl mt-0">
بستن
</AlertDialogCancel>
</div>
</form>
</Form>
</div>
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
{/* <AlertDialogCancel>بستن</AlertDialogCancel> */}
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
<div className="w-full flex flex-row flex-wrap justify-between gap-8 md:gap-4 ">
<AlertDialog open={openEdit} onOpenChange={setOpenEdit}>
<AlertDialogContent className=" w-full max-w-3xl h-full lg:max-h-[28em] max-h-screen sm:max-h-[27em]">
<AlertDialogHeader>
<AlertDialogTitle>
<p className="text-[#464646] text-base font-bold">
تغییر خبر
</p>
<AlertDialogCancel className="p-0 border-0 h-auto">
<IoMdClose />
</AlertDialogCancel>
</AlertDialogTitle>
<AlertDialogDescription>
<Form {...formEdit}>
<form
onSubmit={formEdit.handleSubmit(onSubmitEdit)}
className="w-full flex flex-col"
>
<div className="flex flex-row flex-wrap justify-between">
<FormField
control={formEdit.control}
name="titleNews"
render={({ field }) => (
<FormItem className=" w-full ">
<FormLabel>عنوان</FormLabel>
<FormControl>
<Input
placeholder="عنوان"
{...field}
className=" bg-white"
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={formEdit.control}
name="uploadImg"
render={({ field: { onChange }, ...field }) => {
// Get current uploadFile value (always watched updated)
const uploadImg = formEdit.watch("uploadImg");
var filename: string | undefined = undefined;
if (uploadImg) {
const file: File | null = uploadImg || null;
if (file) {
// Check if the file is an image
const allowedImageTypes = [
"image/jpeg",
"image/png",
"image/webp",
"image/jpg",
];
if (allowedImageTypes.includes(file.type)) {
// Valid image file type
filename = file.name;
} else {
// Invalid file type
// You may want to display an error message or take appropriate action
console.error(
"Invalid file type. Only images (JPEG, PNG, GIF) are allowed."
);
}
}
}
return (
<FormItem className="w-full sm:w-[48%]">
<FormLabel className="text-[#7C838A] text-sm font-medium mt-7">
پیوست
</FormLabel>
{/* File Upload */}
<FormControl>
<Input
type="file"
className="mb-3 bg-white"
accept="image/*"
multiple={false} // Allow only one file
disabled={formEdit.formState.isSubmitting}
{...field}
onChange={(event) => {
const newFile = event.target.files?.[0];
onChange(newFile);
}}
/>
</FormControl>
{/* Show File Name */}
{/* <FormDescription>{filename}</FormDescription> */}
<FormMessage />
</FormItem>
);
}}
/>
<FormField
control={formEdit.control}
name="urlNews"
render={({ field }) => (
<FormItem className="w-full sm:w-[48%]">
<FormLabel>لینک</FormLabel>
<FormControl>
<Input
placeholder="لینک"
{...field}
className=" bg-white"
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={formEdit.control}
name="description"
render={({ field }) => (
<FormItem className="w-full sm:w-[48%]">
<FormLabel>توضیحات</FormLabel>
<FormControl>
<Textarea
placeholder="توضیحات"
className="resize-none bg-white 3xl:min-h-[110px]"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={formEdit.control}
name="content"
render={({ field }) => (
<FormItem className="w-full sm:w-[48%]">
<FormLabel>محتوا</FormLabel>
<FormControl>
<Textarea
placeholder="محتوا"
className="resize-none bg-white 3xl:min-h-[110px]"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
<div className="flex justify-center sm:justify-end gap-2 w-full mt-8">
<Button
type="submit"
className="bg-blue text-white min-w-max p-2 rounded-xl text-center hover:bg-white hover:text-slate-800"
>
تغییر خبر
</Button>
<AlertDialogCancel className="bg-blue text-white rounded-xl mt-0">
بستن
</AlertDialogCancel>
</div>
</form>
</Form>
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter></AlertDialogFooter>
</AlertDialogContent>
{data1?.map((item: any) => {
return (
<div
key={item.id}
className={`flex flex-col justify-center gap-2 w-full lg:w-[49%] h-56 px-5 rounded-md shadow-md items-start bg-[#F5F5F5]
`}
>
<p className=" text-slate-500 text-sm font-normal leading-normal">
عنوان :
<span className=" text-slate-800">{item.title}</span>
</p>
<p className=" text-slate-500 text-sm font-normal leading-normal">
توضیحات:
<span className=" text-slate-800 self-end">
{item.description}
</span>
</p>
<p className=" text-slate-500 text-sm font-normal leading-normal">
محتوا:
<span className=" text-slate-800 self-end">
{item.content}
</span>
</p>
<Image
alt="img"
src={`${process.env.NEXT_PUBLIC_BASE_URL_APP}${item?.image?.url}`}
width={100}
height={100}
quality={100}
className=" w-full h-20 object-contain object-right"
/>
<div className="w-full flex justify-end items-end gap-2">
<Switch
dir="ltr"
checked={!item.isDeleted}
onCheckedChange={() => {
DeleteNewsMutation.mutate({id: item.id});
}}
id={item.id}
/>
<AlertDialogTrigger asChild>
{/* <Button variant="outline">Show Dialog</Button> */}
<FaRegEdit
aria-hidden="true"
className="w-6 h-6 text-slate-600 hover:cursor-pointer self-end"
// onClick={() => setKeyId(item?.id)}
onClick={() =>
handleClickEdit(
item?.id,
item?.title,
item?.description,
item?.content,
item?.url,
item?.image
)
}
/>
</AlertDialogTrigger>
</div>
</div>
);
})}
</AlertDialog>
</div>
</div>
</div>
);
}

View File

@ -252,14 +252,14 @@ export default function AdminOrganizations() {
className="bg-orange-500 text-white"
// disabled={isNewKeyLoading}
>
افزودن سازمان
افزودن دسته بندی
</Button>
</AlertDialogTrigger>
<AlertDialogContent className=" w-full max-w-3xl h-full lg:max-h-[26em] max-h-[24em]">
<AlertDialogHeader>
<AlertDialogTitle>
<p className="text-[#464646] text-base font-bold">
افزودن سازمان
افزودن دسته بندی
</p>
<AlertDialogCancel className="p-0 border-0 h-auto">
<IoMdClose />
@ -269,7 +269,7 @@ export default function AdminOrganizations() {
<AlertDialogDescription>
<div className="w-full ">
<div className="w-full text-right text-neutral-600 text-lg font-bold mb-2">
سازمان ها
افزودن دسته بندی
</div>
<Form {...formAdd}>
@ -347,7 +347,7 @@ export default function AdminOrganizations() {
<AlertDialogHeader>
<AlertDialogTitle>
<p className="text-[#464646] text-base font-bold">
تغییر سازمان
تغییر کلید
</p>
<AlertDialogCancel className="p-0 border-0 h-auto">
<IoMdClose />

View File

@ -1,725 +0,0 @@
"use client";
import React, { useState, useRef, useEffect } from "react";
import { useMutation, useQuery, RefetchOptions } from "@tanstack/react-query";
import {
GetAllSliders,
GetSingleSlider,
SubmitSlider,
UpdateSlider,
DeleteSlider,
GetAllOrganizations,
GetSingleOrganization,
SubmitOrganization,
UpdateOrganization,
DeleteOrganization,
} from "@/utils/adminApi";
import { FaRegEdit } from "react-icons/fa";
import { IoMdClose } from "react-icons/io";
import { RiDeleteBin6Line } from "react-icons/ri";
import { useRouter } from "next/navigation";
import { ThreeDots } from "react-loader-spinner";
import { Button } from "@/components/ui/button";
import { toast } from "sonner";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog";
import {
Form,
FormControl,
FormDescription,
FormField,
FormItem,
FormLabel,
FormMessage,
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
import * as z from "zod";
import { Textarea } from "./ui/textarea";
import { Switch } from "@/components/ui/switch";
import Image from "next/image";
const MAX_IMAGE_SIZE = 5242880; // 5 MB
const ALLOWED_IMAGE_TYPES = [
"image/jpeg",
"image/png",
"image/webp",
"image/jpg",
];
// Form Validation
const EditSliderFormSchema = z.object({
titleSlider: z
.string()
.min(2, {
message: "عنوان باید حداقل 2 کاراکتر باشد.",
})
.max(30, {
message: "عنوان نباید بیشتر از 30 کاراکتر باشد.",
}),
uploadImg: z
.custom<File>((val) => val instanceof File, "Required")
.refine(
(file) => file.size <= MAX_IMAGE_SIZE,
`File size should be less than ${MAX_IMAGE_SIZE / (1024 * 1024)} MB.`
)
.refine(
(file) => ALLOWED_IMAGE_TYPES.includes(file.type),
"Only these types are allowed .jpg, .jpeg, .png and .webp"
)
.nullish(),
urlSlider: z.string(),
description: z.string().max(2000),
});
// Add Key Form
const AddSliderFormSchema = z.object({
titleSlider: z
.string()
.min(2, {
message: "عنوان باید حداقل 2 کاراکتر باشد.",
})
.max(30, {
message: "عنوان نباید بیشتر از 30 کاراکتر باشد.",
}),
uploadImg: z
.custom<File>((val) => val instanceof File, "Required")
.refine(
(file) => file.size <= MAX_IMAGE_SIZE,
`File size should be less than ${MAX_IMAGE_SIZE / (1024 * 1024)} MB.`
)
.refine(
(file) => ALLOWED_IMAGE_TYPES.includes(file.type),
"Only these types are allowed .jpg, .jpeg, .png and .webp"
)
.nullish(),
urlSlider: z.string(),
description: z.string().max(2000),
});
export default function AdminSlider() {
const router = useRouter();
const [keyId, setKeyId] = useState("");
const [titleSlider, settitleSlider] = useState("");
const [descSlider, setDescSlider] = useState("");
const [urlSlider, seturlSlider] = useState("");
const [imageSlider, setImageSlider] = useState("");
const [keyIdDel, setKeyIdDel] = useState("");
const [openAdd, setOpenAdd] = React.useState(false);
const [openEdit, setOpenEdit] = React.useState(false);
const [delOrg, setDelOrg] = React.useState(false);
// List News
const {
data: data1,
error: Error1,
isLoading: isListLoading,
refetch: refetch1,
} = useQuery({
queryKey: ["NewsList"],
queryFn: () => GetAllSliders(),
// refetchOnWindowFocus: false,
});
console.log(data1);
// Edit
const handleClickEdit = (
id: string,
title: string,
description: string,
url: string,
image: string
) => {
// Set state variables
setKeyId(id);
settitleSlider(title);
setDescSlider(description);
seturlSlider(url);
setImageSlider(image);
// Reset the form with new default values
formEdit.reset({
titleSlider: title,
description: description,
urlSlider: url,
// uploadImg:image
});
};
// Form Edit
type EditSliderFormValues = z.infer<typeof EditSliderFormSchema>;
// This can come from your database or API.
const defaultValuesEdit: Partial<EditSliderFormValues> = {
titleSlider: "",
description: "",
urlSlider: "",
};
const formEdit = useForm<EditSliderFormValues>({
resolver: zodResolver(EditSliderFormSchema),
defaultValues: defaultValuesEdit,
mode: "onChange",
});
// Form Add
type AddSliderFormValues = z.infer<typeof AddSliderFormSchema>;
// This can come from your database or API.
const defaultValuesAdd: Partial<AddSliderFormValues> = {
titleSlider: "",
description: "",
urlSlider: "",
};
const formAdd = useForm<AddSliderFormValues>({
resolver: zodResolver(AddSliderFormSchema),
defaultValues: defaultValuesAdd,
mode: "onChange",
});
// Edit Submit
// ............'Mutation' Change Slider Submit
const ChangeSliderMutation = useMutation({
mutationKey: ["ChangeSlider"],
mutationFn: UpdateSlider,
onSuccess: (res) => {
console.log(res);
console.log("Success Change Slider");
setOpenEdit(false);
refetch1();
toast("عملیات شما با موفقیت انجام شد. ", {
className: "!bg-green-500 !text-white",
});
},
onError: (error) => {
console.log(error);
console.log(error?.message);
setOpenEdit(false);
toast(error?.message, {
className: "!bg-red-500 !text-black",
});
},
});
//Delete
const DeleteSliderMutation = useMutation({
mutationKey: ["DeleteSlider"],
mutationFn: DeleteSlider,
onSuccess: (res) => {
console.log(res);
console.log("Success Change Slider");
setOpenEdit(false);
refetch1();
toast("عملیات شما با موفقیت انجام شد. ", {
className: "!bg-green-500 !text-white",
});
},
onError: (error) => {
console.log(error);
console.log(error?.message);
toast(error?.message, {
className: "!bg-red-500 !text-black",
});
},
});
// Add
// ............'Mutation' Add Slider Submit
const AddSliderMutation = useMutation({
mutationKey: ["AddSlider"],
mutationFn: SubmitSlider,
onSuccess: (res) => {
console.log(res);
console.log("Success Change Slider");
setOpenAdd(false);
refetch1();
toast("عملیات شما با موفقیت انجام شد. ", {
className: "!bg-green-500 !text-white",
});
},
onError: (error) => {
console.log(error);
console.log(error?.message);
setOpenAdd(false);
toast(error?.message, {
className: "!bg-red-500 !text-black",
});
},
});
function onSubmitEdit(data: EditSliderFormValues) {
const formData = new FormData();
formData.append("Title", data.titleSlider);
if (data?.uploadImg instanceof File) {
formData.append("Image", data.uploadImg);
}
formData.append("Url", data.urlSlider);
formData.append("Description", data.description);
// if (data?.media && data?.media?.length > 0) {
// for (let i = 0; i < data.media.length; i++) {
// formData.append("Medias", data.media[i]);
// }
// }
ChangeSliderMutation.mutate({id: keyId, payload: formData});
refetch1();
resetField("Title");
resetField("Image");
resetField("Url");
resetField("Description");
console.log(data);
}
const { resetField } = useForm();
function onSubmitAdd(data: AddSliderFormValues) {
const formData = new FormData();
formData.append("Title", data.titleSlider);
formData.append("Url", data.urlSlider);
formData.append("Description", data.description);
if (data?.uploadImg instanceof File) {
formData.append("Image", data.uploadImg);
}
AddSliderMutation.mutate(formData);
console.log(data);
}
return (
<div className="w-full min-h-[85vh] flex justify-center">
<div className="w-[95vw] lg:w-[85vw] 3xl:w-[70vw] mt-8 max-sm:mt-16 pt-9 ">
<div className="flex w-full justify-between flex-row ">
{/* 1 */}
<div className="w-full text-right text-neutral-600 text-lg font-bold my-4">
لیست اسلایدرها
</div>
{/* 2 */}
{/* 1 */}
<AlertDialog open={openAdd} onOpenChange={setOpenAdd}>
<AlertDialogTrigger asChild>
<Button
variant="outline"
// onClick={handleClickAddCat}
className="bg-orange-500 text-white"
// disabled={isNewKeyLoading}
>
افزودن اسلایدر
</Button>
</AlertDialogTrigger>
<AlertDialogContent className=" w-full max-w-3xl h-full lg:max-h-[28em] max-h-screen sm:max-h-[27em]">
<AlertDialogHeader>
<AlertDialogTitle>
<p className="text-[#464646] text-base font-bold">
افزودن اسلایدر
</p>
<AlertDialogCancel className="p-0 border-0 h-auto">
<IoMdClose />
</AlertDialogCancel>
</AlertDialogTitle>
<AlertDialogDescription>
<div className="w-full ">
<Form {...formAdd}>
<form
onSubmit={formAdd.handleSubmit(onSubmitAdd)}
className="w-full flex flex-col "
>
<div className="flex flex-row flex-wrap justify-between">
<FormField
control={formAdd.control}
name="titleSlider"
render={({ field }) => (
<FormItem className=" w-full ">
<FormLabel> عنوان اسلایدر</FormLabel>
<FormControl>
<Input
placeholder="عنوان اسلایدر را وارد نمایید"
{...field}
className=" bg-white"
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={formAdd.control}
name="uploadImg"
render={({ field: { onChange }, ...field }) => {
// Get current uploadFile value (always watched updated)
const uploadImg = formAdd.watch("uploadImg");
var filename: string | undefined = undefined;
if (uploadImg) {
const file: File | null = uploadImg || null;
if (file) {
// Check if the file is an image
const allowedImageTypes = [
"image/jpeg",
"image/png",
"image/webp",
"image/jpg",
];
if (allowedImageTypes.includes(file.type)) {
// Valid image file type
filename = file.name;
} else {
// Invalid file type
// You may want to display an error message or take appropriate action
console.error(
"Invalid file type. Only images (JPEG, PNG, GIF) are allowed."
);
}
}
}
return (
<FormItem className="w-full sm:w-[48%]">
<FormLabel className="text-[#7C838A] text-sm font-medium mt-7">
پیوست
</FormLabel>
{/* File Upload */}
<FormControl>
<Input
type="file"
className="mb-3 bg-white"
accept="image/*"
multiple={false} // Allow only one file
disabled={formAdd.formState.isSubmitting}
{...field}
onChange={(event) => {
const newFile = event.target.files?.[0];
onChange(newFile);
}}
/>
</FormControl>
{/* Show File Name */}
{/* <FormDescription>{filename}</FormDescription> */}
<FormMessage />
</FormItem>
);
}}
/>
<FormField
control={formAdd.control}
name="urlSlider"
render={({ field }) => (
<FormItem className="w-full sm:w-[48%]">
<FormLabel>لینک</FormLabel>
<FormControl>
<Input
placeholder="لینک"
{...field}
className=" bg-white"
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={formAdd.control}
name="description"
render={({ field }) => (
<FormItem className="w-full ">
<FormLabel>توضیحات</FormLabel>
<FormControl>
<Textarea
placeholder="توضیحات"
className="resize-none bg-white 3xl:min-h-[110px]"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
<div className="flex justify-center sm:justify-end gap-2 w-full mt-8">
<Button
type="submit"
className="bg-blue text-white min-w-max rounded-xl text-center hover:bg-white hover:text-slate-800"
>
افزودن
</Button>
<AlertDialogCancel className="bg-blue text-white rounded-xl mt-0">
بستن
</AlertDialogCancel>
</div>
</form>
</Form>
</div>
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
{/* <AlertDialogCancel>بستن</AlertDialogCancel> */}
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
<div className="w-full flex flex-row flex-wrap justify-between gap-8 md:gap-4 ">
<AlertDialog open={openEdit} onOpenChange={setOpenEdit}>
<AlertDialogContent className=" w-full max-w-3xl h-full lg:max-h-[28em] max-h-screen sm:max-h-[27em]">
<AlertDialogHeader>
<AlertDialogTitle>
<p className="text-[#464646] text-base font-bold">
تغییر اسلایدر
</p>
<AlertDialogCancel className="p-0 border-0 h-auto">
<IoMdClose />
</AlertDialogCancel>
</AlertDialogTitle>
<AlertDialogDescription>
<Form {...formEdit}>
<form
onSubmit={formEdit.handleSubmit(onSubmitEdit)}
className="w-full flex flex-col"
>
<div className="flex flex-row flex-wrap justify-between">
<FormField
control={formEdit.control}
name="titleSlider"
render={({ field }) => (
<FormItem className=" w-full ">
<FormLabel>عنوان</FormLabel>
<FormControl>
<Input
placeholder="عنوان"
{...field}
className=" bg-white"
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={formEdit.control}
name="uploadImg"
render={({ field: { onChange }, ...field }) => {
// Get current uploadFile value (always watched updated)
const uploadImg = formEdit.watch("uploadImg");
var filename: string | undefined = undefined;
if (uploadImg) {
const file: File | null = uploadImg || null;
if (file) {
// Check if the file is an image
const allowedImageTypes = [
"image/jpeg",
"image/png",
"image/webp",
"image/jpg",
];
if (allowedImageTypes.includes(file.type)) {
// Valid image file type
filename = file.name;
} else {
// Invalid file type
// You may want to display an error message or take appropriate action
console.error(
"Invalid file type. Only images (JPEG, PNG, GIF) are allowed."
);
}
}
}
return (
<FormItem className="w-full sm:w-[48%]">
<FormLabel className="text-[#7C838A] text-sm font-medium mt-7">
پیوست
</FormLabel>
{/* File Upload */}
<FormControl>
<Input
type="file"
className="mb-3 bg-white"
accept="image/*"
multiple={false} // Allow only one file
disabled={formEdit.formState.isSubmitting}
{...field}
onChange={(event) => {
const newFile = event.target.files?.[0];
onChange(newFile);
}}
/>
</FormControl>
{/* Show File Name */}
{/* <FormDescription>{filename}</FormDescription> */}
<FormMessage />
</FormItem>
);
}}
/>
<FormField
control={formEdit.control}
name="urlSlider"
render={({ field }) => (
<FormItem className="w-full sm:w-[48%]">
<FormLabel>لینک</FormLabel>
<FormControl>
<Input
placeholder="لینک"
{...field}
className=" bg-white"
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={formEdit.control}
name="description"
render={({ field }) => (
<FormItem className="w-full ">
<FormLabel>توضیحات</FormLabel>
<FormControl>
<Textarea
placeholder="توضیحات"
className="resize-none bg-white 3xl:min-h-[110px]"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
<div className="flex justify-center sm:justify-end gap-2 w-full mt-8">
<Button
type="submit"
className="bg-blue text-white min-w-max p-2 rounded-xl text-center hover:bg-white hover:text-slate-800"
>
تغییر اسلایدر
</Button>
<AlertDialogCancel className="bg-blue text-white rounded-xl mt-0">
بستن
</AlertDialogCancel>
</div>
</form>
</Form>
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter></AlertDialogFooter>
</AlertDialogContent>
{data1?.map((item: any) => {
return (
<div
key={item.id}
className={`flex flex-col justify-around gap-2 w-full lg:w-[49%] h-52 px-5 rounded-md shadow-md items-start bg-[#F5F5F5]
`}
>
<p className=" text-slate-500 text-sm font-normal leading-normal">
عنوان :
<span className=" text-slate-800">{item.title}</span>
</p>
<p className=" text-slate-500 text-sm font-normal leading-normal">
توضیحات:
<span className=" text-slate-800 self-end">
{item.description}
</span>
</p>
<Image
alt="img"
src={`${process.env.NEXT_PUBLIC_BASE_URL_APP}${item?.image?.url}`}
width={100}
height={100}
quality={100}
className=" w-full h-20 object-contain object-right"
/>
{/* <p className=" text-slate-500 text-sm font-normal leading-normal">
محتوا:
<span className=" text-slate-800 self-end">
{item.content}
</span>
</p> */}
<div className="w-full flex justify-end items-end gap-2">
<Switch
dir="ltr"
checked={!item.isDeleted}
onCheckedChange={() => {
DeleteSliderMutation.mutate({
id: item.id
})
}}
id={item.id}
/>
<AlertDialogTrigger asChild>
{/* <Button variant="outline">Show Dialog</Button> */}
<FaRegEdit
aria-hidden="true"
className="w-6 h-6 text-slate-600 hover:cursor-pointer self-end"
// onClick={() => setKeyId(item?.id)}
onClick={() =>
handleClickEdit(
item?.id,
item?.title,
item?.description,
item?.url,
item?.image
)
}
/>
</AlertDialogTrigger>
</div>
</div>
);
})}
</AlertDialog>
</div>
</div>
</div>
);
}

View File

@ -1,371 +0,0 @@
"use client";
import React, { useState, useRef, useEffect } from "react";
import { useMutation, useQuery } from "@tanstack/react-query";
import ReactQuill from "react-quill";
import "react-quill/dist/quill.snow.css";
import { Button } from "./ui/button";
import { SubmitWebContents, UpdateWebContents } from "@/utils/adminApi";
import { getContents } from "@/utils/commonApi";
import { toast } from "sonner";
export default function AdminWebContents() {
const [contentValueCall, setContentValueCall] = useState("");
const [contentValueAbout, setContentValueAbout] = useState("");
const [contentValueAfter, setContentValueAfter] = useState("");
const [contentValueBefore, setContentValueBefore] = useState("");
const [callBtn, setCallBtn] = useState("Add");
const [aboutBtn, setAboutBtn] = useState("Add");
const [afterBtn, setAfterBtn] = useState("Add");
const [beforeBtn, setBeforeBtn] = useState("Add");
const [callId, setCallId] = useState("");
const [aboutId, setAboutId] = useState("");
const [afterId, setAfterId] = useState("");
const [beforeId, setBeforeId] = useState("");
const [contentTitle, setContentTitle] = useState("");
const [contentDesc, setContentDesc] = useState("");
// console.log(value);
var toolbarOptions = [
["bold", "italic", "underline", "strike"], // toggled buttons
["blockquote", "code-block"],
[{ header: 1 }, { header: 2 }], // custom button values
[{ list: "ordered" }, { list: "bullet" }],
[{ script: "sub" }, { script: "super" }], // superscript/subscript
[{ indent: "-1" }, { indent: "+1" }], // outdent/indent
[{ direction: "rtl" }], // text direction
[{ size: ["small", false, "large", "huge"] }], // custom dropdown
[{ header: [1, 2, 3, 4, 5, 6, false] }],
[{ color: [] }, { background: [] }], // dropdown with defaults from theme
[{ font: [] }],
[{ align: [] }],
["link", "image", "video"],
["clean"], // remove formatting button
];
const modules = {
toolbar: toolbarOptions,
// clipboard: {
// // toggle to add extra line breaks when pasting HTML:
// matchVisual: false,
// },
};
// Define custom styles for the ReactQuill editor
const editorStyles: React.CSSProperties = {
height: "12em",
border: "1px solid #ccc",
borderRadius: "5px",
direction: "ltr",
};
// Get Content
const {
data: data1,
error: Error1,
isLoading: isListLoading,
refetch: refetch1,
isSuccess: isSuccess1,
} = useQuery({
queryKey: ["WebContents"],
queryFn: () => getContents(),
refetchOnWindowFocus: false,
});
// console.log(data1);
useEffect(() => {
// if (isInitialRender2 && isSuccess1) {
if (isSuccess1) {
// {
data1?.map((item: any) => {
if (item.title === "CallUs") {
console.log("contetn : " + item.content);
setContentValueCall(item.content);
setCallId(item.id);
setCallBtn("Edit");
}
if (item.title === "AboutUs") {
console.log("contetn : " + item.content);
setContentValueAbout(item.content);
setAboutId(item.id);
setAboutBtn("Edit");
}
if (item.title === "AfterRegistration") {
console.log("contetn : " + item.content);
setContentValueAfter(item.content);
setAfterId(item.id);
setAfterBtn("Edit");
}
if (item.title === "BeforeRegistration") {
console.log("contetn : " + item.content);
setContentValueBefore(item.content);
setBeforeId(item.id);
setBeforeBtn("Edit");
}
});
// }
console.log("contetn : " + data1);
}
}, [isSuccess1]);
// Add
// ............'Mutation' Change Key Submit
const AddWebContents = useMutation({
mutationKey: ["AddWebContents"],
mutationFn: SubmitWebContents,
onSuccess: (res) => {
console.log(res);
console.log("Success ChangeCat");
setContentValueCall("");
setContentValueAbout("");
setContentValueAfter("");
setContentValueBefore("");
toast("عملیات ثبت شما با موفقیت انجام شد. ", {
className: "!bg-green-500 !text-white",
});
refetch1();
},
onError: (error) => {
console.log(error);
console.log(error?.message);
toast(error?.message, {
className: "!bg-red-500 !text-black",
});
},
});
// ............'Mutation' Change Web Contents
const EditWebContents = useMutation({
mutationKey: ["EditWebContents"],
mutationFn: UpdateWebContents,
onSuccess: (res) => {
console.log(res);
console.log("Success Change UpdateWebContents");
toast("عملیات ویرایش شما با موفقیت انجام شد . ", {
className: "!bg-green-500 !text-white",
});
refetch1();
},
onError: (error) => {
console.log(error?.message);
toast(error?.message, {
className: "!bg-red-500 !text-black",
});
},
});
// Add Mutation
function onSubmitAddCallUs() {
const formData = new FormData();
// formData.append("title", contentTitle);
// formData.append("description", contentDesc);
formData.append("title", "CallUs");
formData.append("description", "CallUs....");
formData.append("Content", contentValueCall);
AddWebContents.mutate(formData);
console.log(contentValueCall);
// console.log(contentTitle);
// console.log(contentDesc);
}
// AboutUs
function onSubmitAddAboutUs() {
const formData = new FormData();
formData.append("title", "AboutUs");
formData.append("description", "AboutUs....");
formData.append("Content", contentValueAbout);
AddWebContents.mutate(formData);
console.log(contentValueAbout);
}
// AboutUs
function onSubmitAddَAfterText() {
const formData = new FormData();
formData.append("title", "AfterRegistration");
formData.append("description", "AfterRegistration....");
formData.append("Content", contentValueAfter);
AddWebContents.mutate(formData);
console.log(contentValueAfter);
}
// AboutUs
function onSubmitAddBeforeText() {
const formData = new FormData();
formData.append("title", "BeforeRegistration");
formData.append("description", "BeforeRegistration....");
formData.append("Content", contentValueBefore);
AddWebContents.mutate(formData);
console.log(contentValueBefore);
}
// Edit Mutation
function onEditCallUs() {
const formData = new FormData();
formData.append("title", "CallUs");
formData.append("description", "CallUs....");
formData.append("Content", contentValueCall);
EditWebContents.mutate({ id: callId, payload: formData });
console.log("formData"+formData);
}
function onEditAboutUs() {
const formData = new FormData();
formData.append("title", "AboutUs");
formData.append("description", "AboutUs....");
formData.append("Content", contentValueAbout);
EditWebContents.mutate({ id: aboutId, payload: formData });
}
function onEditAfterText() {
const formData = new FormData();
formData.append("title", "AfterRegistration");
formData.append("description", "AfterRegistration....");
formData.append("Content", contentValueAfter);
EditWebContents.mutate({ id: afterId, payload: formData });
console.log("formData22"+formData);
}
function onEditBeforeText() {
const formData = new FormData();
formData.append("title", "BeforeRegistration");
formData.append("description", "BeforeRegistration....");
formData.append("Content", contentValueBefore);
EditWebContents.mutate({ id: beforeId, payload: formData });
}
return (
<div className="w-full min-h-[85vh] flex justify-center">
<div className="w-[95vw] lg:w-[85vw] 3xl:w-[70vw] mt-8 max-sm:mt-16 pt-9 ">
{/* Cull Us */}
<div className="w-full flex flex-col">
<div className=" text-right text-neutral-600 text-base font-bold my-4">
محتوای تماس با ما
</div>
<ReactQuill
modules={modules}
theme="snow"
value={contentValueCall}
onChange={setContentValueCall}
style={editorStyles}
/>
<Button
type="submit"
onClick={() => {
if (callBtn === "Add") {
onSubmitAddCallUs();
} else if (callBtn === "Edit") {
onEditCallUs();
}
// setContentTitle("Test");
// setContentDesc("Test....");
}}
className="w-1/6 self-end my-2"
>
ثبت
</Button>
</div>
{/* About Us */}
<div className="w-full flex flex-col">
<div className=" text-right text-neutral-600 text-base font-bold my-4">
محتوای درباره ما
</div>
<ReactQuill
modules={modules}
theme="snow"
value={contentValueAbout}
onChange={setContentValueAbout}
style={editorStyles}
/>
<Button
type="submit"
onClick={() => {
if (callBtn === "Add") {
onSubmitAddAboutUs();
} else if (callBtn === "Edit") {
onEditAboutUs();
}
}}
className="w-1/6 self-end my-2"
>
ثبت
</Button>
</div>
{/* AfterRegistration */}
<div className="w-full flex flex-col">
<div className=" text-right text-neutral-600 text-base font-bold my-4">
محتوای بعد از ثبت گزارش
</div>
<ReactQuill
modules={modules}
theme="snow"
value={contentValueAfter}
onChange={setContentValueAfter}
style={editorStyles}
/>
<Button
type="submit"
onClick={() => {
if (callBtn === "Add") {
onSubmitAddَAfterText();
} else if (callBtn === "Edit") {
onEditAfterText();
}
}}
className="w-1/6 self-end my-2"
>
ثبت
</Button>
</div>
{/* BeforeRegistration*/}
<div className="w-full flex flex-col">
<div className=" text-right text-neutral-600 text-base font-bold my-4">
محتوای قبل از ثبت گزارش
</div>
<ReactQuill
modules={modules}
theme="snow"
value={contentValueBefore}
onChange={setContentValueBefore}
style={editorStyles}
/>
<Button
type="submit"
onClick={() => {
if (callBtn === "Add") {
onSubmitAddBeforeText();
} else if (callBtn === "Edit") {
onEditBeforeText();
}
}}
className="w-1/6 self-end my-2"
>
ثبت
</Button>
</div>
</div>
</div>
);
}

View File

@ -14,7 +14,6 @@ import { ArrowDownToLine, ArrowRight, File } from "lucide-react";
import { Separator } from "./ui/separator";
import secureLocalStorage from "react-secure-storage";
import { Checkbox } from "./ui/checkbox";
import { useQuery } from "@tanstack/react-query";
import { Button } from "@/components/ui/button";
import {
AlertDialog,
@ -49,8 +48,6 @@ export default function ComplainsDetails({
const router = useRouter();
let data;
const getComplaintMutation = useMutation({
mutationKey: ["Complaint", id],
mutationFn: getComplaint,
@ -59,30 +56,19 @@ export default function ComplainsDetails({
},
onError: (err) => {},
});
useEffect(() => {
const storedData = localStorage.getItem("CompliantData");
const data = JSON.parse(storedData as string);
const prvKey = localStorage.getItem("privateKey") as string;
const cipherKeyInspector = data.cipherKeyInspector;
const newDcKey = Decrypt(cipherKeyInspector, prvKey);
// const pw = localStorage.getItem("privatePassword") as string;
const pw = newDcKey as string;
const pw = localStorage.getItem("privateKey") as string;
localStorage.setItem("trackingNumber", data.trackingNumber);
// if (pw != null) {
if (pw) {
if (pw != null) {
getComplaintMutation.mutate({
trackingNumber: data.trackingNumber,
password: pw,
});
setOpen(false);
}
// else {
// toast("کلید خصوصی وجود ندارد ، بارگداری کنید.", {
// className: "!bg-red-500 !text-white",
// });
// }
}, []);
useEffect(() => {
@ -174,9 +160,7 @@ export default function ComplainsDetails({
console.log(dcKey);
if (dcKey != false && dcKey != null) {
if (check) {
// localStorage.setItem("privateKey", dcKey);
localStorage.setItem("privatePassword", dcKey);
localStorage.setItem("privateKey", selectedFile);
localStorage.setItem("privateKey", dcKey);
}
localStorage.setItem("trackingNumber", item.trackingNumber);
setKey(dcKey);
@ -193,8 +177,6 @@ export default function ComplainsDetails({
};
data = getComplaintMutation?.data;
// console.log("Complainet data"+getComplaintMutation?.data);
return (
<>
<AlertDialog open={open} onOpenChange={setOpen}>
@ -248,7 +230,7 @@ export default function ComplainsDetails({
}}
type="submit"
>
مشاهده
ذخیره
</Button>
</AlertDialogFooter>
</AlertDialogContent>
@ -259,7 +241,7 @@ export default function ComplainsDetails({
onClick={() =>
router.push("/UserPanel/ControllerDashboard/Complaints")
}
className=" my-2 flex gap-1 cursor-pointer text-blue lg:sticky top-20"
className=" my-2 flex gap-1 cursor-pointer text-blue "
>
<span>
<ArrowRight />
@ -268,9 +250,8 @@ export default function ComplainsDetails({
</button>
<div className="w-full flex max-lg:flex-col items-start mt-2 gap-2">
{/* 1 */}
<div className="flex flex-col w-full lg:w-1/3 gap-3 lg:sticky top-28 lg:h-[80vh]">
<div className=" max-lg:hidden bg-[#E9E9E9] rounded-md p-4 px-10 flex flex-col lg:h-full">
<div className="flex flex-col w-full lg:w-1/3 gap-3 lg:sticky top-24">
<div className=" max-lg:hidden bg-[#E9E9E9] rounded-md p-4 px-10 flex flex-col">
<p className="text-[#464646] text-base font-bold mb-1">
انجام عملیات
</p>
@ -283,9 +264,8 @@ export default function ComplainsDetails({
/>
</div>
</div>
{/* 2 */}
<div className="w-full lg:w-2/3 self-stretch rounded-lg flex flex-col gap-2 ">
<div className=" bg-[#E9E9E9] rounded-md py-4 px-10 flex flex-col md:flex-row gap-2 items-center justify-center lg:sticky top-28">
<div className=" bg-[#E9E9E9] rounded-md py-4 px-10 flex flex-col md:flex-row gap-2 items-center justify-center">
{data.user == null ? (
<>
<div className="mt-2 flex flex-col gap-y-1 border rounded-md border-gray-400 w-full p-5 relative">
@ -457,7 +437,6 @@ export default function ComplainsDetails({
</div>
</div>
</div>
{/* 3 */}
<div className=" lg:hidden order-2 w-full bg-[#E9E9E9] rounded-md py-4 px-10 flex flex-col mt-2">
<p className="text-[#464646] text-base font-bold mb-1">
انجام عملیات
@ -470,14 +449,51 @@ export default function ComplainsDetails({
key2={key}
/>
</div>
{/* Left */}
{/* <div className="w-full md:w-1/3 bg-white shadow-lg rounded-md pt-3 px-4 flex flex-row md:flex-col max-md:flex-wrap">
<p className="text-[#464646] text-base font-bold mb-3">
وضعیت درخواست
</p>
{ComplainDetailsItems.map((item, index, array) => {
return (
<div
className="w-full justify-start items-start gap-4 inline-flex "
key={item.id}
>
<div className="grow shrink basis-0 pb-2 flex-col justify-start items-start gap-1 inline-flex">
<div className="self-stretch text-right text-lime-800 text-lg font-semibold leading-[30px]">
{item.title}
</div>
<div className="self-stretch text-right text-zinc-700 text-base font-normal uppercase">
{item.desc}
</div>
<div className="self-stretch text-right text-zinc-700 text-base font-normal">
{item.date} <br /> {item.time}
</div>
</div>
<div className="w-6 self-stretch flex-col justify-start items-center gap-1 inline-flex">
<div className="py-0.5 justify-start items-start gap-2.5 inline-flex">
<Image
src={greenIcon}
alt="greenIcon"
width={100}
height={100}
/>
</div>
<div className="w-1 grow shrink basis-0 bg-lime-800 rounded-[1px]"></div>
</div>
</div>
);
})}
</div> */}
</div>
</>
) : (
<>
{getComplaintMutation.isPending && (
<div className="w-full h-full flex justify-center mt-20">
<Triangle
visible={true}
height="100"

View File

@ -133,7 +133,7 @@ export default function InspectorOperations({
<FormControl>
<Textarea
placeholder="متن خود را وارد نمایید"
className="resize-none bg-white lg:min-h-[20em]"
className="resize-none bg-white"
{...field}
/>
</FormControl>

View File

@ -14,7 +14,6 @@ export default function NavbarPanel() {
const ref = useRef(null);
const router = useRouter();
const pathname = usePathname();
const [activeLink, setActiveLink] = useState('');
const [role, setRole] = useState<string | null>("");
useEffect(() => {
@ -22,12 +21,6 @@ export default function NavbarPanel() {
setRole(userRole);
}, []);
useEffect(() => {
// Set the active link based on the current route
setActiveLink(pathname);
}, [pathname]);
const { data, isLoading, refetch } = useQuery({
queryKey: ["Profile"],
queryFn: () => getProfile(),
@ -108,14 +101,12 @@ export default function NavbarPanel() {
<>
{selectedMenu.map(
(item: { id: number; name: string; href: string }) => {
const isActive = activeLink === item.href;
return (
<Link key={item.id} href={item.href}>
<p
className={`text-white font-normal text-sm max-md:text-xs
className="text-white font-normal text-sm max-md:text-xs
hover:bg-white/50 rounded-sm p-1
animate-out duration-300 ${isActive ? 'bg-white/50 ' : '' }`}
animate-out duration-300 "
>
{item.name}
</p>
@ -142,7 +133,6 @@ export default function NavbarPanel() {
onClick={() => {
deleteCookie("Sootzani_Token");
localStorage.removeItem("privateKey");
localStorage.removeItem("privatePassword");
router.push("/");
}}
className=" text-white cursor-pointer"

View File

@ -1,12 +1,11 @@
"use client";
import React, { useEffect, useState } from "react";
import React, { useState } from "react";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import TableController from "./TableController";
import Search from "./Search";
import { useQuery } from "@tanstack/react-query";
import { getComplaintsList, getPossibleStates } from "@/utils/inspectorApi";
import { getComplaintsList } from "@/utils/inspectorApi";
import { Button } from "@/components/ui/button";
import { Triangle } from "react-loader-spinner";
import {
Dialog,
DialogClose,
@ -52,81 +51,65 @@ export default function TabController() {
});
}
};
const [psblState, setPsblState] = useState(0);
const [selectedTab, setSelectedTab] = useState("0");
const {
data: dataState,
isLoading: isLoadingState,
refetch: refetchState,
} = useQuery({
queryKey: ["PossibleStates"],
queryFn: () => getPossibleStates(),
refetchOnWindowFocus: false,
});
// const initialSelectedTab = dataState[0]?.value || '';
// setSelectedTab(initialSelectedTab);
// console.log(dataState[0]?.title);
const { data, isLoading, refetch } = useQuery({
queryKey: ["ComplaintsList" ,psblState,dataState],
queryFn: () => getComplaintsList(psblState),
queryKey: ["ComplaintsList"],
queryFn: () => getComplaintsList(),
refetchOnWindowFocus: false,
});
console.log("dataState", dataState);
console.log("psblState", psblState);
console.log("data", data);
// useEffect(() => {
// // Handle the data after it has been updated
// console.log(data);
// }, [data]);
console.log(data);
const newComplaints = data?.filter((item: any) => item.status == 0);
const inProgressComplaints = data?.filter((item: any) => item.status == 1);
const waitingForCitizenResponseComplaints = data?.filter(
(item: any) => item.status == 2
);
const citizenRepliedComplaints = data?.filter(
(item: any) => item.status == 3
);
const finishedComplaints = data?.filter((item: any) => item.status == 4);
console.log(newComplaints);
return (
<div className="w-[95vw] lg:w-[82vw] xl:w-[70vw] 3xl:w-[65vw] mt-16 pt-9 mx-auto">
<p className="3xl:ml-6 text-xs sm:text-sm font-bold md:hidden my-2">
لیست شکایت ها
</p>
<Tabs
defaultValue='0'
value={selectedTab}
// onClick={(value) => {
// setPsblState(value);
// setSelectedTab(value);
// refetch();
// }}
className=""
dir="rtl"
>
<Tabs defaultValue="tab1" className="" dir="rtl">
<div className="w-full flex flex-col-reverse lg:flex-row gap-4 lg:gap-5 justify-between items-center mb-10">
{/* Tab Title */}
<TabsList className="w-full flex gap-1 md:gap-4 lg:gap-3">
<TabsList className="w-full flex gap-1 md:gap-4 lg:gap-7">
<p className="3xl:ml-6 text-xs sm:text-sm font-bold max-md:hidden">
لیست شکایت ها |
</p>
{dataState?.map((item: any) => {
// const isActive = item.value === selectedTab;
return (
<TabsTrigger
key={item.value}
className="hover:border-b-2 border-b-blue max-md:flex-1"
value={item.value}
// data-state={isActive ? 'active' : 'inactive'}
onClick={() => {
setPsblState(item.value);
setSelectedTab(item.value);
refetch();
}}
>
{item.title}
</TabsTrigger>
);
})}
<TabsTrigger
value="tab1"
className="hover:border-b-2 border-b-blue max-md:flex-1"
>
جدید
</TabsTrigger>
<TabsTrigger
value="tab2"
className="hover:border-b-2 border-b-blue max-md:flex-1"
>
در انتظار پاسخ
</TabsTrigger>
<TabsTrigger
value="tab3"
className="hover:border-b-2 border-b-blue max-md:flex-1"
>
در حال بررسی
</TabsTrigger>
<TabsTrigger
value="tab4"
className="hover:border-b-2 border-b-blue max-md:flex-1"
>
پاسخ داده شده
</TabsTrigger>
<TabsTrigger
value="tab5"
className="hover:border-b-2 border-b-blue max-md:flex-1"
>
پایان یافته
</TabsTrigger>
</TabsList>
{/* Search Box */}
@ -134,11 +117,40 @@ export default function TabController() {
</div>
{/* Tab Content */}
<TabsContent value={selectedTab} key={selectedTab}>
<TableController checkKey={(item) => checkKey(item)} data={data} />
<TabsContent value="tab1">
<TableController
checkKey={(item: any) => checkKey(item)}
data={newComplaints}
/>
</TabsContent>
<TabsContent value="tab2">
<TableController
checkKey={(item: any) => checkKey(item)}
data={waitingForCitizenResponseComplaints}
/>
</TabsContent>
<TabsContent value="tab3">
<TableController
checkKey={(item: any) => checkKey(item)}
data={inProgressComplaints}
/>
</TabsContent>
<TabsContent value="tab4">
<TableController
checkKey={(item: any) => checkKey(item)}
data={citizenRepliedComplaints}
/>
</TabsContent>
<TabsContent value="tab5">
<TableController
checkKey={(item: any) => checkKey(item)}
data={finishedComplaints}
/>
</TabsContent>
</Tabs>
</div>
);

View File

@ -84,16 +84,12 @@ export default function TableController({
password: Decrypt(item.cipherKeyInspector, selectedFile),
});
secureLocalStorage.setItem("trackingNumber", item.trackingNumber);
secureLocalStorage.setItem("privateKey", selectedFile);
// secureLocalStorage.setItem(
// "privateKey",
// Decrypt(item.cipherKeyInspector, selectedFile)
// );
secureLocalStorage.setItem(
"privateKey",
Decrypt(item.cipherKeyInspector, selectedFile)
);
router.push(`/UserPanel/ControllerDashboard/Complaints/${item.id}`);
} else {
// toast("******کلید شما معتبر نمی باشد.", {
// className: "!bg-red-500 !text-white",
// });
}
};
console.log(check);
@ -104,9 +100,8 @@ export default function TableController({
<TableHeader>
<TableRow>
<TableHead>ردیف</TableHead>
<TableHead>کد پیگیری</TableHead>
<TableHead> تاریخ ثبت</TableHead>
<TableHead>تاریخ</TableHead>
<TableHead>کد پیگیری</TableHead>
<TableHead>موضوع</TableHead>
<TableHead>دستگاه مربوطه</TableHead>
</TableRow>
@ -131,17 +126,14 @@ export default function TableController({
<TableCell className="w-1/12 font-medium ">
{index + 1}
</TableCell>
<TableCell className="w-1/12">{item.trackingNumber}</TableCell>
<TableCell className="w-2/12">
{convertDate(item.registeredAt)}
</TableCell>
<TableCell className="w-2/12">{item.trackingNumber}</TableCell>
<TableCell className="w-2/12">
{convertDate(item.lastChanged)}
</TableCell>
<TableCell className="w-3/12">
{item?.title ? item.title : "-"}
</TableCell>
<TableCell className="w-3/12">
<TableCell className="w-5/12">
{item?.complaintOrganization
? item?.complaintOrganization.title
: "-"}

View File

@ -130,17 +130,17 @@ export const callUsItems = [
];
export const ControllerMenuItems = [
{ id: 1, name: "پیشخوان", href: "/UserPanel/ControllerDashboard" },
{ id: 2, name: "گزارش ها", href: "/UserPanel/ControllerDashboard/Complaints" },
{ id: 1, name: "داشبورد", href: "/UserPanel/ControllerDashboard" },
{ id: 2, name: "شکایات", href: "/UserPanel/ControllerDashboard/Complaints" },
{
id: 3,
name: " آمار و اطلاعات",
name: "گزارشات و آمار",
href: "/UserPanel/ControllerDashboard/Reports",
},
];
export const AdminMenuItems = [
{ id: 1, name: "پیشخوان", href: "/UserPanel/AdminDashboard" },
{ id: 1, name: "داشبورد", href: "/UserPanel/AdminDashboard" },
// { id: 2, name: "مدیریت کاربران", href: "/UserPanel/AdminDashboard/UserManagement" },
{
id: 3,
@ -149,9 +149,6 @@ export const AdminMenuItems = [
},
{ id: 4, name: "سازمان ها", href: "/UserPanel/AdminDashboard/Organizations" },
{ id: 5, name: "دسته بندی ها", href: "/UserPanel/AdminDashboard/Categories" },
{ id: 6, name: "اخبار", href: "/UserPanel/AdminDashboard/News" },
{ id: 7, name: "اسلایدر", href: "/UserPanel/AdminDashboard/Slider" },
{ id: 8, name: "مدیریت محتوا", href: "/UserPanel/AdminDashboard/WebContents" },
];
export const ControllerTableItems = [

View File

@ -1,8 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
output: "standalone",
images: {
domains: ["sootzaniapi.shetabdahi.ir"],
},
};
/** @type {import('next').NextConfig} */
const nextConfig = { output: "standalone" };
module.exports = nextConfig;

147
package-lock.json generated
View File

@ -55,7 +55,6 @@
"react-leaflet": "^4.2.1",
"react-loader-spinner": "^6.1.6",
"react-otp-input": "^3.1.1",
"react-quill": "^2.0.0",
"react-responsive": "^9.0.2",
"react-secure-storage": "^1.3.2",
"react-spinners": "^0.13.8",
@ -1592,14 +1591,6 @@
"integrity": "sha512-ga8y9v9uyeiLdpKddhxYQkxNDrfvuPrlFb0N1qnZZByvcElJaXthF1UhvCh9TLWJBEHeNtdnbysW7Y6Uq8CVng==",
"devOptional": true
},
"node_modules/@types/quill": {
"version": "1.3.10",
"resolved": "https://registry.npmjs.org/@types/quill/-/quill-1.3.10.tgz",
"integrity": "sha512-IhW3fPW+bkt9MLNlycw8u8fWb7oO7W5URC9MfZYHBlA24rex9rs23D5DETChu1zvgVdc5ka64ICjJOgQMr6Shw==",
"dependencies": {
"parchment": "^1.1.2"
}
},
"node_modules/@types/react": {
"version": "18.2.43",
"resolved": "https://registry.npmjs.org/@types/react/-/react-18.2.43.tgz",
@ -2172,6 +2163,7 @@
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.5.tgz",
"integrity": "sha512-C3nQxfFZxFRVoJoGKKI8y3MOEo129NQ+FgQ08iye+Mk4zNZZGdjfs06bVTr+DBSlA66Q2VEcMki/cUCP4SercQ==",
"dev": true,
"dependencies": {
"function-bind": "^1.1.2",
"get-intrinsic": "^1.2.1",
@ -2313,14 +2305,6 @@
"resolved": "https://registry.npmjs.org/client-only/-/client-only-0.0.1.tgz",
"integrity": "sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA=="
},
"node_modules/clone": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/clone/-/clone-2.1.2.tgz",
"integrity": "sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w==",
"engines": {
"node": ">=0.8"
}
},
"node_modules/clsx": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/clsx/-/clsx-2.0.0.tgz",
@ -2508,25 +2492,6 @@
}
}
},
"node_modules/deep-equal": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.1.2.tgz",
"integrity": "sha512-5tdhKF6DbU7iIzrIOa1AOUt39ZRm13cmL1cGEh//aqR8x9+tNfbywRf0n5FD/18OKMdo7DNEtrX2t22ZAkI+eg==",
"dependencies": {
"is-arguments": "^1.1.1",
"is-date-object": "^1.0.5",
"is-regex": "^1.1.4",
"object-is": "^1.1.5",
"object-keys": "^1.1.1",
"regexp.prototype.flags": "^1.5.1"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/deep-is": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz",
@ -2537,6 +2502,7 @@
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.1.tgz",
"integrity": "sha512-E7uGkTzkk1d0ByLeSc6ZsFS79Axg+m1P/VsgYsxHgiuc3tFSj+MjMIwe90FC4lOAZzNBdY7kkO2P2wKdsQ1vgQ==",
"dev": true,
"dependencies": {
"get-intrinsic": "^1.2.1",
"gopd": "^1.0.1",
@ -2550,6 +2516,7 @@
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.2.1.tgz",
"integrity": "sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg==",
"dev": true,
"dependencies": {
"define-data-property": "^1.0.1",
"has-property-descriptors": "^1.0.0",
@ -3197,26 +3164,11 @@
"node": ">=0.10.0"
}
},
"node_modules/eventemitter3": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-2.0.3.tgz",
"integrity": "sha512-jLN68Dx5kyFHaePoXWPsCGW5qdyZQtLYHkxkg02/Mz6g0kYpDx4FyP6XfArhQdlOC4b8Mv+EMxPo/8La7Tzghg=="
},
"node_modules/extend": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz",
"integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g=="
},
"node_modules/fast-deep-equal": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
"integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q=="
},
"node_modules/fast-diff": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.1.2.tgz",
"integrity": "sha512-KaJUt+M9t1qaIteSvjc6P3RbMdXsNhK61GRftR6SNxqmhthcd9MGIi4T+o0jD8LUSpSnSKXE20nLtJ3fOHxQig=="
},
"node_modules/fast-glob": {
"version": "3.3.2",
"resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz",
@ -3462,6 +3414,7 @@
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/functions-have-names/-/functions-have-names-1.2.3.tgz",
"integrity": "sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==",
"dev": true,
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
@ -3470,6 +3423,7 @@
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.2.tgz",
"integrity": "sha512-0gSo4ml/0j98Y3lngkFEot/zhiCeWsbYIlZ+uZOVgzLyLaUw7wxUL+nCTP0XJvJg1AXulJRI3UJi8GsbDuxdGA==",
"dev": true,
"dependencies": {
"function-bind": "^1.1.2",
"has-proto": "^1.0.1",
@ -3606,6 +3560,7 @@
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz",
"integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==",
"dev": true,
"dependencies": {
"get-intrinsic": "^1.1.3"
},
@ -3654,6 +3609,7 @@
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.1.tgz",
"integrity": "sha512-VsX8eaIewvas0xnvinAe9bw4WfIeODpGYikiWYLH+dma0Jw6KHYqWiWfhQlgOVK8D6PvjubK5Uc4P0iIhIcNVg==",
"dev": true,
"dependencies": {
"get-intrinsic": "^1.2.2"
},
@ -3665,6 +3621,7 @@
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.1.tgz",
"integrity": "sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==",
"dev": true,
"engines": {
"node": ">= 0.4"
},
@ -3676,6 +3633,7 @@
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz",
"integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==",
"dev": true,
"engines": {
"node": ">= 0.4"
},
@ -3687,6 +3645,7 @@
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.0.tgz",
"integrity": "sha512-kFjcSNhnlGV1kyoGk7OXKSawH5JOb/LzUc5w9B02hOTO0dfFRjbHQKvg1d6cf3HbeUmtU9VbbV3qzZ2Teh97WQ==",
"dev": true,
"dependencies": {
"has-symbols": "^1.0.2"
},
@ -3800,21 +3759,6 @@
"loose-envify": "^1.0.0"
}
},
"node_modules/is-arguments": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.1.1.tgz",
"integrity": "sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA==",
"dependencies": {
"call-bind": "^1.0.2",
"has-tostringtag": "^1.0.0"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/is-array-buffer": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/is-array-buffer/-/is-array-buffer-3.0.2.tgz",
@ -3910,6 +3854,7 @@
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.5.tgz",
"integrity": "sha512-9YQaSxsAiSwcvS33MBk3wTCVnWK+HhF8VZR2jRxehM16QcVOdHqPn4VPHmRK4lSr38n9JriurInLcP90xsYNfQ==",
"dev": true,
"dependencies": {
"has-tostringtag": "^1.0.0"
},
@ -4023,6 +3968,7 @@
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz",
"integrity": "sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==",
"dev": true,
"dependencies": {
"call-bind": "^1.0.2",
"has-tostringtag": "^1.0.0"
@ -4334,11 +4280,6 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
},
"node_modules/lodash.merge": {
"version": "4.6.2",
"resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz",
@ -7365,25 +7306,11 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/object-is": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/object-is/-/object-is-1.1.5.tgz",
"integrity": "sha512-3cyDsyHgtmi7I7DfSSI2LDp6SK2lwvtbg0p0R1e0RvTqF5ceGx+K2dfSjm1bKDMVCFEDAQvy+o8c6a7VujOddw==",
"dependencies": {
"call-bind": "^1.0.2",
"define-properties": "^1.1.3"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/object-keys": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz",
"integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==",
"dev": true,
"engines": {
"node": ">= 0.4"
}
@ -7534,11 +7461,6 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/parchment": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/parchment/-/parchment-1.1.4.tgz",
"integrity": "sha512-J5FBQt/pM2inLzg4hEWmzQx/8h8D0CiDxaG3vyp9rKrQRSDgBlhjdP5jQGgosEajXPSQouXGHOmVdgo7QmJuOg=="
},
"node_modules/parent-module": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz",
@ -7813,32 +7735,6 @@
}
]
},
"node_modules/quill": {
"version": "1.3.7",
"resolved": "https://registry.npmjs.org/quill/-/quill-1.3.7.tgz",
"integrity": "sha512-hG/DVzh/TiknWtE6QmWAF/pxoZKYxfe3J/d/+ShUWkDvvkZQVTPeVmUJVu1uE6DDooC4fWTiCLh84ul89oNz5g==",
"dependencies": {
"clone": "^2.1.1",
"deep-equal": "^1.0.1",
"eventemitter3": "^2.0.3",
"extend": "^3.0.2",
"parchment": "^1.1.4",
"quill-delta": "^3.6.2"
}
},
"node_modules/quill-delta": {
"version": "3.6.3",
"resolved": "https://registry.npmjs.org/quill-delta/-/quill-delta-3.6.3.tgz",
"integrity": "sha512-wdIGBlcX13tCHOXGMVnnTVFtGRLoP0imqxM696fIPwIf5ODIYUHIvHbZcyvGlZFiFhK5XzDC2lpjbxRhnM05Tg==",
"dependencies": {
"deep-equal": "^1.0.1",
"extend": "^3.0.2",
"fast-diff": "1.1.2"
},
"engines": {
"node": ">=0.10"
}
},
"node_modules/react": {
"version": "18.2.0",
"resolved": "https://registry.npmjs.org/react/-/react-18.2.0.tgz",
@ -7942,20 +7838,6 @@
"react-dom": ">=16.8.6 || ^17.0.0 || ^18.0.0"
}
},
"node_modules/react-quill": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/react-quill/-/react-quill-2.0.0.tgz",
"integrity": "sha512-4qQtv1FtCfLgoD3PXAur5RyxuUbPXQGOHgTlFie3jtxp43mXDtzCKaOgQ3mLyZfi1PUlyjycfivKelFhy13QUg==",
"dependencies": {
"@types/quill": "^1.3.10",
"lodash": "^4.17.4",
"quill": "^1.3.7"
},
"peerDependencies": {
"react": "^16 || ^17 || ^18",
"react-dom": "^16 || ^17 || ^18"
}
},
"node_modules/react-remove-scroll": {
"version": "2.5.5",
"resolved": "https://registry.npmjs.org/react-remove-scroll/-/react-remove-scroll-2.5.5.tgz",
@ -8149,6 +8031,7 @@
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.1.tgz",
"integrity": "sha512-sy6TXMN+hnP/wMy+ISxg3krXx7BAtWVO4UouuCN/ziM9UEne0euamVNafDfvC83bRNr95y0V5iijeDQFUNpvrg==",
"dev": true,
"dependencies": {
"call-bind": "^1.0.2",
"define-properties": "^1.2.0",
@ -8324,6 +8207,7 @@
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.1.1.tgz",
"integrity": "sha512-VoaqjbBJKiWtg4yRcKBQ7g7wnGnLV3M8oLvVWwOk2PdYY6PEFegR1vezXR0tw6fZGF9csVakIRjrJiy2veSBFQ==",
"dev": true,
"dependencies": {
"define-data-property": "^1.1.1",
"get-intrinsic": "^1.2.1",
@ -8338,6 +8222,7 @@
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/set-function-name/-/set-function-name-2.0.1.tgz",
"integrity": "sha512-tMNCiqYVkXIZgc2Hnoy2IvC/f8ezc5koaRFkCjrpWzGpCd3qbZXPzVy9MAZzK1ch/X0jvSkojys3oqJN0qCmdA==",
"dev": true,
"dependencies": {
"define-data-property": "^1.0.1",
"functions-have-names": "^1.2.3",

View File

@ -56,7 +56,6 @@
"react-leaflet": "^4.2.1",
"react-loader-spinner": "^6.1.6",
"react-otp-input": "^3.1.1",
"react-quill": "^2.0.0",
"react-responsive": "^9.0.2",
"react-secure-storage": "^1.3.2",
"react-spinners": "^0.13.8",

View File

@ -32,7 +32,7 @@ export async function ChangeKey(payload: {
return data.data;
}
// .....Categories................................................
// .....Categories.......
export async function GetAllCategories() {
const data = await axios.get("api/ComplaintCategories");
return data.data;
@ -71,7 +71,7 @@ export async function DeleteCategory({
}: {
id: string;
payload: any;
}) {
}) {
const data = await axios.delete(`api/ComplaintCategories/${id}`, {
data: payload,
headers: { "Content-Type": "application/json" },
@ -80,7 +80,7 @@ export async function DeleteCategory({
return data.data;
}
// .....Organizations.............................................
// .....Organizations.......
export async function GetAllOrganizations() {
const data = await axios.get("api/ComplaintOrganizations");
return data.data;
@ -119,114 +119,11 @@ export async function DeleteOrganization({
}: {
id: string;
payload: any;
}) {
}){
const data = await axios.delete(`api/ComplaintOrganizations/${id}`, {
data: payload,
headers: { "Content-Type": "application/json" },
});
return data.data;
}
// .....WebContents.............................................
export async function GetWebContents() {
const data = await axios.get("api/WebContents");
return data.data;
}
export async function GetSingleWebContents({ id }: { id: string }) {
const data = await axios.get(`api/WebContents/${id}`);
return data.data;
}
export async function SubmitWebContents(payload: FormData) {
const data = await axios.post(`api/WebContents`, payload, {
headers: { "Content-Type": "multipart/form-data" },
});
return data.data;
}
export async function UpdateWebContents({
id,
payload,
}: {
id: string;
payload: FormData;
}) {
const data = await axios.put(`api/WebContents/${id}`, payload, {
headers: { "Content-Type": "multipart/form-data" },
});
return data.data;
}
// .....News.................................................
export async function GetAllNews() {
const data = await axios.get("api/News");
return data.data;
}
export async function GetSingleNews({ id }: { id: string }) {
const data = await axios.get(`api/News/${id}`);
return data.data;
}
export async function SubmitNews(payload: FormData) {
const data = await axios.post("api/News", payload , {
headers: { "Content-Type": "multipart/form-data" },
});
return data.data;
}
export async function UpdateNews({
id,
payload,
}: {
id: string;
payload: FormData;
}) {
const data = await axios.put(`api/News/${id}`, payload , {
headers: { "Content-Type": "multipart/form-data" },
});
return data.data;
}
export async function DeleteNews({ id }: { id: string }) {
const data = await axios.delete(`api/News/${id}`);
return data.data;
}
// .....Slider.................................................
export async function GetAllSliders() {
const data = await axios.get("api/Sliders");
return data.data;
}
export async function GetSingleSlider({ id }: { id: string }) {
const data = await axios.get(`api/Sliders/${id}`);
return data.data;
}
export async function SubmitSlider(payload: FormData) {
const data = await axios.post("api/Sliders", payload , {
headers: { "Content-Type": "multipart/form-data" },
});
return data.data;
}
export async function UpdateSlider({
id,
payload,
}: {
id: string;
payload: FormData;
}) {
const data = await axios.put(`api/Sliders/${id}`, payload , {
headers: { "Content-Type": "multipart/form-data" },
});
return data.data;
}
export async function DeleteSlider({ id }: { id: string }) {
const data = await axios.delete(`api/Sliders/${id}`);
return data.data;
}

View File

@ -1,22 +1,22 @@
import axios from "axios";
import { CookieValueTypes } from "cookies-next";
// Get Category
// Get Category
export async function getCategory() {
const data = await axios.get("api/Common/Categories");
return data.data;
}
const data = await axios.get(
"api/Common/Categories",
);
return data.data;
}
// Get Captcha
// Get Captcha
export async function getCaptcha() {
const data = await axios.get("api/Common/Captcha", { responseType: "blob" });
console.log(data);
return data;
}
// Get Captcha
export async function getContents() {
const data = await axios.get("api/Common/Contents");
console.log(data);
return data.data;
}
const data = await axios.get(
"api/Common/Captcha", {responseType:'blob'}
);
console.log(data)
return data;
}

View File

@ -11,15 +11,8 @@ axios.interceptors.request.use(function (config) {
return config;
});
export async function getPossibleStates() {
const data = await axios.get(`api/Inspector/PossibleStates`);
return data.data;
}
export async function getComplaintsList(states: number = 0) {
// export async function getComplaintsList() {
// const data = await axios.get(`api/Inspector/List`);
const data = await axios.get(`api/Inspector/List?States=${states}`);
export async function getComplaintsList() {
const data = await axios.get(`api/Inspector/List`);
return data.data;
}