import { FC, useCallback, useEffect, useState } from "react"; // packages import { RichTextEditor } from "@plane/rich-text-editor"; // components import { IssueReaction } from "./reactions"; // hooks import { useDebouncedCallback } from "use-debounce"; // types import { IIssue } from "types"; // services import { FileService } from "services/file.service"; import { useForm, Controller } from "react-hook-form"; import useReloadConfirmations from "hooks/use-reload-confirmation"; const fileService = new FileService(); interface IPeekOverviewIssueDetails { workspaceSlug: string; issue: IIssue; issueReactions: any; user: any; issueUpdate: (issue: Partial) => void; issueReactionCreate: (reaction: string) => void; issueReactionRemove: (reaction: string) => void; } export const PeekOverviewIssueDetails: FC = (props) => { const { workspaceSlug, issue, issueReactions, user, issueUpdate, issueReactionCreate, issueReactionRemove } = props; const [isSubmitting, setIsSubmitting] = useState<"submitting" | "submitted" | "saved">("saved"); const { handleSubmit, watch, reset, control } = useForm({ defaultValues: { name: "", description_html: "", }, }); const { setShowAlert } = useReloadConfirmations(); useEffect(() => { if (!issue) return; reset({ ...issue, }); }, [issue, reset]); useEffect(() => { if (isSubmitting === "submitted") { setShowAlert(false); setTimeout(async () => { setIsSubmitting("saved"); }, 2000); } else if (isSubmitting === "submitting") { setShowAlert(true); } }, [isSubmitting, setShowAlert]); const handleDescriptionFormSubmit = useCallback( async (formData: Partial) => { if (!formData?.name || formData?.name.length === 0 || formData?.name.length > 255) return; issueUpdate({ name: formData.name ?? "", description_html: formData.description_html }); }, [issueUpdate] ); const debouncedIssueFormSave = useDebouncedCallback(async () => { handleSubmit(handleDescriptionFormSubmit)().finally(() => setIsSubmitting("submitted")); }, 1500); return (
{issue?.project_detail?.identifier}-{issue?.sequence_id}
{watch("name")}
( { setIsSubmitting("submitting"); onChange(description_html); debouncedIssueFormSave(); }} customClassName="p-3 min-h-[80px] shadow-sm" /> )} />
{isSubmitting === "submitting" ? "Saving..." : "Saved"}
); };