2023-08-30 07:56:28 +00:00
|
|
|
import Link from "next/link";
|
|
|
|
|
2023-08-25 12:11:23 +00:00
|
|
|
// hooks
|
|
|
|
import useToast from "hooks/use-toast";
|
|
|
|
// ui
|
2023-11-03 12:31:34 +00:00
|
|
|
import { CenterPanelIcon, CustomSelect, FullScreenPanelIcon, SidePanelIcon } from "@plane/ui";
|
2023-08-30 07:56:28 +00:00
|
|
|
// icons
|
2023-11-03 12:31:34 +00:00
|
|
|
import { LinkIcon, MoveDiagonal, MoveRight, Trash2 } from "lucide-react";
|
2023-08-25 12:11:23 +00:00
|
|
|
// helpers
|
|
|
|
import { copyTextToClipboard } from "helpers/string.helper";
|
|
|
|
// types
|
|
|
|
import { IIssue } from "types";
|
|
|
|
import { TPeekOverviewModes } from "./layout";
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
handleClose: () => void;
|
|
|
|
handleDeleteIssue: () => void;
|
2023-08-30 07:56:28 +00:00
|
|
|
issue: IIssue | undefined;
|
2023-08-25 12:11:23 +00:00
|
|
|
mode: TPeekOverviewModes;
|
|
|
|
setMode: (mode: TPeekOverviewModes) => void;
|
|
|
|
workspaceSlug: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
const peekModes: {
|
|
|
|
key: TPeekOverviewModes;
|
2023-10-16 14:57:22 +00:00
|
|
|
icon: any;
|
2023-08-25 12:11:23 +00:00
|
|
|
label: string;
|
|
|
|
}[] = [
|
2023-11-03 12:31:34 +00:00
|
|
|
{ key: "side", icon: SidePanelIcon, label: "Side Peek" },
|
2023-08-25 12:11:23 +00:00
|
|
|
{
|
|
|
|
key: "modal",
|
2023-11-03 12:31:34 +00:00
|
|
|
icon: CenterPanelIcon,
|
2023-08-25 12:11:23 +00:00
|
|
|
label: "Modal Peek",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "full",
|
2023-11-03 12:31:34 +00:00
|
|
|
icon: FullScreenPanelIcon,
|
2023-08-25 12:11:23 +00:00
|
|
|
label: "Full Screen Peek",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
export const PeekOverviewHeader: React.FC<Props> = ({
|
|
|
|
issue,
|
|
|
|
handleClose,
|
|
|
|
handleDeleteIssue,
|
|
|
|
mode,
|
|
|
|
setMode,
|
|
|
|
workspaceSlug,
|
|
|
|
}) => {
|
|
|
|
const { setToastAlert } = useToast();
|
|
|
|
|
|
|
|
const handleCopyLink = () => {
|
2023-08-30 07:56:28 +00:00
|
|
|
const urlToCopy = window.location.href;
|
2023-08-25 12:11:23 +00:00
|
|
|
|
2023-08-30 07:56:28 +00:00
|
|
|
copyTextToClipboard(urlToCopy).then(() => {
|
2023-08-25 12:11:23 +00:00
|
|
|
setToastAlert({
|
|
|
|
type: "success",
|
|
|
|
title: "Link copied!",
|
|
|
|
message: "Issue link copied to clipboard",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2023-10-16 14:57:22 +00:00
|
|
|
const currentMode = peekModes.find((m) => m.key === mode);
|
|
|
|
|
2023-08-25 12:11:23 +00:00
|
|
|
return (
|
|
|
|
<div className="flex justify-between items-center">
|
|
|
|
<div className="flex items-center gap-4">
|
|
|
|
{mode === "side" && (
|
|
|
|
<button type="button" onClick={handleClose}>
|
2023-10-16 14:57:22 +00:00
|
|
|
<MoveRight className="h-3.5 w-3.5" />
|
2023-08-25 12:11:23 +00:00
|
|
|
</button>
|
|
|
|
)}
|
2023-08-30 07:56:28 +00:00
|
|
|
<Link href={`/${workspaceSlug}/projects/${issue?.project}/issues/${issue?.id}`}>
|
|
|
|
<a>
|
2023-11-03 12:31:34 +00:00
|
|
|
<MoveDiagonal className="h-3.5 w-3.5" />
|
2023-08-30 07:56:28 +00:00
|
|
|
</a>
|
|
|
|
</Link>
|
2023-08-25 12:11:23 +00:00
|
|
|
<CustomSelect
|
|
|
|
value={mode}
|
|
|
|
onChange={(val: TPeekOverviewModes) => setMode(val)}
|
|
|
|
customButton={
|
2023-10-16 14:57:22 +00:00
|
|
|
<button type="button" className={`grid place-items-center ${mode === "full" ? "rotate-45" : ""}`}>
|
|
|
|
{currentMode && <currentMode.icon className="h-3.5 w-3.5" />}
|
2023-08-25 12:11:23 +00:00
|
|
|
</button>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{peekModes.map((mode) => (
|
|
|
|
<CustomSelect.Option key={mode.key} value={mode.key}>
|
|
|
|
<div className="flex items-center gap-1.5">
|
2023-10-16 14:57:22 +00:00
|
|
|
<mode.icon className={`h-4 w-4 flex-shrink-0 -my-1 ${mode.key === "full" ? "rotate-45" : ""}`} />
|
2023-08-25 12:11:23 +00:00
|
|
|
{mode.label}
|
|
|
|
</div>
|
|
|
|
</CustomSelect.Option>
|
|
|
|
))}
|
|
|
|
</CustomSelect>
|
|
|
|
</div>
|
|
|
|
{(mode === "side" || mode === "modal") && (
|
2023-08-30 07:56:28 +00:00
|
|
|
<div className="flex items-center gap-2 flex-shrink-0">
|
2023-08-25 12:11:23 +00:00
|
|
|
<button type="button" onClick={handleCopyLink} className="-rotate-45">
|
2023-10-16 14:57:22 +00:00
|
|
|
<LinkIcon className="h-3.5 w-3.5" />
|
2023-08-25 12:11:23 +00:00
|
|
|
</button>
|
|
|
|
<button type="button" onClick={handleDeleteIssue}>
|
2023-10-16 14:57:22 +00:00
|
|
|
<Trash2 className="h-3.5 w-3.5" />
|
2023-08-25 12:11:23 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|