import React from "react"; import { observer } from "mobx-react"; import Image from "next/image"; import Link from "next/link"; import { useTheme } from "next-themes"; // hooks // components import { Button, TButtonVariant } from "@plane/ui"; // constant import { EMPTY_STATE_DETAILS, EmptyStateType } from "@/constants/empty-state"; // helpers import { cn } from "@/helpers/common.helper"; import { useUser } from "@/hooks/store"; import { ComicBoxButton } from "./comic-box-button"; export type EmptyStateProps = { type: EmptyStateType; size?: "sm" | "md" | "lg"; layout?: "screen-detailed" | "screen-simple"; additionalPath?: string; primaryButtonOnClick?: () => void; primaryButtonLink?: string; secondaryButtonOnClick?: () => void; }; export const EmptyState: React.FC = observer((props) => { const { type, size = "lg", layout = "screen-detailed", additionalPath = "", primaryButtonOnClick, primaryButtonLink, secondaryButtonOnClick, } = props; // store const { membership: { currentWorkspaceRole, currentProjectRole }, } = useUser(); // theme const { resolvedTheme } = useTheme(); // if empty state type is not found if (!EMPTY_STATE_DETAILS[type]) return null; // current empty state details const { key, title, description, path, primaryButton, secondaryButton, accessType, access } = EMPTY_STATE_DETAILS[type]; // resolved empty state path const resolvedEmptyStatePath = `${additionalPath && additionalPath !== "" ? `${path}${additionalPath}` : path}-${ resolvedTheme === "light" ? "light" : "dark" }.webp`; // current access type const currentAccessType = accessType === "workspace" ? currentWorkspaceRole : currentProjectRole; // permission const isEditingAllowed = currentAccessType && access && currentAccessType >= access; const anyButton = primaryButton || secondaryButton; // primary button const renderPrimaryButton = () => { if (!primaryButton) return null; const commonProps = { size: size, variant: "primary" as TButtonVariant, prependIcon: primaryButton.icon, onClick: primaryButtonOnClick ? primaryButtonOnClick : undefined, disabled: !isEditingAllowed, }; if (primaryButton.comicBox) { return ( ); } else if (primaryButtonLink) { return ( ); } else { return ; } }; // secondary button const renderSecondaryButton = () => { if (!secondaryButton) return null; return ( ); }; return ( <> {layout === "screen-detailed" && (
{description ? ( <>

{title}

{description}

) : (

{title}

)}
{path && ( {key )} {anyButton && ( <>
{renderPrimaryButton()} {renderSecondaryButton()}
)}
)} {layout === "screen-simple" && (
{key
{description ? ( <>

{title}

{description}

) : (

{title}

)}
)} ); });