Skip to content

Settings

Create discount modal

A one-screen dialog for quickly creating a discount code, covering code, value, an apply-to item picker, and usage-limit and expiry toggles.
Available
Ports as-is

Examples

Rendered live from the maintained Storybook story. Lantern stores only the story id and embeds Storybook rather than duplicating the component or its demo.

Create discount modal

Rendered live from Storybook

Storybook must be running for this to load — bun run start:storybook from the monorepo root, or set NEXT_PUBLIC_STORYBOOK_URL to a deployed instance.

Props

The component's public API, read from its TypeScript source. Descriptions come from TSDoc on the prop, so this table cannot drift from the component.

PropTypeDefaultDescription
openboolean—Controlled open state. Supply with `onOpenChange`.
defaultOpenbooleanfalseUncontrolled open state — how the open-on-mount stories work.
onOpenChange(open: boolean) => void—Undocumented — add TSDoc to the prop in the library.
onCreate(data: DiscountFormResult) => void—Undocumented — add TSDoc to the prop in the library.
itemsApplyItem[][]Everything the discount can apply to — tiers, products and checkout links flattened into one list. The app builds this from three sources; here it is a prop so the modal never reaches for a context or a data module.
generateCode() => string() => "SPRING26"Backs the Generate link. Fixed by default: the app used `Math.random()` over an alphabet, which would make every screenshot differ.
nowDateDATE_PICKER_INPUT_DEFAULT_NOWReference "today" for the expiry date field. Never reads the machine clock.
initialDiscountType"amount" | "percentage""amount"Seeds the Amount/Percentage switcher so both halves are static stories.
initialCodestring""Undocumented — add TSDoc to the prop in the library.
initialValuestring""Undocumented — add TSDoc to the prop in the library.
initialLimitEnabledbooleanfalseUndocumented — add TSDoc to the prop in the library.
initialLimitCountstring""Undocumented — add TSDoc to the prop in the library.
initialExpiryEnabledbooleanfalseUndocumented — add TSDoc to the prop in the library.
initialEndDateDate—Undocumented — add TSDoc to the prop in the library.
initialEndTimestring"11:59 PM"Undocumented — add TSDoc to the prop in the library.
initialAllItemsCheckedbooleantrueSeeds the "All items" master checkbox.
initialSelectedItemsApplyItem[]—Seeds the selection. Leave undefined for the app's behaviour — everything selected once the modal opens; pass `[]` for a genuinely empty selection.
defaultAccordionValuestring""Pass `"all-items"` to render the Apply-to accordion expanded on mount.
datePickerUsePortalboolean—Pass through the modal's portal suppression for the expiry calendar.

Reference

Transcribed from the component audit. If this disagrees with the source, the source is right.

Source
src/components/settings/CreateDiscountModal.tsx
Portability
Copies across unchanged — only the utils import path moves.
Variants
type: amount | percentageapplyMode: all | itemsinitialDiscountType: amount | percentage
Notes
Use it as the fast path for a simple discount when the full multi-section editor is unnecessary. The master "All items" checkbox is three-state, and clicking it while any items are selected clears the selection rather than completing it; closing by the X, overlay, or Escape always discards the draft.