diff --git a/services/frontend/src/components/Modal/volume/Labels.tsx b/services/frontend/src/components/Modal/volume/Labels.tsx index 710b9e5..b3fbab7 100644 --- a/services/frontend/src/components/Modal/volume/Labels.tsx +++ b/services/frontend/src/components/Modal/volume/Labels.tsx @@ -1,4 +1,98 @@ +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)` + 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 Labels = () => { - return <>; + const formik = useFormikContext(); + const { labels } = formik.values; + + const handleNewLabel = useCallback(() => { + formik.setFieldValue(`labels[${labels.length}]`, { + key: "", + value: "" + }); + }, [formik]); + + const handleRemoveLabel = useCallback( + (index: number) => { + const newLabels = labels.filter( + (_: unknown, currentIndex: number) => currentIndex != index + ); + formik.setFieldValue(`labels`, newLabels); + }, + [formik] + ); + + const emptyLabels = labels && labels.length === 0 ? true : false; + + return ( + + {!emptyLabels && ( + + {labels.map((_: unknown, index: number) => ( + + ))} + + )} + {emptyLabels && ( + + This volume does not have any labels. +
+ Click "+ New label" to add a new label. +
+ )} + + + + New label + +
+ ); }; + export default Labels;