import { useCallback } from "react"; import { PlusIcon } from "@heroicons/react/outline"; import { Button, styled } from "@mui/joy"; import { useFormikContext } from "formik"; import Record from "../../Record"; import { IEditServiceForm } from "../../../types"; const Root = styled("div")` display: flex; flex-direction: column; align-items: center; `; const Records = styled("div")` display: flex; flex-direction: column; row-gap: ${({ theme }) => theme.spacing(1)}; `; const AddButton = styled(Button)` margin-top: ${({ theme }) => theme.spacing(1)}; `; const Description = styled("p")` margin-top: ${({ theme }) => theme.spacing(1)}; text-align: center; color: #7a7a7a; font-size: 14px; `; const Volumes = () => { const formik = useFormikContext(); const { volumes } = formik.values; const handleNewVolume = useCallback(() => { formik.setFieldValue(`volumes[${volumes.length}]`, { name: "", containerPath: "", accessMode: "" }); }, [formik]); const handleRemoveVolume = useCallback( (index: number) => { const newVolumes = volumes.filter( (_: unknown, currentIndex: number) => currentIndex != index ); formik.setFieldValue(`volumes`, newVolumes); }, [formik] ); const emptyVolumes = volumes && volumes.length === 0 ? true : false; return ( {!emptyVolumes && ( {volumes.map((_: unknown, index: number) => ( ))} )} {emptyVolumes && No volumes.} New volume ); }; export default Volumes;