import { Controller, useFieldArray, useWatch } from "react-hook-form" import { currencies } from "../../../../utils/currencies" import { nestedForm, NestedForm } from "../../../../utils/nested-form" import IncludesTaxTooltip from "../../../atoms/includes-tax-tooltip" import InputError from "../../../atoms/input-error" import Switch from "../../../atoms/switch" import CoinsIcon from "../../../fundamentals/icons/coins-icon" import IconTooltip from "../../../molecules/icon-tooltip" import MetadataForm, { MetadataFormType } from "../../general/metadata-form" import PriceFormInput from "../../general/prices-form/price-form-input" type DenominationType = { amount: number currency_code: string includes_tax?: boolean } export type DenominationFormType = { defaultDenomination: DenominationType currencyDenominations: DenominationType[] useSameValue: boolean metadata: MetadataFormType } type Props = { form: NestedForm } const DenominationForm = ({ form }: Props) => { const { control, path, formState: { errors }, } = form const { fields } = useFieldArray({ control, name: path("currencyDenominations"), keyName: "fieldKey", }) const defaultCurrency = useWatch({ control, name: path("defaultDenomination"), }) const useSameValue = useWatch({ control, name: path("useSameValue"), }) return (

Default currency

{defaultCurrency.currency_code.toUpperCase()} {currencies[defaultCurrency.currency_code.toUpperCase()].name}
{ return ( <> ) }} />

Use value for all currencies?

If enabled the value used for the store's default currency code will also be applied to all other currencies in your store.

{ return ( ) }} />
{!useSameValue && (

Other currencies

{fields.map((denom, index) => { return (
{denom.currency_code.toUpperCase()} {currencies[denom.currency_code.toUpperCase()].name}
{ return ( ) }} />
) })}
)}

Metadata

) } export default DenominationForm