2023-03-15 05:31:54 +00:00
|
|
|
import React from "react";
|
|
|
|
import Image from "next/image";
|
|
|
|
|
2023-03-22 11:28:32 +00:00
|
|
|
// ui
|
|
|
|
import { PrimaryButton } from "components/ui";
|
2023-03-15 05:31:54 +00:00
|
|
|
// icon
|
|
|
|
import { PlusIcon } from "@heroicons/react/24/outline";
|
|
|
|
// helper
|
|
|
|
import { capitalizeFirstLetter } from "helpers/string.helper";
|
|
|
|
|
|
|
|
type Props = {
|
2023-04-24 13:23:18 +00:00
|
|
|
type: "cycle" | "module" | "project" | "issue" | "view" | "page" | "estimate";
|
2023-03-15 05:31:54 +00:00
|
|
|
title: string;
|
|
|
|
description: React.ReactNode | string;
|
|
|
|
imgURL: string;
|
2023-03-22 09:17:13 +00:00
|
|
|
action?: () => void;
|
2023-03-15 05:31:54 +00:00
|
|
|
};
|
|
|
|
|
2023-03-22 09:17:13 +00:00
|
|
|
export const EmptyState: React.FC<Props> = ({ type, title, description, imgURL, action }) => {
|
2023-03-15 05:31:54 +00:00
|
|
|
const shortcutKey = (type: string) => {
|
|
|
|
switch (type) {
|
|
|
|
case "cycle":
|
|
|
|
return "Q";
|
|
|
|
case "module":
|
|
|
|
return "M";
|
|
|
|
case "project":
|
|
|
|
return "P";
|
2023-03-22 09:17:13 +00:00
|
|
|
case "issue":
|
2023-03-15 05:31:54 +00:00
|
|
|
return "C";
|
2023-04-03 08:53:50 +00:00
|
|
|
case "view":
|
|
|
|
return "V";
|
|
|
|
case "page":
|
2023-04-24 13:23:18 +00:00
|
|
|
return "D";
|
2023-03-22 09:17:13 +00:00
|
|
|
default:
|
|
|
|
return null;
|
2023-03-15 05:31:54 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
return (
|
|
|
|
<div className="flex h-full w-full flex-col items-center justify-center gap-5 text-center">
|
|
|
|
<div className="h-32 w-72">
|
|
|
|
<Image src={imgURL} height="128" width="288" alt={type} />
|
|
|
|
</div>
|
|
|
|
|
2023-04-24 13:23:18 +00:00
|
|
|
<h3 className="text-xl font-semibold">{title}</h3>
|
2023-03-22 09:17:13 +00:00
|
|
|
{shortcutKey(type) && (
|
|
|
|
<span>
|
|
|
|
Use shortcut{" "}
|
2023-04-24 13:23:18 +00:00
|
|
|
<span className="text-brand-muted-1 mx-1 rounded-sm border border-brand-base bg-brand-surface-1 px-2 py-1 text-sm font-medium">
|
2023-03-22 09:17:13 +00:00
|
|
|
{shortcutKey(type)}
|
|
|
|
</span>{" "}
|
|
|
|
to create {type} from anywhere.
|
|
|
|
</span>
|
|
|
|
)}
|
2023-04-20 08:11:24 +00:00
|
|
|
<p className="max-w-md text-sm text-brand-secondary">{description}</p>
|
2023-03-15 05:31:54 +00:00
|
|
|
|
2023-03-22 11:28:32 +00:00
|
|
|
<PrimaryButton
|
|
|
|
className="flex items-center gap-1"
|
2023-03-15 05:31:54 +00:00
|
|
|
onClick={() => {
|
2023-03-22 09:17:13 +00:00
|
|
|
if (action) {
|
|
|
|
action();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!shortcutKey(type)) return;
|
|
|
|
|
2023-03-15 05:31:54 +00:00
|
|
|
const e = new KeyboardEvent("keydown", {
|
2023-03-22 09:17:13 +00:00
|
|
|
key: shortcutKey(type) as string,
|
2023-03-15 05:31:54 +00:00
|
|
|
});
|
|
|
|
document.dispatchEvent(e);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<PlusIcon className="h-4 w-4 font-bold text-white" />
|
|
|
|
Create New {capitalizeFirstLetter(type)}
|
2023-03-22 11:28:32 +00:00
|
|
|
</PrimaryButton>
|
2023-03-15 05:31:54 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|