2023-09-11 06:54:46 +00:00
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
|
|
|
|
// next
|
|
|
|
import type { NextPage } from "next";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
|
|
|
// cookies
|
|
|
|
import Cookies from "js-cookie";
|
|
|
|
|
|
|
|
// react-hook-form
|
|
|
|
import { Controller, useForm } from "react-hook-form";
|
|
|
|
|
|
|
|
// layouts
|
|
|
|
import WebViewLayout from "layouts/web-view-layout";
|
|
|
|
|
|
|
|
// components
|
2023-10-13 06:35:49 +00:00
|
|
|
import { RichTextEditor } from "@plane/rich-text-editor";
|
|
|
|
import { PrimaryButton, Spinner } from "components/ui";
|
|
|
|
import fileService from "services/file.service";
|
|
|
|
// services
|
2023-09-11 06:54:46 +00:00
|
|
|
|
|
|
|
const Editor: NextPage = () => {
|
|
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug, editable } = router.query;
|
|
|
|
|
|
|
|
const isEditable = editable === "true";
|
|
|
|
|
2023-09-11 07:51:50 +00:00
|
|
|
const { watch, setValue, control } = useForm({
|
2023-09-11 06:54:46 +00:00
|
|
|
defaultValues: {
|
|
|
|
data: "",
|
|
|
|
data_html: "",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
setIsLoading(true);
|
2023-09-11 07:51:50 +00:00
|
|
|
if (!router?.query?.["editable"]) return;
|
2023-09-11 06:54:46 +00:00
|
|
|
setIsLoading(false);
|
|
|
|
const data_html = Cookies.get("data_html");
|
|
|
|
setValue("data_html", data_html ?? "");
|
2023-09-11 07:51:50 +00:00
|
|
|
}, [isEditable, setValue, router]);
|
2023-09-11 06:54:46 +00:00
|
|
|
|
|
|
|
return (
|
2023-10-12 06:58:36 +00:00
|
|
|
<WebViewLayout fullScreen>
|
2023-09-11 06:54:46 +00:00
|
|
|
{isLoading ? (
|
|
|
|
<div className="w-full h-full flex items-center justify-center">
|
|
|
|
<Spinner />
|
|
|
|
</div>
|
|
|
|
) : (
|
2023-10-12 06:58:36 +00:00
|
|
|
<div className="w-full h-full flex flex-col justify-between">
|
2023-09-11 06:54:46 +00:00
|
|
|
<Controller
|
|
|
|
name="data_html"
|
|
|
|
control={control}
|
|
|
|
render={({ field: { value, onChange } }) => (
|
2023-10-13 06:35:49 +00:00
|
|
|
<RichTextEditor
|
|
|
|
uploadFile={fileService.getUploadFileFunction(workspaceSlug as string)}
|
|
|
|
deleteFile={fileService.deleteImage}
|
2023-09-11 06:54:46 +00:00
|
|
|
borderOnFocus={false}
|
|
|
|
value={
|
|
|
|
!value ||
|
|
|
|
value === "" ||
|
|
|
|
(typeof value === "object" && Object.keys(value).length === 0)
|
|
|
|
? watch("data_html")
|
|
|
|
: value
|
|
|
|
}
|
|
|
|
noBorder={true}
|
2023-10-12 06:58:36 +00:00
|
|
|
customClassName="h-full shadow-sm overflow-auto"
|
2023-09-11 06:54:46 +00:00
|
|
|
editorContentCustomClassNames="pb-9"
|
|
|
|
onChange={(description: Object, description_html: string) => {
|
|
|
|
onChange(description_html);
|
|
|
|
setValue("data_html", description_html);
|
|
|
|
setValue("data", JSON.stringify(description));
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
{isEditable && (
|
|
|
|
<PrimaryButton
|
2023-10-12 06:58:36 +00:00
|
|
|
className="mt-4 w-[calc(100%-30px)] h-[45px] mx-[15px] text-[17px] my-[15px]"
|
2023-09-11 06:54:46 +00:00
|
|
|
onClick={() => {
|
|
|
|
console.log(
|
|
|
|
"submitted",
|
|
|
|
JSON.stringify({
|
|
|
|
data_html: watch("data_html"),
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
Submit
|
|
|
|
</PrimaryButton>
|
|
|
|
)}
|
2023-10-12 06:58:36 +00:00
|
|
|
</div>
|
2023-09-11 06:54:46 +00:00
|
|
|
)}
|
|
|
|
</WebViewLayout>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Editor;
|