import { AlertIcon, CheckmarkIcon, ChevronDownIcon, ChevronLeftIcon, TriangleAlertIcon, } from "@/components/icons/icons"; import { useState } from "react"; import { Grid } from "react-loader-spinner"; export type StatusOptions = "in-progress" | "failed" | "warning" | "success"; interface ResponseSectionProps { header: JSX.Element | string; body: JSX.Element | string; status: StatusOptions; desiredOpenStatus: boolean; setDesiredOpenStatus?: (isOpen: boolean) => void; isNotControllable?: boolean; } export const ResponseSection = ({ header, body, status, desiredOpenStatus, setDesiredOpenStatus, isNotControllable, }: ResponseSectionProps) => { const [isOpen, setIsOpen] = useState(null); let icon = null; if (status === "in-progress") { icon = (
); } if (status === "failed") { icon = ; } if (status === "success") { icon = ; } if (status === "warning") { icon = ; } // use `desiredOpenStatus` if user has not clicked to open/close, otherwise use // `isOpen` state const finalIsOpen = isOpen !== null ? isOpen : desiredOpenStatus; return (
{ if (!isNotControllable) { if (isOpen === null) { setIsOpen(!desiredOpenStatus); } else { setIsOpen(!isOpen); } } if (setDesiredOpenStatus) { setDesiredOpenStatus(!desiredOpenStatus); } }} >
{icon}
{header}
{!isNotControllable && (
{finalIsOpen ? ( ) : ( )}
)}
{finalIsOpen &&
{body}
}
); };