238 lines
6.9 KiB
TypeScript
238 lines
6.9 KiB
TypeScript
"use client";
|
||
import React, { useState, useRef, useEffect } from "react";
|
||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||
import ReactQuill from "react-quill";
|
||
import "react-quill/dist/quill.snow.css";
|
||
import { Button } from "./ui/button";
|
||
import { SubmitWebContents } from "@/utils/adminApi";
|
||
import { toast } from "sonner";
|
||
|
||
export default function AdminWebContents() {
|
||
const [contentValueCull, setContentValueCull] = useState("");
|
||
const [contentValueAbout, setContentValueAbout] = useState("");
|
||
const [contentValueAfter, setContentValueAfter] = useState("");
|
||
const [contentValueBefore, setContentValueBefore] = useState("");
|
||
const [contentTitle, setContentTitle] = useState("");
|
||
const [contentDesc, setContentDesc] = useState("");
|
||
// console.log(value);
|
||
var toolbarOptions = [
|
||
["bold", "italic", "underline", "strike"], // toggled buttons
|
||
["blockquote", "code-block"],
|
||
|
||
[{ header: 1 }, { header: 2 }], // custom button values
|
||
[{ list: "ordered" }, { list: "bullet" }],
|
||
[{ script: "sub" }, { script: "super" }], // superscript/subscript
|
||
[{ indent: "-1" }, { indent: "+1" }], // outdent/indent
|
||
[{ direction: "rtl" }], // text direction
|
||
|
||
[{ size: ["small", false, "large", "huge"] }], // custom dropdown
|
||
[{ header: [1, 2, 3, 4, 5, 6, false] }],
|
||
|
||
[{ color: [] }, { background: [] }], // dropdown with defaults from theme
|
||
[{ font: [] }],
|
||
[{ align: [] }],
|
||
|
||
["link", "image", "video"],
|
||
|
||
["clean"], // remove formatting button
|
||
];
|
||
|
||
const modules = {
|
||
toolbar: toolbarOptions,
|
||
// clipboard: {
|
||
// // toggle to add extra line breaks when pasting HTML:
|
||
// matchVisual: false,
|
||
// },
|
||
};
|
||
// Define custom styles for the ReactQuill editor
|
||
const editorStyles: React.CSSProperties = {
|
||
height: "12em",
|
||
border: "1px solid #ccc",
|
||
borderRadius: "5px",
|
||
direction: "ltr",
|
||
};
|
||
|
||
// Add
|
||
// ............'Mutation' Change Key Submit
|
||
const AddWebContents = useMutation({
|
||
mutationKey: ["AddWebContents"],
|
||
mutationFn: SubmitWebContents,
|
||
onSuccess: (res) => {
|
||
console.log(res);
|
||
console.log("Success ChangeCat");
|
||
|
||
setContentValueCull("");
|
||
setContentValueAbout("");
|
||
setContentValueAfter("");
|
||
setContentValueBefore("");
|
||
|
||
toast("عملیات شما با موفقیت انجام شد. ", {
|
||
className: "!bg-green-500 !text-white",
|
||
});
|
||
},
|
||
onError: (error) => {
|
||
console.log(error);
|
||
console.log(error?.message);
|
||
|
||
toast(error?.message, {
|
||
className: "!bg-red-500 !text-black",
|
||
});
|
||
},
|
||
});
|
||
|
||
// function onSubmitAdd(data: typeof contentValue) {
|
||
function onSubmitAddCallUs() {
|
||
const formData = new FormData();
|
||
// formData.append("title", contentTitle);
|
||
// formData.append("description", contentDesc);
|
||
|
||
formData.append("title", "Test2");
|
||
formData.append("description", "Test2....");
|
||
formData.append("Content", contentValueCull);
|
||
|
||
AddWebContents.mutate(formData);
|
||
console.log(contentValueCull);
|
||
// console.log(contentTitle);
|
||
// console.log(contentDesc);
|
||
}
|
||
|
||
// AboutUs
|
||
function onSubmitAddAboutUs() {
|
||
const formData = new FormData();
|
||
formData.append("title", "AboutUs");
|
||
formData.append("description", "AboutUs....");
|
||
formData.append("Content", contentValueAbout);
|
||
|
||
AddWebContents.mutate(formData);
|
||
console.log(contentValueAbout);
|
||
}
|
||
|
||
// AboutUs
|
||
function onSubmitAddَAfterText() {
|
||
const formData = new FormData();
|
||
formData.append("title", "AfterRegistration");
|
||
formData.append("description", "AfterRegistration....");
|
||
formData.append("Content", contentValueAfter);
|
||
|
||
AddWebContents.mutate(formData);
|
||
console.log(contentValueAfter);
|
||
}
|
||
|
||
// AboutUs
|
||
function onSubmitAddBeforeText() {
|
||
const formData = new FormData();
|
||
formData.append("title", "BeforeRegistration");
|
||
formData.append("description", "BeforeRegistration....");
|
||
formData.append("Content", contentValueBefore);
|
||
|
||
AddWebContents.mutate(formData);
|
||
console.log(contentValueBefore);
|
||
}
|
||
|
||
|
||
return (
|
||
<div className="w-full min-h-[85vh] flex justify-center">
|
||
<div className="w-[95vw] lg:w-[85vw] 3xl:w-[70vw] mt-8 max-sm:mt-16 pt-9 ">
|
||
{/* Cull Us */}
|
||
<div className="w-full flex flex-col">
|
||
<div className=" text-right text-neutral-600 text-base font-bold my-4">
|
||
محتوای تماس با ما
|
||
</div>
|
||
|
||
<ReactQuill
|
||
modules={modules}
|
||
theme="snow"
|
||
value={contentValueCull}
|
||
onChange={setContentValueCull}
|
||
style={editorStyles}
|
||
/>
|
||
<Button
|
||
type="submit"
|
||
onClick={() => {
|
||
onSubmitAddCallUs();
|
||
// setContentTitle("Test");
|
||
// setContentDesc("Test....");
|
||
}}
|
||
className="w-1/6 self-end my-2"
|
||
>
|
||
ثبت
|
||
</Button>
|
||
</div>
|
||
|
||
{/* About Us */}
|
||
<div className="w-full flex flex-col">
|
||
<div className=" text-right text-neutral-600 text-base font-bold my-4">
|
||
محتوای درباره ما
|
||
</div>
|
||
|
||
<ReactQuill
|
||
modules={modules}
|
||
theme="snow"
|
||
value={contentValueAbout}
|
||
onChange={setContentValueAbout}
|
||
style={editorStyles}
|
||
/>
|
||
<Button
|
||
type="submit"
|
||
onClick={() => {
|
||
onSubmitAddAboutUs();
|
||
}}
|
||
className="w-1/6 self-end my-2"
|
||
>
|
||
ثبت
|
||
</Button>
|
||
</div>
|
||
|
||
{/* AfterRegistration */}
|
||
<div className="w-full flex flex-col">
|
||
<div className=" text-right text-neutral-600 text-base font-bold my-4">
|
||
محتوای بعد از ثبت گزارش
|
||
</div>
|
||
|
||
<ReactQuill
|
||
modules={modules}
|
||
theme="snow"
|
||
value={contentValueAfter}
|
||
onChange={setContentValueAfter}
|
||
style={editorStyles}
|
||
/>
|
||
<Button
|
||
type="submit"
|
||
onClick={() => {
|
||
onSubmitAddَAfterText();
|
||
}}
|
||
className="w-1/6 self-end my-2"
|
||
>
|
||
ثبت
|
||
</Button>
|
||
</div>
|
||
|
||
{/* BeforeRegistration*/}
|
||
<div className="w-full flex flex-col">
|
||
<div className=" text-right text-neutral-600 text-base font-bold my-4">
|
||
محتوای قبل از ثبت گزارش
|
||
</div>
|
||
|
||
<ReactQuill
|
||
modules={modules}
|
||
theme="snow"
|
||
value={contentValueBefore}
|
||
onChange={setContentValueBefore}
|
||
style={editorStyles}
|
||
/>
|
||
<Button
|
||
type="submit"
|
||
onClick={() => {
|
||
onSubmitAddBeforeText();
|
||
}}
|
||
className="w-1/6 self-end my-2"
|
||
>
|
||
ثبت
|
||
</Button>
|
||
</div>
|
||
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|