2023-10-31 06:56:10 +00:00
|
|
|
import { FC, useCallback, useEffect, useState } from "react";
|
2023-10-18 14:28:05 +00:00
|
|
|
// packages
|
|
|
|
import { RichTextEditor } from "@plane/rich-text-editor";
|
2023-10-20 07:03:39 +00:00
|
|
|
// components
|
|
|
|
import { IssueReaction } from "./reactions";
|
2023-10-18 14:28:05 +00:00
|
|
|
// hooks
|
|
|
|
import { useDebouncedCallback } from "use-debounce";
|
|
|
|
// types
|
|
|
|
import { IIssue } from "types";
|
|
|
|
// services
|
|
|
|
import { FileService } from "services/file.service";
|
2023-10-31 06:56:10 +00:00
|
|
|
import { useForm, Controller } from "react-hook-form";
|
|
|
|
import useReloadConfirmations from "hooks/use-reload-confirmation";
|
2023-10-18 14:28:05 +00:00
|
|
|
|
|
|
|
const fileService = new FileService();
|
|
|
|
|
|
|
|
interface IPeekOverviewIssueDetails {
|
|
|
|
workspaceSlug: string;
|
|
|
|
issue: IIssue;
|
2023-10-20 07:03:39 +00:00
|
|
|
issueReactions: any;
|
|
|
|
user: any;
|
2023-10-18 14:28:05 +00:00
|
|
|
issueUpdate: (issue: Partial<IIssue>) => void;
|
2023-10-20 07:03:39 +00:00
|
|
|
issueReactionCreate: (reaction: string) => void;
|
|
|
|
issueReactionRemove: (reaction: string) => void;
|
2023-10-18 14:28:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const PeekOverviewIssueDetails: FC<IPeekOverviewIssueDetails> = (props) => {
|
2023-10-20 07:03:39 +00:00
|
|
|
const { workspaceSlug, issue, issueReactions, user, issueUpdate, issueReactionCreate, issueReactionRemove } = props;
|
2023-10-31 06:56:10 +00:00
|
|
|
const [isSubmitting, setIsSubmitting] = useState<"submitting" | "submitted" | "saved">("saved");
|
2023-10-18 14:28:05 +00:00
|
|
|
|
2023-10-31 06:56:10 +00:00
|
|
|
const { handleSubmit, watch, reset, control } = useForm<IIssue>({
|
|
|
|
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<IIssue>) => {
|
|
|
|
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"));
|
2023-10-18 14:28:05 +00:00
|
|
|
}, 1500);
|
|
|
|
|
|
|
|
return (
|
2023-10-20 12:25:20 +00:00
|
|
|
<div className="space-y-4">
|
2023-10-18 14:28:05 +00:00
|
|
|
<div className="font-medium text-sm text-custom-text-200">
|
|
|
|
{issue?.project_detail?.identifier}-{issue?.sequence_id}
|
|
|
|
</div>
|
|
|
|
|
2023-10-31 06:56:10 +00:00
|
|
|
<div className="font-medium text-xl">{watch("name")}</div>
|
2023-10-18 14:28:05 +00:00
|
|
|
|
2023-10-20 07:03:39 +00:00
|
|
|
<div className="space-y-2">
|
2023-10-31 06:56:10 +00:00
|
|
|
<div className="relative">
|
|
|
|
<Controller
|
|
|
|
name="description_html"
|
|
|
|
control={control}
|
|
|
|
render={({ field: { value, onChange } }) => (
|
|
|
|
<RichTextEditor
|
|
|
|
uploadFile={fileService.getUploadFileFunction(workspaceSlug)}
|
|
|
|
deleteFile={fileService.deleteImage}
|
|
|
|
value={value}
|
|
|
|
onChange={(description: Object, description_html: string) => {
|
|
|
|
setIsSubmitting("submitting");
|
|
|
|
onChange(description_html);
|
|
|
|
debouncedIssueFormSave();
|
|
|
|
}}
|
|
|
|
customClassName="p-3 min-h-[80px] shadow-sm"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<div
|
|
|
|
className={`absolute right-5 bottom-5 text-xs text-custom-text-200 border border-custom-border-400 rounded-xl w-[6.5rem] py-1 z-10 flex items-center justify-center ${
|
|
|
|
isSubmitting === "saved" ? "fadeOut" : "fadeIn"
|
|
|
|
}`}
|
|
|
|
>
|
|
|
|
{isSubmitting === "submitting" ? "Saving..." : "Saved"}
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-10-20 07:03:39 +00:00
|
|
|
|
|
|
|
<IssueReaction
|
|
|
|
issueReactions={issueReactions}
|
|
|
|
user={user}
|
|
|
|
issueReactionCreate={issueReactionCreate}
|
|
|
|
issueReactionRemove={issueReactionRemove}
|
|
|
|
/>
|
|
|
|
</div>
|
2023-10-18 14:28:05 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|