import { useState } from "react"; import { usePopper } from "react-popper"; import { Calendar, History, Info } from "lucide-react"; // types import { DocumentDetails } from "../types/editor-types"; type Props = { documentDetails: DocumentDetails; }; // function to render a Date in the format- 25 May 2023 at 2:53PM const renderDate = (date: Date): string => { const options: Intl.DateTimeFormatOptions = { day: "numeric", month: "long", year: "numeric", hour: "numeric", minute: "numeric", hour12: true, }; const formattedDate: string = new Intl.DateTimeFormat( "en-US", options, ).format(date); return formattedDate; }; export const InfoPopover: React.FC = (props) => { const { documentDetails } = props; const [isPopoverOpen, setIsPopoverOpen] = useState(false); const [referenceElement, setReferenceElement] = useState(null); const [popperElement, setPopperElement] = useState( null, ); const { styles: infoPopoverStyles, attributes: infoPopoverAttributes } = usePopper(referenceElement, popperElement, { placement: "bottom-start", }); return (
setIsPopoverOpen(true)} onMouseLeave={() => setIsPopoverOpen(false)} > {isPopoverOpen && (
Last updated on
{renderDate(new Date(documentDetails.last_updated_at))}
Created on
{renderDate(new Date(documentDetails.created_on))}
)}
); };