@get-asset/react

Global Receipts Config

Drop-in styled receipt-request setting: the rule's title and copy, one threshold row per country, and a Save that commits the lot. Each row is the same styled AssetReceiptsThreshold body, so a row looks and behaves identically whether it stands alone or sits in this list. The tenant's configs are read and written for you: GET /v0/tenant/rules/receipts fills the rows, and Save PATCHes the whole set back and reseeds the rows from the response, which puts the button to sleep again. onSaveSuccess / onSaveError tell you how it went — for a toast — and onSave takes the request over entirely.

Preview

Loading preview…

API reference

Root props

PropTypeDefaultDescription
titlerequiredstringThe card's label, e.g. "Auto-request Receipts". Renders as a heading in sentence case.
subtitlerequiredstringThe muted line explaining what the rule does.
notestringA second muted line for who the setting applies to, e.g. "This is the default for your businesses." Optional — nothing renders without it.
thresholdsGlobalReceiptsConfigThreshold[]Override the fetched configs, skipping the request entirely — for tests, stories, or a host that already holds the setting. One row per entry: { id, title, subtitle, currency, amount, enabled }.
state"loading" | "error" | "empty"Force a state, skipping the request — tests/stories.
saveErrorErrorForce the save-error message — tests/stories. A real one only appears after a failed write, which needs an edit and a press to reach.
emptyMessagestringOverride the copy shown when no country has a threshold configured. Defaults to “No receipt thresholds set yet. Configured countries will appear here.”
onSave(thresholds: GlobalReceiptsConfigThreshold[]) => void | Promise<void>Own the write: called with the whole edited set instead of the built-in PATCH. Return a promise and the card stays in its saving state until it settles, and shows the save-error message if it rejects.
onSaveSuccess(thresholds: GlobalReceiptsConfigThreshold[]) => voidCalled after a save succeeds, with the rows as saved — the server-confirmed set when the card wrote, the submitted set when onSave did.
onSaveError(error: Error) => voidCalled when a save fails, with the same error the card shows beside Save. Use it for a toast, or leave the inline message to do the talking.
savingbooleanForce the saving state — tests/stories. Otherwise it follows the write in flight: the rows go inert and Save stops responding.
disabledbooleanMake the whole card inert (e.g. the viewer can't change the setting).
editablebooleanWhether the setting can be changed here. Defaults to true; pass false and the controls go inert and Save isn't rendered at all. Different from disabled, which keeps the button on screen but unpressable — that says “not now”, this says “not here”.
saveLabelstringOverride the copy on the save button. Defaults to "Save".
classNamestringForwarded to the card.

States

LoadingReading the tenant's configs — a silhouette per row until they land.

Loading preview…

ErrorThe read failed: the copy stands, and Try Again refetches.

Loading preview…

EmptyThe read succeeded, but no country has a threshold configured.

Loading preview…

DefaultSave is inert until something differs — edit a threshold or flip a switch and it wakes up.

Loading preview…

Rule offOne row switched off: its threshold field dims and goes inert, and the card still saves the pair.

Loading preview…

Savingsaving — the rows go inert while the write is in flight.

Loading preview…

Save failedThe write was rejected: the rows and the edit survive, and a quiet line beside Save says so — a retry costs no retyping.

Loading preview…

Disableddisabled — the whole card is frozen at its current setting.

Loading preview…

Behavior notes

  • One row per country in the payload. The response carries the setting only (is_enabled, threshold_amount), so each row's label, explanation and currency come from the SDK's country map — Canada in CAD, the United States in USD. A country the tenant hasn't configured gets no row.
  • The rows edit a draft, not the server: a row commit (blur, Enter, a switch flip) moves the draft, and only Save writes — the whole set, in one PATCH. Save is inert while the configs load, while the read is failing, and until something actually differs.
  • A failed write keeps the draft and says so in a quiet line beside Save — the same surface AssetTransactionMatch uses for a failed action — so a retry costs no retyping. A failed read replaces the rows instead: different problem, different surface.
  • Save compares values rather than counting edits, so a threshold typed away from 30 and back to 30 leaves nothing to save and the button goes inert again.
  • A row paints exactly like a standalone AssetReceiptsThreshold — same recessed --asset-surface row, same --asset-card field. This card adds layout around the rows, not colour of its own, so retheming a token moves both the same way.
  • Below ~420px of row width each row changes shape: its switch comes up beside the title, with the subtitle and the threshold field full width underneath. The rows measure themselves, not the viewport, so the card reflows correctly in a narrow column on a wide page.