fixed content text editor

This commit is contained in:
syedmujahidahmed 2024-03-28 12:44:18 +05:30
parent a88dae7cb2
commit dcc2256b76
4 changed files with 50 additions and 26 deletions

View File

@ -1,27 +1,28 @@
import { Typography } from "@material-ui/core"; 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 React, { useEffect, useState } from "react";
import ReactrichTextEditor from "./reactrichTextEditor";
import ReactQuill from "react-quill"; import ReactQuill from "react-quill";
import "react-quill/dist/quill.snow.css"; import "react-quill/dist/quill.snow.css";
import axios from "axios"; import axios from "axios";
import { isAutheticated } from "src/auth"; import { isAutheticated } from "src/auth";
import { useNavigate, useNavigation } from "react-router-dom";
const TOOLBAR_OPTIONS = [ const TOOLBAR_OPTIONS = [
[{ header: [1, 2, 3, 4, 5, 6, false] }], [{ header: [1, 2, 3, 4, 5, 6, false] }],
[{ font: [] }], [{ font: [] }],
[{ list: "ordered" }, { list: "bullet" }], [{ list: "ordered" }, { list: "bullet" }],
["bold", "italic", "underline"], ["bold", "italic", "underline", "strike"],
[{ color: [] }, { background: [] }], [{ color: [] }, { background: [] }],
[{ align: [] }], [{ align: [] }],
[{ script: "super" }, { script: "sub" }],
["undo", "redo"],
]; ];
export default function EditPrivacyPolicy() { export default function EditPrivacyPolicy() {
const [title, setTitle] = useState("Privacy Policy"); const [title, setTitle] = useState("Privacy Policy");
const [content, setContent] = useState(""); const [content, setContent] = useState("");
const [added, setAdded] = useState(false); const [added, setAdded] = useState(false);
const [olderContent, setOlderContent] = useState(""); const [olderContent, setOlderContent] = useState("");
const navigation = useNavigate(); const [id, setId] = useState(null);
const token = isAutheticated(); const token = isAutheticated();
const handleContentChange = (content, delta, source, editor) => { const handleContentChange = (content, delta, source, editor) => {
@ -37,6 +38,7 @@ export default function EditPrivacyPolicy() {
// console.log(response); // console.log(response);
setContent(response?.data?.privacyAndPolicy[0]?.privacyAndPolicyContent); setContent(response?.data?.privacyAndPolicy[0]?.privacyAndPolicyContent);
setId(response?.data?.privacyAndPolicy[0]?._id);
setOlderContent( setOlderContent(
response?.data?.privacyAndPolicy[0]?.privacyAndPolicyContent response?.data?.privacyAndPolicy[0]?.privacyAndPolicyContent
); );
@ -70,15 +72,17 @@ export default function EditPrivacyPolicy() {
"/api/content/privacy-and-policy-update", "/api/content/privacy-and-policy-update",
{ content }, { content },
{ {
params: { id: id },
headers: { headers: {
Authorization: `Bearer ${token}`, Authorization: `Bearer ${token}`,
}, },
} }
); );
if (response.status === 200) { if (response.status === 200) {
swal({ swal({
title: "Congratulations!!", title: "Congratulations!",
text: "Terms and condition updated successfully!", text: "Privacy policy updated successfully!",
icon: "success", icon: "success",
button: "OK", button: "OK",
}); });
@ -93,16 +97,15 @@ export default function EditPrivacyPolicy() {
} }
}; };
const handleSaveClick = async () => { const handleSaveClick = async () => {
if (olderContent === undefined) { if (olderContent.length===0) {
await addPrivacyPolicy(); await addPrivacyPolicy();
setAdded(true); setAdded(true);
} else { } else {
await updateContent();
setAdded(false); setAdded(false);
await updateContent();
} }
// // Reload terms and conditions
// Reload terms and conditions // await getPrivacyPolicy();
await getPrivacyPolicy();
}; };
useEffect(() => { useEffect(() => {
// addTermsandConditions(); // addTermsandConditions();

View File

@ -12,16 +12,20 @@ const TOOLBAR_OPTIONS = [
[{ header: [1, 2, 3, 4, 5, 6, false] }], [{ header: [1, 2, 3, 4, 5, 6, false] }],
[{ font: [] }], [{ font: [] }],
[{ list: "ordered" }, { list: "bullet" }], [{ list: "ordered" }, { list: "bullet" }],
["bold", "italic", "underline"], ["bold", "italic", "underline", "strike"],
[{ color: [] }, { background: [] }], [{ color: [] }, { background: [] }],
[{ align: [] }], [{ align: [] }],
[{ script: "super" }, { script: "sub" }],
["undo", "redo"],
]; ];
export default function editRefundPolicy() { export default function editRefundPolicy() {
const [title, setTitle] = useState("Refund policy"); const [title, setTitle] = useState("Refund policy");
const [content, setContent] = useState(""); const [content, setContent] = useState("");
const [added, setAdded] = useState(false); const [added, setAdded] = useState(false);
const [olderContent, setOlderContent] = useState(""); const [olderContent, setOlderContent] = useState("");
const navigation = useNavigate(); const [id, setId] = useState(null)
const token = isAutheticated(); const token = isAutheticated();
const handleContentChange = (content, delta, source, editor) => { const handleContentChange = (content, delta, source, editor) => {
@ -37,6 +41,7 @@ export default function editRefundPolicy() {
// console.log(response); // console.log(response);
setContent(response?.data?.Refundpolicys[0]?.Refundpolicy); setContent(response?.data?.Refundpolicys[0]?.Refundpolicy);
setOlderContent(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 updateContent = async () => {
const response = await axios.patch( const response = await axios.patch(
"/api/content//refund-policy", "/api/content/refund-policy-update",
{ content }, { content },
{ {
params: { id: id },
headers: { headers: {
Authorization: `Bearer ${token}`, Authorization: `Bearer ${token}`,
}, },
} }
); );
if (response.status === 200) { if (response.status === 200) {
swal({ swal({
@ -90,7 +97,7 @@ export default function editRefundPolicy() {
} }
}; };
const handleSaveClick = async () => { const handleSaveClick = async () => {
if (olderContent === undefined) { if (olderContent.length===0) {
await addTermsandConditions(); await addTermsandConditions();
setAdded(true); setAdded(true);
} else { } else {
@ -99,7 +106,7 @@ export default function editRefundPolicy() {
} }
// Reload terms and conditions // Reload terms and conditions
await getTermsAndConditions(); // await getTermsAndConditions();
}; };
useEffect(() => { useEffect(() => {
// addTermsandConditions(); // addTermsandConditions();

View File

@ -12,16 +12,20 @@ const TOOLBAR_OPTIONS = [
[{ header: [1, 2, 3, 4, 5, 6, false] }], [{ header: [1, 2, 3, 4, 5, 6, false] }],
[{ font: [] }], [{ font: [] }],
[{ list: "ordered" }, { list: "bullet" }], [{ list: "ordered" }, { list: "bullet" }],
["bold", "italic", "underline"], ["bold", "italic", "underline", "strike"],
[{ color: [] }, { background: [] }], [{ color: [] }, { background: [] }],
[{ align: [] }], [{ align: [] }],
[{ script: "super" }, { script: "sub" }],
["undo", "redo"],
]; ];
export default function EditShippingPolicy() { export default function EditShippingPolicy() {
const [title, setTitle] = useState("Shipping Policy"); const [title, setTitle] = useState("Shipping Policy");
const [content, setContent] = useState(""); const [content, setContent] = useState("");
const [added, setAdded] = useState(false); const [added, setAdded] = useState(false);
const [olderContent, setOlderContent] = useState(""); const [olderContent, setOlderContent] = useState("");
const navigation = useNavigate(); const [id, setId] = useState(null)
const token = isAutheticated(); const token = isAutheticated();
const handleContentChange = (content, delta, source, editor) => { const handleContentChange = (content, delta, source, editor) => {
@ -38,6 +42,7 @@ export default function EditShippingPolicy() {
setContent(response?.data?.shipping[0]?.shippingContent); setContent(response?.data?.shipping[0]?.shippingContent);
setOlderContent(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", "/api/content/shipping-and-policy-update",
{ content }, { content },
{ {
params: { id: id },
headers: { headers: {
Authorization: `Bearer ${token}`, Authorization: `Bearer ${token}`,
}, },
@ -76,7 +82,7 @@ export default function EditShippingPolicy() {
if (response.status === 200) { if (response.status === 200) {
swal({ swal({
title: "Congratulations!!", title: "Congratulations!!",
text: "Terms and condition updated successfully!", text: "Shipping Policy updated successfully!",
icon: "success", icon: "success",
button: "OK", button: "OK",
}); });
@ -91,7 +97,7 @@ export default function EditShippingPolicy() {
} }
}; };
const handleSaveClick = async () => { const handleSaveClick = async () => {
if (olderContent === undefined) { if (olderContent.length===0) {
await addShipping(); await addShipping();
setAdded(true); setAdded(true);
} else { } else {
@ -100,7 +106,7 @@ export default function EditShippingPolicy() {
} }
// Reload terms and conditions // Reload terms and conditions
await getShipping(); // await getShipping();
}; };
useEffect(() => { useEffect(() => {
// addTermsandConditions(); // addTermsandConditions();

View File

@ -12,16 +12,20 @@ const TOOLBAR_OPTIONS = [
[{ header: [1, 2, 3, 4, 5, 6, false] }], [{ header: [1, 2, 3, 4, 5, 6, false] }],
[{ font: [] }], [{ font: [] }],
[{ list: "ordered" }, { list: "bullet" }], [{ list: "ordered" }, { list: "bullet" }],
["bold", "italic", "underline"], ["bold", "italic", "underline", "strike"],
[{ color: [] }, { background: [] }], [{ color: [] }, { background: [] }],
[{ align: [] }], [{ align: [] }],
[{ script: "super" }, { script: "sub" }],
["undo", "redo"],
]; ];
export default function EditTermsConditions() { export default function EditTermsConditions() {
const [title, setTitle] = useState("Terms and conditions"); const [title, setTitle] = useState("Terms and conditions");
const [content, setContent] = useState(""); const [content, setContent] = useState("");
const [added, setAdded] = useState(false); const [added, setAdded] = useState(false);
const [olderContent, setOlderContent] = useState(""); const [olderContent, setOlderContent] = useState("");
const navigation = useNavigate(); const [id, setId] = useState(null)
const token = isAutheticated(); const token = isAutheticated();
const handleContentChange = (content, delta, source, editor) => { const handleContentChange = (content, delta, source, editor) => {
@ -39,6 +43,9 @@ export default function EditTermsConditions() {
setOlderContent( setOlderContent(
response?.data?.termsAndCondition[0]?.termsAndContionContent 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", "/api/content/terms-and-condition-update",
{ content }, { content },
{ {
params: { id: id },
headers: { headers: {
Authorization: `Bearer ${token}`, Authorization: `Bearer ${token}`,
}, },
@ -92,7 +100,7 @@ export default function EditTermsConditions() {
} }
}; };
const handleSaveClick = async () => { const handleSaveClick = async () => {
if (olderContent === undefined) { if (olderContent.length===0) {
await addTermsandConditions(); await addTermsandConditions();
setAdded(true); setAdded(true);
} else { } else {
@ -101,7 +109,7 @@ export default function EditTermsConditions() {
} }
// Reload terms and conditions // Reload terms and conditions
await getTermsAndConditions(); // await getTermsAndConditions();
}; };
useEffect(() => { useEffect(() => {
// addTermsandConditions(); // addTermsandConditions();