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.
| Prop | Type | Default | Description |
|---|---|---|---|
open | boolean | — | Controlled open state. Supply with `onOpenChange`. |
defaultOpen | boolean | false | Uncontrolled 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. |
items | ApplyItem[] | [] | 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. |
now | Date | DATE_PICKER_INPUT_DEFAULT_NOW | Reference "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. |
initialCode | string | "" | Undocumented — add TSDoc to the prop in the library. |
initialValue | string | "" | Undocumented — add TSDoc to the prop in the library. |
initialLimitEnabled | boolean | false | Undocumented — add TSDoc to the prop in the library. |
initialLimitCount | string | "" | Undocumented — add TSDoc to the prop in the library. |
initialExpiryEnabled | boolean | false | Undocumented — add TSDoc to the prop in the library. |
initialEndDate | Date | — | Undocumented — add TSDoc to the prop in the library. |
initialEndTime | string | "11:59 PM" | Undocumented — add TSDoc to the prop in the library. |
initialAllItemsChecked | boolean | true | Seeds the "All items" master checkbox. |
initialSelectedItems | ApplyItem[] | — | Seeds the selection. Leave undefined for the app's behaviour — everything selected once the modal opens; pass `[]` for a genuinely empty selection. |
defaultAccordionValue | string | "" | Pass `"all-items"` to render the Apply-to accordion expanded on mount. |
datePickerUsePortal | boolean | — | 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.