import { Typography } from "@material-ui/core"; import { Box, Button, TextField } 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 { Link, 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", "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 [id, setId] = useState(null); const token = isAutheticated(); const handleContentChange = (content, delta, source, editor) => { setContent(editor.getHTML()); }; const getTermsAndConditions = async () => { const response = await axios.get("/api/content/refund-policy", { headers: { Authorization: `Bearer ${token}`, }, }); if (response.status === 200) { // console.log(response); setContent(response?.data?.Refundpolicys[0]?.Refundpolicy); setOlderContent(response?.data?.Refundpolicys[0]?.Refundpolicy); setId(response?.data?.Refundpolicys[0]?._id); } }; const addTermsandConditions = async () => { const response = await axios.post( "/api/content/refund-policy", { content }, { headers: { Authorization: `Bearer ${token}`, }, } ); if (response.status == 201) { swal({ title: "Congratulations!!", text: "Refund policy added successfully!", icon: "success", button: "OK", }); } }; const handleCancelClick = () => { setContent(olderContent); }; const updateContent = async () => { const response = await axios.patch( "/api/content/refund-policy-update", { content }, { params: { id: id }, headers: { Authorization: `Bearer ${token}`, }, } ); if (response.status === 200) { swal({ title: "Congratulations!!", text: "Refund policy updated successfully!", icon: "success", button: "OK", }); } else { swal({ title: "Sorry, please try again", text: "Something went wrong!", icon: "error", button: "Retry", dangerMode: true, }); } }; const handleSaveClick = async () => { if (olderContent === undefined || olderContent === "") { await addTermsandConditions(); setAdded(true); } else { await updateContent(); setAdded(false); } // Reload terms and conditions // await getTermsAndConditions(); }; useEffect(() => { // addTermsandConditions(); getTermsAndConditions(); }, [added]); return (
{/* setTitle(e.target.value)} variant="outlined" size="small" fullWidth /> */} {" "} Refund policy:{" "} Body
); }