2023-03-25 18:09:46 +00:00
|
|
|
import React from "react";
|
|
|
|
|
|
|
|
import Link from "next/link";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
2023-04-11 06:40:22 +00:00
|
|
|
// hooks
|
|
|
|
import useUser from "hooks/use-user";
|
2023-04-21 10:16:28 +00:00
|
|
|
import useToast from "hooks/use-toast";
|
2023-03-25 18:09:46 +00:00
|
|
|
// ui
|
2023-04-11 06:40:22 +00:00
|
|
|
import { CustomMenu, Tooltip } from "components/ui";
|
2023-03-25 18:09:46 +00:00
|
|
|
// icons
|
2023-04-03 18:00:29 +00:00
|
|
|
import {
|
2023-04-21 10:16:28 +00:00
|
|
|
LinkIcon,
|
2023-04-03 18:00:29 +00:00
|
|
|
LockClosedIcon,
|
|
|
|
LockOpenIcon,
|
|
|
|
PencilIcon,
|
|
|
|
StarIcon,
|
|
|
|
TrashIcon,
|
|
|
|
} from "@heroicons/react/24/outline";
|
2023-04-12 12:37:50 +00:00
|
|
|
import { ExclamationIcon } from "components/icons";
|
2023-03-25 18:09:46 +00:00
|
|
|
// helpers
|
2023-04-21 10:16:28 +00:00
|
|
|
import { copyTextToClipboard, truncateText } from "helpers/string.helper";
|
2023-07-12 06:15:45 +00:00
|
|
|
import {
|
|
|
|
render24HourFormatTime,
|
|
|
|
renderShortDate,
|
|
|
|
renderLongDateFormat,
|
|
|
|
} from "helpers/date-time.helper";
|
2023-03-25 18:09:46 +00:00
|
|
|
// types
|
2023-04-12 12:37:50 +00:00
|
|
|
import { IPage, IProjectMember } from "types";
|
2023-03-25 18:09:46 +00:00
|
|
|
|
|
|
|
type TSingleStatProps = {
|
|
|
|
page: IPage;
|
2023-04-12 12:37:50 +00:00
|
|
|
people: IProjectMember[] | undefined;
|
2023-03-25 18:09:46 +00:00
|
|
|
handleEditPage: () => void;
|
|
|
|
handleDeletePage: () => void;
|
|
|
|
handleAddToFavorites: () => void;
|
|
|
|
handleRemoveFromFavorites: () => void;
|
2023-04-03 18:00:29 +00:00
|
|
|
partialUpdatePage: (page: IPage, formData: Partial<IPage>) => void;
|
2023-03-25 18:09:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const SinglePageDetailedItem: React.FC<TSingleStatProps> = ({
|
|
|
|
page,
|
2023-04-12 12:37:50 +00:00
|
|
|
people,
|
2023-03-25 18:09:46 +00:00
|
|
|
handleEditPage,
|
|
|
|
handleDeletePage,
|
|
|
|
handleAddToFavorites,
|
|
|
|
handleRemoveFromFavorites,
|
2023-04-03 18:00:29 +00:00
|
|
|
partialUpdatePage,
|
2023-03-25 18:09:46 +00:00
|
|
|
}) => {
|
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug, projectId } = router.query;
|
|
|
|
|
2023-04-11 06:40:22 +00:00
|
|
|
const { user } = useUser();
|
|
|
|
|
2023-04-21 10:16:28 +00:00
|
|
|
const { setToastAlert } = useToast();
|
|
|
|
|
|
|
|
const handleCopyText = () => {
|
|
|
|
const originURL =
|
|
|
|
typeof window !== "undefined" && window.location.origin ? window.location.origin : "";
|
|
|
|
copyTextToClipboard(
|
|
|
|
`${originURL}/${workspaceSlug}/projects/${projectId}/pages/${page.id}`
|
|
|
|
).then(() => {
|
|
|
|
setToastAlert({
|
|
|
|
type: "success",
|
|
|
|
title: "Link Copied!",
|
|
|
|
message: "Page link copied to clipboard.",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2023-03-25 18:09:46 +00:00
|
|
|
return (
|
2023-04-11 12:48:49 +00:00
|
|
|
<div className="relative">
|
2023-04-04 13:01:28 +00:00
|
|
|
<Link href={`/${workspaceSlug}/projects/${projectId}/pages/${page.id}`}>
|
2023-04-20 06:39:48 +00:00
|
|
|
<a className="block p-4">
|
2023-04-03 18:00:29 +00:00
|
|
|
<div className="flex items-center justify-between gap-2">
|
|
|
|
<div className="flex items-center gap-2">
|
2023-04-20 20:45:21 +00:00
|
|
|
<p className="mr-2 truncate text-sm">{truncateText(page.name, 75)}</p>
|
2023-04-03 18:00:29 +00:00
|
|
|
{page.label_details.length > 0 &&
|
|
|
|
page.label_details.map((label) => (
|
|
|
|
<div
|
|
|
|
key={label.id}
|
2023-07-17 10:58:23 +00:00
|
|
|
className="group flex items-center gap-1 rounded-2xl border border-custom-border-200 px-2 py-0.5 text-xs"
|
2023-04-03 18:00:29 +00:00
|
|
|
style={{
|
|
|
|
backgroundColor: `${
|
|
|
|
label?.color && label.color !== "" ? label.color : "#000000"
|
|
|
|
}20`,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<span
|
|
|
|
className="h-1.5 w-1.5 flex-shrink-0 rounded-full"
|
|
|
|
style={{
|
|
|
|
backgroundColor:
|
|
|
|
label?.color && label.color !== "" ? label.color : "#000000",
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
{label.name}
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="flex items-center gap-2">
|
2023-04-11 12:48:49 +00:00
|
|
|
<Tooltip
|
|
|
|
tooltipContent={`Last updated at ${
|
2023-07-12 06:15:45 +00:00
|
|
|
render24HourFormatTime(page.updated_at) +
|
2023-04-11 12:48:49 +00:00
|
|
|
` ${new Date(page.updated_at).getHours() < 12 ? "am" : "pm"}`
|
|
|
|
} on ${renderShortDate(page.updated_at)}`}
|
|
|
|
>
|
2023-07-12 06:15:45 +00:00
|
|
|
<p className="text-sm text-custom-text-200">
|
|
|
|
{render24HourFormatTime(page.updated_at)}
|
|
|
|
</p>
|
2023-04-11 12:48:49 +00:00
|
|
|
</Tooltip>
|
2023-04-03 18:00:29 +00:00
|
|
|
{page.is_favorite ? (
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
onClick={(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
handleRemoveFromFavorites();
|
|
|
|
}}
|
|
|
|
className="z-10 grid place-items-center"
|
|
|
|
>
|
|
|
|
<StarIcon className="h-4 w-4 text-orange-400" fill="#f6ad55" />
|
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
onClick={(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
handleAddToFavorites();
|
|
|
|
}}
|
|
|
|
className="z-10 grid place-items-center"
|
|
|
|
>
|
2023-07-10 07:17:00 +00:00
|
|
|
<StarIcon className="h-4 w-4 " color="rgb(var(--color-text-200))" />
|
2023-04-03 18:00:29 +00:00
|
|
|
</button>
|
|
|
|
)}
|
2023-04-11 06:40:22 +00:00
|
|
|
{page.created_by === user?.id && (
|
|
|
|
<Tooltip
|
|
|
|
tooltipContent={`${
|
|
|
|
page.access
|
|
|
|
? "This page is only visible to you."
|
|
|
|
: "This page can be viewed by anyone in the project."
|
|
|
|
}`}
|
2023-04-03 18:00:29 +00:00
|
|
|
>
|
2023-04-11 06:40:22 +00:00
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
onClick={(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
partialUpdatePage(page, { access: page.access ? 0 : 1 });
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{page.access ? (
|
2023-07-10 07:17:00 +00:00
|
|
|
<LockClosedIcon className="h-4 w-4" color="rgb(var(--color-text-200))" />
|
2023-04-11 06:40:22 +00:00
|
|
|
) : (
|
2023-07-10 07:17:00 +00:00
|
|
|
<LockOpenIcon className="h-4 w-4" color="rgb(var(--color-text-200))" />
|
2023-04-11 06:40:22 +00:00
|
|
|
)}
|
|
|
|
</button>
|
|
|
|
</Tooltip>
|
|
|
|
)}
|
2023-04-12 12:37:50 +00:00
|
|
|
<Tooltip
|
|
|
|
position="top-right"
|
|
|
|
tooltipContent={`Created by ${
|
|
|
|
people?.find((person) => person.member.id === page.created_by)?.member
|
2023-08-08 07:31:43 +00:00
|
|
|
.display_name ?? ""
|
2023-04-12 12:37:50 +00:00
|
|
|
} on ${renderLongDateFormat(`${page.created_at}`)}`}
|
|
|
|
>
|
|
|
|
<span>
|
2023-07-10 07:17:00 +00:00
|
|
|
<ExclamationIcon className="h-4 w-4 fill-current text-custom-text-200" />
|
2023-04-12 12:37:50 +00:00
|
|
|
</span>
|
|
|
|
</Tooltip>
|
2023-04-03 18:00:29 +00:00
|
|
|
<CustomMenu verticalEllipsis>
|
|
|
|
<CustomMenu.MenuItem
|
|
|
|
onClick={(e: any) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
handleEditPage();
|
2023-03-25 18:09:46 +00:00
|
|
|
}}
|
2023-04-03 18:00:29 +00:00
|
|
|
>
|
|
|
|
<span className="flex items-center justify-start gap-2">
|
|
|
|
<PencilIcon className="h-3.5 w-3.5" />
|
|
|
|
<span>Edit Page</span>
|
|
|
|
</span>
|
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
<CustomMenu.MenuItem
|
|
|
|
onClick={(e: any) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
handleDeletePage();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<span className="flex items-center justify-start gap-2">
|
|
|
|
<TrashIcon className="h-3.5 w-3.5" />
|
|
|
|
<span>Delete Page</span>
|
|
|
|
</span>
|
|
|
|
</CustomMenu.MenuItem>
|
2023-04-21 10:16:28 +00:00
|
|
|
<CustomMenu.MenuItem
|
|
|
|
onClick={(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
handleCopyText();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<div className="flex items-center justify-start gap-2">
|
|
|
|
<LinkIcon className="h-4 w-4" />
|
|
|
|
<span>Copy Page link</span>
|
|
|
|
</div>
|
|
|
|
</CustomMenu.MenuItem>
|
2023-04-03 18:00:29 +00:00
|
|
|
</CustomMenu>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-07-10 07:17:00 +00:00
|
|
|
<div className="relative mt-2 space-y-2 text-sm text-custom-text-200">
|
2023-04-04 13:01:28 +00:00
|
|
|
{page.blocks.length > 0
|
|
|
|
? page.blocks.slice(0, 3).map((block) => <h4>{block.name}</h4>)
|
|
|
|
: null}
|
2023-04-03 18:00:29 +00:00
|
|
|
</div>
|
2023-04-04 13:01:28 +00:00
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
</div>
|
2023-03-25 18:09:46 +00:00
|
|
|
);
|
|
|
|
};
|