2024-04-08 13:41:47 +00:00
|
|
|
import { Dispatch, SetStateAction, useEffect, useMemo } from "react";
|
|
|
|
import { observer } from "mobx-react";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
import { TIssue } from "@plane/types";
|
2024-04-15 07:19:14 +00:00
|
|
|
import { Loader, TOAST_TYPE, setToast } from "@plane/ui";
|
2024-04-08 13:41:47 +00:00
|
|
|
// components
|
2024-04-15 07:19:14 +00:00
|
|
|
import { InboxIssueContentProperties } from "@/components/inbox/content";
|
2024-04-08 13:41:47 +00:00
|
|
|
import {
|
|
|
|
IssueDescriptionInput,
|
|
|
|
IssueTitleInput,
|
|
|
|
IssueActivity,
|
|
|
|
IssueReaction,
|
|
|
|
TIssueOperations,
|
|
|
|
} from "@/components/issues";
|
|
|
|
// hooks
|
2024-04-15 07:19:14 +00:00
|
|
|
import { useEventTracker, useProjectInbox, useUser } from "@/hooks/store";
|
2024-04-08 13:41:47 +00:00
|
|
|
import useReloadConfirmations from "@/hooks/use-reload-confirmation";
|
|
|
|
// store types
|
|
|
|
import { IInboxIssueStore } from "@/store/inbox/inbox-issue.store";
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
workspaceSlug: string;
|
|
|
|
projectId: string;
|
|
|
|
inboxIssue: IInboxIssueStore;
|
2024-04-10 10:38:31 +00:00
|
|
|
isEditable: boolean;
|
2024-04-08 13:41:47 +00:00
|
|
|
isSubmitting: "submitting" | "submitted" | "saved";
|
|
|
|
setIsSubmitting: Dispatch<SetStateAction<"submitting" | "submitted" | "saved">>;
|
2024-04-11 15:58:59 +00:00
|
|
|
swrIssueDescription: string | undefined;
|
2024-04-08 13:41:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const InboxIssueMainContent: React.FC<Props> = observer((props) => {
|
|
|
|
const router = useRouter();
|
2024-04-11 15:58:59 +00:00
|
|
|
const { workspaceSlug, projectId, inboxIssue, isEditable, isSubmitting, setIsSubmitting, swrIssueDescription } =
|
|
|
|
props;
|
2024-04-08 13:41:47 +00:00
|
|
|
// hooks
|
|
|
|
const { currentUser } = useUser();
|
|
|
|
const { setShowAlert } = useReloadConfirmations(isSubmitting === "submitting");
|
|
|
|
const { captureIssueEvent } = useEventTracker();
|
2024-04-15 07:19:14 +00:00
|
|
|
const { loader } = useProjectInbox();
|
2024-04-08 13:41:47 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (isSubmitting === "submitted") {
|
|
|
|
setShowAlert(false);
|
|
|
|
setTimeout(async () => {
|
|
|
|
setIsSubmitting("saved");
|
|
|
|
}, 3000);
|
|
|
|
} else if (isSubmitting === "submitting") {
|
|
|
|
setShowAlert(true);
|
|
|
|
}
|
|
|
|
}, [isSubmitting, setShowAlert, setIsSubmitting]);
|
|
|
|
|
|
|
|
const issue = inboxIssue.issue;
|
|
|
|
if (!issue) return <></>;
|
|
|
|
|
|
|
|
const issueOperations: TIssueOperations = useMemo(
|
|
|
|
() => ({
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
fetch: async (workspaceSlug: string, projectId: string, issueId: string) => {
|
|
|
|
try {
|
|
|
|
return;
|
|
|
|
} catch (error) {
|
|
|
|
setToast({
|
|
|
|
title: "Issue fetch failed",
|
|
|
|
type: TOAST_TYPE.ERROR,
|
|
|
|
message: "Issue fetch failed",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
remove: async (workspaceSlug: string, projectId: string, issueId: string) => {
|
|
|
|
try {
|
|
|
|
return;
|
|
|
|
} catch (error) {
|
|
|
|
setToast({
|
|
|
|
title: "Issue remove failed",
|
|
|
|
type: TOAST_TYPE.ERROR,
|
|
|
|
message: "Issue remove failed",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
update: async (workspaceSlug: string, projectId: string, issueId: string, data: Partial<TIssue>) => {
|
|
|
|
try {
|
|
|
|
await inboxIssue.updateIssue(data);
|
|
|
|
captureIssueEvent({
|
|
|
|
eventName: "Inbox issue updated",
|
|
|
|
payload: { ...data, state: "SUCCESS", element: "Inbox" },
|
|
|
|
updates: {
|
|
|
|
changed_property: Object.keys(data).join(","),
|
|
|
|
change_details: Object.values(data).join(","),
|
|
|
|
},
|
|
|
|
path: router.asPath,
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
setToast({
|
|
|
|
title: "Issue update failed",
|
|
|
|
type: TOAST_TYPE.ERROR,
|
|
|
|
message: "Issue update failed",
|
|
|
|
});
|
|
|
|
captureIssueEvent({
|
|
|
|
eventName: "Inbox issue updated",
|
|
|
|
payload: { state: "SUCCESS", element: "Inbox" },
|
|
|
|
updates: {
|
|
|
|
changed_property: Object.keys(data).join(","),
|
|
|
|
change_details: Object.values(data).join(","),
|
|
|
|
},
|
|
|
|
path: router.asPath,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
[inboxIssue]
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!issue?.project_id || !issue?.id) return <></>;
|
2024-04-11 15:58:59 +00:00
|
|
|
|
2024-04-08 13:41:47 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className="rounded-lg space-y-4">
|
|
|
|
<IssueTitleInput
|
|
|
|
workspaceSlug={workspaceSlug}
|
|
|
|
projectId={issue.project_id}
|
|
|
|
issueId={issue.id}
|
|
|
|
isSubmitting={isSubmitting}
|
|
|
|
setIsSubmitting={(value) => setIsSubmitting(value)}
|
|
|
|
issueOperations={issueOperations}
|
2024-04-10 10:38:31 +00:00
|
|
|
disabled={!isEditable}
|
2024-04-08 13:41:47 +00:00
|
|
|
value={issue.name}
|
|
|
|
/>
|
|
|
|
|
2024-04-15 07:19:14 +00:00
|
|
|
{loader === "issue-loading" ? (
|
|
|
|
<Loader className="min-h-[6rem] rounded-md border border-custom-border-200">
|
|
|
|
<Loader.Item width="100%" height="140px" />
|
|
|
|
</Loader>
|
|
|
|
) : (
|
|
|
|
<IssueDescriptionInput
|
|
|
|
workspaceSlug={workspaceSlug}
|
|
|
|
projectId={issue.project_id}
|
|
|
|
issueId={issue.id}
|
|
|
|
swrIssueDescription={swrIssueDescription}
|
|
|
|
initialValue={issue.description_html ?? "<p></p>"}
|
|
|
|
disabled={!isEditable}
|
|
|
|
issueOperations={issueOperations}
|
|
|
|
setIsSubmitting={(value) => setIsSubmitting(value)}
|
|
|
|
/>
|
|
|
|
)}
|
2024-04-08 13:41:47 +00:00
|
|
|
|
|
|
|
{currentUser && (
|
|
|
|
<IssueReaction
|
|
|
|
workspaceSlug={workspaceSlug}
|
|
|
|
projectId={projectId}
|
|
|
|
issueId={issue.id}
|
|
|
|
currentUser={currentUser}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
|
2024-04-15 07:19:14 +00:00
|
|
|
<InboxIssueContentProperties
|
2024-04-08 13:41:47 +00:00
|
|
|
workspaceSlug={workspaceSlug}
|
|
|
|
projectId={projectId}
|
|
|
|
issue={issue}
|
|
|
|
issueOperations={issueOperations}
|
2024-04-10 10:38:31 +00:00
|
|
|
isEditable={isEditable}
|
2024-04-10 08:22:57 +00:00
|
|
|
duplicateIssueDetails={inboxIssue?.duplicate_issue_detail}
|
2024-04-08 13:41:47 +00:00
|
|
|
/>
|
|
|
|
|
|
|
|
<div className="pb-12">
|
|
|
|
<IssueActivity workspaceSlug={workspaceSlug} projectId={projectId} issueId={issue.id} />
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
});
|