import { Form, Formik, FormikErrors, FormikProps, FormikTouched, FormikValues, } from "formik"; import type { ComponentPropsWithoutRef, ReactNode, SetStateAction, } from "react"; import Modal from "react-modal"; import { Button as ThemeButton, Close, Flex, Heading } from "theme-ui"; import { Button } from "@/legacy/components/Button"; import SliceMachineModal from "@/legacy/components/SliceMachineModal"; import { Card, useCardRadius } from "../Card"; type ModalCardProps = { children: (props: { isValid: boolean; isSubmitting: boolean; errors: FormikErrors; touched: FormikTouched; setFieldValue: ( field: string, // eslint-disable-next-line @typescript-eslint/no-explicit-any value: any, shouldValidate?: boolean | undefined, ) => Promise>; values: T; setValues: ( values: SetStateAction, shouldValidate?: boolean | undefined, ) => void; }) => JSX.Element; close: () => void; isOpen: boolean; formId: string; buttonLabel?: string; validate?: (values: T) => FormikErrors | void; widthInPx?: string; onSubmit: (values: T) => void; initialValues: T; content: { title: string }; cardProps?: ComponentPropsWithoutRef; omitFooter?: boolean; isLoading?: boolean; testId?: string; actionMessage?: ((props: FormikProps) => ReactNode) | ReactNode; }; function ModalCard({ children, close, isOpen, formId, validate, onSubmit, widthInPx, initialValues, content: { title }, cardProps, omitFooter = false, isLoading = false, buttonLabel = "Save", testId, actionMessage, }: ModalCardProps): JSX.Element { Modal.setAppElement("#__next"); return ( (validate ? validate(values) : undefined)} // eslint-disable-next-line @typescript-eslint/no-unused-vars onSubmit={(values) => { onSubmit(values); }} > {(formikProps) => { const { isValid, isSubmitting, values, errors, touched, setFieldValue, setValues, } = formikProps; return (
{title} } Footer={ !omitFooter ? ( {typeof actionMessage === "function" ? actionMessage(formikProps) : actionMessage} Cancel