2023-08-30 07:56:28 +00:00
|
|
|
import React, { useEffect, useState } from "react";
|
2023-08-25 12:11:23 +00:00
|
|
|
|
2023-08-30 07:56:28 +00:00
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
2023-09-01 08:22:55 +00:00
|
|
|
import { mutate } from "swr";
|
2023-08-30 07:56:28 +00:00
|
|
|
// mobx
|
|
|
|
import { observer } from "mobx-react-lite";
|
|
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
2023-08-25 12:11:23 +00:00
|
|
|
// headless ui
|
|
|
|
import { Dialog, Transition } from "@headlessui/react";
|
2023-08-30 07:56:28 +00:00
|
|
|
// hooks
|
|
|
|
import useUser from "hooks/use-user";
|
|
|
|
// components
|
2023-09-01 08:22:55 +00:00
|
|
|
import { DeleteIssueModal, FullScreenPeekView, SidePeekView } from "components/issues";
|
2023-08-25 12:11:23 +00:00
|
|
|
// types
|
|
|
|
import { IIssue } from "types";
|
2023-09-01 08:22:55 +00:00
|
|
|
// fetch-keys
|
|
|
|
import { PROJECT_ISSUES_ACTIVITY } from "constants/fetch-keys";
|
2023-08-25 12:11:23 +00:00
|
|
|
|
|
|
|
type Props = {
|
2023-08-30 07:56:28 +00:00
|
|
|
handleMutation: () => void;
|
|
|
|
projectId: string;
|
2023-08-25 12:11:23 +00:00
|
|
|
readOnly: boolean;
|
2023-08-30 07:56:28 +00:00
|
|
|
workspaceSlug: string;
|
2023-08-25 12:11:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export type TPeekOverviewModes = "side" | "modal" | "full";
|
|
|
|
|
2023-08-30 07:56:28 +00:00
|
|
|
export const IssuePeekOverview: React.FC<Props> = observer(
|
|
|
|
({ handleMutation, projectId, readOnly, workspaceSlug }) => {
|
|
|
|
const [isSidePeekOpen, setIsSidePeekOpen] = useState(false);
|
|
|
|
const [isModalPeekOpen, setIsModalPeekOpen] = useState(false);
|
|
|
|
const [peekOverviewMode, setPeekOverviewMode] = useState<TPeekOverviewModes>("side");
|
2023-09-01 08:22:55 +00:00
|
|
|
const [deleteIssueModal, setDeleteIssueModal] = useState(false);
|
2023-08-30 07:56:28 +00:00
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
const { peekIssue } = router.query;
|
|
|
|
|
|
|
|
const { issues: issuesStore } = useMobxStore();
|
|
|
|
const { deleteIssue, getIssueById, issues, updateIssue } = issuesStore;
|
|
|
|
|
|
|
|
const issue = issues[peekIssue?.toString() ?? ""];
|
|
|
|
|
|
|
|
const { user } = useUser();
|
|
|
|
|
|
|
|
const handleClose = () => {
|
|
|
|
const { query } = router;
|
|
|
|
delete query.peekIssue;
|
|
|
|
|
|
|
|
router.push({
|
|
|
|
pathname: router.pathname,
|
|
|
|
query: { ...query },
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleUpdateIssue = async (formData: Partial<IIssue>) => {
|
|
|
|
if (!issue || !user) return;
|
|
|
|
|
|
|
|
await updateIssue(workspaceSlug, projectId, issue.id, formData, user);
|
2023-09-01 08:22:55 +00:00
|
|
|
mutate(PROJECT_ISSUES_ACTIVITY(issue.id));
|
2023-08-30 07:56:28 +00:00
|
|
|
handleMutation();
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleDeleteIssue = async () => {
|
|
|
|
if (!issue || !user) return;
|
|
|
|
|
|
|
|
await deleteIssue(workspaceSlug, projectId, issue.id, user);
|
|
|
|
handleMutation();
|
|
|
|
|
|
|
|
handleClose();
|
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (!peekIssue) return;
|
|
|
|
|
|
|
|
getIssueById(workspaceSlug, projectId, peekIssue.toString());
|
|
|
|
}, [getIssueById, peekIssue, projectId, workspaceSlug]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (peekIssue) {
|
|
|
|
if (peekOverviewMode === "side") {
|
|
|
|
setIsSidePeekOpen(true);
|
|
|
|
setIsModalPeekOpen(false);
|
|
|
|
} else {
|
|
|
|
setIsModalPeekOpen(true);
|
|
|
|
setIsSidePeekOpen(false);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
setIsSidePeekOpen(false);
|
|
|
|
setIsModalPeekOpen(false);
|
|
|
|
}
|
|
|
|
}, [peekIssue, peekOverviewMode]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2023-09-01 08:22:55 +00:00
|
|
|
<DeleteIssueModal
|
|
|
|
isOpen={deleteIssueModal}
|
|
|
|
handleClose={() => setDeleteIssueModal(false)}
|
|
|
|
data={issue ? { ...issue } : null}
|
|
|
|
onSubmit={handleDeleteIssue}
|
|
|
|
user={user}
|
|
|
|
/>
|
2023-08-30 07:56:28 +00:00
|
|
|
<Transition.Root appear show={isSidePeekOpen} as={React.Fragment}>
|
|
|
|
<Dialog as="div" className="relative z-20" onClose={handleClose}>
|
2023-09-01 08:22:55 +00:00
|
|
|
<div className="fixed inset-0 z-20 h-full w-full overflow-y-auto">
|
|
|
|
<Transition.Child
|
|
|
|
as={React.Fragment}
|
|
|
|
enter="transition-transform duration-300"
|
|
|
|
enterFrom="translate-x-full"
|
|
|
|
enterTo="translate-x-0"
|
|
|
|
leave="transition-transform duration-200"
|
|
|
|
leaveFrom="translate-x-0"
|
|
|
|
leaveTo="translate-x-full"
|
|
|
|
>
|
|
|
|
<Dialog.Panel className="fixed z-20 bg-custom-background-100 top-0 right-0 h-full w-1/2 shadow-custom-shadow-md">
|
|
|
|
<SidePeekView
|
|
|
|
handleClose={handleClose}
|
|
|
|
handleDeleteIssue={() => setDeleteIssueModal(true)}
|
|
|
|
handleUpdateIssue={handleUpdateIssue}
|
|
|
|
issue={issue}
|
|
|
|
mode={peekOverviewMode}
|
|
|
|
readOnly={readOnly}
|
|
|
|
setMode={(mode) => setPeekOverviewMode(mode)}
|
|
|
|
workspaceSlug={workspaceSlug}
|
|
|
|
/>
|
|
|
|
</Dialog.Panel>
|
|
|
|
</Transition.Child>
|
2023-08-30 07:56:28 +00:00
|
|
|
</div>
|
|
|
|
</Dialog>
|
|
|
|
</Transition.Root>
|
|
|
|
<Transition.Root appear show={isModalPeekOpen} as={React.Fragment}>
|
|
|
|
<Dialog as="div" className="relative z-20" onClose={handleClose}>
|
2023-08-25 12:11:23 +00:00
|
|
|
<Transition.Child
|
|
|
|
as={React.Fragment}
|
|
|
|
enter="ease-out duration-300"
|
2023-08-30 07:56:28 +00:00
|
|
|
enterFrom="opacity-0"
|
|
|
|
enterTo="opacity-100"
|
2023-08-25 12:11:23 +00:00
|
|
|
leave="ease-in duration-200"
|
2023-08-30 07:56:28 +00:00
|
|
|
leaveFrom="opacity-100"
|
|
|
|
leaveTo="opacity-0"
|
2023-08-25 12:11:23 +00:00
|
|
|
>
|
2023-08-30 07:56:28 +00:00
|
|
|
<div className="fixed inset-0 bg-custom-backdrop bg-opacity-50 transition-opacity" />
|
2023-08-25 12:11:23 +00:00
|
|
|
</Transition.Child>
|
2023-09-01 08:22:55 +00:00
|
|
|
<div className="fixed inset-0 z-20 h-full w-full overflow-y-auto">
|
|
|
|
<Transition.Child
|
|
|
|
as={React.Fragment}
|
|
|
|
enter="ease-out duration-300"
|
|
|
|
enterFrom="opacity-0"
|
|
|
|
enterTo="opacity-100"
|
|
|
|
leave="ease-in duration-200"
|
|
|
|
leaveFrom="opacity-100"
|
|
|
|
leaveTo="opacity-0"
|
|
|
|
>
|
2023-09-03 05:55:37 +00:00
|
|
|
<Dialog.Panel>
|
|
|
|
<div
|
|
|
|
className={`fixed z-20 bg-custom-background-100 top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 rounded-lg shadow-custom-shadow-xl transition-all duration-300 ${
|
|
|
|
peekOverviewMode === "modal" ? "h-[70%] w-3/5" : "h-[95%] w-[95%]"
|
|
|
|
}`}
|
|
|
|
>
|
|
|
|
{peekOverviewMode === "modal" && (
|
|
|
|
<SidePeekView
|
|
|
|
handleClose={handleClose}
|
|
|
|
handleDeleteIssue={() => setDeleteIssueModal(true)}
|
|
|
|
handleUpdateIssue={handleUpdateIssue}
|
|
|
|
issue={issue}
|
|
|
|
mode={peekOverviewMode}
|
|
|
|
readOnly={readOnly}
|
|
|
|
setMode={(mode) => setPeekOverviewMode(mode)}
|
|
|
|
workspaceSlug={workspaceSlug}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{peekOverviewMode === "full" && (
|
|
|
|
<FullScreenPeekView
|
|
|
|
handleClose={handleClose}
|
|
|
|
handleDeleteIssue={() => setDeleteIssueModal(true)}
|
|
|
|
handleUpdateIssue={handleUpdateIssue}
|
|
|
|
issue={issue}
|
|
|
|
mode={peekOverviewMode}
|
|
|
|
readOnly={readOnly}
|
|
|
|
setMode={(mode) => setPeekOverviewMode(mode)}
|
|
|
|
workspaceSlug={workspaceSlug}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
2023-09-01 08:22:55 +00:00
|
|
|
</Dialog.Panel>
|
|
|
|
</Transition.Child>
|
2023-08-30 07:56:28 +00:00
|
|
|
</div>
|
|
|
|
</Dialog>
|
|
|
|
</Transition.Root>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|