π₯π₯π₯ Open-source Jira, Linear, Monday, and ClickUp alternative. Plane is a modern project management platform to manage tasks, sprints, docs, and triage.
TypeScript boardsbug-trackerdjangodockerganttissue-trackerjirajira-alternativekanbanlinearpostgresqlproduct-managementproject-managementproject-planningpythonreactredistypesciptvitework-management
[WEB-1401] chore: toast refactor in space app. (#4546)
Prateek Shouryab08484456517
diff --git a/space/app/layout.tsx b/space/app/layout.tsxindex 86e51266f9..b2bbd1227c 100644--- a/space/app/layout.tsx+++ b/space/app/layout.tsx@@ -6,6 +6,7 @@ import { InstanceProvider } from "@/lib/instance-provider";import { StoreProvider } from "@/lib/store-provider";// stylesimport "@/styles/globals.css";+import { ToastProvider } from "@/lib/toast-provider";export const metadata: Metadata = {title: "Plane Deploy | Make your Plane boards public with one-click",@@ -34,7 +35,9 @@ export default function RootLayout({ children }: { children: React.ReactNode })</head><body><StoreProvider>- <InstanceProvider>{children}</InstanceProvider>+ <ToastProvider>+ <InstanceProvider>{children}</InstanceProvider>+ </ToastProvider></StoreProvider></body></html>diff --git a/space/components/issues/peek-overview/comment/add-comment.tsx b/space/components/issues/peek-overview/comment/add-comment.tsxindex 96366eadd9..a1647c9c54 100644--- a/space/components/issues/peek-overview/comment/add-comment.tsx+++ b/space/components/issues/peek-overview/comment/add-comment.tsx@@ -1,12 +1,14 @@import React, { useRef } from "react";import { observer } from "mobx-react-lite";import { useForm, Controller } from "react-hook-form";-// components+// editorimport { EditorRefApi } from "@plane/lite-text-editor";+// ui+import { TOAST_TYPE, setToast } from "@plane/ui";+// editor componentsimport { LiteTextEditor } from "@/components/editor/lite-text-editor";// hooksimport { useIssueDetails, useProject, useUser } from "@/hooks/store";-import useToast from "@/hooks/use-toast";// typesimport { Comment } from "@/types/issue";@@ -39,8 +41,6 @@ export const AddComment: React.FC<Props> = observer((props) => {formState: { isSubmitting },reset,} = useForm<Comment>({ defaultValues });- // toast alert- const { setToastAlert } = useToast();const onSubmit = async (formData: Comment) => {if (!workspaceSlug || !projectId || !issueId || isSubmitting || !formData.comment_html) return;@@ -51,8 +51,8 @@ export const AddComment: React.FC<Props> = observer((props) => {editorRef.current?.clearEditor();}).catch(() =>- setToastAlert({- type: "error",+ setToast({+ type: TOAST_TYPE.ERROR,title: "Error!",message: "Comment could not be posted. Please try again.",})diff --git a/space/components/issues/peek-overview/header.tsx b/space/components/issues/peek-overview/header.tsxindex 80e2f785f3..0e9b93ab9f 100644--- a/space/components/issues/peek-overview/header.tsx+++ b/space/components/issues/peek-overview/header.tsx@@ -3,17 +3,15 @@ import { observer } from "mobx-react-lite";import { MoveRight } from "lucide-react";import { Listbox, Transition } from "@headlessui/react";// ui+import { setToast, TOAST_TYPE } from "@plane/ui";import { Icon } from "@/components/ui";// helpersimport { copyTextToClipboard } from "@/helpers/string.helper";// hooksimport { useIssueDetails } from "@/hooks/store";import useClipboardWritePermission from "@/hooks/use-clipboard-write-permission";-import useToast from "@/hooks/use-toast";-// store-import { IPeekMode } from "@/store/issue-detail.store";// types-import { IIssue } from "@/types/issue";+import { IIssue, IPeekMode } from "@/types/issue";type Props = {handleClose: () => void;@@ -44,14 +42,12 @@ export const PeekOverviewHeader: React.FC<Props> = observer((props) => {const { peekMode, setPeekMode } = useIssueDetails();const isClipboardWriteAllowed = useClipboardWritePermission();- const { setToastAlert } = useToast();-const handleCopyLink = () => {const urlToCopy = window.location.href;copyTextToClipboard(urlToCopy).then(() => {- setToastAlert({- type: "success",+ setToast({+ type: TOAST_TYPE.INFO,title: "Link copied!",message: "Issue link copied to clipboard",});diff --git a/space/components/issues/peek-overview/issue-properties.tsx b/space/components/issues/peek-overview/issue-properties.tsxindex 32d39b540b..08d22b3124 100644--- a/space/components/issues/peek-overview/issue-properties.tsx+++ b/space/components/issues/peek-overview/issue-properties.tsx@@ -1,17 +1,15 @@-// hooks// ui-import { StateGroupIcon } from "@plane/ui";+import { StateGroupIcon, TOAST_TYPE, setToast } from "@plane/ui";// iconsimport { Icon } from "@/components/ui";-// helpers+// constantsimport { issueGroupFilter, issuePriorityFilter } from "@/constants/issue";+// helpersimport { renderFullDate } from "@/helpers/date-time.helper";import { copyTextToClipboard, addSpaceIfCamelCase } from "@/helpers/string.helper";// types-import { IPeekMode } from "@/store/issue-detail.store";-// constants-import useToast from "hooks/use-toast";-import { IIssue } from "types/issue";+import { IIssue, IPeekMode } from "@/types/issue";+// componentsimport { dueDateIconDetails } from "../board-views/block-due-date";type Props = {@@ -20,8 +18,6 @@ type Props = {};export const PeekOverviewIssueProperties: React.FC<Props> = ({ issueDetails, mode }) => {- const { setToastAlert } = useToast();-const state = issueDetails.state_detail;const stateGroup = issueGroupFilter(state.group);@@ -33,8 +29,8 @@ export const PeekOverviewIssueProperties: React.FC<Props> = ({ issueDetails, modconst urlToCopy = window.location.href;copyTextToClipboard(urlToCopy).then(() => {- setToastAlert({- type: "success",+ setToast({+ type: TOAST_TYPE.INFO,title: "Link copied!",message: "Issue link copied to clipboard",});diff --git a/space/components/ui/toast-alert.tsx b/space/components/ui/toast-alert.tsxdeleted file mode 100644index 7e7804d32a..0000000000--- a/space/components/ui/toast-alert.tsx+++ /dev/null@@ -1,61 +0,0 @@-import React from "react";-import { AlertTriangle, CheckCircle, Info, X, XCircle } from "lucide-react";-// hooks-import useToast from "hooks/use-toast";-// icons--const ToastAlerts = () => {- const { alerts, removeAlert } = useToast();-- if (!alerts) return null;-- return (- <div className="pointer-events-none fixed right-5 top-5 z-50 h-full w-80 space-y-5 overflow-hidden">- {alerts.map((alert) => (- <div className="relative overflow-hidden rounded-md text-white" key={alert.id}>- <div className="absolute right-1 top-1">- <button- type="button"- className="pointer-events-auto inline-flex rounded-md p-1.5 focus:outline-none focus:ring-2 focus:ring-offset-2"- onClick={() => removeAlert(alert.id)}- >- <span className="sr-only">Dismiss</span>- <X className="h-5 w-5" aria-hidden="true" />- </button>- </div>- <div- className={`px-2 py-4 ${- alert.type === "success"- ? "bg-[#06d6a0]"- : alert.type === "error"- ? "bg-[#ef476f]"- : alert.type === "warning"- ? "bg-[#e98601]"- : "bg-[#1B9aaa]"- }`}- >- <div className="flex items-center gap-x-3">- <div className="flex-shrink-0">- {alert.type === "success" ? (- <CheckCircle className="h-8 w-8" aria-hidden="true" />- ) : alert.type === "error" ? (- <XCircle className="h-8 w-8" />- ) : alert.type === "warning" ? (- <AlertTriangle className="h-8 w-8" aria-hidden="true" />- ) : (- <Info className="h-8 w-8" />- )}- </div>- <div>- <p className="font-semibold">{alert.title}</p>- {alert.message && <p className="mt-1 text-xs">{alert.message}</p>}- </div>- </div>- </div>- </div>- ))}- </div>- );-};--export default ToastAlerts;diff --git a/space/contexts/toast.context.tsx b/space/contexts/toast.context.tsxdeleted file mode 100644index 86608f02c9..0000000000--- a/space/contexts/toast.context.tsx+++ /dev/null@@ -1,97 +0,0 @@-import React, { createContext, useCallback, useReducer } from "react";-// uuid-import { v4 as uuid } from "uuid";-// components-import ToastAlert from "@/components/ui/toast-alert";--export const toastContext = createContext<ContextType>({} as ContextType);--// types-type ToastAlert = {- id: string;- title: string;- message?: string;- type: "success" | "error" | "warning" | "info";-};--type ReducerActionType = {- type: "SET_TOAST_ALERT" | "REMOVE_TOAST_ALERT";- payload: ToastAlert;-};--type ContextType = {- alerts?: ToastAlert[];- removeAlert: (id: string) => void;- setToastAlert: (data: {- title: string;- type?: "success" | "error" | "warning" | "info" | undefined;- message?: string | undefined;- }) => void;-};--type StateType = {- toastAlerts?: ToastAlert[];-};--type ReducerFunctionType = (state: StateType, action: ReducerActionType) => StateType;--export const initialState: StateType = {- toastAlerts: [],-};--export const reducer: ReducerFunctionType = (state, action) => {- const { type, payload } = action;-- switch (type) {- case "SET_TOAST_ALERT":- return {- ...state,- toastAlerts: [...(state.toastAlerts ?? []), payload],- };-- case "REMOVE_TOAST_ALERT":- return {- ...state,- toastAlerts: state.toastAlerts?.filter((toastAlert) => toastAlert.id !== payload.id),- };-- default: {- return state;- }- }-};--export const ToastContextProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {- const [state, dispatch] = useReducer(reducer, initialState);-- const removeAlert = useCallback((id: string) => {- dispatch({- type: "REMOVE_TOAST_ALERT",- payload: { id, title: "", message: "", type: "success" },- });- }, []);-- const setToastAlert = useCallback(- (data: { title: string; type?: "success" | "error" | "warning" | "info"; message?: string }) => {- const id = uuid();- const { title, type, message } = data;- dispatch({- type: "SET_TOAST_ALERT",- payload: { id, title, message, type: type ?? "success" },- });-- const timer = setTimeout(() => {- removeAlert(id);- clearTimeout(timer);- }, 3000);- },- [removeAlert]- );-- return (- <toastContext.Provider value={{ setToastAlert, removeAlert, alerts: state.toastAlerts }}>- <ToastAlert />- {children}- </toastContext.Provider>- );-};diff --git a/space/helpers/common.helper.ts b/space/helpers/common.helper.tsindex b2101e3c40..52c61e4e20 100644--- a/space/helpers/common.helper.ts+++ b/space/helpers/common.helper.ts@@ -15,3 +15,6 @@ export const GOD_MODE_URL = encodeURI(`${ADMIN_BASE_URL}${ADMIN_BASE_PATH}`);export const ASSET_PREFIX = SPACE_BASE_PATH;export const cn = (...inputs: ClassValue[]) => twMerge(clsx(inputs));++export const resolveGeneralTheme = (resolvedTheme: string | undefined) =>+ resolvedTheme?.includes("light") ? "light" : resolvedTheme?.includes("dark") ? "dark" : "system";diff --git a/space/hooks/use-toast.tsx b/space/hooks/use-toast.tsxdeleted file mode 100644index 13f598f88a..0000000000--- a/space/hooks/use-toast.tsx+++ /dev/null@@ -1,9 +0,0 @@-import { useContext } from "react";-import { toastContext } from "@/contexts/toast.context";--const useToast = () => {- const toastContextData = useContext(toastContext);- return toastContextData;-};--export default useToast;diff --git a/space/lib/toast-provider.tsx b/space/lib/toast-provider.tsxnew file mode 100644index 0000000000..1083cb6af6--- /dev/null+++ b/space/lib/toast-provider.tsx@@ -0,0 +1,20 @@+"use client";++import { ReactNode } from "react";+import { useTheme } from "next-themes"+// ui+import { Toast } from "@plane/ui";+// helpers+import { resolveGeneralTheme } from "@/helpers/common.helper";++export const ToastProvider = ({ children }: { children: ReactNode }) => {+ // themes+ const { resolvedTheme } = useTheme();++ return (+ <>+ <Toast theme={resolveGeneralTheme(resolvedTheme)} />+ {children}+ </>+ );+};diff --git a/space/store/issue-detail.store.ts b/space/store/issue-detail.store.tsindex b6734640be..03f611cc0a 100644--- a/space/store/issue-detail.store.ts+++ b/space/store/issue-detail.store.ts@@ -5,9 +5,7 @@ import IssueService from "@/services/issue.service";// store typesimport { RootStore } from "@/store/root.store";// types-import { IIssue, IVote } from "@/types/issue";--export type IPeekMode = "side" | "modal" | "full";+import { IIssue, IPeekMode, IVote } from "@/types/issue";export interface IIssueDetailStore {loader: boolean;diff --git a/space/types/issue.d.ts b/space/types/issue.d.tsindex 9735bedc2f..f2625fb764 100644--- a/space/types/issue.d.ts+++ b/space/types/issue.d.ts@@ -66,6 +66,8 @@ export interface IIssue {votes: IVote[];}+export type IPeekMode = "side" | "modal" | "full";+export interface IIssueState {id: string;name: string;