"use client"; 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, TButtonSizes, TButtonVariant } from "@plane/ui"; // constant import { EMPTY_STATE_DETAILS, EmptyStateType } from "@/constants/empty-state"; // helpers import { cn } from "@/helpers/common.helper"; import { useUserPermissions } from "@/hooks/store"; import { EUserPermissionsLevel } from "@/plane-web/constants/user-permissions"; import { ComicBoxButton } from "./comic-box-button"; export type EmptyStateProps = { size?: TButtonSizes; type: EmptyStateType; layout?: "screen-detailed" | "screen-simple"; additionalPath?: string; primaryButtonConfig?: { size?: TButtonSizes; variant?: TButtonVariant; }; primaryButtonOnClick?: () => void; primaryButtonLink?: string; secondaryButtonOnClick?: () => void; }; export const EmptyState: React.FC = observer((props) => { const { size = "lg", type, layout = "screen-detailed", additionalPath = "", primaryButtonConfig = { size: "lg", variant: "primary", }, primaryButtonOnClick, primaryButtonLink, secondaryButtonOnClick, } = props; // store const { allowPermissions } = useUserPermissions(); // 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`; // permission const isEditingAllowed = access && accessType && allowPermissions( access, accessType === "workspace" ? EUserPermissionsLevel.WORKSPACE : EUserPermissionsLevel.PROJECT ); const anyButton = primaryButton || secondaryButton; // primary button const renderPrimaryButton = () => { if (!primaryButton) return null; const commonProps = { size: primaryButtonConfig.size, variant: primaryButtonConfig.variant, 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}

)} {anyButton && (
{renderPrimaryButton()} {renderSecondaryButton()}
)}
)} ); });