diff --git a/services/frontend/src/components/Modal/Service/General.tsx b/services/frontend/src/components/Modal/Service/General.tsx index 961fd71..2c19327 100644 --- a/services/frontend/src/components/Modal/Service/General.tsx +++ b/services/frontend/src/components/Modal/Service/General.tsx @@ -1,10 +1,114 @@ 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 { IService } from "../../../types"; + +const Root = styled("div")` + display: flex; + flex-direction: column; + align-items: center; + margin-top: ${({ theme }) => theme.spacing(1)}; +`; + +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 GroupTitle = styled("h5")` + font-size: 14px; + font-weight: bold; +`; const General = () => { + const formik = useFormikContext<{ + serviceConfig: IService; + }>(); + const labels = (formik.values.serviceConfig.labels as []) || []; + + const handleNewLabel = useCallback(() => { + formik.setFieldValue(`serviceConfig.labels[${labels.length}]`, { + key: "", + value: "" + }); + }, [formik]); + + const handleRemoveLabel = useCallback( + (index: number) => { + const newLabels = labels.filter( + (_: unknown, currentIndex: number) => currentIndex != index + ); + formik.setFieldValue(`serviceConfig.labels`, newLabels); + }, + [formik] + ); + + const emptyLabels = labels && labels.length === 0 ? true : false; + return ( <> + + Ports + + + {!emptyLabels && ( + + {labels.map((_: unknown, index: number) => ( + + ))} + + )} + {emptyLabels && ( + + This service does not have any ports. +
+ Click "+ New port" to add a new port. +
+ )} + + + + New port + +
); };