[WEB-570] chore: toast refactor (#3836)

* 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>
This commit is contained in:
Prateek Shourya 2024-03-06 14:18:41 +05:30 committed by GitHub
parent c06ef4d1d7
commit 53367a6bc4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
167 changed files with 1827 additions and 1896 deletions

View file

@ -5,9 +5,8 @@ import { TwitterPicker } from "react-color";
import { Popover, Transition } from "@headlessui/react";
// hooks
import { useIssueDetail } from "hooks/store";
import useToast from "hooks/use-toast";
// ui
import { Input } from "@plane/ui";
import { Input, TOAST_TYPE, setToast } from "@plane/ui";
// types
import { TLabelOperations } from "./root";
import { IIssueLabel } from "@plane/types";
@ -28,7 +27,6 @@ const defaultValues: Partial<IIssueLabel> = {
export const LabelCreate: FC<ILabelCreate> = (props) => {
const { workspaceSlug, projectId, issueId, labelOperations, disabled = false } = props;
// hooks
const { setToastAlert } = useToast();
const {
issue: { getIssueById },
} = useIssueDetail();
@ -63,9 +61,9 @@ export const LabelCreate: FC<ILabelCreate> = (props) => {
await labelOperations.updateIssue(workspaceSlug, projectId, issueId, { label_ids: currentLabels });
reset(defaultValues);
} catch (error) {
setToastAlert({
setToast({
title: "Label creation failed",
type: "error",
type: TOAST_TYPE.ERROR,
message: "Label creation failed. Please try again sometime later.",
});
}

View file

@ -4,9 +4,10 @@ import { observer } from "mobx-react-lite";
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";
import useToast from "hooks/use-toast";
export type TIssueLabel = {
workspaceSlug: string;
@ -27,7 +28,6 @@ export const IssueLabel: FC<TIssueLabel> = observer((props) => {
// hooks
const { updateIssue } = useIssueDetail();
const { createLabel } = useLabel();
const { setToastAlert } = useToast();
const labelOperations: TLabelOperations = useMemo(
() => ({
@ -35,16 +35,10 @@ export const IssueLabel: FC<TIssueLabel> = observer((props) => {
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({
setToast({
title: "Issue update failed",
type: "error",
type: TOAST_TYPE.ERROR,
message: "Issue update failed",
});
}
@ -53,23 +47,23 @@ export const IssueLabel: FC<TIssueLabel> = observer((props) => {
try {
const labelResponse = await createLabel(workspaceSlug, projectId, data);
if (!isInboxIssue)
setToastAlert({
setToast({
title: "Label created successfully",
type: "success",
type: TOAST_TYPE.SUCCESS,
message: "Label created successfully",
});
return labelResponse;
} catch (error) {
setToastAlert({
setToast({
title: "Label creation failed",
type: "error",
type: TOAST_TYPE.ERROR,
message: "Label creation failed",
});
return error;
}
},
}),
[updateIssue, createLabel, setToastAlert, onLabelUpdate]
[updateIssue, createLabel, onLabelUpdate]
);
return (