Skip to Content
@get-asset/sdkComponents

Receipt Rules

List a business's own receipt rules — when a receipt is asked for on a ledger — and delete one.

List a business's own receipt rules — when a receipt is asked for on a ledger — and delete one. A ledger is judged by the first of these that exists: the business's rule for it, the business's default, the tenant's rule for its name, the tenant's default. Add and Edit hand off to your own editor, or to the Receipt Rule Editor.

Anatomy

Import the primitive and compose the parts you need.

<ReceiptRules.Root onAddRule={openCreate} onEditRule={openEdit}>
  <ReceiptRules.AddRuleTrigger />
  <ReceiptRules.Loading>Loading rules…</ReceiptRules.Loading>
  <ReceiptRules.Error>
    <ReceiptRules.ErrorMessage />
    <ReceiptRules.Retry>Try again</ReceiptRules.Retry>
  </ReceiptRules.Error>
  <ReceiptRules.Empty>No rules</ReceiptRules.Empty>
  <ReceiptRules.Success>
    <ReceiptRules.Rules>
      <ReceiptRules.Rule>
        <ReceiptRules.Sentence>
          <ReceiptRules.Clause>
            <ReceiptRules.ClauseConnector />
            <ReceiptRules.ClauseValues><ReceiptRules.ClauseValue /></ReceiptRules.ClauseValues>
          </ReceiptRules.Clause>
        </ReceiptRules.Sentence>
        <ReceiptRules.LedgerName />
        <ReceiptRules.Summary />
        <ReceiptRules.Threshold />
        <ReceiptRules.Reason />
        <ReceiptRules.EditTrigger />
        <ReceiptRules.DeleteTrigger />
      </ReceiptRules.Rule>
    </ReceiptRules.Rules>
  </ReceiptRules.Success>
  <ReceiptRules.WriteErrorToast><ReceiptRules.WriteError /></ReceiptRules.WriteErrorToast>
</ReceiptRules.Root>

Required scopes

The access token used by AssetProvider must include these scopes for this primitive to fetch data successfully:

  • business:read
  • business:update

API reference

Root props

PropTypeRequiredDefaultDescription
state"loading" | "error" | "empty"NoForce a specific state for testing/storybook.
rulesBusinessReceiptRulePublic[]NoOverride fetched rules for testing/storybook. Skips the API call.
onAddRule() => voidNoThe host opens its own rule editor.
onEditRule(ruleId: string) => voidNoThe host opens its own rule editor, for this rule. The default rule goes by the id "default", which ReceiptRuleEditor takes as its ruleId.
currencystringNoISO-4217 code the amounts are denominated in. Resolved from the business's own country when omitted — a Canadian business's thresholds are in CAD — which costs a Business lookup the other receipt components already make.
formatAmount(value: number) => stringNoAmount formatting inside a summary. Defaults to currency, in US English.

Parts

Compound parts

Value, wrapper and action parts support asChild. Gates and iterators take children. Row parts must be nested inside Rules.

PartPropsDescription
ReceiptRules.RootOwns the business-scoped read of the receipt rules and the delete.
ReceiptRules.LoadingRenders during the initial read.
ReceiptRules.ErrorRenders on read failure.
ReceiptRules.SuccessRenders once the list has loaded. A fetched list always has the default row, reading Use system defaults until the business saves its own.
ReceiptRules.EmptyRenders when there is no row: only with state="empty" or an empty rules override, since a fetched list always has the default row.
ReceiptRules.ErrorMessageFriendly load-error copy; accepts format(error).
ReceiptRules.RetryRetry the failed read.
ReceiptRules.AddRuleTriggerCalls onAddRule to open the host editor. Renders nothing without onAddRule.
ReceiptRules.RulesIterates the rules, providing row context.
ReceiptRules.RuleRow wrapper with data-rule-id and data-mode (never, every or threshold).
ReceiptRules.SentenceIterates the current rule's sentence clauses.
ReceiptRules.ClauseClause wrapper with data-clause (ledger, amount, action or reason).
ReceiptRules.ClauseConnectorThe words leading into the clause's values, e.g. 'and the amount is at least'.
ReceiptRules.ClauseValuesIterates the current clause's values.
ReceiptRules.ClauseValueOne value, with data-kind: trigger (the ledger), literal (the amount), enum (what the rule does) or reason.
ReceiptRules.DefaultRuleRenders children only on the business's default rule, which ends the list. Until the business saves its own, the row reads Use system defaults.
ReceiptRules.LedgerNameThe ledger the rule is for, as the business typed it. On the business's default rule, which has no ledger: "Any other expense ledger", or "Any expense ledger" when the business has no ledger rules.
ReceiptRules.SummaryWhat the rule does as a sentence, e.g. 'Ask for receipts of $25 or more'; carries data-mode.
ReceiptRules.ThresholdThe amount the rule asks over; renders nothing unless the rule asks over an amount. Accepts format(number).
ReceiptRules.ReasonThe reason shown on the request; renders nothing when the rule has none.
ReceiptRules.EditTriggerCalls onEditRule with the current rule id. Renders nothing without onEditRule.
ReceiptRules.DeleteTriggerDeletes the current rule, so its ledger follows the business's default again, or without one the tenant's rule for its name. Disabled while any rule's delete is pending; renders nothing without the update scope.
ReceiptRules.HasRowActionsGate for a row's action menu: renders when the row can be edited or deleted.
ReceiptRules.WriteErrorToastGate for a delete error.
ReceiptRules.WriteErrorFriendly write-error copy; accepts format(error).
ReceiptRules.DismissWriteErrorDismisses the write error.
ReceiptRules.useReceiptRulesRoot context hook for rows, loading, errors and actions.
ReceiptRules.useClauseCurrent sentence clause hook; use within Sentence.
ReceiptRules.useClauseValueCurrent clause value hook; use within ClauseValues.
ReceiptRules.useReceiptRuleCurrent rule context hook; use within Rules.
ReceiptRules.scopesRequired OAuth scope array.

On this page