Expense claims
An employee sees who they are signed in as and their expense claims, and can withdraw a pending claim, giving their approver a reason. The host owns the employee, the claims and the decision to withdraw; the micro-app lists the claims, collects the reason and sends it.
An agent built this document from one request (see Built by the agent):
My host can give the signed-in employee (name, team) and their expense claims (merchant, amount, status). Let people see their claims and withdraw a pending one with a reason.
Try this
Section titled “Try this”- Watch the first load: Loading your claims… shows until the host answers.
- Only the pending claim has a Withdraw button. Press it: the withdraw page shows that claim.
- Withdraw claim appears once you type a reason. Type
Dupand press it. The declaration’s own rule (at least 3 characters) passes, but the stand-in host wants 10 or more, so its message shows under the reason and you stay on the page with the reason kept. - Write a longer reason and withdraw. You are back on the list, where the
claim now reads Withdrawn and has no button. In Actions, only the
updateran: nothing refetched the list.
How it works
Section titled “How it works”Two host objects, fetched at startup
Section titled “Two host objects, fetched at startup”The employee is one record and the claims a list; neither fetch takes
inputs, so each is declared "fetch": {}. Withdrawing is an update with a
single withdrawalReason input: the document never sends a status, because
the host decides what withdrawing does.
{ "capabilities": { "fetch": {}, "update": { "inputs": { "withdrawalReason": { "kind": "string", "required": true, "nullable": false, "minLength": 3, "maxLength": 500 } } } }, "lifecycle": { "startup": [ { "action": "fetch", "params": { "object": "employee" } }, { "action": "fetch", "params": { "object": "claims" } } ] }}A Withdraw button only where it applies
Section titled “A Withdraw button only where it applies”The button sits in the row template. It is visible only on a pending claim,
and only while the host does not report update as not allowed. It copies the
row into a /withdraw draft and opens the withdraw page:
{ "claim-withdraw": { "type": "Button", "props": { "label": "Withdraw", "variant": "ghost", "size": "sm", "disabled": false, "fullWidth": false }, "children": [], "on": { "press": [ { "action": "setState", "params": { "statePath": "/withdraw", "value": { "id": { "$item": "id" }, "merchant": { "$item": "merchant" }, "amount": { "$item": "amount" }, "reason": "" } } }, { "action": "goToPage", "params": { "page": "page-withdraw" } } ] }, "visible": [ { "$item": "status", "eq": "pending" }, { "$state": "/meta/objects/claims/capabilities/update/allowed", "neq": false } ] }}The designer’s preview seeds every host operation as not allowed, so this
button stays hidden there; it shows here because the stand-in host implements
update.
Update the row, then go back
Section titled “Update the row, then go back”The update names the claim by its identity in row and sends the reason. A
rejected update stops the event, so the draft survives for another try. A
successful one merges the claim the host returns into the list in place, so
the list needs no refetch. The button is busy while the update runs, and the
reason Input’s error shows the host’s field error:
{ "withdraw-submit": { "type": "Button", "props": { "label": "Withdraw claim", "variant": "danger", "size": "md", "disabled": false, "fullWidth": false, "busy": { "$cond": { "$state": "/meta/objects/claims/operations/update/phase", "eq": "loading" }, "$then": true, "$else": false }, "busyLabel": "Withdrawing…" }, "children": [], "on": { "press": [ { "action": "update", "params": { "object": "claims", "row": { "id": { "$state": "/withdraw/id" } }, "inputs": { "withdrawalReason": { "$state": "/withdraw/reason" } } } }, { "action": "setState", "params": { "statePath": "/withdraw", "value": { "id": "", "merchant": "", "amount": 0, "reason": "" } } }, { "action": "goToPage", "params": { "page": "page-claims" } } ] }, "visible": { "$state": "/withdraw/reason" } }, "withdraw-reason": { "type": "Input", "props": { "label": "Reason for withdrawing", "placeholder": "e.g. Submitted twice by mistake", "inputType": "text", "lines": 3, "required": true, "helpText": "Your approver will see this reason.", "maxLength": 500, "value": { "$bindState": "/withdraw/reason" }, "error": { "$state": "/meta/objects/claims/operations/update/error/fieldErrors/withdrawalReason" } }, "children": [] }}The host contract
Section titled “The host contract”employee = hr.Employee (one record) fetch() -> {id, name: string, team: string}claims = expenses.Claim (a list of records) fetch() -> [{id, merchant: string, amount: number, status: pending|approved|rejected|withdrawn}] update(id, withdrawalReason: string (minLength 3, maxLength 500)) -> {id, merchant: string, amount: number, status: pending|approved|rejected|withdrawn}At startup: fetch employee, fetch claimsComplete document — examples/documents/expense-claims.json
{ "envelopeVersion": 1, "ui": { "root": "app", "elements": { "app": { "type": "PageStack", "props": { "name": "My expense claims" }, "children": [ "page-claims", "page-withdraw" ] }, "stack-1": { "type": "Stack", "props": { "direction": "vertical", "gap": "xs", "align": "stretch", "justify": "start", "wrap": false, "padding": "none", "surface": null }, "children": [ "employee-name", "employee-team" ] }, "employee-name": { "type": "Heading", "props": { "content": { "$state": "/objects/employee/data/name" }, "level": "1", "align": "left", "accent": false }, "children": [] }, "employee-team": { "type": "Text", "props": { "content": { "$state": "/objects/employee/data/team" }, "size": "md", "tone": "muted", "align": "left", "italic": false }, "children": [] }, "claims-section": { "type": "Section", "props": { "eyebrow": "EXPENSES", "title": "Your claims", "tone": "outlined", "padding": "lg" }, "children": [ "claims-loading", "claims-error", "claims-empty", "claims-list" ] }, "claims-loading": { "type": "Text", "props": { "content": "Loading your claims…", "size": "md", "tone": "muted", "align": "left", "italic": false }, "children": [], "visible": { "$state": "/meta/objects/claims/operations/fetch/phase", "eq": "loading" } }, "claims-error": { "type": "Stack", "props": { "direction": "vertical", "gap": "sm", "align": "stretch", "justify": "start", "wrap": false, "padding": "none", "surface": null }, "children": [ "text-1", "claims-retry" ], "visible": { "$state": "/meta/objects/claims/operations/fetch/phase", "eq": "error" } }, "text-1": { "type": "Text", "props": { "content": "Your claims could not be loaded.", "size": "md", "tone": "accent", "align": "left", "italic": false }, "children": [] }, "claims-retry": { "type": "Button", "props": { "label": "Try again", "variant": "outline", "size": "sm", "disabled": false, "fullWidth": false }, "children": [], "on": { "press": [ { "action": "fetch", "params": { "object": "claims" } } ] } }, "claims-empty": { "type": "Text", "props": { "content": "You have no expense claims yet.", "size": "md", "tone": "muted", "align": "left", "italic": false }, "children": [], "visible": [ { "$state": "/meta/objects/claims/operations/fetch/phase", "eq": "success" }, { "$state": "/meta/objects/claims/count", "eq": 0 } ] }, "claims-list": { "type": "Stack", "props": { "direction": "vertical", "gap": "sm", "align": "stretch", "justify": "start", "wrap": false, "padding": "none", "surface": null }, "children": [ "claim-row" ], "repeat": { "statePath": "/objects/claims/data", "key": "id" } }, "claim-row": { "type": "Stack", "props": { "direction": "horizontal", "gap": "md", "align": "center", "justify": "between", "wrap": true, "padding": "sm", "surface": "paper" }, "children": [ "claim-info", "claim-side" ] }, "claim-info": { "type": "Stack", "props": { "direction": "vertical", "gap": "xs", "align": "stretch", "justify": "start", "wrap": false, "padding": "none", "surface": null }, "children": [ "claim-merchant", "claim-amount" ] }, "claim-merchant": { "type": "Text", "props": { "content": { "$item": "merchant" }, "size": "md", "tone": "default", "align": "left", "italic": false }, "children": [] }, "claim-amount": { "type": "Text", "props": { "content": { "$format": "currency", "value": { "$item": "amount" }, "currency": "EUR" }, "size": "sm", "tone": "muted", "align": "left", "italic": false }, "children": [] }, "claim-side": { "type": "Stack", "props": { "direction": "horizontal", "gap": "sm", "align": "center", "justify": "start", "wrap": false, "padding": "none", "surface": null }, "children": [ "status-pending", "status-approved", "status-rejected", "status-withdrawn", "claim-withdraw" ] }, "status-pending": { "type": "Text", "props": { "content": "Pending", "size": "sm", "tone": "accent", "align": "left", "italic": false }, "children": [], "visible": { "$item": "status", "eq": "pending" } }, "status-approved": { "type": "Text", "props": { "content": "Approved", "size": "sm", "tone": "default", "align": "left", "italic": false }, "children": [], "visible": { "$item": "status", "eq": "approved" } }, "status-rejected": { "type": "Text", "props": { "content": "Rejected", "size": "sm", "tone": "muted", "align": "left", "italic": false }, "children": [], "visible": { "$item": "status", "eq": "rejected" } }, "status-withdrawn": { "type": "Text", "props": { "content": "Withdrawn", "size": "sm", "tone": "muted", "align": "left", "italic": true }, "children": [], "visible": { "$item": "status", "eq": "withdrawn" } }, "claim-withdraw": { "type": "Button", "props": { "label": "Withdraw", "variant": "ghost", "size": "sm", "disabled": false, "fullWidth": false }, "children": [], "on": { "press": [ { "action": "setState", "params": { "statePath": "/withdraw", "value": { "id": { "$item": "id" }, "merchant": { "$item": "merchant" }, "amount": { "$item": "amount" }, "reason": "" } } }, { "action": "goToPage", "params": { "page": "page-withdraw" } } ] }, "visible": [ { "$item": "status", "eq": "pending" }, { "$state": "/meta/objects/claims/capabilities/update/allowed", "neq": false } ] }, "page-claims": { "type": "Page", "props": { "title": "My claims", "background": "mist" }, "children": [ "stack-1", "claims-section" ] }, "heading-1": { "type": "Heading", "props": { "content": "Withdraw a claim", "level": "1", "align": "left", "accent": false }, "children": [] }, "withdraw-section": { "type": "Section", "props": { "eyebrow": "PENDING CLAIM", "title": null, "tone": "outlined", "padding": "lg" }, "children": [ "stack-2", "withdraw-reason", "withdraw-error", "stack-3" ] }, "stack-2": { "type": "Stack", "props": { "direction": "horizontal", "gap": "md", "align": "center", "justify": "between", "wrap": false, "padding": "none", "surface": null }, "children": [ "withdraw-merchant", "withdraw-amount" ] }, "withdraw-merchant": { "type": "Heading", "props": { "content": { "$state": "/withdraw/merchant" }, "level": "3", "align": "left", "accent": false }, "children": [] }, "withdraw-amount": { "type": "Text", "props": { "content": { "$format": "currency", "value": { "$state": "/withdraw/amount" }, "currency": "EUR" }, "size": "md", "tone": "default", "align": "left", "italic": false }, "children": [] }, "withdraw-reason": { "type": "Input", "props": { "label": "Reason for withdrawing", "placeholder": "e.g. Submitted twice by mistake", "inputType": "text", "lines": 3, "required": true, "helpText": "Your approver will see this reason.", "maxLength": 500, "value": { "$bindState": "/withdraw/reason" }, "error": { "$state": "/meta/objects/claims/operations/update/error/fieldErrors/withdrawalReason" } }, "children": [] }, "withdraw-error": { "type": "Text", "props": { "content": { "$state": "/meta/objects/claims/operations/update/error/message" }, "size": "sm", "tone": "accent", "align": "left", "italic": false }, "children": [], "visible": { "$state": "/meta/objects/claims/operations/update/phase", "eq": "error" } }, "stack-3": { "type": "Stack", "props": { "direction": "horizontal", "gap": "md", "align": "center", "justify": "between", "wrap": false, "padding": "none", "surface": null }, "children": [ "withdraw-cancel", "withdraw-hint", "withdraw-submit" ] }, "withdraw-cancel": { "type": "Button", "props": { "label": "Keep claim", "variant": "ghost", "size": "md", "disabled": false, "fullWidth": false }, "children": [], "on": { "press": [ { "action": "goToPage", "params": { "page": "page-claims" } } ] } }, "withdraw-hint": { "type": "Text", "props": { "content": "Add a reason to withdraw.", "size": "sm", "tone": "muted", "align": "left", "italic": false }, "children": [], "visible": { "$state": "/withdraw/reason", "not": true } }, "withdraw-submit": { "type": "Button", "props": { "label": "Withdraw claim", "variant": "danger", "size": "md", "disabled": false, "fullWidth": false, "busy": { "$cond": { "$state": "/meta/objects/claims/operations/update/phase", "eq": "loading" }, "$then": true, "$else": false }, "busyLabel": "Withdrawing…" }, "children": [], "on": { "press": [ { "action": "update", "params": { "object": "claims", "row": { "id": { "$state": "/withdraw/id" } }, "inputs": { "withdrawalReason": { "$state": "/withdraw/reason" } } } }, { "action": "setState", "params": { "statePath": "/withdraw", "value": { "id": "", "merchant": "", "amount": 0, "reason": "" } } }, { "action": "goToPage", "params": { "page": "page-claims" } } ] }, "visible": { "$state": "/withdraw/reason" } }, "page-withdraw": { "type": "Page", "props": { "title": "Withdraw claim", "background": "mist" }, "children": [ "heading-1", "withdraw-section" ] } }, "state": { "withdraw": { "id": "", "merchant": "", "amount": 0, "reason": "" } } }, "meta": { "pack": { "id": "mica.core", "version": "1.0.0" } }, "objects": { "employee": { "type": "hr.Employee", "cardinality": "one", "identity": "id", "fields": { "id": { "kind": "string", "required": true, "nullable": false }, "name": { "kind": "string", "required": true, "nullable": false }, "team": { "kind": "string", "required": true, "nullable": false } }, "capabilities": { "fetch": {} }, "sample": { "id": "e-102", "name": "Priya Shah", "team": "Field Sales" } }, "claims": { "type": "expenses.Claim", "cardinality": "many", "identity": "id", "fields": { "id": { "kind": "string", "required": true, "nullable": false }, "merchant": { "kind": "string", "required": true, "nullable": false }, "amount": { "kind": "number", "required": true, "nullable": false }, "status": { "kind": "string", "required": true, "nullable": false, "enum": [ "pending", "approved", "rejected", "withdrawn" ] } }, "capabilities": { "fetch": {}, "update": { "inputs": { "withdrawalReason": { "kind": "string", "required": true, "nullable": false, "minLength": 3, "maxLength": 500 } } } }, "sample": [ { "id": "c-301", "merchant": "Northline Rail", "amount": 84.5, "status": "pending" }, { "id": "c-298", "merchant": "Hotel Aurora", "amount": 212, "status": "approved" }, { "id": "c-290", "merchant": "Café Meridian", "amount": 18.2, "status": "rejected" } ] } }, "lifecycle": { "startup": [ { "action": "fetch", "params": { "object": "employee" } }, { "action": "fetch", "params": { "object": "claims" } } ] }}