a part of Admin panel Added
parent
85a75c8dab
commit
1d36e37376
|
|
@ -344,7 +344,7 @@ export default function AdminCategories() {
|
||||||
<AlertDialogHeader>
|
<AlertDialogHeader>
|
||||||
<AlertDialogTitle>
|
<AlertDialogTitle>
|
||||||
<p className="text-[#464646] text-base font-bold">
|
<p className="text-[#464646] text-base font-bold">
|
||||||
تغییر کلید
|
تغییر دسته بندی
|
||||||
</p>
|
</p>
|
||||||
<AlertDialogCancel className="p-0 border-0 h-auto">
|
<AlertDialogCancel className="p-0 border-0 h-auto">
|
||||||
<IoMdClose />
|
<IoMdClose />
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,766 @@
|
||||||
import React from 'react'
|
"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() {
|
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 (
|
return (
|
||||||
<div>AdminNews</div>
|
<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>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -252,14 +252,14 @@ export default function AdminOrganizations() {
|
||||||
className="bg-orange-500 text-white"
|
className="bg-orange-500 text-white"
|
||||||
// disabled={isNewKeyLoading}
|
// disabled={isNewKeyLoading}
|
||||||
>
|
>
|
||||||
افزودن دسته بندی
|
افزودن سازمان
|
||||||
</Button>
|
</Button>
|
||||||
</AlertDialogTrigger>
|
</AlertDialogTrigger>
|
||||||
<AlertDialogContent className=" w-full max-w-3xl h-full lg:max-h-[26em] max-h-[24em]">
|
<AlertDialogContent className=" w-full max-w-3xl h-full lg:max-h-[26em] max-h-[24em]">
|
||||||
<AlertDialogHeader>
|
<AlertDialogHeader>
|
||||||
<AlertDialogTitle>
|
<AlertDialogTitle>
|
||||||
<p className="text-[#464646] text-base font-bold">
|
<p className="text-[#464646] text-base font-bold">
|
||||||
افزودن دسته بندی
|
افزودن سازمان
|
||||||
</p>
|
</p>
|
||||||
<AlertDialogCancel className="p-0 border-0 h-auto">
|
<AlertDialogCancel className="p-0 border-0 h-auto">
|
||||||
<IoMdClose />
|
<IoMdClose />
|
||||||
|
|
@ -269,7 +269,7 @@ export default function AdminOrganizations() {
|
||||||
<AlertDialogDescription>
|
<AlertDialogDescription>
|
||||||
<div className="w-full ">
|
<div className="w-full ">
|
||||||
<div className="w-full text-right text-neutral-600 text-lg font-bold mb-2">
|
<div className="w-full text-right text-neutral-600 text-lg font-bold mb-2">
|
||||||
افزودن دسته بندی
|
سازمان ها
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Form {...formAdd}>
|
<Form {...formAdd}>
|
||||||
|
|
@ -347,7 +347,7 @@ export default function AdminOrganizations() {
|
||||||
<AlertDialogHeader>
|
<AlertDialogHeader>
|
||||||
<AlertDialogTitle>
|
<AlertDialogTitle>
|
||||||
<p className="text-[#464646] text-base font-bold">
|
<p className="text-[#464646] text-base font-bold">
|
||||||
تغییر کلید
|
تغییر سازمان
|
||||||
</p>
|
</p>
|
||||||
<AlertDialogCancel className="p-0 border-0 h-auto">
|
<AlertDialogCancel className="p-0 border-0 h-auto">
|
||||||
<IoMdClose />
|
<IoMdClose />
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,725 @@
|
||||||
import React from 'react'
|
"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() {
|
export default function AdminSlider() {
|
||||||
return (
|
const router = useRouter();
|
||||||
<div>AdminSlider</div>
|
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>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,8 @@
|
||||||
/** @type {import('next').NextConfig} */
|
/** @type {import('next').NextConfig} */
|
||||||
const nextConfig = { output: "standalone" };
|
const nextConfig = {
|
||||||
|
output: "standalone",
|
||||||
|
images: {
|
||||||
|
domains: ["sootzaniapi.shetabdahi.ir"],
|
||||||
|
},
|
||||||
|
};
|
||||||
module.exports = nextConfig;
|
module.exports = nextConfig;
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ export async function ChangeKey(payload: {
|
||||||
return data.data;
|
return data.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
// .....Categories.......
|
// .....Categories................................................
|
||||||
export async function GetAllCategories() {
|
export async function GetAllCategories() {
|
||||||
const data = await axios.get("api/ComplaintCategories");
|
const data = await axios.get("api/ComplaintCategories");
|
||||||
return data.data;
|
return data.data;
|
||||||
|
|
@ -80,7 +80,7 @@ export async function DeleteCategory({
|
||||||
return data.data;
|
return data.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
// .....Organizations.......
|
// .....Organizations.............................................
|
||||||
export async function GetAllOrganizations() {
|
export async function GetAllOrganizations() {
|
||||||
const data = await axios.get("api/ComplaintOrganizations");
|
const data = await axios.get("api/ComplaintOrganizations");
|
||||||
return data.data;
|
return data.data;
|
||||||
|
|
@ -119,7 +119,7 @@ export async function DeleteOrganization({
|
||||||
}: {
|
}: {
|
||||||
id: string;
|
id: string;
|
||||||
payload: any;
|
payload: any;
|
||||||
}){
|
}) {
|
||||||
const data = await axios.delete(`api/ComplaintOrganizations/${id}`, {
|
const data = await axios.delete(`api/ComplaintOrganizations/${id}`, {
|
||||||
data: payload,
|
data: payload,
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
|
|
@ -128,9 +128,7 @@ export async function DeleteOrganization({
|
||||||
return data.data;
|
return data.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// .....WebContents.............................................
|
||||||
|
|
||||||
// .....WebContents.......
|
|
||||||
export async function GetWebContents() {
|
export async function GetWebContents() {
|
||||||
const data = await axios.get("api/WebContents");
|
const data = await axios.get("api/WebContents");
|
||||||
return data.data;
|
return data.data;
|
||||||
|
|
@ -141,8 +139,7 @@ export async function GetSingleWebContents({ id }: { id: string }) {
|
||||||
return data.data;
|
return data.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function SubmitWebContents(payload: FormData) {
|
||||||
export async function SubmitWebContents( payload: FormData) {
|
|
||||||
const data = await axios.post(`api/WebContents`, payload, {
|
const data = await axios.post(`api/WebContents`, payload, {
|
||||||
headers: { "Content-Type": "multipart/form-data" },
|
headers: { "Content-Type": "multipart/form-data" },
|
||||||
});
|
});
|
||||||
|
|
@ -154,7 +151,7 @@ export async function UpdateWebContents({
|
||||||
payload,
|
payload,
|
||||||
}: {
|
}: {
|
||||||
id: string;
|
id: string;
|
||||||
payload: FormData
|
payload: FormData;
|
||||||
}) {
|
}) {
|
||||||
const data = await axios.put(`api/WebContents/${id}`, payload, {
|
const data = await axios.put(`api/WebContents/${id}`, payload, {
|
||||||
headers: { "Content-Type": "multipart/form-data" },
|
headers: { "Content-Type": "multipart/form-data" },
|
||||||
|
|
@ -162,6 +159,74 @@ export async function UpdateWebContents({
|
||||||
return data.data;
|
return data.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
// .....News.......
|
// .....News.................................................
|
||||||
|
export async function GetAllNews() {
|
||||||
|
const data = await axios.get("api/News");
|
||||||
|
return data.data;
|
||||||
|
}
|
||||||
|
|
||||||
// .....Slider.......
|
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;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue