import React from "react"; import Link from "next/link"; import { useRouter } from "next/router"; import { mutate } from "swr"; // services import pagesService from "services/pages.service"; // ui import { CustomMenu } from "components/ui"; // icons import { PencilIcon, StarIcon, TrashIcon } from "@heroicons/react/24/outline"; // helpers import { truncateText } from "helpers/string.helper"; // hooks import useToast from "hooks/use-toast"; // types import { IPage } from "types"; // fetch keys import { PAGE_LIST } from "constants/fetch-keys"; import Label from "./page-label"; type TSingleStatProps = { page: IPage; handleEditPage: () => void; handleDeletePage: () => void; }; export const SinglePageGridItem: React.FC = (props) => { const { page, handleEditPage, handleDeletePage } = props; const router = useRouter(); const { workspaceSlug, projectId } = router.query; const { setToastAlert } = useToast(); const handleAddToFavorites = () => { if (!workspaceSlug && !projectId && !page) return; pagesService .addPageToFavorites(workspaceSlug as string, projectId as string, { page: page.id, }) .then(() => { mutate( PAGE_LIST(projectId as string), (prevData) => (prevData ?? []).map((m) => ({ ...m, is_favorite: m.id === page.id ? true : m.is_favorite, })), false ); setToastAlert({ type: "success", title: "Success!", message: "Successfully added the page to favorites.", }); }) .catch(() => { setToastAlert({ type: "error", title: "Error!", message: "Couldn't add the page to favorites. Please try again.", }); }); }; const handleRemoveFromFavorites = () => { if (!workspaceSlug || !page) return; pagesService .removePageFromFavorites(workspaceSlug as string, projectId as string, page.id) .then(() => { mutate( PAGE_LIST(projectId as string), (prevData) => (prevData ?? []).map((m) => ({ ...m, is_favorite: m.id === page.id ? false : m.is_favorite, })), false ); setToastAlert({ type: "success", title: "Success!", message: "Successfully removed the page from favorites.", }); }) .catch(() => { setToastAlert({ type: "error", title: "Error!", message: "Couldn't remove the page from favorites. Please try again.", }); }); }; return (
  • {truncateText(page.name, 75)}

    {new Date(page.updated_at).toLocaleTimeString()}

    {page.is_favorite ? ( ) : ( )} Edit Page Delete Page

    Lorem ipsum dolor sit amet consectetur adipisicing elit. Reiciendis atque aliquam saepe sapiente illo ratione delectus dolorem repellat, id autem, molestiae neque quaerat ipsum perspiciatis pariatur? Unde consectetur quibusdam ut.

    Quisquam quas expedita cupiditate ipsum cumque fugit at, optio quia ea? Id doloribus assumenda ad magni laborum aut, aspernatur nemo similique, suscipit dolores porro necessitatibus, inventore ab aliquid molestias. Aspernatur.

    Beatae obcaecati minus temporibus sunt, quo nulla, tenetur nisi sit maiores aspernatur numquam facilis asperiores eos rerum, ad dolorem quos laboriosam dicta eaque! Pariatur magni eos, architecto itaque esse minus.

    Dolorum saepe impedit officiis odit! Porro aliquid dolorum corporis impedit eaque iusto, illo hic neque quia vero aperiam? Nemo aliquam, hic incidunt mollitia totam asperiores sunt nam inventore voluptatibus eum?

  • ); };