import { MinusCircle, PlusCircle } from "lucide-react"; import { Button } from "@/src/components/ui/button"; import { Input } from "@/src/components/ui/input"; import { FormLabel } from "@/src/components/ui/form"; import { PricePreview } from "../PricePreview"; import type { UseFormReturn } from "react-hook-form"; import type { FormUpsertModel } from "../../validation"; type TierPriceEditorProps = { tierIndex: number; form: UseFormReturn; isDefault: boolean; }; export type { TierPriceEditorProps }; export function TierPriceEditor({ tierIndex, form, isDefault, }: TierPriceEditorProps) { const prices = form.watch(`pricingTiers.${tierIndex}.prices`) || {}; return (
Prices
Usage type Price
{Object.entries(prices).map(([key, value], priceIndex) => (
{ const newPrices = { ...prices }; const oldValue = newPrices[key]; delete newPrices[key]; newPrices[e.target.value] = oldValue; form.setValue(`pricingTiers.${tierIndex}.prices`, newPrices); }} className={!isDefault ? "cursor-not-allowed bg-muted" : ""} />
{ form.setValue(`pricingTiers.${tierIndex}.prices`, { ...prices, [key]: parseFloat(e.target.value), }); }} /> {isDefault && ( )}
))} {isDefault && ( )}
); }