Working on subadmin update and add post
This commit is contained in:
@@ -22,10 +22,10 @@ import { Toaster, toaster } from "../../../components/ui/toaster";
|
||||
import { Template } from "../../../Redux/Service/template.master.service";
|
||||
import axios from "axios";
|
||||
|
||||
// const IMGURL = import.meta.env.VITE_IMG_TEMPLATES
|
||||
const IMGURL = import.meta.env.VITE_IMG_TEMPLATES
|
||||
const APIURL = import.meta.env.VITE_API_URL
|
||||
|
||||
function EditTemplateModel({ id, localData, refetch }: { id: number, localData: any, refetch:VoidFunction }) {
|
||||
function EditTemplateModel({ id, localData, refetch }: { id: number, localData: any, refetch: VoidFunction }) {
|
||||
const [title, setTitle] = useState("");
|
||||
const [subTitle, setSubTitle] = useState("");
|
||||
const [userType, setUserType] = useState<number | "">("");
|
||||
@@ -63,8 +63,8 @@ function EditTemplateModel({ id, localData, refetch }: { id: number, localData:
|
||||
setUserType(template.principle_type_xid?.toString() || "");
|
||||
|
||||
// Convert image URLs to File objects if needed
|
||||
// const templateImages = template.post_template_image.map((img: any) => `${IMGURL}${img.image_name}`);
|
||||
// setImages(templateImages);
|
||||
const templateImages = template.post_template_image.map((img: any) => `${IMGURL}${img.image_name}`);
|
||||
setImages(templateImages);
|
||||
|
||||
setIsOpen(true);
|
||||
}
|
||||
@@ -90,7 +90,9 @@ function EditTemplateModel({ id, localData, refetch }: { id: number, localData:
|
||||
return;
|
||||
}
|
||||
|
||||
if (images.length === 0) {
|
||||
const newImages = images.filter((image) => image instanceof File);
|
||||
|
||||
if (newImages.length === 0) {
|
||||
toaster.create({
|
||||
title: "Error",
|
||||
description: "Please upload at least one image.",
|
||||
@@ -105,14 +107,8 @@ function EditTemplateModel({ id, localData, refetch }: { id: number, localData:
|
||||
formData.append("title", title);
|
||||
formData.append("sub_title", subTitle);
|
||||
|
||||
images.forEach((image, index) => {
|
||||
if (typeof image === "string") {
|
||||
// Append existing image URLs
|
||||
formData.append(`existing_images[${index}]`, image);
|
||||
} else {
|
||||
// Append new image files
|
||||
formData.append(`new_images[${index}]`, image, image.name);
|
||||
}
|
||||
newImages.forEach((image, index) => {
|
||||
formData.append(`image_name[${index}]`, image, image.name);
|
||||
});
|
||||
|
||||
try {
|
||||
@@ -130,7 +126,11 @@ function EditTemplateModel({ id, localData, refetch }: { id: number, localData:
|
||||
refetch()
|
||||
} catch (error) {
|
||||
console.error("Error updating template:", error);
|
||||
alert("Failed to update template");
|
||||
toaster.create({
|
||||
title: "Error",
|
||||
description: "Failed to update template. Please try again.",
|
||||
type: "error",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -283,6 +283,9 @@ function EditTemplateModel({ id, localData, refetch }: { id: number, localData:
|
||||
</Box>
|
||||
<FiUpload color="#000" />
|
||||
</Box>
|
||||
<Box>
|
||||
|
||||
</Box>
|
||||
|
||||
{/* <Input placeholder="" bgColor="#EEEEEE" color="black" border="none" pl={1} fontSize="12px" height="30px" /> */}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user