|
|
|
@ -15,8 +15,11 @@ import Record, { IFieldType } from "./Record";
|
|
|
|
import { useFormikContext } from "formik";
|
|
|
|
import { useFormikContext } from "formik";
|
|
|
|
import lodash from "lodash";
|
|
|
|
import lodash from "lodash";
|
|
|
|
import IconButton from "@mui/joy/IconButton";
|
|
|
|
import IconButton from "@mui/joy/IconButton";
|
|
|
|
|
|
|
|
import { useAccordionState } from "../hooks";
|
|
|
|
|
|
|
|
import { useParams } from "react-router-dom";
|
|
|
|
|
|
|
|
|
|
|
|
export interface IRecordsProps {
|
|
|
|
export interface IRecordsProps {
|
|
|
|
|
|
|
|
defaultOpen?: boolean;
|
|
|
|
title: string;
|
|
|
|
title: string;
|
|
|
|
name: string;
|
|
|
|
name: string;
|
|
|
|
fields: (index: number) => IFieldType[];
|
|
|
|
fields: (index: number) => IFieldType[];
|
|
|
|
@ -93,6 +96,7 @@ const Records: FunctionComponent<IRecordsProps> = (
|
|
|
|
props: IRecordsProps
|
|
|
|
props: IRecordsProps
|
|
|
|
): ReactElement => {
|
|
|
|
): ReactElement => {
|
|
|
|
const {
|
|
|
|
const {
|
|
|
|
|
|
|
|
defaultOpen = false,
|
|
|
|
title,
|
|
|
|
title,
|
|
|
|
name,
|
|
|
|
name,
|
|
|
|
fields,
|
|
|
|
fields,
|
|
|
|
@ -103,14 +107,13 @@ const Records: FunctionComponent<IRecordsProps> = (
|
|
|
|
renderBorder
|
|
|
|
renderBorder
|
|
|
|
} = props;
|
|
|
|
} = props;
|
|
|
|
|
|
|
|
|
|
|
|
const [open, setOpen] = useState(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const formik = useFormikContext();
|
|
|
|
const formik = useFormikContext();
|
|
|
|
const items = lodash.get(formik.values, name);
|
|
|
|
const items = lodash.get(formik.values, name);
|
|
|
|
|
|
|
|
|
|
|
|
const handleToggle = useCallback(() => {
|
|
|
|
const { uuid } = useParams<{ uuid: string }>();
|
|
|
|
setOpen((open) => !open);
|
|
|
|
|
|
|
|
}, []);
|
|
|
|
const id = `${uuid}.${name}`;
|
|
|
|
|
|
|
|
const { open, toggle } = useAccordionState(id, defaultOpen);
|
|
|
|
|
|
|
|
|
|
|
|
const handleNew = useCallback(() => {
|
|
|
|
const handleNew = useCallback(() => {
|
|
|
|
formik.setFieldValue(`${name}[${items.length}]`, newValue);
|
|
|
|
formik.setFieldValue(`${name}[${items.length}]`, newValue);
|
|
|
|
@ -134,7 +137,7 @@ const Records: FunctionComponent<IRecordsProps> = (
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<Group empty={empty}>
|
|
|
|
<Group empty={empty}>
|
|
|
|
<Top onClick={handleToggle}>
|
|
|
|
<Top onClick={toggle}>
|
|
|
|
<GroupTitle>{title}</GroupTitle>
|
|
|
|
<GroupTitle>{title}</GroupTitle>
|
|
|
|
<ExpandButton size="sm" variant="plain">
|
|
|
|
<ExpandButton size="sm" variant="plain">
|
|
|
|
{open && <ChevronUpIcon className="h-5 w-5" />}
|
|
|
|
{open && <ChevronUpIcon className="h-5 w-5" />}
|
|
|
|
|