2024-01-24 13:42:54 +00:00
|
|
|
import React from "react";
|
2024-03-06 14:46:54 +00:00
|
|
|
import Link from "next/link";
|
2024-01-25 08:53:55 +00:00
|
|
|
import Image from "next/image";
|
2024-03-06 14:46:54 +00:00
|
|
|
|
|
|
|
import { useTheme } from "next-themes";
|
|
|
|
// hooks
|
|
|
|
import { useUser } from "hooks/store";
|
2024-01-24 13:42:54 +00:00
|
|
|
// components
|
2024-03-06 14:46:54 +00:00
|
|
|
import { Button, TButtonVariant } from "@plane/ui";
|
2024-03-06 13:09:14 +00:00
|
|
|
import { ComicBoxButton } from "./comic-box-button";
|
2024-03-06 14:46:54 +00:00
|
|
|
// constant
|
|
|
|
import { EMPTY_STATE_DETAILS, EmptyStateKeys } from "constants/empty-state";
|
|
|
|
// helpers
|
|
|
|
import { cn } from "helpers/common.helper";
|
2024-01-24 13:42:54 +00:00
|
|
|
|
2024-03-06 14:46:54 +00:00
|
|
|
export type EmptyStateProps = {
|
|
|
|
type: EmptyStateKeys;
|
|
|
|
size?: "sm" | "md" | "lg";
|
|
|
|
layout?: "widget-simple" | "screen-detailed" | "screen-simple";
|
|
|
|
additionalPath?: string;
|
|
|
|
primaryButtonOnClick?: () => void;
|
|
|
|
primaryButtonLink?: string;
|
|
|
|
secondaryButtonOnClick?: () => void;
|
2024-01-24 13:42:54 +00:00
|
|
|
};
|
|
|
|
|
2024-03-06 14:46:54 +00:00
|
|
|
export const EmptyState: React.FC<EmptyStateProps> = (props) => {
|
|
|
|
const {
|
|
|
|
type,
|
|
|
|
size = "lg",
|
|
|
|
layout = "screen-detailed",
|
|
|
|
additionalPath = "",
|
|
|
|
primaryButtonOnClick,
|
|
|
|
primaryButtonLink,
|
|
|
|
secondaryButtonOnClick,
|
|
|
|
} = props;
|
|
|
|
// store
|
|
|
|
const {
|
|
|
|
membership: { currentWorkspaceRole, currentProjectRole },
|
|
|
|
} = useUser();
|
|
|
|
// theme
|
|
|
|
const { resolvedTheme } = useTheme();
|
2024-03-08 12:27:48 +00:00
|
|
|
|
|
|
|
// if empty state type is not found
|
|
|
|
if (!EMPTY_STATE_DETAILS[type]) return null;
|
|
|
|
|
2024-03-06 14:46:54 +00:00
|
|
|
// 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;
|
2024-01-24 13:42:54 +00:00
|
|
|
|
2024-03-06 14:46:54 +00:00
|
|
|
// primary button
|
|
|
|
const renderPrimaryButton = () => {
|
|
|
|
if (!primaryButton) return null;
|
2024-01-24 13:42:54 +00:00
|
|
|
|
2024-03-06 14:46:54 +00:00
|
|
|
const commonProps = {
|
|
|
|
size: size,
|
|
|
|
variant: "primary" as TButtonVariant,
|
|
|
|
prependIcon: primaryButton.icon,
|
|
|
|
onClick: primaryButtonOnClick ? primaryButtonOnClick : undefined,
|
|
|
|
disabled: !isEditingAllowed,
|
|
|
|
};
|
2024-01-24 13:42:54 +00:00
|
|
|
|
2024-03-06 14:46:54 +00:00
|
|
|
if (primaryButton.comicBox) {
|
|
|
|
return (
|
|
|
|
<ComicBoxButton
|
|
|
|
label={primaryButton.text}
|
|
|
|
icon={primaryButton.icon}
|
|
|
|
title={primaryButton.comicBox?.title}
|
|
|
|
description={primaryButton.comicBox?.description}
|
|
|
|
onClick={primaryButtonOnClick}
|
|
|
|
disabled={!isEditingAllowed}
|
2024-01-25 08:53:55 +00:00
|
|
|
/>
|
2024-03-06 14:46:54 +00:00
|
|
|
);
|
|
|
|
} else if (primaryButtonLink) {
|
|
|
|
return (
|
|
|
|
<Link href={primaryButtonLink}>
|
|
|
|
<Button {...commonProps}>{primaryButton.text}</Button>
|
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return <Button {...commonProps}>{primaryButton.text}</Button>;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
// secondary button
|
|
|
|
const renderSecondaryButton = () => {
|
|
|
|
if (!secondaryButton) return null;
|
2024-01-24 13:42:54 +00:00
|
|
|
|
2024-03-06 14:46:54 +00:00
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
size={size}
|
|
|
|
variant="neutral-primary"
|
|
|
|
prependIcon={secondaryButton.icon}
|
|
|
|
onClick={secondaryButtonOnClick}
|
|
|
|
disabled={!isEditingAllowed}
|
|
|
|
>
|
|
|
|
{secondaryButton.text}
|
|
|
|
</Button>
|
|
|
|
);
|
|
|
|
};
|
2024-01-24 13:42:54 +00:00
|
|
|
|
2024-03-06 14:46:54 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{layout === "screen-detailed" && (
|
|
|
|
<div className="flex items-center justify-center min-h-full min-w-full overflow-y-auto py-10 md:px-20 px-5">
|
|
|
|
<div
|
|
|
|
className={cn("flex flex-col gap-5", {
|
|
|
|
"md:min-w-[24rem] max-w-[45rem]": size === "sm",
|
|
|
|
"md:min-w-[30rem] max-w-[60rem]": size === "lg",
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<div className="flex flex-col gap-1.5 flex-shrink">
|
|
|
|
{description ? (
|
|
|
|
<>
|
|
|
|
<h3 className="text-xl font-semibold">{title}</h3>
|
|
|
|
<p className="text-sm">{description}</p>
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<h3 className="text-xl font-medium">{title}</h3>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{path && (
|
|
|
|
<Image
|
|
|
|
src={resolvedEmptyStatePath}
|
|
|
|
alt={key || "button image"}
|
|
|
|
width={384}
|
|
|
|
height={250}
|
|
|
|
layout="responsive"
|
|
|
|
lazyBoundary="100%"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{anyButton && (
|
|
|
|
<>
|
|
|
|
<div className="relative flex items-center justify-center gap-2 flex-shrink-0 w-full">
|
|
|
|
{renderPrimaryButton()}
|
|
|
|
{renderSecondaryButton()}
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
2024-01-24 13:42:54 +00:00
|
|
|
</div>
|
2024-03-06 14:46:54 +00:00
|
|
|
)}
|
|
|
|
</>
|
2024-01-24 13:42:54 +00:00
|
|
|
);
|
|
|
|
};
|