From 4ab9acdfab1695fac0122a9b3e861469d9ce6e3c Mon Sep 17 00:00:00 2001 From: Samuel Rowe Date: Tue, 19 Jul 2022 22:47:38 +0530 Subject: [PATCH] feat(frontend): implemented records form in volumes tab --- .../src/components/Modal/Service/Volumes.tsx | 98 ++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) diff --git a/services/frontend/src/components/Modal/Service/Volumes.tsx b/services/frontend/src/components/Modal/Service/Volumes.tsx index 054bed2..ab75f3a 100644 --- a/services/frontend/src/components/Modal/Service/Volumes.tsx +++ b/services/frontend/src/components/Modal/Service/Volumes.tsx @@ -1,5 +1,101 @@ +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; +`; + +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; +`; + const Volumes = () => { - return <>; + const formik = useFormikContext<{ + serviceConfig: IService; + }>(); + const volumes = (formik.values.serviceConfig.volumes as []) || []; + + const handleNewVolume = useCallback(() => { + formik.setFieldValue(`serviceConfig.volumes[${volumes.length}]`, { + key: "", + value: "" + }); + }, [formik]); + + const handleRemoveVolume = useCallback( + (index: number) => { + const newVolumes = volumes.filter( + (_: unknown, currentIndex: number) => currentIndex != index + ); + formik.setFieldValue(`serviceConfig.volumes`, newVolumes); + }, + [formik] + ); + + const emptyVolumes = volumes && volumes.length === 0 ? true : false; + + return ( + + {!emptyVolumes && ( + + {volumes.map((_: unknown, index: number) => ( + + ))} + + )} + {emptyVolumes && ( + + This service does not have any volumes. +
+ Click "+ New volume" to add a new volume. +
+ )} + + + + New volume + +
+ ); }; export default Volumes;