import { useState } from "react"; import { useTranslation } from "react-i18next"; import Modal from "../modals/Modal"; import clsx from "clsx"; import toast from "react-hot-toast"; export default function ShowPayloadModalButton({ payload, title, description, withCopy = true, className, size = "xl", }: { payload: string; title?: string; description?: React.ReactNode; withCopy?: boolean; className?: string; size?: "sm" | "md" | "lg" | "xl" | "2xl" | "3xl" | "4xl" | "5xl" | "6xl" | "7xl" | "full"; }) { const { t } = useTranslation(); const [open, setOpen] = useState(false); function stringifyDetails() { if (typeof payload === "string") { return payload; } try { return JSON.stringify(JSON.parse(payload ?? "{}"), null, "\t"); } catch (e) { return JSON.stringify(payload, null, "\t"); } } return ( <>
{payload !== null && ( )}
{title ?? t("shared.details")}
{withCopy && ( )}
{stringifyDetails()}
); }