diff --git a/package.json b/package.json
index cdf13a9..0cee480 100644
--- a/package.json
+++ b/package.json
@@ -48,6 +48,7 @@
"country-state-city": "^3.2.1",
"draft-js": "^0.11.7",
"draft-js-export-html": "^1.4.1",
+ "draft-js-import-html": "^1.4.1",
"md5": "^2.3.0",
"moment": "^2.30.1",
"prop-types": "^15.7.2",
diff --git a/src/_nav.js b/src/_nav.js
index 2360dcf..19e5933 100644
--- a/src/_nav.js
+++ b/src/_nav.js
@@ -253,7 +253,7 @@ const _nav = [
{
component: CNavGroup,
name: "Blog",
- icon: ,
+ icon: ,
items: [
{
component: CNavItem,
diff --git a/src/routes.js b/src/routes.js
index ad812ad..e0d91d1 100644
--- a/src/routes.js
+++ b/src/routes.js
@@ -118,6 +118,8 @@ import EditTestimonial from "./views/Testimonials/EditTestimonial";
//Blogs
import Blogs from "./views/Blog/Blogs";
import CreateBlog from "./views/Blog/CreateBlog";
+import UpdateBlog from "./views/Blog/EditBlog";
+import ViewBlog from "./views/Blog/ViewBlog";
const routes = [
{ path: "/", exact: true, name: "Home" },
{
@@ -492,6 +494,16 @@ const routes = [
name: "Blogs",
element: CreateBlog,
},
+ {
+ path: "/blog/edit/:id",
+ name: "Blogs",
+ element: UpdateBlog,
+ },
+ {
+ path: "/blog/view/:id",
+ name: "Blogs",
+ element: ViewBlog,
+ },
];
export default routes;
diff --git a/src/views/Blog/Blogs.jsx b/src/views/Blog/Blogs.jsx
index 13547c1..13c7cc5 100644
--- a/src/views/Blog/Blogs.jsx
+++ b/src/views/Blog/Blogs.jsx
@@ -18,34 +18,33 @@ import SearchIcon from "@mui/icons-material/Search";
import Fuse from "fuse.js";
import { Typography } from "@material-ui/core";
import { AppBlockingSharp } from "@mui/icons-material";
+
const Blogs = () => {
const token = isAutheticated();
const [query, setQuery] = useState("");
const navigate = useNavigate();
const [loading, setLoading] = useState(true);
const [success, setSuccess] = useState(true);
- const [productsData, setProductsData] = useState([]);
- const [filterData, setFilterData] = useState([]);
- const [queryData, setQueryData] = useState([]);
+ const [BlogsData, setBlogsData] = useState([]);
const [currentPage, setCurrentPage] = useState(1);
const [itemPerPage, setItemPerPage] = useState(10);
- const [showData, setShowData] = useState(productsData);
+ const [showData, setShowData] = useState(BlogsData);
const handleShowEntries = (e) => {
setCurrentPage(1);
setItemPerPage(e.target.value);
};
- const getProductsData = async () => {
+ const getBlogsData = async () => {
axios
- .get(`/api/product/getAll/`, {
+ .get(`/api/v1/blog/getallblog/`, {
headers: {
Authorization: `Bearer ${token}`,
},
})
.then((res) => {
- setProductsData(res.data?.product);
+ setBlogsData(res?.data?.BlogData);
setLoading(false);
})
.catch((error) => {
@@ -61,17 +60,17 @@ const Blogs = () => {
};
useEffect(() => {
- getProductsData();
+ getBlogsData();
}, [success]);
useEffect(() => {
const loadData = () => {
const indexOfLastPost = currentPage * itemPerPage;
const indexOfFirstPost = indexOfLastPost - itemPerPage;
- setShowData(productsData.slice(indexOfFirstPost, indexOfLastPost));
+ setShowData(BlogsData.slice(indexOfFirstPost, indexOfLastPost));
};
loadData();
- }, [currentPage, itemPerPage, productsData]);
+ }, [currentPage, itemPerPage, BlogsData]);
const handleDelete = (id) => {
swal({
@@ -84,7 +83,7 @@ const Blogs = () => {
}).then((value) => {
if (value === true) {
axios
- .delete(`/api/product/delete/${id}`, {
+ .delete(`/api/v1/blog/deleteblog/${id}`, { // Correct the API endpoint
headers: {
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
@@ -93,7 +92,7 @@ const Blogs = () => {
.then((res) => {
swal({
title: "Deleted",
- text: "Product Deleted successfully!",
+ text: "Blog Deleted successfully!",
icon: "success",
button: "ok",
});
@@ -111,54 +110,24 @@ const Blogs = () => {
}
});
};
- const [filterCategory, setFilterCategory] = useState("");
-
- const handleSearchClick = (query) => {
- const option = {
- isCaseSensitive: true,
- includeScore: false,
- shouldSort: true,
- includeMatches: false,
- findAllMatches: false,
- minMatchCharLength: 1,
- location: 0,
- threshold: 0.6,
- distance: 100,
- useExtendedSearch: true,
- ignoreLocation: false,
- ignoreFieldNorm: false,
- fieldNormWeight: 1,
- keys: ["name"],
- };
-
- const fuse = new Fuse(productsData, option);
- const result = fuse.search(query);
-
- const searchedResult = result.map((result) => result.item);
- console.log(searchedResult);
- setQueryData(searchedResult);
- };
- useEffect(() => {
- if (query !== "") {
- setFilterCategory("");
- }
- setTimeout(() => handleSearchClick(query), 100);
- }, [query]);
useEffect(() => {
setTimeout(() => {
- if (filterCategory !== "") {
- const filteredProducts = productsData.filter(
- (product) => product.category?.categoryName === filterCategory
+ if (query !== "") {
+ let searchedResult = [];
+ searchedResult = BlogsData.filter((item) =>
+ item.title.toString().includes(query)
);
- setFilterData(filteredProducts);
- } else {
- // If no category is selected, show all products
- setShowData(productsData);
- // setFilterData(filteredProducts);
+ setShowData(searchedResult);
+ }
+ else{
+ getBlogsData();
}
}, 100);
- }, [filterCategory, productsData]);
+ }, [query]);
+
+
+
return (
@@ -167,11 +136,11 @@ const Blogs = () => {
Blogs
@@ -201,20 +170,20 @@ const Blogs = () => {
-
+
Show :
handleShowEntries(e)}
className="
- select-w
- custom-select custom-select-sm
- form-control form-control-sm
- "
+ select-w
+ custom-select custom-select-sm
+ form-control form-control-sm
+ "
>
10
25
@@ -240,7 +209,7 @@ const Blogs = () => {
marginRight: "1rem",
}}
>
- Search by Blog name :
+ Search by Blog Title :
{
padding: "0.5rem",
borderRadius: "8px",
flex: "1",
- border: " 1px solid grey",
+ border: "1px solid grey",
marginRight: "2rem",
height: "3rem",
position: "relative",
+ width: "300px",
}}
placeholder="Search here..."
variant="standard"
@@ -264,7 +234,6 @@ const Blogs = () => {
sx={{
background: "white",
color: "grey",
- // marginTop: "0.1rem",
height: "2.9rem",
width: "3rem",
position: "absolute",
@@ -272,7 +241,7 @@ const Blogs = () => {
top: "-8px",
borderRadius: "0px 8px 8px 0px",
}}
- onClick={() => handleSearchClick(query)}
+ // onClick={() => handleSearchClick(query)}
>
@@ -312,342 +281,97 @@ const Blogs = () => {
{!loading && showData.length === 0 && (
-
+
No Data Available
)}
{loading ? (
-
+
Loading...
- ) : query === "" && filterCategory == "" ? (
- showData.map((product, i) => {
- return (
-
-
- {/* {product.image &&
- product.image.map((i, j) => (
-
- ))} */}
- {product.image && (
-
- )}
-
- {/* {product.name} */}
-
- The All new Samsumg s22 Ultra stormed the
- market of India
-
- {/*
- {product.category?.categoryName !== ""
- ? product.category?.categoryName
- : "Category Not selected "}
- */}
-
-
- {new Date(product.createdAt).toLocaleString(
- "en-IN",
- {
- weekday: "short",
- month: "short",
- day: "numeric",
- year: "numeric",
- hour: "numeric",
- minute: "numeric",
- hour12: true,
- }
- )}
-
-
-
-
- View
-
-
-
-
- Edit
-
-
-
- {
- handleDelete(product._id);
- }}
- >
- Delete
-
-
-
-
- );
- })
- ) : query !== "" ? (
- queryData.map((product, i) => {
- return (
-
-
- {product.image &&
- product.image.map((i, j) => (
-
- ))}
-
- {product.name}
-
- {product.category !== ""
- ? product.category?.categoryName
- : "Category Not selected "}
-
- ₹{product.price}
-
- {new Date(product.createdAt).toLocaleString(
- "en-IN",
- {
- weekday: "short",
- month: "short",
- day: "numeric",
- year: "numeric",
- hour: "numeric",
- minute: "numeric",
- hour12: true,
- }
- )}
-
-
-
-
- View
-
-
-
-
- Edit
-
-
-
- {
- handleDelete(product._id);
- }}
- >
- Delete
-
-
-
-
- );
- })
) : (
- query == "" &&
- filterData.map((product, i) => {
- return (
-
-
- {product.image &&
- product.image.map((i, j) => (
-
- ))}
-
- {product.name}
-
- {product.category?.categoryName}
-
- ₹{product.price}
-
- {new Date(product.createdAt).toLocaleString(
- "en-IN",
- {
- weekday: "short",
- month: "short",
- day: "numeric",
- year: "numeric",
- hour: "numeric",
- minute: "numeric",
- hour12: true,
- }
- )}
-
-
-
-
+ )}
+
+ {blog.title}
+
+ {new Date(blog.createdAt).toLocaleString(
+ "en-IN",
+ {
+ weekday: "short",
+ month: "short",
+ day: "numeric",
+ year: "numeric",
+ hour: "numeric",
+ minute: "numeric",
+ hour12: true,
+ }
+ )}
+
+
+
+
- View
-
-
-
-
- Edit
-
-
-
-
+ Edit
+
+
+ {
- handleDelete(product._id);
- }}
- >
- Delete
-
-
-
-
- );
- })
+ onClick={() => handleDelete(blog._id)}
+ >
+ Delete
+
+
+
+ ))
)}
-
{
Showing {currentPage * itemPerPage - itemPerPage + 1} to{" "}
{Math.min(
currentPage * itemPerPage,
- productsData.length
+ BlogsData.length
)}{" "}
- of {productsData.length} entries
+ of {BlogsData.length} entries
@@ -709,7 +433,7 @@ const Blogs = () => {
{!(
(currentPage + 1) * itemPerPage - itemPerPage >
- productsData.length - 1
+ BlogsData.length - 1
) && (
{
className={
!(
(currentPage + 1) * itemPerPage - itemPerPage >
- productsData.length - 1
+ BlogsData.length - 1
)
? "paginate_button page-item next"
: "paginate_button page-item next disabled"
diff --git a/src/views/Blog/CreateBlog.jsx b/src/views/Blog/CreateBlog.jsx
index 6391208..03ebf00 100644
--- a/src/views/Blog/CreateBlog.jsx
+++ b/src/views/Blog/CreateBlog.jsx
@@ -26,110 +26,149 @@ const CreateBlog = () => {
const [loading, setLoading] = useState(false);
- const [imagesPreview, setImagesPreview] = useState([]);
- // const [allimage, setAllImage] = useState([]);
+ const [image, setimage] = useState(null);
const [title, setTitle] = useState("");
- const [tag, setTag] = useState([]); //tags array
- const [productImages, setProductImages] = useState([]);
+ const [tag, setTag] = useState(""); //tags array
const [blogContent, setBlogContent] = useState(EditorState.createEmpty());
- // const [htmlData, setHtmlData] = useState();
const [error, setError] = useState("");
const handleFileChange = (e) => {
const files = e.target.files;
+ // Reset error state
+ setError("");
- // Check the total number of selected files
- if (productImages.length + files.length > 4) {
- setError("You can only upload up to 4 images.");
+ // Check if more than one image is selected
+ if (files.length > 1) {
+ setError("You can only upload one image.");
return;
}
// Check file types and append to selectedFiles
const allowedTypes = ["image/jpeg", "image/png", "image/jpg"];
- const selected = [];
+ const file = files[0]; // Only one file is selected, so we get the first one
- for (let i = 0; i < files.length; i++) {
- if (productImages.length + selected.length >= 4) {
- break; // Don't allow more than 4 images
- }
-
- if (allowedTypes.includes(files[i].type)) {
- selected.push(files[i]);
- }
- }
-
- if (selected.length === 0) {
- setError("Please upload only PNG, JPEG, or JPG files.");
+ if (allowedTypes.includes(file.type)) {
+ setimage(file);
} else {
- setError("");
- setProductImages([...productImages, ...selected]);
+ setError("Please upload only PNG, JPEG, or JPG files.");
}
};
const handelDelete = (image) => {
- const filtered = productImages.filter((item) => item !== image);
- setProductImages(filtered);
+ setimage(null);
};
+ // const handleSubmit = () => {
+ // setLoading(true);
+
+ // const contentState = blogContent.getCurrentContent();
+ // const htmlData = stateToHTML(contentState);
+ // // console.log(title, typeof htmlData, image, tag);
+
+ // const formData = new FormData();
+ // formData.append("title", title);
+ // formData.append("blog_content", htmlData);
+
+ // formData.append("image", image);
+ // formData.append("tags", tag);
+ // // for (let entry of formData.entries()) {
+ // // console.log(entry);
+ // // }
+ // axios
+ // .post(`/api/v1/blog/create`, formData, {
+ // headers: {
+ // Authorization: `Bearer ${token}`,
+ // "Content-Type": "multipart/form-data",
+ // "Access-Control-Allow-Origin": "*",
+ // },
+ // })
+ // .then((res) => {
+ // swal({
+ // title: "Added",
+ // text: "Blog added successfully!",
+ // icon: "success",
+ // button: "ok",
+ // });
+ // setLoading(false);
+ // navigate("/blogs");
+ // })
+ // .catch((err) => {
+ // console.log(err);
+ // setLoading(false);
+ // const message = err.response?.data?.message
+ // ? err.response?.data?.message
+ // : "Something went wrong!";
+ // swal({
+ // title: "Warning",
+ // text: message,
+ // icon: "error",
+ // button: "Retry",
+ // dangerMode: true,
+ // });
+ // });
+ // };
const handleSubmit = () => {
+ // Check if any of the required fields are empty
+ if (!title || !image || !tag || !blogContent) {
+ swal({
+ title: "Warning",
+ text: "All fields are required!",
+ icon: "error",
+ button: "Retry",
+ dangerMode: true,
+ });
+ return; // Exit the function early if any field is empty
+ }
+
setLoading(true);
const contentState = blogContent.getCurrentContent();
const htmlData = stateToHTML(contentState);
- console.log(title, typeof htmlData, productImages, tag);
+
const formData = new FormData();
formData.append("title", title);
formData.append("blog_content", htmlData);
+ formData.append("image", image);
+ formData.append("tags", tag);
- // Append each file from productImages array individually
- productImages.forEach((file, index) => {
- formData.append(`image${index}`, file);
- });
-
- // Append each tag from selected array individually
- tag.forEach((tag, index) => {
- formData.append(`tag${index}`, tag);
- });
- for (let entry of formData.entries()) {
- console.log(entry);
- }
- // axios
- // .post(`/api/v1/blog/create`, formData, {
- // headers: {
- // Authorization: `Bearer ${token}`,
- // "Content-Type": "multipart/form-data",
- // "Access-Control-Allow-Origin": "*",
- // },
- // })
- // .then((res) => {
- // swal({
- // title: "Added",
- // text: "Product added successfully!",
- // icon: "success",
- // button: "ok",
- // });
- // setLoading(false);
- // // navigate("/products", { replace: true });
- // })
- // .catch((err) => {
- // console.log(err);
- // setLoading(false);
- // const message = err.response?.data?.message
- // ? err.response?.data?.message
- // : "Something went wrong!";
- // swal({
- // title: "Warning",
- // text: message,
- // icon: "error",
- // button: "Retry",
- // dangerMode: true,
- // });
- // });
+ axios
+ .post(`/api/v1/blog/create`, formData, {
+ headers: {
+ Authorization: `Bearer ${token}`,
+ "Content-Type": "multipart/form-data",
+ "Access-Control-Allow-Origin": "*",
+ },
+ })
+ .then((res) => {
+ swal({
+ title: "Added",
+ text: "Blog added successfully!",
+ icon: "success",
+ button: "ok",
+ });
+ setLoading(false);
+ navigate("/blogs");
+ })
+ .catch((err) => {
+ console.log(err);
+ setLoading(false);
+ const message = err.response?.data?.message
+ ? err.response?.data?.message
+ : "Something went wrong!";
+ swal({
+ title: "Warning",
+ text: message,
+ icon: "error",
+ button: "Retry",
+ dangerMode: true,
+ });
+ });
};
+
// console.log(data);
// console.log(productImages);
// To log the content when needed...
-
+ // console.log(tag);
return (
@@ -143,7 +182,7 @@ const CreateBlog = () => {
"
>
- Add Product
+ Add Blog
@@ -193,13 +232,14 @@ const CreateBlog = () => {
type="text"
className="form-control"
id="name"
+ placeHolder="enter Title"
value={title}
onChange={(e) => setTitle(e.target.value)}
/>
- {name ? (
+ {title ? (
<>
- {25 - name.length} characters left
+ {25 - title.length} characters left
>
) : (
@@ -208,15 +248,19 @@ const CreateBlog = () => {
- Tags
-
+ Tags
+
+ setTag(e.target.value)}
+ className="form-control"
+ id="tag"
placeHolder="enter Tags"
/>
- press enter or comma to add new tag
+ enter space or comma to add new tag
@@ -273,48 +317,42 @@ const CreateBlog = () => {
Upload jpg, jpeg and png only*
-
- {productImages &&
- productImages.map((image, i) => (
-
-
+
- handelDelete(image)}
- fontSize="small"
- sx={{
- color: "white",
- position: "absolute",
- cursor: "pointer",
- padding: "0.2rem",
- background: "black",
- borderRadius: "50%",
- }}
- />
- {/* */}
-
- ))}
-
+ marginBottom: "1rem",
+ }}
+ />
+ {/*
handelDelete(image)}
+ fontSize="small"
+ sx={{
+ color: "white",
+ position: "absolute",
+ cursor: "pointer",
+ padding: "0.2rem",
+ background: "black",
+ borderRadius: "50%",
+ }}
+ /> */}
+ {/* */}
+
+ )}
-
*/}
diff --git a/src/views/Blog/EditBlog.jsx b/src/views/Blog/EditBlog.jsx
new file mode 100644
index 0000000..b2f6ad7
--- /dev/null
+++ b/src/views/Blog/EditBlog.jsx
@@ -0,0 +1,419 @@
+import React, { useEffect, useState } from "react";
+import Button from "@material-ui/core/Button";
+import { Link, useNavigate, useParams } from "react-router-dom";
+import swal from "sweetalert";
+import axios from "axios";
+import { isAutheticated } from "src/auth";
+import CloudUploadIcon from "@mui/icons-material/CloudUpload";
+import DeleteSharpIcon from "@mui/icons-material/DeleteSharp";
+import {
+ Box,
+ FormControl,
+ IconButton,
+ MenuItem,
+ Select,
+ TextField,
+} from "@mui/material";
+import { Editor } from "react-draft-wysiwyg";
+import { EditorState, convertFromHTML, ContentState } from "draft-js";
+import { stateToHTML } from "draft-js-export-html"; // This is for converting Draft.js content state to HTML
+import { stateFromHTML } from "draft-js-import-html"; // This is for converting HTML to Draft.js content state
+
+const UpdateBlog = () => {
+ const token = isAutheticated();
+ const navigate = useNavigate();
+
+ const [loading, setLoading] = useState(false);
+
+ const [image, setimage] = useState(null);
+ const [title, setTitle] = useState("");
+ const [tag, setTag] = useState(""); //tags array
+ const [blogContent, setBlogContent] = useState(EditorState.createEmpty());
+ const [error, setError] = useState("");
+ const [newUpdatedImages, setNewUpdatedImages] = useState(null);
+ const [Img, setImg] = useState(true);
+ const id = useParams()?.id;
+ //get Blogdata
+ const getBlog = async () => {
+ try {
+ const res = await axios.get(`/api/v1/blog/getoneblog/${id}`, {
+ headers: {
+ "Access-Control-Allow-Origin": "*",
+ Authorization: `Bearer ${token}`,
+ },
+ });
+
+ // console.log(res?.data?.blog);
+ setTitle(res?.data?.blog?.title);
+ setimage(res?.data?.blog?.image);
+ // Convert HTML content to Draft.js EditorState
+ const contentState = stateFromHTML(res?.data?.blog?.blog_content);
+ const editorState = EditorState.createWithContent(contentState);
+ setBlogContent(editorState);
+
+ setImg(false);
+
+ // Joining the tags array into a string separated by commas
+ const tagsString = res?.data?.blog?.tags.join(",");
+ setTag(tagsString);
+ } catch (err) {
+ swal({
+ title: "Error",
+ text: "Unable to fetch the blog",
+ icon: "error",
+ button: "Retry",
+ dangerMode: true,
+ });
+ }
+ };
+
+ useEffect(() => {
+ getBlog();
+ }, []);
+
+ const handleFileChange = (e) => {
+ const files = e.target.files;
+ // Reset error state
+ setError("");
+
+ // Check if more than one image is selected
+ if (files.length > 1 || Img === false || newUpdatedImages !== null) {
+ setError("You can only upload one image.");
+ return;
+ }
+
+ // Check file types and append to selectedFiles
+ const allowedTypes = ["image/jpeg", "image/png", "image/jpg"];
+ const file = files[0]; // Only one file is selected, so we get the first one
+
+ if (allowedTypes.includes(file.type)) {
+ setNewUpdatedImages(file);
+ } else {
+ setError("Please upload only PNG, JPEG, or JPG files.");
+ }
+ };
+
+ const handelDelete = async (public_id) => {
+ const ary = public_id.split("/");
+
+ const res = await axios.delete(
+ `/api/v1/blog/deleteImage/jatinMor/Blog/${ary[2]}`,
+ {
+ headers: {
+ "Access-Control-Allow-Origin": "*",
+ Authorization: `Bearer ${token}`,
+ },
+ }
+ );
+ if (res) {
+ setimage(null);
+ setImg(true);
+ }
+ };
+ const handellocalDelete = () => {
+ setNewUpdatedImages(null);
+ };
+ const handleSubmit = () => {
+ if (title === "" || blogContent === "" || tag === "") {
+ swal({
+ title: "Warning",
+ text: "Fill all mandatory fields",
+ icon: "error",
+ button: "Close",
+ dangerMode: true,
+ });
+ return;
+ }
+ setLoading(true);
+ const contentState = blogContent.getCurrentContent();
+ const htmlData = stateToHTML(contentState);
+
+ const formData = new FormData();
+ formData.append("title", title);
+ formData.append("blog_content", htmlData);
+ formData.append("tags", tag);
+
+ if (newUpdatedImages !== null) {
+ formData.append("image", newUpdatedImages);
+ }
+
+ axios
+ .patch(`/api/v1/blog/updateblog/${id}`, formData, {
+ headers: {
+ Authorization: `Bearer ${token}`,
+ "Content-Type": "multipart/form-data",
+ "Access-Control-Allow-Origin": "*",
+ },
+ })
+ .then((res) => {
+ swal({
+ title: "Updated",
+ text: "Blog Updated successfully!",
+ icon: "success",
+ button: "ok",
+ });
+ setLoading(false);
+ navigate("/blogs", { replace: true });
+ })
+ .catch((err) => {
+ setLoading(false);
+
+ const message = err.response?.data?.message
+ ? err.response?.data?.message
+ : "Something went wrong!";
+ swal({
+ title: "Warning",
+ text: message,
+ icon: "error",
+ button: "Retry",
+ dangerMode: true,
+ });
+ });
+ };
+ return (
+
+
+
+
+
+ Update Blog
+
+
+
+
+
+
+ handleSubmit()}
+ disabled={loading}
+ >
+ {loading ? "Loading" : "Save"}
+
+
+
+ Back
+
+
+
+
+
+
+
+
+
+
+
+
+ Blog Title
+
+ setTitle(e.target.value)}
+ />
+ {title ? (
+ <>
+
+ {25 - title.length} characters left
+
+ >
+ ) : (
+ <>>
+ )}{" "}
+
+
+
+
+ Tags
+
+ setTag(e.target.value)}
+ className="form-control"
+ id="tag"
+ placeHolder="enter Tags"
+ />
+
+ enter space or comma to add new tag
+
+
+
+
+ Blog Image
+
+
+
+ handleFileChange(e)}
+ />
+
+
+
+
+
+ {error &&
{error}
}
+
+
+ *You cannot upload more than 1 image
+
+
+
+
+ {Img === false && image !== null ? (
+
+
+ handelDelete(image.public_id)}
+ fontSize="small"
+ sx={{
+ color: "white",
+ position: "absolute",
+ cursor: "pointer",
+ padding: "0.2rem",
+ background: "black",
+ borderRadius: "50%",
+ }}
+ />
+
+ ) : null}
+
+ {newUpdatedImages !== null && Img && (
+
+
+ handellocalDelete()}
+ fontSize="small"
+ sx={{
+ color: "white",
+ position: "absolute",
+ cursor: "pointer",
+ padding: "0.2rem",
+ background: "black",
+ borderRadius: "50%",
+ }}
+ />
+ {/* */}
+
+ )}
+
+
+
+ {/*
*/}
+
+
+
+
+
+
+ Blog Content
+ {/* Note : style at _custom.scss */}
+ {
+ setBlogContent(editorState);
+ }}
+ />
+ {/* Log Content */}
+
+
+
+
+
+ );
+};
+
+export default UpdateBlog;
diff --git a/src/views/Blog/ViewBlog.jsx b/src/views/Blog/ViewBlog.jsx
new file mode 100644
index 0000000..5a2b6c7
--- /dev/null
+++ b/src/views/Blog/ViewBlog.jsx
@@ -0,0 +1,135 @@
+import React, { useEffect, useState } from "react";
+import Button from "@material-ui/core/Button";
+import { Link, useParams } from "react-router-dom";
+import swal from "sweetalert";
+import axios from "axios";
+import { Box } from "@mui/material";
+
+const ViewBlog = () => {
+ const [image, setImage] = useState(null);
+ const [title, setTitle] = useState("");
+ const [tag, setTag] = useState([]);
+ const [blogContent, setBlogContent] = useState(""); // Changed to string
+
+ const { id } = useParams();
+
+ const getBlog = async () => {
+ try {
+ const res = await axios.get(`/api/v1/blog/getoneblog/${id}`);
+
+ setTitle(res?.data?.blog?.title);
+ setImage(res?.data?.blog?.image);
+ setTag(res?.data?.blog?.tags);
+ // setBlogContent(res?.data?.blog?.blog_content);
+ setBlogContent(addStylesToHTML(res?.data?.blog?.blog_content));
+ } catch (err) {
+ console.error(err);
+ swal({
+ title: "Error",
+ text: "Unable to fetch the blog",
+ icon: "error",
+ button: "Retry",
+ dangerMode: true,
+ });
+ }
+ };
+ const addStylesToHTML = (content) => {
+ // Example: Add styles to
and