import clsx from "clsx" import { useAdminRegions } from "medusa-react" import { useMemo } from "react" import { Controller, useWatch } from "react-hook-form" import { Option } from "../../../../types/shared" import FormValidator from "../../../../utils/form-validator" import { NestedForm } from "../../../../utils/nested-form" import InputError from "../../../atoms/input-error" import IconTooltip from "../../../molecules/icon-tooltip" import IndeterminateCheckbox from "../../../molecules/indeterminate-checkbox" import InputField from "../../../molecules/input" import { NextSelect } from "../../../molecules/select/next-select" import TextArea from "../../../molecules/textarea" import PriceFormInput from "../../general/prices-form/price-form-input" type DiscountRegionOption = Option & { currency_code: string } enum DiscountRuleType { FIXED = "fixed", PERCENTAGE = "percentage", FREE_SHIPPING = "free_shipping", } export type DiscountGeneralFormType = { region_ids: DiscountRegionOption[] code: string value?: number description: string is_dynamic?: boolean } type DiscountGeneralFormProps = { form: NestedForm type: DiscountRuleType isEdit?: boolean } const DiscountGeneralForm = ({ form, type, isEdit, }: DiscountGeneralFormProps) => { const { register, path, control, formState: { errors }, } = form const { regions } = useAdminRegions() const regionOptions = useMemo(() => { return ( regions?.map((r) => ({ value: r.id, label: r.name, currency_code: r.currency_code, })) || [] ) }, [regions]) const selectedRegionCurrency = useWatch({ control, name: path("region_ids.0.currency_code"), defaultValue: "usd", }) return (
{ return ( { onChange(type === DiscountRuleType.FIXED ? [value] : value) }} label="Choose valid regions" isMulti={type !== DiscountRuleType.FIXED} selectAll={type !== DiscountRuleType.FIXED} isSearchable required options={regionOptions} errors={errors} /> ) }} />
{type === DiscountRuleType.FIXED ? ( { return ( ) }} /> ) : type === DiscountRuleType.PERCENTAGE ? ( ) : null}

The code your customers will enter during checkout. This will appear on your customer's invoice. Uppercase letters and numbers only.