2023-04-11 17:49:47 +00:00
|
|
|
import React, { useCallback, useEffect, useRef, useState } from "react";
|
2023-03-23 05:31:06 +00:00
|
|
|
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
|
|
|
import useSWR, { mutate } from "swr";
|
|
|
|
|
2023-03-25 18:09:46 +00:00
|
|
|
// react-hook-form
|
|
|
|
import { useForm } from "react-hook-form";
|
|
|
|
// headless ui
|
|
|
|
import { Popover, Transition } from "@headlessui/react";
|
|
|
|
// react-color
|
|
|
|
import { TwitterPicker } from "react-color";
|
2023-04-03 18:00:29 +00:00
|
|
|
// react-beautiful-dnd
|
|
|
|
import { DragDropContext, DropResult } from "react-beautiful-dnd";
|
|
|
|
import StrictModeDroppable from "components/dnd/StrictModeDroppable";
|
2023-03-23 05:31:06 +00:00
|
|
|
// services
|
|
|
|
import projectService from "services/project.service";
|
2023-03-25 18:09:46 +00:00
|
|
|
import pagesService from "services/pages.service";
|
|
|
|
import issuesService from "services/issues.service";
|
|
|
|
// hooks
|
|
|
|
import useToast from "hooks/use-toast";
|
2023-04-11 06:40:22 +00:00
|
|
|
import useUser from "hooks/use-user";
|
2023-03-23 05:31:06 +00:00
|
|
|
// layouts
|
2023-04-08 08:16:46 +00:00
|
|
|
import { ProjectAuthorizationWrapper } from "layouts/auth-layout";
|
2023-03-25 18:09:46 +00:00
|
|
|
// components
|
2023-04-03 18:00:29 +00:00
|
|
|
import { CreateUpdateBlockInline, SinglePageBlock } from "components/pages";
|
2023-04-25 06:38:56 +00:00
|
|
|
import { CreateLabelModal } from "components/labels";
|
2023-03-23 05:31:06 +00:00
|
|
|
// ui
|
|
|
|
import { BreadcrumbItem, Breadcrumbs } from "components/breadcrumbs";
|
2023-03-28 18:50:00 +00:00
|
|
|
import { CustomSearchSelect, Loader, PrimaryButton, TextArea, Tooltip } from "components/ui";
|
2023-03-25 18:09:46 +00:00
|
|
|
// icons
|
2023-04-03 18:00:29 +00:00
|
|
|
import {
|
|
|
|
ArrowLeftIcon,
|
|
|
|
LockClosedIcon,
|
|
|
|
LockOpenIcon,
|
|
|
|
PlusIcon,
|
|
|
|
StarIcon,
|
2023-04-11 17:49:47 +00:00
|
|
|
LinkIcon,
|
2023-04-12 12:37:50 +00:00
|
|
|
XMarkIcon,
|
2023-04-03 18:00:29 +00:00
|
|
|
} from "@heroicons/react/24/outline";
|
2023-04-11 12:48:49 +00:00
|
|
|
import { ColorPalletteIcon, ClipboardIcon } from "components/icons";
|
2023-03-25 18:09:46 +00:00
|
|
|
// helpers
|
2023-04-11 12:48:49 +00:00
|
|
|
import { renderShortTime, renderShortDate } from "helpers/date-time.helper";
|
2023-03-25 18:09:46 +00:00
|
|
|
import { copyTextToClipboard } from "helpers/string.helper";
|
2023-04-03 18:00:29 +00:00
|
|
|
import { orderArrayBy } from "helpers/array.helper";
|
2023-03-23 05:31:06 +00:00
|
|
|
// types
|
2023-04-08 08:16:46 +00:00
|
|
|
import type { NextPage } from "next";
|
|
|
|
import { IIssueLabels, IPage, IPageBlock } from "types";
|
2023-03-25 18:09:46 +00:00
|
|
|
// fetch-keys
|
|
|
|
import {
|
|
|
|
PAGE_BLOCKS_LIST,
|
|
|
|
PAGE_DETAILS,
|
|
|
|
PROJECT_DETAILS,
|
|
|
|
PROJECT_ISSUE_LABELS,
|
|
|
|
} from "constants/fetch-keys";
|
2023-03-23 05:31:06 +00:00
|
|
|
|
2023-04-08 08:16:46 +00:00
|
|
|
const SinglePage: NextPage = () => {
|
2023-04-03 18:00:29 +00:00
|
|
|
const [createBlockForm, setCreateBlockForm] = useState(false);
|
2023-04-25 06:38:56 +00:00
|
|
|
const [labelModal, setLabelModal] = useState(false);
|
2023-03-27 17:49:05 +00:00
|
|
|
|
2023-04-04 10:51:46 +00:00
|
|
|
const scrollToRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
2023-03-25 18:09:46 +00:00
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug, projectId, pageId } = router.query;
|
2023-03-23 05:31:06 +00:00
|
|
|
|
|
|
|
const { setToastAlert } = useToast();
|
|
|
|
|
2023-04-11 06:40:22 +00:00
|
|
|
const { user } = useUser();
|
|
|
|
|
2023-04-03 18:00:29 +00:00
|
|
|
const { handleSubmit, reset, watch, setValue } = useForm<IPage>({
|
2023-03-25 18:09:46 +00:00
|
|
|
defaultValues: { name: "" },
|
|
|
|
});
|
|
|
|
|
|
|
|
const { data: projectDetails } = useSWR(
|
2023-03-23 05:31:06 +00:00
|
|
|
workspaceSlug && projectId ? PROJECT_DETAILS(projectId as string) : null,
|
|
|
|
workspaceSlug && projectId
|
|
|
|
? () => projectService.getProject(workspaceSlug as string, projectId as string)
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
|
2023-03-25 18:09:46 +00:00
|
|
|
const { data: pageDetails } = useSWR(
|
|
|
|
workspaceSlug && projectId && pageId ? PAGE_DETAILS(pageId as string) : null,
|
|
|
|
workspaceSlug && projectId
|
|
|
|
? () =>
|
2023-04-03 12:44:50 +00:00
|
|
|
pagesService.getPageDetails(
|
|
|
|
workspaceSlug as string,
|
|
|
|
projectId as string,
|
|
|
|
pageId as string
|
|
|
|
)
|
2023-03-25 18:09:46 +00:00
|
|
|
: null
|
|
|
|
);
|
|
|
|
|
2023-03-23 05:31:06 +00:00
|
|
|
const { data: pageBlocks } = useSWR(
|
2023-03-25 18:09:46 +00:00
|
|
|
workspaceSlug && projectId && pageId ? PAGE_BLOCKS_LIST(pageId as string) : null,
|
2023-03-23 05:31:06 +00:00
|
|
|
workspaceSlug && projectId
|
|
|
|
? () =>
|
2023-04-03 12:44:50 +00:00
|
|
|
pagesService.listPageBlocks(
|
|
|
|
workspaceSlug as string,
|
|
|
|
projectId as string,
|
|
|
|
pageId as string
|
|
|
|
)
|
2023-03-23 05:31:06 +00:00
|
|
|
: null
|
|
|
|
);
|
|
|
|
|
2023-03-25 18:09:46 +00:00
|
|
|
const { data: labels } = useSWR<IIssueLabels[]>(
|
|
|
|
workspaceSlug && projectId ? PROJECT_ISSUE_LABELS(projectId as string) : null,
|
|
|
|
workspaceSlug && projectId
|
|
|
|
? () => issuesService.getIssueLabels(workspaceSlug as string, projectId as string)
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
|
|
|
|
const updatePage = async (formData: IPage) => {
|
|
|
|
if (!workspaceSlug || !projectId || !pageId) return;
|
|
|
|
|
|
|
|
if (!formData.name || formData.name.length === 0 || formData.name === "") return;
|
|
|
|
|
|
|
|
await pagesService
|
|
|
|
.patchPage(workspaceSlug as string, projectId as string, pageId as string, formData)
|
|
|
|
.then(() => {
|
|
|
|
mutate<IPage>(
|
|
|
|
PAGE_DETAILS(pageId as string),
|
|
|
|
(prevData) => ({
|
|
|
|
...prevData,
|
|
|
|
...formData,
|
|
|
|
}),
|
|
|
|
false
|
|
|
|
);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const partialUpdatePage = async (formData: Partial<IPage>) => {
|
|
|
|
if (!workspaceSlug || !projectId || !pageId) return;
|
|
|
|
|
|
|
|
mutate<IPage>(
|
|
|
|
PAGE_DETAILS(pageId as string),
|
|
|
|
(prevData) => ({
|
|
|
|
...(prevData as IPage),
|
|
|
|
...formData,
|
|
|
|
labels: formData.labels_list ? formData.labels_list : (prevData as IPage).labels,
|
|
|
|
}),
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
|
|
|
await pagesService
|
|
|
|
.patchPage(workspaceSlug as string, projectId as string, pageId as string, formData)
|
|
|
|
.then(() => {
|
|
|
|
mutate(PAGE_DETAILS(pageId as string));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleAddToFavorites = () => {
|
|
|
|
if (!workspaceSlug || !projectId || !pageId) return;
|
|
|
|
|
|
|
|
mutate<IPage>(
|
|
|
|
PAGE_DETAILS(pageId as string),
|
|
|
|
(prevData) => ({
|
|
|
|
...(prevData as IPage),
|
|
|
|
is_favorite: true,
|
|
|
|
}),
|
|
|
|
false
|
2023-04-11 12:48:49 +00:00
|
|
|
).then(() => {
|
|
|
|
setToastAlert({
|
|
|
|
type: "success",
|
|
|
|
title: "Success",
|
|
|
|
message: "Added to favorites",
|
|
|
|
});
|
2023-04-11 17:49:47 +00:00
|
|
|
});
|
2023-03-25 18:09:46 +00:00
|
|
|
|
|
|
|
pagesService.addPageToFavorites(workspaceSlug as string, projectId as string, {
|
|
|
|
page: pageId as string,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleRemoveFromFavorites = () => {
|
|
|
|
if (!workspaceSlug || !projectId || !pageId) return;
|
|
|
|
|
|
|
|
mutate<IPage>(
|
|
|
|
PAGE_DETAILS(pageId as string),
|
|
|
|
(prevData) => ({
|
|
|
|
...(prevData as IPage),
|
|
|
|
is_favorite: false,
|
|
|
|
}),
|
|
|
|
false
|
2023-04-11 12:48:49 +00:00
|
|
|
).then(() => {
|
|
|
|
setToastAlert({
|
|
|
|
type: "success",
|
|
|
|
title: "Success",
|
|
|
|
message: "Removed from favorites",
|
|
|
|
});
|
2023-04-11 17:49:47 +00:00
|
|
|
});
|
2023-03-25 18:09:46 +00:00
|
|
|
|
2023-04-11 17:49:47 +00:00
|
|
|
pagesService.removePageFromFavorites(
|
|
|
|
workspaceSlug as string,
|
|
|
|
projectId as string,
|
|
|
|
pageId as string
|
|
|
|
);
|
2023-03-25 18:09:46 +00:00
|
|
|
};
|
|
|
|
|
2023-04-03 18:00:29 +00:00
|
|
|
const handleOnDragEnd = (result: DropResult) => {
|
|
|
|
if (!result.destination || !workspaceSlug || !projectId || !pageId || !pageBlocks) return;
|
|
|
|
|
|
|
|
const { source, destination } = result;
|
|
|
|
|
|
|
|
let newSortOrder = pageBlocks.find((p) => p.id === result.draggableId)?.sort_order ?? 65535;
|
|
|
|
|
|
|
|
if (destination.index === 0) newSortOrder = pageBlocks[0].sort_order - 10000;
|
|
|
|
else if (destination.index === pageBlocks.length - 1)
|
|
|
|
newSortOrder = pageBlocks[pageBlocks.length - 1].sort_order + 10000;
|
|
|
|
else {
|
|
|
|
if (destination.index > source.index)
|
|
|
|
newSortOrder =
|
|
|
|
(pageBlocks[destination.index].sort_order +
|
|
|
|
pageBlocks[destination.index + 1].sort_order) /
|
|
|
|
2;
|
|
|
|
else if (destination.index < source.index)
|
|
|
|
newSortOrder =
|
|
|
|
(pageBlocks[destination.index - 1].sort_order +
|
|
|
|
pageBlocks[destination.index].sort_order) /
|
|
|
|
2;
|
|
|
|
}
|
|
|
|
|
|
|
|
const newBlocksList = pageBlocks.map((p) => ({
|
|
|
|
...p,
|
|
|
|
sort_order: p.id === result.draggableId ? newSortOrder : p.sort_order,
|
|
|
|
}));
|
|
|
|
mutate<IPageBlock[]>(
|
|
|
|
PAGE_BLOCKS_LIST(pageId as string),
|
|
|
|
orderArrayBy(newBlocksList, "sort_order", "ascending"),
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
|
|
|
pagesService.patchPageBlock(
|
|
|
|
workspaceSlug as string,
|
|
|
|
projectId as string,
|
|
|
|
pageId as string,
|
|
|
|
result.draggableId,
|
|
|
|
{
|
|
|
|
sort_order: newSortOrder,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-03-25 18:09:46 +00:00
|
|
|
const handleCopyText = () => {
|
|
|
|
const originURL =
|
|
|
|
typeof window !== "undefined" && window.location.origin ? window.location.origin : "";
|
|
|
|
|
|
|
|
copyTextToClipboard(`${originURL}/${workspaceSlug}/projects/${projectId}/pages/${pageId}`).then(
|
|
|
|
() => {
|
|
|
|
setToastAlert({
|
|
|
|
type: "success",
|
|
|
|
title: "Link Copied!",
|
|
|
|
message: "Page link copied to clipboard.",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-04-11 17:49:47 +00:00
|
|
|
const handleNewBlock = useCallback(() => {
|
2023-04-04 10:51:46 +00:00
|
|
|
setCreateBlockForm(true);
|
|
|
|
scrollToRef.current?.scrollIntoView({
|
|
|
|
behavior: "smooth",
|
|
|
|
});
|
2023-04-11 17:49:47 +00:00
|
|
|
}, [setCreateBlockForm, scrollToRef]);
|
2023-04-04 10:51:46 +00:00
|
|
|
|
2023-03-25 18:09:46 +00:00
|
|
|
const options =
|
|
|
|
labels?.map((label) => ({
|
|
|
|
value: label.id,
|
|
|
|
query: label.name,
|
|
|
|
content: (
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
<span
|
|
|
|
className="h-2 w-2 flex-shrink-0 rounded-full"
|
|
|
|
style={{
|
|
|
|
backgroundColor: label.color && label.color !== "" ? label.color : "#000000",
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
{label.name}
|
|
|
|
</div>
|
|
|
|
),
|
|
|
|
})) ?? [];
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (!pageDetails) return;
|
|
|
|
|
|
|
|
reset({
|
|
|
|
...pageDetails,
|
|
|
|
});
|
|
|
|
}, [reset, pageDetails]);
|
|
|
|
|
2023-04-11 17:49:47 +00:00
|
|
|
useEffect(() => {
|
|
|
|
const openCreateBlockForm = (e: KeyboardEvent) => {
|
|
|
|
if (e.shiftKey && e.key === "Enter") handleNewBlock();
|
|
|
|
};
|
|
|
|
|
|
|
|
window.addEventListener("keydown", openCreateBlockForm);
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
window.removeEventListener("keydown", openCreateBlockForm);
|
|
|
|
};
|
|
|
|
}, [handleNewBlock, createBlockForm]);
|
|
|
|
|
2023-03-23 05:31:06 +00:00
|
|
|
return (
|
2023-04-08 08:16:46 +00:00
|
|
|
<ProjectAuthorizationWrapper
|
2023-03-23 05:31:06 +00:00
|
|
|
meta={{
|
|
|
|
title: "Plane - Pages",
|
|
|
|
}}
|
|
|
|
breadcrumbs={
|
|
|
|
<Breadcrumbs>
|
|
|
|
<BreadcrumbItem title="Projects" link={`/${workspaceSlug}/projects`} />
|
2023-03-25 18:09:46 +00:00
|
|
|
<BreadcrumbItem title={`${projectDetails?.name ?? "Project"} Pages`} />
|
2023-03-23 05:31:06 +00:00
|
|
|
</Breadcrumbs>
|
|
|
|
}
|
|
|
|
>
|
2023-03-25 18:09:46 +00:00
|
|
|
{pageDetails ? (
|
2023-05-05 11:37:29 +00:00
|
|
|
<div className="space-y-4 p-4">
|
2023-03-25 18:09:46 +00:00
|
|
|
<div className="flex items-center justify-between gap-2 px-3">
|
|
|
|
<button
|
|
|
|
type="button"
|
2023-04-20 08:11:24 +00:00
|
|
|
className="flex items-center gap-2 text-sm text-brand-secondary"
|
2023-03-25 18:09:46 +00:00
|
|
|
onClick={() => router.back()}
|
|
|
|
>
|
|
|
|
<ArrowLeftIcon className="h-4 w-4" />
|
|
|
|
Back
|
|
|
|
</button>
|
|
|
|
<div className="flex flex-wrap gap-1">
|
|
|
|
{pageDetails.labels.length > 0 ? (
|
|
|
|
<>
|
|
|
|
{pageDetails.labels.map((labelId) => {
|
|
|
|
const label = labels?.find((label) => label.id === labelId);
|
|
|
|
|
|
|
|
if (!label) return;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
key={label.id}
|
2023-04-20 20:45:21 +00:00
|
|
|
className="group flex cursor-pointer items-center gap-1 rounded-2xl border border-brand-base px-2 py-0.5 text-xs hover:border-red-500 hover:bg-red-50"
|
2023-04-12 12:37:50 +00:00
|
|
|
onClick={() => {
|
|
|
|
const updatedLabels = pageDetails.labels.filter((l) => l !== labelId);
|
|
|
|
partialUpdatePage({ labels_list: updatedLabels });
|
|
|
|
}}
|
2023-03-25 18:09:46 +00:00
|
|
|
style={{
|
2023-04-03 12:44:50 +00:00
|
|
|
backgroundColor: `${
|
|
|
|
label?.color && label.color !== "" ? label.color : "#000000"
|
|
|
|
}20`,
|
2023-03-25 18:09:46 +00:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
<span
|
|
|
|
className="h-1.5 w-1.5 flex-shrink-0 rounded-full"
|
|
|
|
style={{
|
|
|
|
backgroundColor:
|
|
|
|
label?.color && label.color !== "" ? label.color : "#000000",
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
{label.name}
|
2023-04-12 12:37:50 +00:00
|
|
|
<XMarkIcon className="h-2.5 w-2.5 group-hover:text-red-500" />
|
2023-03-25 18:09:46 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
<CustomSearchSelect
|
|
|
|
customButton={
|
|
|
|
<button
|
|
|
|
type="button"
|
2023-04-21 05:16:04 +00:00
|
|
|
className="flex items-center gap-1 rounded-md bg-brand-surface-2 p-1.5 text-xs"
|
2023-03-25 18:09:46 +00:00
|
|
|
>
|
|
|
|
<PlusIcon className="h-3.5 w-3.5" />
|
|
|
|
</button>
|
|
|
|
}
|
|
|
|
value={pageDetails.labels}
|
|
|
|
onChange={(val: string[]) => partialUpdatePage({ labels_list: val })}
|
|
|
|
options={options}
|
|
|
|
multiple
|
|
|
|
noChevron
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<CustomSearchSelect
|
|
|
|
customButton={
|
|
|
|
<button
|
|
|
|
type="button"
|
2023-04-21 05:16:04 +00:00
|
|
|
className="flex items-center gap-1 rounded-md bg-brand-surface-2 px-3 py-1.5 text-xs"
|
2023-03-25 18:09:46 +00:00
|
|
|
>
|
|
|
|
<PlusIcon className="h-3 w-3" />
|
2023-04-11 12:48:49 +00:00
|
|
|
Add label
|
2023-03-25 18:09:46 +00:00
|
|
|
</button>
|
|
|
|
}
|
|
|
|
value={pageDetails.labels}
|
|
|
|
onChange={(val: string[]) => partialUpdatePage({ labels_list: val })}
|
2023-04-25 06:38:56 +00:00
|
|
|
footerOption={
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="flex w-full select-none items-center rounded py-2 px-1 hover:bg-brand-surface-2"
|
|
|
|
onClick={() => {
|
|
|
|
setLabelModal(true);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<span className="flex items-center justify-start gap-1 text-brand-secondary">
|
|
|
|
<PlusIcon className="h-4 w-4" aria-hidden="true" />
|
|
|
|
<span>Create New Label</span>
|
|
|
|
</span>
|
|
|
|
</button>
|
|
|
|
}
|
2023-03-25 18:09:46 +00:00
|
|
|
options={options}
|
|
|
|
multiple
|
|
|
|
noChevron
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
2023-04-20 20:45:21 +00:00
|
|
|
<div className="flex items-center gap-6 text-brand-secondary">
|
2023-03-28 18:50:00 +00:00
|
|
|
<Tooltip
|
2023-04-11 12:48:49 +00:00
|
|
|
tooltipContent={`Last updated at ${renderShortTime(
|
|
|
|
pageDetails.updated_at
|
|
|
|
)} on ${renderShortDate(pageDetails.updated_at)}`}
|
2023-03-28 18:50:00 +00:00
|
|
|
>
|
2023-04-20 20:45:21 +00:00
|
|
|
<p className="text-sm">{renderShortTime(pageDetails.updated_at)}</p>
|
2023-03-28 18:50:00 +00:00
|
|
|
</Tooltip>
|
2023-04-11 12:48:49 +00:00
|
|
|
<button className="flex items-center gap-2" onClick={handleCopyText}>
|
|
|
|
<LinkIcon className="h-4 w-4" />
|
|
|
|
</button>
|
2023-03-25 18:09:46 +00:00
|
|
|
<div className="flex-shrink-0">
|
|
|
|
<Popover className="relative grid place-items-center">
|
|
|
|
{({ open }) => (
|
|
|
|
<>
|
|
|
|
<Popover.Button
|
|
|
|
type="button"
|
2023-04-03 12:44:50 +00:00
|
|
|
className={`group inline-flex items-center outline-none ${
|
2023-04-20 08:11:24 +00:00
|
|
|
open ? "text-brand-base" : "text-brand-secondary"
|
2023-04-03 12:44:50 +00:00
|
|
|
}`}
|
2023-03-25 18:09:46 +00:00
|
|
|
>
|
|
|
|
{watch("color") && watch("color") !== "" ? (
|
|
|
|
<span
|
|
|
|
className="h-4 w-4 rounded"
|
|
|
|
style={{
|
|
|
|
backgroundColor: watch("color") ?? "black",
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
) : (
|
2023-04-20 20:45:21 +00:00
|
|
|
<ColorPalletteIcon height={16} width={16} />
|
2023-03-25 18:09:46 +00:00
|
|
|
)}
|
|
|
|
</Popover.Button>
|
|
|
|
|
|
|
|
<Transition
|
|
|
|
as={React.Fragment}
|
|
|
|
enter="transition ease-out duration-200"
|
|
|
|
enterFrom="opacity-0 translate-y-1"
|
|
|
|
enterTo="opacity-100 translate-y-0"
|
|
|
|
leave="transition ease-in duration-150"
|
|
|
|
leaveFrom="opacity-100 translate-y-0"
|
|
|
|
leaveTo="opacity-0 translate-y-1"
|
|
|
|
>
|
|
|
|
<Popover.Panel className="absolute top-full right-0 z-20 mt-1 max-w-xs px-2 sm:px-0">
|
|
|
|
<TwitterPicker
|
|
|
|
color={pageDetails.color}
|
|
|
|
onChange={(val) => partialUpdatePage({ color: val.hex })}
|
|
|
|
/>
|
|
|
|
</Popover.Panel>
|
|
|
|
</Transition>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Popover>
|
|
|
|
</div>
|
2023-04-11 06:40:22 +00:00
|
|
|
{pageDetails.created_by === user?.id && (
|
2023-04-11 12:48:49 +00:00
|
|
|
<Tooltip
|
|
|
|
tooltipContent={`${
|
|
|
|
pageDetails.access
|
|
|
|
? "This page is only visible to you."
|
|
|
|
: "This page can be viewed by anyone in the project."
|
|
|
|
}`}
|
|
|
|
theme="dark"
|
|
|
|
>
|
2023-04-11 06:40:22 +00:00
|
|
|
{pageDetails.access ? (
|
|
|
|
<button onClick={() => partialUpdatePage({ access: 0 })} className="z-10">
|
|
|
|
<LockClosedIcon className="h-4 w-4" />
|
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<button
|
|
|
|
onClick={() => partialUpdatePage({ access: 1 })}
|
|
|
|
type="button"
|
|
|
|
className="z-10"
|
|
|
|
>
|
|
|
|
<LockOpenIcon className="h-4 w-4" />
|
|
|
|
</button>
|
|
|
|
)}
|
2023-04-11 12:48:49 +00:00
|
|
|
</Tooltip>
|
2023-04-03 18:00:29 +00:00
|
|
|
)}
|
2023-03-25 18:09:46 +00:00
|
|
|
{pageDetails.is_favorite ? (
|
|
|
|
<button onClick={handleRemoveFromFavorites} className="z-10">
|
|
|
|
<StarIcon className="h-4 w-4 text-orange-400" fill="#f6ad55" />
|
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<button onClick={handleAddToFavorites} type="button" className="z-10">
|
|
|
|
<StarIcon className="h-4 w-4" />
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-04-11 12:48:49 +00:00
|
|
|
<div className="px-4 pt-6">
|
2023-03-25 18:09:46 +00:00
|
|
|
<TextArea
|
|
|
|
id="name"
|
|
|
|
name="name"
|
2023-04-11 12:48:49 +00:00
|
|
|
placeholder="Page Title"
|
2023-03-25 18:09:46 +00:00
|
|
|
value={watch("name")}
|
|
|
|
onBlur={handleSubmit(updatePage)}
|
|
|
|
onChange={(e) => setValue("name", e.target.value)}
|
|
|
|
required={true}
|
2023-04-20 20:45:21 +00:00
|
|
|
className="min-h-10 block w-full resize-none overflow-hidden rounded border-none bg-transparent px-3 py-2 text-2xl font-semibold outline-none ring-0 placeholder:text-[#858E96]"
|
2023-03-25 18:09:46 +00:00
|
|
|
role="textbox"
|
|
|
|
/>
|
|
|
|
</div>
|
2023-04-11 12:48:49 +00:00
|
|
|
<div className="px-7">
|
2023-03-25 18:09:46 +00:00
|
|
|
{pageBlocks ? (
|
2023-03-27 17:49:05 +00:00
|
|
|
<>
|
2023-04-03 18:00:29 +00:00
|
|
|
<DragDropContext onDragEnd={handleOnDragEnd}>
|
|
|
|
{pageBlocks.length !== 0 && (
|
|
|
|
<StrictModeDroppable droppableId="blocks-list">
|
2023-04-04 10:51:46 +00:00
|
|
|
{(provided) => (
|
|
|
|
<div ref={provided.innerRef} {...provided.droppableProps}>
|
2023-04-03 18:00:29 +00:00
|
|
|
{pageBlocks.map((block, index) => (
|
|
|
|
<SinglePageBlock
|
|
|
|
key={block.id}
|
|
|
|
block={block}
|
|
|
|
projectDetails={projectDetails}
|
|
|
|
index={index}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
{provided.placeholder}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</StrictModeDroppable>
|
|
|
|
)}
|
|
|
|
</DragDropContext>
|
|
|
|
{!createBlockForm && (
|
|
|
|
<button
|
|
|
|
type="button"
|
2023-04-21 05:16:04 +00:00
|
|
|
className="mt-4 flex items-center gap-1 rounded-full bg-brand-base px-2 py-1 pr-2.5 text-xs hover:bg-brand-surface-2"
|
2023-04-04 10:51:46 +00:00
|
|
|
onClick={handleNewBlock}
|
2023-04-03 18:00:29 +00:00
|
|
|
>
|
2023-04-04 10:51:46 +00:00
|
|
|
<PlusIcon className="h-3 w-3" />
|
|
|
|
Add new block
|
2023-04-03 18:00:29 +00:00
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
{createBlockForm && (
|
2023-04-04 13:01:28 +00:00
|
|
|
<div className="mt-4" ref={scrollToRef}>
|
2023-04-04 10:51:46 +00:00
|
|
|
<CreateUpdateBlockInline
|
|
|
|
handleClose={() => setCreateBlockForm(false)}
|
|
|
|
focus="name"
|
|
|
|
/>
|
|
|
|
</div>
|
2023-03-27 17:49:05 +00:00
|
|
|
)}
|
2023-04-25 06:38:56 +00:00
|
|
|
{labelModal && typeof projectId === "string" && (
|
|
|
|
<CreateLabelModal
|
|
|
|
isOpen={labelModal}
|
|
|
|
handleClose={() => setLabelModal(false)}
|
|
|
|
projectId={projectId}
|
|
|
|
/>
|
|
|
|
)}
|
2023-03-27 17:49:05 +00:00
|
|
|
</>
|
2023-03-25 18:09:46 +00:00
|
|
|
) : (
|
|
|
|
<Loader>
|
|
|
|
<Loader.Item height="150px" />
|
|
|
|
<Loader.Item height="150px" />
|
|
|
|
</Loader>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<Loader>
|
|
|
|
<Loader.Item height="200px" />
|
|
|
|
</Loader>
|
|
|
|
)}
|
2023-04-08 08:16:46 +00:00
|
|
|
</ProjectAuthorizationWrapper>
|
2023-03-23 05:31:06 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-03-25 18:09:46 +00:00
|
|
|
export default SinglePage;
|