2023-03-23 05:31:06 +00:00
|
|
|
import React from "react";
|
2023-03-25 18:09:46 +00:00
|
|
|
|
2023-03-23 05:31:06 +00:00
|
|
|
import Link from "next/link";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
|
|
|
// ui
|
2023-03-25 18:09:46 +00:00
|
|
|
import { CustomMenu, Tooltip } from "components/ui";
|
2023-03-23 05:31:06 +00:00
|
|
|
// icons
|
|
|
|
import { PencilIcon, StarIcon, TrashIcon } from "@heroicons/react/24/outline";
|
|
|
|
// helpers
|
|
|
|
import { truncateText } from "helpers/string.helper";
|
2023-03-25 18:09:46 +00:00
|
|
|
import { renderShortDate, renderShortTime } from "helpers/date-time.helper";
|
2023-03-23 05:31:06 +00:00
|
|
|
// types
|
|
|
|
import { IPage } from "types";
|
2023-03-26 06:06:10 +00:00
|
|
|
import { PencilScribbleIcon } from "components/icons";
|
2023-03-23 05:31:06 +00:00
|
|
|
|
|
|
|
type TSingleStatProps = {
|
|
|
|
page: IPage;
|
|
|
|
handleEditPage: () => void;
|
|
|
|
handleDeletePage: () => void;
|
2023-03-25 18:09:46 +00:00
|
|
|
handleAddToFavorites: () => void;
|
|
|
|
handleRemoveFromFavorites: () => void;
|
2023-03-23 05:31:06 +00:00
|
|
|
};
|
|
|
|
|
2023-03-25 18:09:46 +00:00
|
|
|
export const SinglePageListItem: React.FC<TSingleStatProps> = ({
|
|
|
|
page,
|
|
|
|
handleEditPage,
|
|
|
|
handleDeletePage,
|
|
|
|
handleAddToFavorites,
|
|
|
|
handleRemoveFromFavorites,
|
|
|
|
}) => {
|
2023-03-23 05:31:06 +00:00
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug, projectId } = router.query;
|
|
|
|
|
|
|
|
return (
|
2023-03-25 18:09:46 +00:00
|
|
|
<li>
|
2023-03-27 17:49:05 +00:00
|
|
|
<Link href={`/${workspaceSlug}/projects/${projectId}/pages/${page.id}`}>
|
|
|
|
<a>
|
|
|
|
<div className="relative rounded p-4 hover:bg-gray-100">
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
<PencilScribbleIcon />
|
2023-03-25 18:09:46 +00:00
|
|
|
<p className="mr-2 truncate text-sm font-medium">{truncateText(page.name, 75)}</p>
|
2023-03-27 17:49:05 +00:00
|
|
|
{page.label_details.length > 0 &&
|
|
|
|
page.label_details.map((label) => (
|
|
|
|
<div
|
|
|
|
key={label.id}
|
|
|
|
className="group flex items-center gap-1 rounded-2xl border px-2 py-0.5 text-xs"
|
|
|
|
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="ml-2 flex flex-shrink-0">
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
<Tooltip
|
|
|
|
tooltipContent={`Last updated at ${renderShortTime(
|
|
|
|
page.updated_at
|
|
|
|
)} ${renderShortDate(page.updated_at)}`}
|
|
|
|
>
|
|
|
|
<p className="text-sm text-gray-400">{renderShortTime(page.updated_at)}</p>
|
|
|
|
</Tooltip>
|
|
|
|
{page.is_favorite ? (
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
onClick={(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
handleRemoveFromFavorites();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<StarIcon className="h-4 w-4 text-orange-400" fill="#f6ad55" />
|
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
onClick={(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
handleAddToFavorites();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<StarIcon className="h-4 w-4 " color="#858e96" />
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
<CustomMenu width="auto" verticalEllipsis>
|
|
|
|
<CustomMenu.MenuItem
|
|
|
|
onClick={(e: any) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
handleEditPage();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<span className="flex items-center justify-start gap-2 text-gray-800">
|
|
|
|
<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 text-gray-800">
|
|
|
|
<TrashIcon className="h-3.5 w-3.5" />
|
|
|
|
<span>Delete Page</span>
|
|
|
|
</span>
|
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
</CustomMenu>
|
2023-03-25 18:09:46 +00:00
|
|
|
</div>
|
2023-03-27 17:49:05 +00:00
|
|
|
</div>
|
2023-03-23 05:31:06 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-03-27 17:49:05 +00:00
|
|
|
</a>
|
|
|
|
</Link>
|
2023-03-25 18:09:46 +00:00
|
|
|
</li>
|
2023-03-23 05:31:06 +00:00
|
|
|
);
|
|
|
|
};
|