mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
53367a6bc4
* new toast setup * chore: new toast implementation. * chore: move toast component to ui package. * chore: replace `setToast` with `setPromiseToast` in required places for better UX. * chore: code cleanup. * chore: update theme. * fix: theme switching issue. * chore: remove toast from issue update operations. * chore: add promise toast for add/ remove issue to cycle/ module and remove local spinners. --------- Co-authored-by: rahulramesha <rahulramesham@gmail.com>
99 lines
3.0 KiB
TypeScript
99 lines
3.0 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";
|
|
// ui
|
|
import { TOAST_TYPE, setToast } from "@plane/ui";
|
|
// types
|
|
import { IIssueLabel, TIssue } from "@plane/types";
|
|
|
|
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 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);
|
|
} catch (error) {
|
|
setToast({
|
|
title: "Issue update failed",
|
|
type: TOAST_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)
|
|
setToast({
|
|
title: "Label created successfully",
|
|
type: TOAST_TYPE.SUCCESS,
|
|
message: "Label created successfully",
|
|
});
|
|
return labelResponse;
|
|
} catch (error) {
|
|
setToast({
|
|
title: "Label creation failed",
|
|
type: TOAST_TYPE.ERROR,
|
|
message: "Label creation failed",
|
|
});
|
|
return error;
|
|
}
|
|
},
|
|
}),
|
|
[updateIssue, createLabel, 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>
|
|
);
|
|
});
|