import TextField from "../../global/FormElements/InputField"; 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 Fields = styled("div")` display: flex; flex-direction: column; row-gap: ${({ theme }) => theme.spacing(1)}; `; const ImageNameGroup = styled("div")` display: flex; flex-direction: row; column-gap: ${({ theme }) => theme.spacing(1)}; width: 100%; `; const Group = styled("div")` display: flex; flex-direction: column; align-items: center; `; const GroupTitle = styled("h5")` font-size: 0.75rem; color: #374151; font-weight: 500; width: 100%; text-align: left; `; const Records = styled("div")` display: flex; flex-direction: column; row-gap: ${({ theme }) => theme.spacing(1)}; `; const AddButton = styled(Button)` width: 140px; margin-top: ${({ theme }) => theme.spacing(2)}; `; const Description = styled("p")` margin-top: ${({ theme }) => theme.spacing(2)}; text-align: center; color: #7a7a7a; font-size: 14px; `; const General = () => { const formik = useFormikContext(); const { ports } = formik.values; const handleNewPort = useCallback(() => { formik.setFieldValue(`ports[${ports.length}]`, { hostPort: "", containerPort: "", protocol: "" }); }, [formik]); const handleRemovePort = useCallback( (index: number) => { const newPorts = ports.filter( (_: unknown, currentIndex: number) => currentIndex != index ); formik.setFieldValue(`ports`, newPorts); }, [formik] ); const emptyPorts = ports && ports.length === 0 ? true : false; return ( <> Ports {!emptyPorts && ( {ports.map((_: unknown, index: number) => ( ))} )} {emptyPorts && ( This service does not have any ports.
Click "+ New port" to add a new port.
)} New port
); }; export default General;