Skip to Content
@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:read
  • business:update
  • ledger:read

API reference

Root props

PropTypeRequiredDefaultDescription
ruleIdstringNoThe 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.
ruleBusinessReceiptRulePublicNoOverride the fetched rule for testing/storybook. Skips the API call.
ledgersLedgerPublic[]NoOverride the ledgers to choose from for testing/storybook. Skips the API call.
previewReceiptRuleEditorPreviewNoOverride the preview and disable its request for testing/storybook.
currencystringNoISO-4217 code amounts are in. Resolved from the business's country when omitted.
formatAmount(value: number) => stringNoAmount formatting in preview rows. Defaults to currency, in US English.
formatDate(value: string) => stringNoDate formatting in preview rows. Defaults to "Jan 31, 2026".
state"loading" | "error"NoForce a specific state for testing/storybook.
saveErrorErrorNoForce the save-error state for testing/storybook.
onSaved(rule: BusinessReceiptRulePublic | null) => voidNoCalled with the saved rule once the write goes through; with null when the default rule was set back to the system's defaults.
onCancel() => voidNoThe 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.

PartPropsDescription
ReceiptRuleEditor.RootOwns the read of the rule being edited, the draft, validation and the write.
ReceiptRuleEditor.LoadingRenders while the rule being edited loads.
ReceiptRuleEditor.ErrorRenders when the rule being edited couldn't be loaded.
ReceiptRuleEditor.SuccessRenders once the form is ready: always for a new rule, after the read for an edit.
ReceiptRuleEditor.ErrorMessageFriendly load-error copy; accepts format(error).
ReceiptRuleEditor.RetryRetry the failed read.
ReceiptRuleEditor.LedgerFieldWrapper for the ledger; carries data-invalid while it has an error to show.
ReceiptRuleEditor.LedgerSelectWires a Select-root-shaped child (value, onValueChange, disabled) to the chosen ledger, which is picked from the business's own.
ReceiptRuleEditor.LedgerOptionsIterates the business's ledgers by name, providing per-ledger context.
ReceiptRuleEditor.LedgerOptionOne ledger: its name as the text, its id as value and data-ledger-id.
ReceiptRuleEditor.ModeOptionChooses 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.LedgerRuleRenders children for a rule that is for a ledger: every new rule, and every saved one but the default.
ReceiptRuleEditor.DefaultRuleRenders children for the business's default rule, which has no ledger to choose.
ReceiptRuleEditor.AsksRenders children while the rule asks for receipts, every time or over an amount: when there is a request to give a reason on.
ReceiptRuleEditor.OwnRuleRenders children while the rule has settings of its own: always, but for a default left on the system's defaults.
ReceiptRuleEditor.SystemDefaultsRenders children while the default rule is set to use the system's defaults.
ReceiptRuleEditor.LedgerSummaryThe chosen ledger's name, or what the default rule covers; renders nothing while none is chosen.
ReceiptRuleEditor.ReasonSummaryThe 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.RuleSummaryWhat the draft does, in a sentence: 'Ask for receipts of $25 or more'.
ReceiptRuleEditor.ThresholdFieldWrapper for the amount; renders only while the mode is threshold.
ReceiptRuleEditor.ThresholdInputThe amount to ask over, typed as money and settled to two decimals on blur.
ReceiptRuleEditor.ReasonFieldWrapper for the reason; carries data-invalid while it has an error to show.
ReceiptRuleEditor.ReasonInputThe reason shown on the request in place of the default message.
ReceiptRuleEditor.FieldErrorOne field's error; requires field and renders nothing until the field was left or a save was tried.
ReceiptRuleEditor.PreviewRuns 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.PreviewIdleRenders before a preview has been asked for.
ReceiptRuleEditor.PreviewRunningRenders while the preview is out.
ReceiptRuleEditor.PreviewResultsRenders when the rule matches at least one recent transaction.
ReceiptRuleEditor.PreviewEmptyRenders when the rule matches none of the recent transactions.
ReceiptRuleEditor.PreviewOffRenders beside the preview's matches, or none, when automatic receipt requests are off for the business, so the rule asks for none.
ReceiptRuleEditor.PreviewErrorRenders when the preview failed.
ReceiptRuleEditor.PreviewStaleRenders while the shown preview is of an earlier draft.
ReceiptRuleEditor.PreviewTitleThe preview's heading.
ReceiptRuleEditor.PreviewSubtitleHow many transactions the preview shows.
ReceiptRuleEditor.PreviewStaleMessageCopy for a preview of an earlier draft.
ReceiptRuleEditor.PreviewErrorMessagePreview-error copy; accepts format(error).
ReceiptRuleEditor.PreviewRetryAsks for the same preview again.
ReceiptRuleEditor.PreviewRowsIterates the matched transactions, newest first, providing row context.
ReceiptRuleEditor.PreviewRowRow wrapper with data-transaction-id.
ReceiptRuleEditor.PreviewDescriptionThe transaction's description.
ReceiptRuleEditor.PreviewLedgerThe ledger the spend is on: the rule's own, or the one the default rule matched on.
ReceiptRuleEditor.PreviewDateThe transaction's date; accepts format(ISO string).
ReceiptRuleEditor.PreviewAmountThe transaction's spend on the matched ledger, which the rule's amount is compared with; accepts format(number).
ReceiptRuleEditor.usePreviewRowCurrent preview row hook; use within PreviewRows.
ReceiptRuleEditor.SaveWrites 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.CancelCalls onCancel.
ReceiptRuleEditor.SaveErrorGateGate for a save error.
ReceiptRuleEditor.SaveErrorSave-error copy, including a ledger that already has a rule; accepts format(error).
ReceiptRuleEditor.useReceiptRuleEditorRoot 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.scopesRequired OAuth scope array.

On this page