2023-08-30 18:42:45 +00:00
|
|
|
import { useRouter } from "next/router";
|
|
|
|
import { ArrowRightAlt, CloseFullscreen, East, OpenInFull } from "@mui/icons-material";
|
2023-08-30 07:19:15 +00:00
|
|
|
// hooks
|
|
|
|
import useToast from "hooks/use-toast";
|
|
|
|
// ui
|
|
|
|
import { Icon } from "components/ui";
|
|
|
|
// helpers
|
|
|
|
import { copyTextToClipboard } from "helpers/string.helper";
|
2023-08-30 18:42:45 +00:00
|
|
|
// store
|
|
|
|
import { IPeekMode } from "store/issue_details";
|
|
|
|
import { RootStore } from "store/root";
|
|
|
|
// lib
|
|
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
2023-08-30 07:19:15 +00:00
|
|
|
// types
|
2023-08-30 18:42:45 +00:00
|
|
|
import { IIssue } from "types";
|
2023-08-30 07:19:15 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
handleClose: () => void;
|
2023-08-30 18:42:45 +00:00
|
|
|
issueDetails: IIssue;
|
2023-08-30 07:19:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const peekModes: {
|
2023-08-30 18:42:45 +00:00
|
|
|
key: IPeekMode;
|
2023-08-30 07:19:15 +00:00
|
|
|
icon: string;
|
|
|
|
label: string;
|
|
|
|
}[] = [
|
|
|
|
{ key: "side", icon: "side_navigation", label: "Side Peek" },
|
|
|
|
{
|
|
|
|
key: "modal",
|
|
|
|
icon: "dialogs",
|
|
|
|
label: "Modal Peek",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "full",
|
|
|
|
icon: "nearby",
|
|
|
|
label: "Full Screen Peek",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2023-08-30 18:42:45 +00:00
|
|
|
export const PeekOverviewHeader: React.FC<Props> = (props) => {
|
|
|
|
const { issueDetails, handleClose } = props;
|
|
|
|
|
|
|
|
const { issueDetails: issueDetailStore }: RootStore = useMobxStore();
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug } = router.query;
|
|
|
|
|
2023-08-30 07:19:15 +00:00
|
|
|
const { setToastAlert } = useToast();
|
|
|
|
|
|
|
|
const handleCopyLink = () => {
|
|
|
|
const originURL = typeof window !== "undefined" && window.location.origin ? window.location.origin : "";
|
|
|
|
|
2023-08-30 18:42:45 +00:00
|
|
|
copyTextToClipboard(`${originURL}/${workspaceSlug}/projects/${issueDetails.project}/`).then(() => {
|
2023-08-30 07:19:15 +00:00
|
|
|
setToastAlert({
|
|
|
|
type: "success",
|
|
|
|
title: "Link copied!",
|
|
|
|
message: "Issue link copied to clipboard",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="flex justify-between items-center">
|
|
|
|
<div className="flex items-center gap-4">
|
2023-08-30 18:42:45 +00:00
|
|
|
{issueDetailStore.peekMode === "side" && (
|
2023-08-30 07:19:15 +00:00
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
onClick={() => {
|
|
|
|
handleClose();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<East
|
|
|
|
sx={{
|
|
|
|
fontSize: "14px",
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
)}
|
2023-08-30 18:42:45 +00:00
|
|
|
{issueDetailStore.peekMode === "modal" || issueDetailStore.peekMode === "full" ? (
|
|
|
|
<button type="button" onClick={() => issueDetailStore.setPeekMode("side")}>
|
2023-08-30 07:19:15 +00:00
|
|
|
<CloseFullscreen
|
|
|
|
sx={{
|
|
|
|
fontSize: "14px",
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
) : (
|
2023-08-30 18:42:45 +00:00
|
|
|
<button type="button" onClick={() => issueDetailStore.setPeekMode("modal")}>
|
2023-08-30 07:19:15 +00:00
|
|
|
<OpenInFull
|
|
|
|
sx={{
|
|
|
|
fontSize: "14px",
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
)}
|
2023-08-30 18:42:45 +00:00
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className={`grid place-items-center ${issueDetailStore.peekMode === "full" ? "rotate-45" : ""}`}
|
|
|
|
>
|
|
|
|
<Icon iconName={peekModes.find((m) => m.key === issueDetailStore.peekMode)?.icon ?? ""} />
|
2023-08-30 07:19:15 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
2023-08-30 18:42:45 +00:00
|
|
|
{(issueDetailStore.peekMode === "side" || issueDetailStore.peekMode === "modal") && (
|
2023-08-30 07:19:15 +00:00
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
<button type="button" onClick={handleCopyLink} className="-rotate-45">
|
|
|
|
<Icon iconName="link" />
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|