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-03-25 18:09:46 +00:00
|
|
|
type: "cycle" | "module" | "project" | "issue" | "view" | "page";
|
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-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>
|
|
|
|
|
|
|
|
<h3 className="text-xl font-semibold">{title}</h3>
|
2023-03-22 09:17:13 +00:00
|
|
|
{shortcutKey(type) && (
|
|
|
|
<span>
|
|
|
|
Use shortcut{" "}
|
|
|
|
<span className="mx-1 rounded-sm border border-gray-200 bg-gray-100 px-2 py-1 text-sm font-medium text-gray-800">
|
|
|
|
{shortcutKey(type)}
|
|
|
|
</span>{" "}
|
|
|
|
to create {type} from anywhere.
|
|
|
|
</span>
|
|
|
|
)}
|
2023-03-15 05:31:54 +00:00
|
|
|
<p className="max-w-md text-sm text-gray-500">{description}</p>
|
|
|
|
|
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>
|
|
|
|
);
|
|
|
|
};
|