mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
34d6b135f2
* chore: draft issue update request * chore: changed the serializer * chore: handled issue description in issue modal, inbox issues mutation and draft issue mutaion and changed the endpoints * chore: handled draft toggle in make a issue payload in issues * chore: handled issue labels in the inbox issues --------- Co-authored-by: NarayanBavisetti <narayan3119@gmail.com>
105 lines
3.2 KiB
TypeScript
105 lines
3.2 KiB
TypeScript
import { FC, useMemo } from "react";
|
|
import { observer } from "mobx-react-lite";
|
|
// components
|
|
import { LabelList, LabelCreate, IssueLabelSelectRoot } from "./";
|
|
// hooks
|
|
import { useIssueDetail, useLabel } from "hooks/store";
|
|
// types
|
|
import { IIssueLabel, TIssue } from "@plane/types";
|
|
import useToast from "hooks/use-toast";
|
|
|
|
export type TIssueLabel = {
|
|
workspaceSlug: string;
|
|
projectId: string;
|
|
issueId: string;
|
|
disabled: boolean;
|
|
isInboxIssue?: boolean;
|
|
onLabelUpdate?: (labelIds: string[]) => void;
|
|
};
|
|
|
|
export type TLabelOperations = {
|
|
updateIssue: (workspaceSlug: string, projectId: string, issueId: string, data: Partial<TIssue>) => Promise<void>;
|
|
createLabel: (workspaceSlug: string, projectId: string, data: Partial<IIssueLabel>) => Promise<any>;
|
|
};
|
|
|
|
export const IssueLabel: FC<TIssueLabel> = observer((props) => {
|
|
const { workspaceSlug, projectId, issueId, disabled = false, isInboxIssue = false, onLabelUpdate } = props;
|
|
// hooks
|
|
const { updateIssue } = useIssueDetail();
|
|
const { createLabel } = useLabel();
|
|
const { setToastAlert } = useToast();
|
|
|
|
const labelOperations: TLabelOperations = useMemo(
|
|
() => ({
|
|
updateIssue: async (workspaceSlug: string, projectId: string, issueId: string, data: Partial<TIssue>) => {
|
|
try {
|
|
if (onLabelUpdate) onLabelUpdate(data.label_ids || []);
|
|
else await updateIssue(workspaceSlug, projectId, issueId, data);
|
|
if (!isInboxIssue)
|
|
setToastAlert({
|
|
title: "Issue updated successfully",
|
|
type: "success",
|
|
message: "Issue updated successfully",
|
|
});
|
|
} catch (error) {
|
|
setToastAlert({
|
|
title: "Issue update failed",
|
|
type: "error",
|
|
message: "Issue update failed",
|
|
});
|
|
}
|
|
},
|
|
createLabel: async (workspaceSlug: string, projectId: string, data: Partial<IIssueLabel>) => {
|
|
try {
|
|
const labelResponse = await createLabel(workspaceSlug, projectId, data);
|
|
if (!isInboxIssue)
|
|
setToastAlert({
|
|
title: "Label created successfully",
|
|
type: "success",
|
|
message: "Label created successfully",
|
|
});
|
|
return labelResponse;
|
|
} catch (error) {
|
|
setToastAlert({
|
|
title: "Label creation failed",
|
|
type: "error",
|
|
message: "Label creation failed",
|
|
});
|
|
return error;
|
|
}
|
|
},
|
|
}),
|
|
[updateIssue, createLabel, setToastAlert, onLabelUpdate]
|
|
);
|
|
|
|
return (
|
|
<div className="relative flex flex-wrap items-center gap-1">
|
|
<LabelList
|
|
workspaceSlug={workspaceSlug}
|
|
projectId={projectId}
|
|
issueId={issueId}
|
|
labelOperations={labelOperations}
|
|
disabled={disabled}
|
|
/>
|
|
|
|
{!disabled && (
|
|
<IssueLabelSelectRoot
|
|
workspaceSlug={workspaceSlug}
|
|
projectId={projectId}
|
|
issueId={issueId}
|
|
labelOperations={labelOperations}
|
|
/>
|
|
)}
|
|
|
|
{!disabled && (
|
|
<LabelCreate
|
|
workspaceSlug={workspaceSlug}
|
|
projectId={projectId}
|
|
issueId={issueId}
|
|
labelOperations={labelOperations}
|
|
/>
|
|
)}
|
|
</div>
|
|
);
|
|
});
|