2023-11-22 07:02:49 +00:00
|
|
|
import { useState } from "react";
|
|
|
|
import { usePopper } from "react-popper";
|
|
|
|
import { Calendar, History, Info } from "lucide-react";
|
2024-04-11 15:58:59 +00:00
|
|
|
// helpers
|
|
|
|
import { renderFormattedDate } from "@/helpers/date-time.helper";
|
|
|
|
// store
|
|
|
|
import { IPageStore } from "@/store/pages/page.store";
|
2023-11-22 07:02:49 +00:00
|
|
|
|
|
|
|
type Props = {
|
2024-04-11 15:58:59 +00:00
|
|
|
pageStore: IPageStore;
|
2023-11-22 07:02:49 +00:00
|
|
|
};
|
|
|
|
|
2024-04-11 15:58:59 +00:00
|
|
|
export const PageInfoPopover: React.FC<Props> = (props) => {
|
|
|
|
const { pageStore } = props;
|
|
|
|
// states
|
2023-11-22 07:02:49 +00:00
|
|
|
const [isPopoverOpen, setIsPopoverOpen] = useState<boolean>(false);
|
2024-04-11 15:58:59 +00:00
|
|
|
// refs
|
2023-12-10 10:18:10 +00:00
|
|
|
const [referenceElement, setReferenceElement] = useState<HTMLButtonElement | null>(null);
|
|
|
|
const [popperElement, setPopperElement] = useState<HTMLDivElement | null>(null);
|
2024-04-11 15:58:59 +00:00
|
|
|
// popper-js
|
2023-12-10 10:18:10 +00:00
|
|
|
const { styles: infoPopoverStyles, attributes: infoPopoverAttributes } = usePopper(referenceElement, popperElement, {
|
|
|
|
placement: "bottom-start",
|
|
|
|
});
|
2024-04-11 15:58:59 +00:00
|
|
|
// derived values
|
|
|
|
const { created_at, updated_at } = pageStore;
|
2023-11-22 07:02:49 +00:00
|
|
|
|
|
|
|
return (
|
2023-12-10 10:18:10 +00:00
|
|
|
<div onMouseEnter={() => setIsPopoverOpen(true)} onMouseLeave={() => setIsPopoverOpen(false)}>
|
2023-12-07 06:34:21 +00:00
|
|
|
<button type="button" ref={setReferenceElement} className="block">
|
2023-11-22 07:02:49 +00:00
|
|
|
<Info className="h-3.5 w-3.5" />
|
|
|
|
</button>
|
|
|
|
{isPopoverOpen && (
|
|
|
|
<div
|
2023-12-10 10:18:10 +00:00
|
|
|
className="z-10 w-64 space-y-2.5 rounded border-[0.5px] border-custom-border-200 bg-custom-background-100 p-3 shadow-custom-shadow-rg"
|
2023-11-22 07:02:49 +00:00
|
|
|
ref={setPopperElement}
|
|
|
|
style={infoPopoverStyles.popper}
|
|
|
|
{...infoPopoverAttributes.popper}
|
|
|
|
>
|
|
|
|
<div className="space-y-1.5">
|
2023-12-10 10:18:10 +00:00
|
|
|
<h6 className="text-xs text-custom-text-400">Last updated on</h6>
|
|
|
|
<h5 className="flex items-center gap-1 text-sm">
|
2023-11-22 07:02:49 +00:00
|
|
|
<History className="h-3 w-3" />
|
2024-04-11 15:58:59 +00:00
|
|
|
{renderFormattedDate(updated_at)}
|
2023-11-22 07:02:49 +00:00
|
|
|
</h5>
|
|
|
|
</div>
|
|
|
|
<div className="space-y-1.5">
|
2023-12-10 10:18:10 +00:00
|
|
|
<h6 className="text-xs text-custom-text-400">Created on</h6>
|
|
|
|
<h5 className="flex items-center gap-1 text-sm">
|
2023-11-22 07:02:49 +00:00
|
|
|
<Calendar className="h-3 w-3" />
|
2024-04-11 15:58:59 +00:00
|
|
|
{renderFormattedDate(created_at)}
|
2023-11-22 07:02:49 +00:00
|
|
|
</h5>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|