@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:readbusiness:update
API reference
Root props
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
state | "loading" | "error" | "empty" | No | Force a specific state for testing/storybook. | |
rules | BusinessReceiptRulePublic[] | No | Override fetched rules for testing/storybook. Skips the API call. | |
onAddRule | () => void | No | The host opens its own rule editor. | |
onEditRule | (ruleId: string) => void | No | The host opens its own rule editor, for this rule. The default rule goes by the id "default", which ReceiptRuleEditor takes as its ruleId. | |
currency | string | No | ISO-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) => string | No | Amount 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.
| Part | Props | Description |
|---|---|---|
ReceiptRules.Root | Owns the business-scoped read of the receipt rules and the delete. | |
ReceiptRules.Loading | Renders during the initial read. | |
ReceiptRules.Error | Renders on read failure. | |
ReceiptRules.Success | Renders once the list has loaded. A fetched list always has the default row, reading Use system defaults until the business saves its own. | |
ReceiptRules.Empty | Renders when there is no row: only with state="empty" or an empty rules override, since a fetched list always has the default row. | |
ReceiptRules.ErrorMessage | Friendly load-error copy; accepts format(error). | |
ReceiptRules.Retry | Retry the failed read. | |
ReceiptRules.AddRuleTrigger | Calls onAddRule to open the host editor. Renders nothing without onAddRule. | |
ReceiptRules.Rules | Iterates the rules, providing row context. | |
ReceiptRules.Rule | Row wrapper with data-rule-id and data-mode (never, every or threshold). | |
ReceiptRules.Sentence | Iterates the current rule's sentence clauses. | |
ReceiptRules.Clause | Clause wrapper with data-clause (ledger, amount, action or reason). | |
ReceiptRules.ClauseConnector | The words leading into the clause's values, e.g. 'and the amount is at least'. | |
ReceiptRules.ClauseValues | Iterates the current clause's values. | |
ReceiptRules.ClauseValue | One value, with data-kind: trigger (the ledger), literal (the amount), enum (what the rule does) or reason. | |
ReceiptRules.DefaultRule | Renders 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.LedgerName | The 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.Summary | What the rule does as a sentence, e.g. 'Ask for receipts of $25 or more'; carries data-mode. | |
ReceiptRules.Threshold | The amount the rule asks over; renders nothing unless the rule asks over an amount. Accepts format(number). | |
ReceiptRules.Reason | The reason shown on the request; renders nothing when the rule has none. | |
ReceiptRules.EditTrigger | Calls onEditRule with the current rule id. Renders nothing without onEditRule. | |
ReceiptRules.DeleteTrigger | Deletes 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.HasRowActions | Gate for a row's action menu: renders when the row can be edited or deleted. | |
ReceiptRules.WriteErrorToast | Gate for a delete error. | |
ReceiptRules.WriteError | Friendly write-error copy; accepts format(error). | |
ReceiptRules.DismissWriteError | Dismisses the write error. | |
ReceiptRules.useReceiptRules | Root context hook for rows, loading, errors and actions. | |
ReceiptRules.useClause | Current sentence clause hook; use within Sentence. | |
ReceiptRules.useClauseValue | Current clause value hook; use within ClauseValues. | |
ReceiptRules.useReceiptRule | Current rule context hook; use within Rules. | |
ReceiptRules.scopes | Required OAuth scope array. |