import { useState } from "react"; import Image from "next/image"; import { Controller, useForm } from "react-hook-form"; import { Disclosure } from "@headlessui/react"; // components import { ColorPicker, Input } from "components/custom-attributes"; // ui import { PrimaryButton, SecondaryButton, ToggleSwitch } from "components/ui"; // icons import { CheckCircle2, ChevronDown } from "lucide-react"; // assets import NumericalRepresentation from "public/custom-attributes/number/numerical.svg"; import BarRepresentation from "public/custom-attributes/number/bar.svg"; import RingRepresentation from "public/custom-attributes/number/ring.svg"; // types import { ICustomAttribute } from "types"; // constants import { CUSTOM_ATTRIBUTES_LIST } from "constants/custom-attributes"; type Props = { attributeDetails: ICustomAttribute; handleDeleteAttribute: () => Promise; handleUpdateAttribute: (data: Partial) => Promise; }; const numberAttributeRepresentations = [ { image: NumericalRepresentation, key: "numerical", label: "Numerical", }, { image: BarRepresentation, key: "bar", label: "Bar", }, { image: RingRepresentation, key: "ring", label: "Ring", }, ]; const typeMetaData = CUSTOM_ATTRIBUTES_LIST.number; export const NumberAttributeForm: React.FC = (props) => { const { attributeDetails, handleDeleteAttribute, handleUpdateAttribute } = props; const [isRemoving, setIsRemoving] = useState(false); const { control, formState: { isSubmitting }, handleSubmit, watch, } = useForm({ defaultValues: typeMetaData.defaultFormValues }); const handleDelete = async () => { setIsRemoving(true); await handleDeleteAttribute().finally(() => setIsRemoving(false)); }; return ( {({ open }) => ( <>
{attributeDetails.display_name ?? typeMetaData.label}
( )} /> ( )} />
Show as
( <> {numberAttributeRepresentations.map((representation) => (
onChange(representation.key)} >
{representation.label}
{representation.label} {value === representation.key && ( )}
))} )} />
{watch && (watch("extra_settings.representation") === "bar" || watch("extra_settings.representation") === "ring") && (
<>
Divided by
( )} />
<>
Color
( )} />
<>
Show number
( )} />
)}
( )} /> Mandatory field
{isRemoving ? "Removing..." : "Remove"} {isSubmitting ? "Saving..." : "Save"}
)} ); };