Merge branch 'master' of http://128.199.30.231/possibillion/smellika-admin
This commit is contained in:
commit
0f2bcb30bf
@ -46,6 +46,8 @@
|
||||
"axios": "^0.25.0",
|
||||
"bootstrap": "^5.1.3",
|
||||
"country-state-city": "^3.2.1",
|
||||
"draft-js": "^0.11.7",
|
||||
"draft-js-export-html": "^1.4.1",
|
||||
"md5": "^2.3.0",
|
||||
"moment": "^2.30.1",
|
||||
"prop-types": "^15.7.2",
|
||||
@ -54,12 +56,14 @@
|
||||
"react-bootstrap": "^2.7.0",
|
||||
"react-datepicker": "^4.8.0",
|
||||
"react-dom": "^18.0.0",
|
||||
"react-draft-wysiwyg": "^1.15.0",
|
||||
"react-hot-toast": "^2.4.0",
|
||||
"react-qr-code": "^2.0.11",
|
||||
"react-quill": "^2.0.0",
|
||||
"react-redux": "^7.2.9",
|
||||
"react-router-dom": "^6.7.0",
|
||||
"react-spinners": "^0.11.0",
|
||||
"react-tag-input-component": "^2.0.2",
|
||||
"react-to-print": "^2.14.11",
|
||||
"redux": "4.1.2",
|
||||
"serve": "^13.0.2",
|
||||
|
14
src/_nav.js
14
src/_nav.js
@ -249,6 +249,20 @@ const _nav = [
|
||||
},
|
||||
],
|
||||
},
|
||||
//Blog start
|
||||
{
|
||||
component: CNavGroup,
|
||||
name: "Blog",
|
||||
icon: <CIcon icon={cilCart} customClassName="nav-icon" />,
|
||||
items: [
|
||||
{
|
||||
component: CNavItem,
|
||||
name: "Blog",
|
||||
icon: <CIcon icon={cilNotes} customClassName="nav-icon" />,
|
||||
to: "/blogs",
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export default _nav;
|
||||
|
@ -1,5 +1,6 @@
|
||||
import "@coreui/coreui/dist/css/coreui.min.css";
|
||||
import "bootstrap/dist/css/bootstrap.min.css";
|
||||
import "react-draft-wysiwyg/dist/react-draft-wysiwyg.css";
|
||||
import "react-app-polyfill/stable";
|
||||
import "core-js";
|
||||
import React from "react";
|
||||
|
@ -115,7 +115,9 @@ import SupportReply from "./views/CustomerSupport/SupportReply";
|
||||
import SupportRequestClosed from "./views/CustomerSupport/SupportRequestClosed";
|
||||
import CloseRequestView from "./views/CustomerSupport/CloseRequestView";
|
||||
import EditTestimonial from "./views/Testimonials/EditTestimonial";
|
||||
|
||||
//Blogs
|
||||
import Blogs from "./views/Blog/Blogs";
|
||||
import CreateBlog from "./views/Blog/CreateBlog";
|
||||
const routes = [
|
||||
{ path: "/", exact: true, name: "Home" },
|
||||
{
|
||||
@ -295,26 +297,26 @@ const routes = [
|
||||
|
||||
// { path: '/complaint/view/:id', name: 'view Complain', element: ViewComplaint },
|
||||
//Complaints
|
||||
{
|
||||
{
|
||||
path: "/testimonials",
|
||||
name: "Testimonials",
|
||||
element: Testimonials
|
||||
name: "Testimonials",
|
||||
element: Testimonials,
|
||||
},
|
||||
|
||||
{
|
||||
{
|
||||
path: "/testimonial/new",
|
||||
name: "AddTestimonial",
|
||||
element: AddTestimonial
|
||||
name: "AddTestimonial",
|
||||
element: AddTestimonial,
|
||||
},
|
||||
{
|
||||
path: "/testimonial/view/:id",
|
||||
name: "ViewTestimonial",
|
||||
element: ViewTestimonial,
|
||||
},
|
||||
{
|
||||
{
|
||||
path: "/testimonial/edit/:id",
|
||||
name: "EditTestimonial",
|
||||
element: EditTestimonial
|
||||
name: "EditTestimonial",
|
||||
element: EditTestimonial,
|
||||
},
|
||||
{
|
||||
path: "/banner",
|
||||
@ -479,6 +481,17 @@ const routes = [
|
||||
name: "Edit Coupon",
|
||||
element: CouponHistory,
|
||||
},
|
||||
//Blogs Section
|
||||
{
|
||||
path: "/blogs",
|
||||
name: "Blogs",
|
||||
element: Blogs,
|
||||
},
|
||||
{
|
||||
path: "/blogs/create",
|
||||
name: "Blogs",
|
||||
element: CreateBlog,
|
||||
},
|
||||
];
|
||||
|
||||
export default routes;
|
||||
|
@ -21,3 +21,15 @@ $a-tags: "a, a:active, a:hover, a:visited";
|
||||
.past-row {
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
//blogEditor in CreateBlog.jsx
|
||||
.blog-content {
|
||||
// background-color: #f4f4f4;
|
||||
// border: 1px solid black;
|
||||
height: 20rem;
|
||||
scrollbar-width: none;
|
||||
box-shadow: rgba(0, 0, 0, 0.16) 0px 1px 4px;
|
||||
border-radius: 0px 0px 10px 10px;
|
||||
}
|
||||
.blog-toolbar {
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
|
759
src/views/Blog/Blogs.jsx
Normal file
759
src/views/Blog/Blogs.jsx
Normal file
@ -0,0 +1,759 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import Button from "@material-ui/core/Button";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import axios from "axios";
|
||||
import { isAutheticated } from "src/auth";
|
||||
import swal from "sweetalert";
|
||||
import {
|
||||
Box,
|
||||
FormControl,
|
||||
IconButton,
|
||||
InputLabel,
|
||||
MenuItem,
|
||||
Select,
|
||||
TextField,
|
||||
} from "@mui/material";
|
||||
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 [currentPage, setCurrentPage] = useState(1);
|
||||
const [itemPerPage, setItemPerPage] = useState(10);
|
||||
const [showData, setShowData] = useState(productsData);
|
||||
|
||||
const handleShowEntries = (e) => {
|
||||
setCurrentPage(1);
|
||||
setItemPerPage(e.target.value);
|
||||
};
|
||||
|
||||
const getProductsData = async () => {
|
||||
axios
|
||||
.get(`/api/product/getAll/`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
})
|
||||
.then((res) => {
|
||||
setProductsData(res.data?.product);
|
||||
setLoading(false);
|
||||
})
|
||||
.catch((error) => {
|
||||
swal({
|
||||
title: error,
|
||||
text: "please login to access the resource or refresh the page ",
|
||||
icon: "error",
|
||||
button: "Retry",
|
||||
dangerMode: true,
|
||||
});
|
||||
setLoading(false);
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getProductsData();
|
||||
}, [success]);
|
||||
|
||||
useEffect(() => {
|
||||
const loadData = () => {
|
||||
const indexOfLastPost = currentPage * itemPerPage;
|
||||
const indexOfFirstPost = indexOfLastPost - itemPerPage;
|
||||
setShowData(productsData.slice(indexOfFirstPost, indexOfLastPost));
|
||||
};
|
||||
loadData();
|
||||
}, [currentPage, itemPerPage, productsData]);
|
||||
|
||||
const handleDelete = (id) => {
|
||||
swal({
|
||||
title: "Are you sure?",
|
||||
icon: "error",
|
||||
buttons: {
|
||||
Yes: { text: "Yes", value: true },
|
||||
Cancel: { text: "Cancel", value: "cancel" },
|
||||
},
|
||||
}).then((value) => {
|
||||
if (value === true) {
|
||||
axios
|
||||
.delete(`/api/product/delete/${id}`, {
|
||||
headers: {
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
})
|
||||
.then((res) => {
|
||||
swal({
|
||||
title: "Deleted",
|
||||
text: "Product Deleted successfully!",
|
||||
icon: "success",
|
||||
button: "ok",
|
||||
});
|
||||
setSuccess((prev) => !prev);
|
||||
})
|
||||
.catch((err) => {
|
||||
swal({
|
||||
title: "Warning",
|
||||
text: "Something went wrong!",
|
||||
icon: "error",
|
||||
button: "Retry",
|
||||
dangerMode: true,
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
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
|
||||
);
|
||||
|
||||
setFilterData(filteredProducts);
|
||||
} else {
|
||||
// If no category is selected, show all products
|
||||
setShowData(productsData);
|
||||
// setFilterData(filteredProducts);
|
||||
}
|
||||
}, 100);
|
||||
}, [filterCategory, productsData]);
|
||||
return (
|
||||
<div className="main-content">
|
||||
<div className="page-content">
|
||||
<div className="container-fluid">
|
||||
<div className="row">
|
||||
<div className="col-12">
|
||||
<div
|
||||
className="
|
||||
page-title-box
|
||||
d-flex
|
||||
align-items-center
|
||||
justify-content-between
|
||||
"
|
||||
>
|
||||
<div style={{ fontSize: "22px" }} className="fw-bold">
|
||||
Blogs
|
||||
</div>
|
||||
|
||||
<div className="page-title-right">
|
||||
<Button
|
||||
variant="contained"
|
||||
color="primary"
|
||||
style={{
|
||||
fontWeight: "bold",
|
||||
marginBottom: "1rem",
|
||||
textTransform: "capitalize",
|
||||
}}
|
||||
onClick={() => {
|
||||
navigate("/blogs/create", { replace: true });
|
||||
}}
|
||||
>
|
||||
Create Blog
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="row">
|
||||
<div className="col-lg-12">
|
||||
<div className="card">
|
||||
<div className="card-body">
|
||||
<div className="row ml-0 mr-0 mb-10 ">
|
||||
<div className="col-sm-12 col-md-12">
|
||||
<div className="dataTables_length">
|
||||
<label className="w-100 d-flex gap-2 align-items-center">
|
||||
Show :
|
||||
<select
|
||||
style={{ width: "5%" }}
|
||||
name=""
|
||||
onChange={(e) => handleShowEntries(e)}
|
||||
className="
|
||||
select-w
|
||||
custom-select custom-select-sm
|
||||
form-control form-control-sm
|
||||
"
|
||||
>
|
||||
<option value="10">10</option>
|
||||
<option value="25">25</option>
|
||||
<option value="50">50</option>
|
||||
<option value="100">100</option>
|
||||
</select>
|
||||
entries
|
||||
</label>
|
||||
<div style={{ display: "flex" }}>
|
||||
<div
|
||||
style={{
|
||||
flex: "1",
|
||||
display: "flex",
|
||||
margin: "1rem 1rem 1rem 0rem",
|
||||
}}
|
||||
>
|
||||
<Typography
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
fontWeight: "bold",
|
||||
marginRight: "1rem",
|
||||
}}
|
||||
>
|
||||
Search by Blog name :
|
||||
</Typography>
|
||||
<TextField
|
||||
style={{
|
||||
background: "white",
|
||||
padding: "0.5rem",
|
||||
borderRadius: "8px",
|
||||
flex: "1",
|
||||
border: " 1px solid grey",
|
||||
marginRight: "2rem",
|
||||
height: "3rem",
|
||||
position: "relative",
|
||||
}}
|
||||
placeholder="Search here..."
|
||||
variant="standard"
|
||||
color="white"
|
||||
value={query}
|
||||
onChange={(e) => setQuery(e.target.value)}
|
||||
InputProps={{
|
||||
endAdornment: (
|
||||
<IconButton
|
||||
sx={{
|
||||
background: "white",
|
||||
color: "grey",
|
||||
// marginTop: "0.1rem",
|
||||
height: "2.9rem",
|
||||
width: "3rem",
|
||||
position: "absolute",
|
||||
right: "-8px",
|
||||
top: "-8px",
|
||||
borderRadius: "0px 8px 8px 0px",
|
||||
}}
|
||||
onClick={() => handleSearchClick(query)}
|
||||
>
|
||||
<SearchIcon fontSize="small" />
|
||||
</IconButton>
|
||||
),
|
||||
disableUnderline: true,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
flex: "1",
|
||||
display: "flex",
|
||||
margin: "1rem 0rem",
|
||||
}}
|
||||
></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="table-responsive table-shoot mt-3">
|
||||
<table
|
||||
className="table table-centered table-nowrap"
|
||||
style={{ border: "1px solid" }}
|
||||
>
|
||||
<thead
|
||||
className="thead-info"
|
||||
style={{ background: "rgb(140, 213, 213)" }}
|
||||
>
|
||||
<tr>
|
||||
<th className="text-start">Image</th>
|
||||
<th className="text-start">Title</th>
|
||||
<th className="text-start">Added On</th>
|
||||
<th className="text-start">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{!loading && showData.length === 0 && (
|
||||
<tr className="text-center">
|
||||
<td colSpan="6">
|
||||
<h5>No Data Available</h5>
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
{loading ? (
|
||||
<tr>
|
||||
<td className="text-center" colSpan="6">
|
||||
Loading...
|
||||
</td>
|
||||
</tr>
|
||||
) : query === "" && filterCategory == "" ? (
|
||||
showData.map((product, i) => {
|
||||
return (
|
||||
<tr key={i}>
|
||||
<th>
|
||||
{/* {product.image &&
|
||||
product.image.map((i, j) => (
|
||||
<img
|
||||
key={j}
|
||||
className="me-2"
|
||||
src={`${i?.url}`}
|
||||
width="40"
|
||||
alt=""
|
||||
/>
|
||||
))} */}
|
||||
{product.image && (
|
||||
<img
|
||||
key="test"
|
||||
className="me-2"
|
||||
src="https://img.freepik.com/free-photo/pink-headphones-wireless-digital-device_53876-96804.jpg"
|
||||
width="40"
|
||||
alt=""
|
||||
/>
|
||||
)}
|
||||
</th>
|
||||
{/* <td className="text-start">{product.name}</td> */}
|
||||
<td>
|
||||
The All new Samsumg s22 Ultra stormed the
|
||||
market of India
|
||||
</td>
|
||||
{/* <td className="text-start">
|
||||
{product.category?.categoryName !== ""
|
||||
? product.category?.categoryName
|
||||
: "Category Not selected "}
|
||||
</td> */}
|
||||
|
||||
<td className="text-start">
|
||||
{new Date(product.createdAt).toLocaleString(
|
||||
"en-IN",
|
||||
{
|
||||
weekday: "short",
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
year: "numeric",
|
||||
hour: "numeric",
|
||||
minute: "numeric",
|
||||
hour12: true,
|
||||
}
|
||||
)}
|
||||
</td>
|
||||
<td className="text-start">
|
||||
<Link to={`/product/view/${product._id}`}>
|
||||
<button
|
||||
style={{
|
||||
color: "white",
|
||||
marginRight: "1rem",
|
||||
}}
|
||||
type="button"
|
||||
className="
|
||||
btn btn-primary btn-sm
|
||||
waves-effect waves-light
|
||||
btn-table
|
||||
mx-1
|
||||
mt-1
|
||||
"
|
||||
>
|
||||
View
|
||||
</button>
|
||||
</Link>
|
||||
<Link to={`/product/edit/${product._id}`}>
|
||||
<button
|
||||
style={{
|
||||
color: "black",
|
||||
backgroundColor: "white",
|
||||
marginRight: "1rem",
|
||||
borderColor: "black",
|
||||
}}
|
||||
type="button"
|
||||
className="
|
||||
btn btn-info btn-sm
|
||||
waves-effect waves-light
|
||||
btn-table
|
||||
mt-1
|
||||
mx-1
|
||||
"
|
||||
>
|
||||
Edit
|
||||
</button>
|
||||
</Link>
|
||||
<Link
|
||||
to={"#"}
|
||||
style={{
|
||||
marginRight: "1rem",
|
||||
}}
|
||||
>
|
||||
<button
|
||||
style={{ color: "white" }}
|
||||
type="button"
|
||||
className="
|
||||
btn btn-danger btn-sm
|
||||
waves-effect waves-light
|
||||
btn-table
|
||||
mt-1
|
||||
mx-1
|
||||
|
||||
"
|
||||
onClick={() => {
|
||||
handleDelete(product._id);
|
||||
}}
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
</Link>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
})
|
||||
) : query !== "" ? (
|
||||
queryData.map((product, i) => {
|
||||
return (
|
||||
<tr key={i}>
|
||||
<th>
|
||||
{product.image &&
|
||||
product.image.map((i, j) => (
|
||||
<img
|
||||
key={j}
|
||||
className="me-2"
|
||||
src={`${i?.url}`}
|
||||
width="40"
|
||||
alt=""
|
||||
/>
|
||||
))}
|
||||
</th>
|
||||
<td className="text-start">{product.name}</td>
|
||||
<td className="text-start">
|
||||
{product.category !== ""
|
||||
? product.category?.categoryName
|
||||
: "Category Not selected "}
|
||||
</td>
|
||||
<th className="text-start">₹{product.price}</th>
|
||||
<td className="text-start">
|
||||
{new Date(product.createdAt).toLocaleString(
|
||||
"en-IN",
|
||||
{
|
||||
weekday: "short",
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
year: "numeric",
|
||||
hour: "numeric",
|
||||
minute: "numeric",
|
||||
hour12: true,
|
||||
}
|
||||
)}
|
||||
</td>
|
||||
<td className="text-start">
|
||||
<Link to={`/product/view/${product._id}`}>
|
||||
<button
|
||||
style={{
|
||||
color: "white",
|
||||
marginRight: "1rem",
|
||||
}}
|
||||
type="button"
|
||||
className="
|
||||
btn btn-primary btn-sm
|
||||
waves-effect waves-light
|
||||
btn-table
|
||||
mx-1
|
||||
mt-1
|
||||
"
|
||||
>
|
||||
View
|
||||
</button>
|
||||
</Link>
|
||||
<Link to={`/product/edit/${product._id}`}>
|
||||
<button
|
||||
style={{
|
||||
color: "white",
|
||||
marginRight: "1rem",
|
||||
}}
|
||||
type="button"
|
||||
className="
|
||||
btn btn-info btn-sm
|
||||
waves-effect waves-light
|
||||
btn-table
|
||||
mt-1
|
||||
mx-1
|
||||
"
|
||||
>
|
||||
Edit
|
||||
</button>
|
||||
</Link>
|
||||
<Link
|
||||
to={"#"}
|
||||
style={{
|
||||
marginRight: "1rem",
|
||||
}}
|
||||
>
|
||||
<button
|
||||
style={{ color: "white" }}
|
||||
type="button"
|
||||
className="
|
||||
btn btn-danger btn-sm
|
||||
waves-effect waves-light
|
||||
btn-table
|
||||
mt-1
|
||||
mx-1
|
||||
|
||||
"
|
||||
onClick={() => {
|
||||
handleDelete(product._id);
|
||||
}}
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
</Link>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
})
|
||||
) : (
|
||||
query == "" &&
|
||||
filterData.map((product, i) => {
|
||||
return (
|
||||
<tr key={i}>
|
||||
<th>
|
||||
{product.image &&
|
||||
product.image.map((i, j) => (
|
||||
<img
|
||||
key={j}
|
||||
className="me-2"
|
||||
src={`${i?.url}`}
|
||||
width="40"
|
||||
alt=""
|
||||
/>
|
||||
))}
|
||||
</th>
|
||||
<td className="text-start">{product.name}</td>
|
||||
<td className="text-start">
|
||||
{product.category?.categoryName}
|
||||
</td>
|
||||
<th className="text-start">₹{product.price}</th>
|
||||
<td className="text-start">
|
||||
{new Date(product.createdAt).toLocaleString(
|
||||
"en-IN",
|
||||
{
|
||||
weekday: "short",
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
year: "numeric",
|
||||
hour: "numeric",
|
||||
minute: "numeric",
|
||||
hour12: true,
|
||||
}
|
||||
)}
|
||||
</td>
|
||||
<td className="text-start">
|
||||
<Link to={`/product/view/${product._id}`}>
|
||||
<button
|
||||
style={{
|
||||
color: "white",
|
||||
marginRight: "1rem",
|
||||
}}
|
||||
type="button"
|
||||
className="
|
||||
btn btn-primary btn-sm
|
||||
waves-effect waves-light
|
||||
btn-table
|
||||
mx-1
|
||||
mt-1
|
||||
"
|
||||
>
|
||||
View
|
||||
</button>
|
||||
</Link>
|
||||
<Link to={`/product/edit/${product._id}`}>
|
||||
<button
|
||||
style={{
|
||||
color: "white",
|
||||
marginRight: "1rem",
|
||||
}}
|
||||
type="button"
|
||||
className="
|
||||
btn btn-info btn-sm
|
||||
waves-effect waves-light
|
||||
btn-table
|
||||
mt-1
|
||||
mx-1
|
||||
"
|
||||
>
|
||||
Edit
|
||||
</button>
|
||||
</Link>
|
||||
<Link
|
||||
to={"#"}
|
||||
style={{
|
||||
marginRight: "1rem",
|
||||
}}
|
||||
>
|
||||
<button
|
||||
style={{ color: "white" }}
|
||||
type="button"
|
||||
className="
|
||||
btn btn-danger btn-sm
|
||||
waves-effect waves-light
|
||||
btn-table
|
||||
mt-1
|
||||
mx-1
|
||||
|
||||
"
|
||||
onClick={() => {
|
||||
handleDelete(product._id);
|
||||
}}
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
</Link>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
})
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div className="row mt-20">
|
||||
<div className="col-sm-12 col-md-6 mb-20">
|
||||
<div
|
||||
className="dataTables_info"
|
||||
id="datatable_info"
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
>
|
||||
Showing {currentPage * itemPerPage - itemPerPage + 1} to{" "}
|
||||
{Math.min(
|
||||
currentPage * itemPerPage,
|
||||
productsData.length
|
||||
)}{" "}
|
||||
of {productsData.length} entries
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="col-sm-12 col-md-6">
|
||||
<div className="d-flex">
|
||||
<ul className="pagination ms-auto">
|
||||
<li
|
||||
className={
|
||||
currentPage === 1
|
||||
? "paginate_button page-item previous disabled"
|
||||
: "paginate_button page-item previous"
|
||||
}
|
||||
>
|
||||
<span
|
||||
className="page-link"
|
||||
style={{ cursor: "pointer" }}
|
||||
onClick={() => setCurrentPage((prev) => prev - 1)}
|
||||
>
|
||||
Previous
|
||||
</span>
|
||||
</li>
|
||||
|
||||
{!(currentPage - 1 < 1) && (
|
||||
<li className="paginate_button page-item">
|
||||
<span
|
||||
className="page-link"
|
||||
style={{ cursor: "pointer" }}
|
||||
onClick={(e) =>
|
||||
setCurrentPage((prev) => prev - 1)
|
||||
}
|
||||
>
|
||||
{currentPage - 1}
|
||||
</span>
|
||||
</li>
|
||||
)}
|
||||
|
||||
<li className="paginate_button page-item active">
|
||||
<span
|
||||
className="page-link"
|
||||
style={{ cursor: "pointer" }}
|
||||
>
|
||||
{currentPage}
|
||||
</span>
|
||||
</li>
|
||||
|
||||
{!(
|
||||
(currentPage + 1) * itemPerPage - itemPerPage >
|
||||
productsData.length - 1
|
||||
) && (
|
||||
<li className="paginate_button page-item ">
|
||||
<span
|
||||
className="page-link"
|
||||
style={{ cursor: "pointer" }}
|
||||
onClick={() => {
|
||||
setCurrentPage((prev) => prev + 1);
|
||||
}}
|
||||
>
|
||||
{currentPage + 1}
|
||||
</span>
|
||||
</li>
|
||||
)}
|
||||
|
||||
<li
|
||||
className={
|
||||
!(
|
||||
(currentPage + 1) * itemPerPage - itemPerPage >
|
||||
productsData.length - 1
|
||||
)
|
||||
? "paginate_button page-item next"
|
||||
: "paginate_button page-item next disabled"
|
||||
}
|
||||
>
|
||||
<span
|
||||
className="page-link"
|
||||
style={{ cursor: "pointer" }}
|
||||
onClick={() => setCurrentPage((prev) => prev + 1)}
|
||||
>
|
||||
Next
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Blogs;
|
344
src/views/Blog/CreateBlog.jsx
Normal file
344
src/views/Blog/CreateBlog.jsx
Normal file
@ -0,0 +1,344 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import Button from "@material-ui/core/Button";
|
||||
import { Link, useNavigate } 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 { TagsInput } from "react-tag-input-component";
|
||||
import {
|
||||
Box,
|
||||
FormControl,
|
||||
IconButton,
|
||||
MenuItem,
|
||||
Select,
|
||||
TextField,
|
||||
} from "@mui/material";
|
||||
import { Editor } from "react-draft-wysiwyg";
|
||||
import { EditorState, convertToRaw } from "draft-js";
|
||||
import { stateToHTML } from "draft-js-export-html";
|
||||
// import { WebsiteURL } from '../WebsiteURL'
|
||||
|
||||
const CreateBlog = () => {
|
||||
const token = isAutheticated();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const [imagesPreview, setImagesPreview] = useState([]);
|
||||
// const [allimage, setAllImage] = useState([]);
|
||||
const [title, setTitle] = useState("");
|
||||
const [tag, setTag] = useState([]); //tags array
|
||||
const [productImages, setProductImages] = useState([]);
|
||||
const [blogContent, setBlogContent] = useState(EditorState.createEmpty());
|
||||
// const [htmlData, setHtmlData] = useState();
|
||||
const [error, setError] = useState("");
|
||||
|
||||
const handleFileChange = (e) => {
|
||||
const files = e.target.files;
|
||||
|
||||
// Check the total number of selected files
|
||||
if (productImages.length + files.length > 4) {
|
||||
setError("You can only upload up to 4 images.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check file types and append to selectedFiles
|
||||
const allowedTypes = ["image/jpeg", "image/png", "image/jpg"];
|
||||
const selected = [];
|
||||
|
||||
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.");
|
||||
} else {
|
||||
setError("");
|
||||
setProductImages([...productImages, ...selected]);
|
||||
}
|
||||
};
|
||||
|
||||
const handelDelete = (image) => {
|
||||
const filtered = productImages.filter((item) => item !== image);
|
||||
setProductImages(filtered);
|
||||
};
|
||||
|
||||
const handleSubmit = () => {
|
||||
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);
|
||||
|
||||
// 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,
|
||||
// });
|
||||
// });
|
||||
};
|
||||
// console.log(data);
|
||||
// console.log(productImages);
|
||||
// To log the content when needed...
|
||||
|
||||
return (
|
||||
<div className="container">
|
||||
<div className="row">
|
||||
<div className="col-12">
|
||||
<div
|
||||
className="
|
||||
page-title-box
|
||||
d-flex
|
||||
align-items-center
|
||||
justify-content-between
|
||||
"
|
||||
>
|
||||
<div style={{ fontSize: "22px" }} className="fw-bold">
|
||||
Add Product
|
||||
</div>
|
||||
<div style={{ display: "flex", gap: "1rem" }}>
|
||||
<h4 className="mb-0"></h4>
|
||||
</div>
|
||||
|
||||
<div className="page-title-right">
|
||||
<Button
|
||||
variant="contained"
|
||||
color="primary"
|
||||
style={{
|
||||
fontWeight: "bold",
|
||||
marginBottom: "1rem",
|
||||
textTransform: "capitalize",
|
||||
marginRight: "5px",
|
||||
}}
|
||||
onClick={() => handleSubmit()}
|
||||
disabled={loading}
|
||||
>
|
||||
{loading ? "Loading" : "Save"}
|
||||
</Button>
|
||||
<Link to="/blogs">
|
||||
<Button
|
||||
variant="contained"
|
||||
color="secondary"
|
||||
style={{
|
||||
fontWeight: "bold",
|
||||
marginBottom: "1rem",
|
||||
textTransform: "capitalize",
|
||||
}}
|
||||
>
|
||||
Back
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="row">
|
||||
<div className="col-lg-6 col-md-6 col-sm-12 my-1">
|
||||
<div className="card h-100">
|
||||
<div className="card-body px-5">
|
||||
<div className="mb-3">
|
||||
<label htmlFor="title" className="form-label">
|
||||
Blog Title
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
className="form-control"
|
||||
id="name"
|
||||
value={title}
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
/>
|
||||
{name ? (
|
||||
<>
|
||||
<small className="charLeft mt-4 fst-italic">
|
||||
{25 - name.length} characters left
|
||||
</small>
|
||||
</>
|
||||
) : (
|
||||
<></>
|
||||
)}{" "}
|
||||
</div>
|
||||
|
||||
<div className="mb-3">
|
||||
<label>Tags</label>
|
||||
<TagsInput
|
||||
value={tag}
|
||||
onChange={setTag}
|
||||
name="Tags"
|
||||
placeHolder="enter Tags"
|
||||
/>
|
||||
<em style={{ fontSize: "0.8rem" }}>
|
||||
press enter or comma to add new tag
|
||||
</em>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="image" className="form-label">
|
||||
Blog Image
|
||||
</label>
|
||||
<Box>
|
||||
<label htmlFor="upload-Image">
|
||||
<TextField
|
||||
style={{
|
||||
display: "none",
|
||||
width: "350px",
|
||||
height: "350px",
|
||||
borderRadius: "10%",
|
||||
}}
|
||||
fullWidth
|
||||
id="upload-Image"
|
||||
type="file"
|
||||
accept=".jpg , .png ,.jpeg"
|
||||
label="file"
|
||||
variant="outlined"
|
||||
onChange={(e) => handleFileChange(e)}
|
||||
/>
|
||||
<Box
|
||||
style={{ borderRadius: "10%" }}
|
||||
sx={{
|
||||
margin: "1rem 0rem",
|
||||
cursor: "pointer",
|
||||
width: "100px",
|
||||
height: "100px",
|
||||
border: "2px solid grey",
|
||||
display: "grid",
|
||||
placeItems: "center",
|
||||
// borderRadius: '50%',
|
||||
|
||||
"&:hover": {
|
||||
background: "rgba(112,112,112,0.5)",
|
||||
},
|
||||
}}
|
||||
>
|
||||
<CloudUploadIcon
|
||||
style={{
|
||||
color: "grey",
|
||||
margin: "auto",
|
||||
fontSize: "5rem",
|
||||
}}
|
||||
fontSize="large"
|
||||
/>
|
||||
</Box>
|
||||
</label>
|
||||
</Box>
|
||||
|
||||
{error && <p style={{ color: "red" }}>{error}</p>}
|
||||
<p className="pt-1 pl-2 text-secondary">
|
||||
Upload jpg, jpeg and png only*
|
||||
</p>
|
||||
<Box style={{ display: "flex" }}>
|
||||
{productImages &&
|
||||
productImages.map((image, i) => (
|
||||
<Box marginRight={"2rem"}>
|
||||
<img
|
||||
src={URL.createObjectURL(image)}
|
||||
alt="BlogImage"
|
||||
style={{
|
||||
width: 70,
|
||||
height: 70,
|
||||
|
||||
marginBottom: "1rem",
|
||||
}}
|
||||
/>
|
||||
<DeleteSharpIcon
|
||||
onClick={() => handelDelete(image)}
|
||||
fontSize="small"
|
||||
sx={{
|
||||
color: "white",
|
||||
position: "absolute",
|
||||
cursor: "pointer",
|
||||
padding: "0.2rem",
|
||||
background: "black",
|
||||
borderRadius: "50%",
|
||||
}}
|
||||
/>
|
||||
{/* </IconButton> */}
|
||||
</Box>
|
||||
))}
|
||||
</Box>
|
||||
</div>
|
||||
|
||||
<div id="createProductFormImage" className="w-25 d-flex">
|
||||
{imagesPreview.map((image, index) => (
|
||||
<img
|
||||
className=" w-50 p-1 "
|
||||
key={index}
|
||||
src={image}
|
||||
alt="Blog Image Preview"
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-lg-6 col-md-6 col-sm-12 my-1">
|
||||
<div className="card h-100">
|
||||
<div className="card-body px-5">
|
||||
<label>Blog Content</label>
|
||||
{/* Note : style at _custom.scss */}
|
||||
<Editor
|
||||
editorState={blogContent}
|
||||
toolbarClassName="blog-toolbar"
|
||||
wrapperClassName="wrapperClassName"
|
||||
editorClassName="blog-content"
|
||||
onEditorStateChange={(editorState) => {
|
||||
setBlogContent(editorState);
|
||||
}}
|
||||
/>
|
||||
{/* <Button onClick={logContent}>Log Content</Button> */}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default CreateBlog;
|
0
src/views/Blog/test.jsx
Normal file
0
src/views/Blog/test.jsx
Normal file
@ -1,27 +1,28 @@
|
||||
import { Typography } from "@material-ui/core";
|
||||
import { Box, Button, TextField } from "@mui/material";
|
||||
import { Box, Button } from "@mui/material";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import ReactrichTextEditor from "./reactrichTextEditor";
|
||||
import ReactQuill from "react-quill";
|
||||
import "react-quill/dist/quill.snow.css";
|
||||
import axios from "axios";
|
||||
import { isAutheticated } from "src/auth";
|
||||
import { useNavigate, useNavigation } from "react-router-dom";
|
||||
|
||||
const TOOLBAR_OPTIONS = [
|
||||
[{ header: [1, 2, 3, 4, 5, 6, false] }],
|
||||
[{ font: [] }],
|
||||
[{ list: "ordered" }, { list: "bullet" }],
|
||||
["bold", "italic", "underline"],
|
||||
["bold", "italic", "underline", "strike"],
|
||||
[{ color: [] }, { background: [] }],
|
||||
[{ align: [] }],
|
||||
[{ script: "super" }, { script: "sub" }],
|
||||
["undo", "redo"],
|
||||
];
|
||||
|
||||
export default function EditPrivacyPolicy() {
|
||||
const [title, setTitle] = useState("Privacy Policy");
|
||||
const [content, setContent] = useState("");
|
||||
const [added, setAdded] = useState(false);
|
||||
const [olderContent, setOlderContent] = useState("");
|
||||
const navigation = useNavigate();
|
||||
const [id, setId] = useState(null);
|
||||
|
||||
const token = isAutheticated();
|
||||
const handleContentChange = (content, delta, source, editor) => {
|
||||
@ -37,6 +38,7 @@ export default function EditPrivacyPolicy() {
|
||||
// console.log(response);
|
||||
|
||||
setContent(response?.data?.privacyAndPolicy[0]?.privacyAndPolicyContent);
|
||||
setId(response?.data?.privacyAndPolicy[0]?._id);
|
||||
setOlderContent(
|
||||
response?.data?.privacyAndPolicy[0]?.privacyAndPolicyContent
|
||||
);
|
||||
@ -70,15 +72,17 @@ export default function EditPrivacyPolicy() {
|
||||
"/api/content/privacy-and-policy-update",
|
||||
{ content },
|
||||
{
|
||||
params: { id: id },
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
|
||||
);
|
||||
if (response.status === 200) {
|
||||
swal({
|
||||
title: "Congratulations!!",
|
||||
text: "Terms and condition updated successfully!",
|
||||
title: "Congratulations!",
|
||||
text: "Privacy policy updated successfully!",
|
||||
icon: "success",
|
||||
button: "OK",
|
||||
});
|
||||
@ -93,16 +97,15 @@ export default function EditPrivacyPolicy() {
|
||||
}
|
||||
};
|
||||
const handleSaveClick = async () => {
|
||||
if (olderContent === undefined) {
|
||||
if (olderContent.length===0) {
|
||||
await addPrivacyPolicy();
|
||||
setAdded(true);
|
||||
} else {
|
||||
await updateContent();
|
||||
setAdded(false);
|
||||
await updateContent();
|
||||
}
|
||||
|
||||
// Reload terms and conditions
|
||||
await getPrivacyPolicy();
|
||||
// // Reload terms and conditions
|
||||
// await getPrivacyPolicy();
|
||||
};
|
||||
useEffect(() => {
|
||||
// addTermsandConditions();
|
||||
|
@ -12,16 +12,20 @@ const TOOLBAR_OPTIONS = [
|
||||
[{ header: [1, 2, 3, 4, 5, 6, false] }],
|
||||
[{ font: [] }],
|
||||
[{ list: "ordered" }, { list: "bullet" }],
|
||||
["bold", "italic", "underline"],
|
||||
["bold", "italic", "underline", "strike"],
|
||||
[{ color: [] }, { background: [] }],
|
||||
[{ align: [] }],
|
||||
[{ script: "super" }, { script: "sub" }],
|
||||
["undo", "redo"],
|
||||
];
|
||||
|
||||
export default function editRefundPolicy() {
|
||||
const [title, setTitle] = useState("Refund policy");
|
||||
const [content, setContent] = useState("");
|
||||
const [added, setAdded] = useState(false);
|
||||
const [olderContent, setOlderContent] = useState("");
|
||||
const navigation = useNavigate();
|
||||
const [id, setId] = useState(null)
|
||||
|
||||
|
||||
const token = isAutheticated();
|
||||
const handleContentChange = (content, delta, source, editor) => {
|
||||
@ -37,6 +41,7 @@ export default function editRefundPolicy() {
|
||||
// console.log(response);
|
||||
setContent(response?.data?.Refundpolicys[0]?.Refundpolicy);
|
||||
setOlderContent(response?.data?.Refundpolicys[0]?.Refundpolicy);
|
||||
setId(response?.data?.Refundpolicys[0]?._id);
|
||||
}
|
||||
};
|
||||
|
||||
@ -64,13 +69,15 @@ export default function editRefundPolicy() {
|
||||
};
|
||||
const updateContent = async () => {
|
||||
const response = await axios.patch(
|
||||
"/api/content//refund-policy",
|
||||
"/api/content/refund-policy-update",
|
||||
{ content },
|
||||
{
|
||||
params: { id: id },
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
|
||||
);
|
||||
if (response.status === 200) {
|
||||
swal({
|
||||
@ -90,7 +97,7 @@ export default function editRefundPolicy() {
|
||||
}
|
||||
};
|
||||
const handleSaveClick = async () => {
|
||||
if (olderContent === undefined) {
|
||||
if (olderContent.length===0) {
|
||||
await addTermsandConditions();
|
||||
setAdded(true);
|
||||
} else {
|
||||
@ -99,7 +106,7 @@ export default function editRefundPolicy() {
|
||||
}
|
||||
|
||||
// Reload terms and conditions
|
||||
await getTermsAndConditions();
|
||||
// await getTermsAndConditions();
|
||||
};
|
||||
useEffect(() => {
|
||||
// addTermsandConditions();
|
||||
|
@ -12,16 +12,20 @@ const TOOLBAR_OPTIONS = [
|
||||
[{ header: [1, 2, 3, 4, 5, 6, false] }],
|
||||
[{ font: [] }],
|
||||
[{ list: "ordered" }, { list: "bullet" }],
|
||||
["bold", "italic", "underline"],
|
||||
["bold", "italic", "underline", "strike"],
|
||||
[{ color: [] }, { background: [] }],
|
||||
[{ align: [] }],
|
||||
[{ script: "super" }, { script: "sub" }],
|
||||
["undo", "redo"],
|
||||
];
|
||||
|
||||
export default function EditShippingPolicy() {
|
||||
const [title, setTitle] = useState("Shipping Policy");
|
||||
const [content, setContent] = useState("");
|
||||
const [added, setAdded] = useState(false);
|
||||
const [olderContent, setOlderContent] = useState("");
|
||||
const navigation = useNavigate();
|
||||
const [id, setId] = useState(null)
|
||||
|
||||
|
||||
const token = isAutheticated();
|
||||
const handleContentChange = (content, delta, source, editor) => {
|
||||
@ -38,6 +42,7 @@ export default function EditShippingPolicy() {
|
||||
|
||||
setContent(response?.data?.shipping[0]?.shippingContent);
|
||||
setOlderContent(response?.data?.shipping[0]?.shippingContent);
|
||||
setId(response?.data?.shipping[0]?._id);
|
||||
}
|
||||
};
|
||||
|
||||
@ -68,6 +73,7 @@ export default function EditShippingPolicy() {
|
||||
"/api/content/shipping-and-policy-update",
|
||||
{ content },
|
||||
{
|
||||
params: { id: id },
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
@ -76,7 +82,7 @@ export default function EditShippingPolicy() {
|
||||
if (response.status === 200) {
|
||||
swal({
|
||||
title: "Congratulations!!",
|
||||
text: "Terms and condition updated successfully!",
|
||||
text: "Shipping Policy updated successfully!",
|
||||
icon: "success",
|
||||
button: "OK",
|
||||
});
|
||||
@ -91,7 +97,7 @@ export default function EditShippingPolicy() {
|
||||
}
|
||||
};
|
||||
const handleSaveClick = async () => {
|
||||
if (olderContent === undefined) {
|
||||
if (olderContent.length===0) {
|
||||
await addShipping();
|
||||
setAdded(true);
|
||||
} else {
|
||||
@ -100,7 +106,7 @@ export default function EditShippingPolicy() {
|
||||
}
|
||||
|
||||
// Reload terms and conditions
|
||||
await getShipping();
|
||||
// await getShipping();
|
||||
};
|
||||
useEffect(() => {
|
||||
// addTermsandConditions();
|
||||
|
@ -12,16 +12,20 @@ const TOOLBAR_OPTIONS = [
|
||||
[{ header: [1, 2, 3, 4, 5, 6, false] }],
|
||||
[{ font: [] }],
|
||||
[{ list: "ordered" }, { list: "bullet" }],
|
||||
["bold", "italic", "underline"],
|
||||
["bold", "italic", "underline", "strike"],
|
||||
[{ color: [] }, { background: [] }],
|
||||
[{ align: [] }],
|
||||
[{ script: "super" }, { script: "sub" }],
|
||||
["undo", "redo"],
|
||||
];
|
||||
|
||||
export default function EditTermsConditions() {
|
||||
const [title, setTitle] = useState("Terms and conditions");
|
||||
const [content, setContent] = useState("");
|
||||
const [added, setAdded] = useState(false);
|
||||
const [olderContent, setOlderContent] = useState("");
|
||||
const navigation = useNavigate();
|
||||
const [id, setId] = useState(null)
|
||||
|
||||
|
||||
const token = isAutheticated();
|
||||
const handleContentChange = (content, delta, source, editor) => {
|
||||
@ -39,6 +43,9 @@ export default function EditTermsConditions() {
|
||||
setOlderContent(
|
||||
response?.data?.termsAndCondition[0]?.termsAndContionContent
|
||||
);
|
||||
setId(
|
||||
response?.data?.termsAndCondition[0]?._id
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@ -69,6 +76,7 @@ export default function EditTermsConditions() {
|
||||
"/api/content/terms-and-condition-update",
|
||||
{ content },
|
||||
{
|
||||
params: { id: id },
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
@ -92,7 +100,7 @@ export default function EditTermsConditions() {
|
||||
}
|
||||
};
|
||||
const handleSaveClick = async () => {
|
||||
if (olderContent === undefined) {
|
||||
if (olderContent.length===0) {
|
||||
await addTermsandConditions();
|
||||
setAdded(true);
|
||||
} else {
|
||||
@ -101,7 +109,7 @@ export default function EditTermsConditions() {
|
||||
}
|
||||
|
||||
// Reload terms and conditions
|
||||
await getTermsAndConditions();
|
||||
// await getTermsAndConditions();
|
||||
};
|
||||
useEffect(() => {
|
||||
// addTermsandConditions();
|
||||
|
Loading…
Reference in New Issue
Block a user