@get-asset/sdkComponents
Receipt Rule Editor
Make or change one of a business's receipt rules — the ledger it names, whether to never ask, ask every time or ask over an amount, and the reason shown on the request.
Make or change one of a business's receipt rules: the ledger it names, whether to never ask, ask every time or ask over an amount, and the reason shown on the request.
Anatomy
Import the primitive and compose the parts you need.
<ReceiptRuleEditor.Root ruleId={ruleId} onSaved={back} onCancel={back}>
<ReceiptRuleEditor.Loading>Loading rule…</ReceiptRuleEditor.Loading>
<ReceiptRuleEditor.Error>
<ReceiptRuleEditor.ErrorMessage />
<ReceiptRuleEditor.Retry>Try again</ReceiptRuleEditor.Retry>
</ReceiptRuleEditor.Error>
<ReceiptRuleEditor.Success>
<ReceiptRuleEditor.LedgerField>
<ReceiptRuleEditor.LedgerSelect>
<Select>
<ReceiptRuleEditor.LedgerOptions>
<ReceiptRuleEditor.LedgerOption asChild><Option /></ReceiptRuleEditor.LedgerOption>
</ReceiptRuleEditor.LedgerOptions>
</Select>
</ReceiptRuleEditor.LedgerSelect>
<ReceiptRuleEditor.FieldError field="ledgerId" />
</ReceiptRuleEditor.LedgerField>
<ReceiptRuleEditor.ModeOption mode="never" />
<ReceiptRuleEditor.ModeOption mode="every" />
<ReceiptRuleEditor.ModeOption mode="threshold" />
<ReceiptRuleEditor.ThresholdField>
<ReceiptRuleEditor.ThresholdInput />
<ReceiptRuleEditor.FieldError field="threshold" />
</ReceiptRuleEditor.ThresholdField>
<ReceiptRuleEditor.ReasonField>
<ReceiptRuleEditor.ReasonInput />
</ReceiptRuleEditor.ReasonField>
<ReceiptRuleEditor.Preview />
<ReceiptRuleEditor.PreviewIdle>Preview to see what it matches</ReceiptRuleEditor.PreviewIdle>
<ReceiptRuleEditor.PreviewRunning>Checking…</ReceiptRuleEditor.PreviewRunning>
<ReceiptRuleEditor.PreviewEmpty>No recent transactions match</ReceiptRuleEditor.PreviewEmpty>
<ReceiptRuleEditor.PreviewOff>Receipts are not asked for</ReceiptRuleEditor.PreviewOff>
<ReceiptRuleEditor.PreviewError><ReceiptRuleEditor.PreviewErrorMessage /></ReceiptRuleEditor.PreviewError>
<ReceiptRuleEditor.PreviewStale><ReceiptRuleEditor.PreviewStaleMessage /></ReceiptRuleEditor.PreviewStale>
<ReceiptRuleEditor.PreviewResults>
<ReceiptRuleEditor.PreviewRows>
<ReceiptRuleEditor.PreviewRow>
<ReceiptRuleEditor.PreviewDescription />
<ReceiptRuleEditor.PreviewDate />
<ReceiptRuleEditor.PreviewAmount />
<ReceiptRuleEditor.PreviewLedger />
</ReceiptRuleEditor.PreviewRow>
</ReceiptRuleEditor.PreviewRows>
</ReceiptRuleEditor.PreviewResults>
<ReceiptRuleEditor.SaveError />
<ReceiptRuleEditor.Cancel />
<ReceiptRuleEditor.Save />
</ReceiptRuleEditor.Success>
</ReceiptRuleEditor.Root>Required scopes
The access token used by AssetProvider must include these scopes for this primitive to fetch data successfully:
business:readbusiness:updateledger:read
API reference
Root props
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
ruleId | string | No | The rule to edit. Omit to make a new one. "default" is the business's default rule, made on save if the business has none yet. | |
rule | BusinessReceiptRulePublic | No | Override the fetched rule for testing/storybook. Skips the API call. | |
ledgers | LedgerPublic[] | No | Override the ledgers to choose from for testing/storybook. Skips the API call. | |
preview | ReceiptRuleEditorPreview | No | Override the preview and disable its request for testing/storybook. | |
currency | string | No | ISO-4217 code amounts are in. Resolved from the business's country when omitted. | |
formatAmount | (value: number) => string | No | Amount formatting in preview rows. Defaults to currency, in US English. | |
formatDate | (value: string) => string | No | Date formatting in preview rows. Defaults to "Jan 31, 2026". | |
state | "loading" | "error" | No | Force a specific state for testing/storybook. | |
saveError | Error | No | Force the save-error state for testing/storybook. | |
onSaved | (rule: BusinessReceiptRulePublic | null) => void | No | Called with the saved rule once the write goes through; with null when the default rule was set back to the system's defaults. | |
onCancel | () => void | No | The host closes the form without saving. |
Parts
Compound parts
Input, wrapper and action parts support asChild. Gates take children. Nothing is sent until Save, and Save sends nothing while a field is invalid.
| Part | Props | Description |
|---|---|---|
ReceiptRuleEditor.Root | Owns the read of the rule being edited, the draft, validation and the write. | |
ReceiptRuleEditor.Loading | Renders while the rule being edited loads. | |
ReceiptRuleEditor.Error | Renders when the rule being edited couldn't be loaded. | |
ReceiptRuleEditor.Success | Renders once the form is ready: always for a new rule, after the read for an edit. | |
ReceiptRuleEditor.ErrorMessage | Friendly load-error copy; accepts format(error). | |
ReceiptRuleEditor.Retry | Retry the failed read. | |
ReceiptRuleEditor.LedgerField | Wrapper for the ledger; carries data-invalid while it has an error to show. | |
ReceiptRuleEditor.LedgerSelect | Wires a Select-root-shaped child (value, onValueChange, disabled) to the chosen ledger, which is picked from the business's own. | |
ReceiptRuleEditor.LedgerOptions | Iterates the business's ledgers by name, providing per-ledger context. | |
ReceiptRuleEditor.LedgerOption | One ledger: its name as the text, its id as value and data-ledger-id. | |
ReceiptRuleEditor.ModeOption | Chooses when a receipt is asked for; requires mode="never", "every" or "threshold" and carries data-selected and aria-checked. mode="system" renders only on the default rule: it uses the system's defaults, the tenant's rules, and saving it removes the default the business saved. | |
ReceiptRuleEditor.LedgerRule | Renders children for a rule that is for a ledger: every new rule, and every saved one but the default. | |
ReceiptRuleEditor.DefaultRule | Renders children for the business's default rule, which has no ledger to choose. | |
ReceiptRuleEditor.Asks | Renders children while the rule asks for receipts, every time or over an amount: when there is a request to give a reason on. | |
ReceiptRuleEditor.OwnRule | Renders children while the rule has settings of its own: always, but for a default left on the system's defaults. | |
ReceiptRuleEditor.SystemDefaults | Renders children while the default rule is set to use the system's defaults. | |
ReceiptRuleEditor.LedgerSummary | The chosen ledger's name, or what the default rule covers; renders nothing while none is chosen. | |
ReceiptRuleEditor.ReasonSummary | The reason the request will give for wanting the receipt: the draft's own, that it gives none, or that a rule which never asks sends no request. | |
ReceiptRuleEditor.RuleSummary | What the draft does, in a sentence: 'Ask for receipts of $25 or more'. | |
ReceiptRuleEditor.ThresholdField | Wrapper for the amount; renders only while the mode is threshold. | |
ReceiptRuleEditor.ThresholdInput | The amount to ask over, typed as money and settled to two decimals on blur. | |
ReceiptRuleEditor.ReasonField | Wrapper for the reason; carries data-invalid while it has an error to show. | |
ReceiptRuleEditor.ReasonInput | The reason shown on the request in place of the default message. | |
ReceiptRuleEditor.FieldError | One field's error; requires field and renders nothing until the field was left or a save was tried. | |
ReceiptRuleEditor.Preview | Runs the draft over the business's recent confirmed transactions without saving it, to list the ones it matches; the default rule runs over every expense ledger the business has no rule for. Pressing it with a field wrong shows what is wrong; disabled while a preview or save is in flight. | |
ReceiptRuleEditor.PreviewIdle | Renders before a preview has been asked for. | |
ReceiptRuleEditor.PreviewRunning | Renders while the preview is out. | |
ReceiptRuleEditor.PreviewResults | Renders when the rule matches at least one recent transaction. | |
ReceiptRuleEditor.PreviewEmpty | Renders when the rule matches none of the recent transactions. | |
ReceiptRuleEditor.PreviewOff | Renders beside the preview's matches, or none, when automatic receipt requests are off for the business, so the rule asks for none. | |
ReceiptRuleEditor.PreviewError | Renders when the preview failed. | |
ReceiptRuleEditor.PreviewStale | Renders while the shown preview is of an earlier draft. | |
ReceiptRuleEditor.PreviewTitle | The preview's heading. | |
ReceiptRuleEditor.PreviewSubtitle | How many transactions the preview shows. | |
ReceiptRuleEditor.PreviewStaleMessage | Copy for a preview of an earlier draft. | |
ReceiptRuleEditor.PreviewErrorMessage | Preview-error copy; accepts format(error). | |
ReceiptRuleEditor.PreviewRetry | Asks for the same preview again. | |
ReceiptRuleEditor.PreviewRows | Iterates the matched transactions, newest first, providing row context. | |
ReceiptRuleEditor.PreviewRow | Row wrapper with data-transaction-id. | |
ReceiptRuleEditor.PreviewDescription | The transaction's description. | |
ReceiptRuleEditor.PreviewLedger | The ledger the spend is on: the rule's own, or the one the default rule matched on. | |
ReceiptRuleEditor.PreviewDate | The transaction's date; accepts format(ISO string). | |
ReceiptRuleEditor.PreviewAmount | The transaction's spend on the matched ledger, which the rule's amount is compared with; accepts format(number). | |
ReceiptRuleEditor.usePreviewRow | Current preview row hook; use within PreviewRows. | |
ReceiptRuleEditor.Save | Writes the rule. Pressing it with a field wrong shows what is wrong; disabled while saving, for an edit until something changed, and for an unsaved default left on Use system defaults. Renders nothing without the update scope. | |
ReceiptRuleEditor.Cancel | Calls onCancel. | |
ReceiptRuleEditor.SaveErrorGate | Gate for a save error. | |
ReceiptRuleEditor.SaveError | Save-error copy, including a ledger that already has a rule; accepts format(error). | |
ReceiptRuleEditor.useReceiptRuleEditor | Root context hook for the draft, errors and actions. Its save() does nothing when there is nothing to save, the same cases in which Save is disabled. | |
ReceiptRuleEditor.scopes | Required OAuth scope array. |