|
|
|
@ -1,9 +1,5 @@
|
|
|
|
import { useCallback } from "react";
|
|
|
|
import { styled } from "@mui/joy";
|
|
|
|
import { PlusIcon } from "@heroicons/react/outline";
|
|
|
|
import Records from "../../Records";
|
|
|
|
import { Button, styled } from "@mui/joy";
|
|
|
|
|
|
|
|
import { useFormikContext } from "formik";
|
|
|
|
|
|
|
|
import Record from "../../Record";
|
|
|
|
|
|
|
|
import { IEditServiceForm } from "../../../types";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const Root = styled("div")`
|
|
|
|
const Root = styled("div")`
|
|
|
|
display: flex;
|
|
|
|
display: flex;
|
|
|
|
@ -11,79 +7,29 @@ const Root = styled("div")`
|
|
|
|
align-items: center;
|
|
|
|
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 Labels = () => {
|
|
|
|
const Labels = () => {
|
|
|
|
const formik = useFormikContext<IEditServiceForm>();
|
|
|
|
|
|
|
|
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 (
|
|
|
|
return (
|
|
|
|
<Root>
|
|
|
|
<Root>
|
|
|
|
{!emptyLabels && (
|
|
|
|
<Records
|
|
|
|
<Records>
|
|
|
|
name="labels"
|
|
|
|
{labels.map((_: unknown, index: number) => (
|
|
|
|
title=""
|
|
|
|
<Record
|
|
|
|
collapsible={false}
|
|
|
|
key={index}
|
|
|
|
fields={(index: number) => [
|
|
|
|
index={index}
|
|
|
|
{
|
|
|
|
fields={[
|
|
|
|
name: `labels[${index}].key`,
|
|
|
|
{
|
|
|
|
placeholder: "Key",
|
|
|
|
name: `labels[${index}].key`,
|
|
|
|
required: true,
|
|
|
|
placeholder: "Key",
|
|
|
|
type: "text"
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
type: "text"
|
|
|
|
{
|
|
|
|
},
|
|
|
|
name: `labels[${index}].value`,
|
|
|
|
{
|
|
|
|
placeholder: "Value",
|
|
|
|
name: `labels[${index}].value`,
|
|
|
|
required: true,
|
|
|
|
placeholder: "Value",
|
|
|
|
type: "text"
|
|
|
|
required: false,
|
|
|
|
}
|
|
|
|
type: "text"
|
|
|
|
]}
|
|
|
|
}
|
|
|
|
newValue={{ key: "", value: "" }}
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
onRemove={handleRemoveLabel}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
))}
|
|
|
|
|
|
|
|
</Records>
|
|
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
{emptyLabels && <Description>No labels.</Description>}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<AddButton size="sm" variant="plain" onClick={handleNewLabel}>
|
|
|
|
|
|
|
|
<PlusIcon className="h-4 w-4 mr-2" />
|
|
|
|
|
|
|
|
New label
|
|
|
|
|
|
|
|
</AddButton>
|
|
|
|
|
|
|
|
</Root>
|
|
|
|
</Root>
|
|
|
|
);
|
|
|
|
);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|