DiscountForm
Percentage or fixed-amount discount entry, inline or as the body of an Add discount dialog
Import
import { DiscountForm } from '@tallyui/components';Usage
<DiscountForm
title="Order discount"
currency={sale.order.currency}
onApply={(discount) => sale.applyDiscount(null, discount)}
onClose={() => setDiscountOpen(false)}
/>Renders a title, percentage or fixed-amount selector, discount input, and Apply and Cancel buttons. Parsing errors and refusals from onApply appear inline; a successful application closes the form through onClose.
Dialog layout
<DialogContent><DialogHeader><DialogTitle>Add discount</DialogTitle></DialogHeader>
<DiscountForm layout="dialog" currency={currency} onApply={apply} onClose={close} />
</DialogContent>Coupon tab
<DiscountForm layout="dialog" currency={currency} onApply={apply} onClose={close}
onApplyCoupon={(code) => sale.applyCoupon(code)}
coupons={[{ code: 'SUMMER10', detail: 'Percentage discount', amountLabel: '10%' }]} />With onApplyCoupon, the dialog opens on a "Quick discount" tab (the body above) beside a "Coupon" tab, as WCPOS v2's Add Discount sheet does. The Coupon tab picks one of coupons from a searchable list ("Search coupons..." matches the code or the detail, without regard to case; "No coupons found" when nothing matches). Apply stays disabled until a coupon is picked and while it is applying. A refusal string shows inline and the dialog stays open; a rejection shows "Failed to apply coupon."; null closes the dialog through onClose. Only listed coupons can be applied: the store's coupon list is the app's data. With onNewCoupon, a "New coupon" (+) button sits beside the picker and calls it without closing the dialog (creating the coupon is the app's job); with newCouponDisabledReason it is disabled and gives that reason as its tooltip and accessibility hint.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
title | string | 'Discount' (group label) | Heading (inline layout only) and accessible group label; omitted, no heading renders |
layout | 'inline' | 'dialog' | 'inline' | 'dialog': v2 Add Discount body for a host dialog (no heading, field first, starts at Amount, a DialogFooter with Cancel and "Add discount") |
currency | string | required | Currency used to parse fixed amounts into minor units and label the amount input |
onApply | (discount: Discount) => string | null | required | Receives the parsed discount; return a refusal to show inline or null once applied |
onClose | () => void | required | Called on Cancel or after onApply returns null |
onApplyCoupon | (code: string) => Promise<string | null> | — | layout="dialog" only: shows the Quick discount / Coupon tabs. Resolve a refusal to show inline, or null once applied (e.g. sale.applyCoupon) |
coupons | readonly DiscountCoupon[] | [] | The coupons the Coupon tab lists |
onNewCoupon | () => void | — | Shows the Coupon tab's "New coupon" (+) button, which calls this; the dialog stays open |
newCouponDisabledReason | string | — | Already-translated reason the New coupon button is disabled, e.g. "Coupons are created when the store is reachable"; shown as its tooltip and accessibility hint |
DiscountCoupon
One of the store's coupons, already formatted by the app (import type { DiscountCoupon } from '@tallyui/components').
| Field | Type | Description |
|---|---|---|
code | string | The coupon code, shown on the row and passed to onApplyCoupon |
detail | string (optional) | Muted text under the code, e.g. the description or "Percentage discount" |
amountLabel | string (optional) | Shown on the right, e.g. "10%" or "€5.00" |