Skip to content

Purchase approval

A budget holder receives a link to a pending purchase request. The micro-app loads the request, shows what is being bought and why, and records the decision in the host’s procurement system. A rejection must say why; an approval may.

  • Press Record decision without choosing: the decision input is required, so nothing is sent and the error shows under the choice.
  • Choose Reject. The comment gains its Required marker. Recording the decision without a comment is blocked.
  • Choose Approve instead and record it without a comment. The outcome page shows the status the host stored.
  • Go back to Review: the decision card is gone, because the request is no longer pending, and an Already decided card shows instead.

update takes a decision limited to two values and a comment that is required only while /drafts/decision is rejected:

{
"request": {
"type": "procurement.purchase_request",
"cardinality": "one",
"identity": "id",
"fields": {
"id": {
"kind": "string",
"required": true
},
"title": {
"kind": "string",
"required": true
},
"requester": {
"kind": "string",
"required": true
},
"amount": {
"kind": "number",
"required": true
},
"justification": {
"kind": "string"
},
"status": {
"kind": "string",
"required": true,
"enum": [
"pending",
"approved",
"rejected"
]
},
"decisionComment": {
"kind": "string",
"nullable": true
}
},
"capabilities": {
"fetch": {
"inputs": {
"requestId": {
"kind": "string",
"required": true
}
}
},
"update": {
"inputs": {
"decision": {
"kind": "string",
"required": true,
"enum": [
"approved",
"rejected"
]
},
"comment": {
"kind": "string",
"requiredWhen": {
"$state": "/drafts/decision",
"eq": "rejected"
},
"maxLength": 280
}
}
}
},
"sample": {
"id": "PR-0000",
"title": "Sample request",
"requester": "Sample Person",
"amount": 100,
"justification": "Sample justification",
"status": "pending",
"decisionComment": null
}
}
}

Approve and Reject are one segmented Choice bound to /drafts/decision. The note under it and the comment’s Required marker follow the same state:

{
"decision": {
"type": "Choice",
"props": {
"label": "Decision",
"display": "segmented",
"options": [
{
"value": "approved",
"label": "Approve"
},
{
"value": "rejected",
"label": "Reject"
}
],
"required": true,
"helpText": null,
"value": {
"$bindState": "/drafts/decision"
},
"error": {
"$state": "/meta/objects/request/operations/update/error/fieldErrors/decision"
}
},
"children": []
},
"comment": {
"type": "Input",
"props": {
"label": "Comment for the requester",
"placeholder": "Optional when approving",
"inputType": "text",
"lines": 3,
"required": {
"$cond": {
"$state": "/drafts/decision",
"eq": "rejected"
},
"$then": true,
"$else": false
},
"helpText": "Required when you reject. Up to 280 characters.",
"value": {
"$bindState": "/drafts/comment"
},
"error": {
"$state": "/meta/objects/request/operations/update/error/fieldErrors/comment"
}
},
"children": []
}
}

update sends the current request’s id plus the two inputs. It rejects when the rules or the host refuse, so goToPage runs only after a recorded decision. The button is busy, reading Recording…, while the update runs:

{
"submit": {
"type": "Button",
"props": {
"label": "Record decision",
"variant": "outline",
"size": "md",
"disabled": false,
"fullWidth": true,
"busy": {
"$cond": {
"$state": "/meta/objects/request/operations/update/phase",
"eq": "loading"
},
"$then": true,
"$else": false
},
"busyLabel": "Recording…"
},
"children": [],
"on": {
"press": [
{
"action": "update",
"params": {
"object": "request",
"inputs": {
"decision": {
"$state": "/drafts/decision"
},
"comment": {
"$state": "/drafts/comment"
}
}
}
},
{
"action": "goToPage",
"params": {
"page": "page-done"
}
}
]
}
}
}

The decision card needs two conditions to hold — the request is loaded and still pending — so a decided request cannot be decided again from this screen:

{
"decision-card": {
"type": "Section",
"props": {
"eyebrow": "SIGN-OFF",
"title": "Your decision",
"tone": "outlined",
"padding": "lg"
},
"children": [
"decision",
"decision-approve-note",
"decision-reject-note",
"comment",
"submit",
"submit-error"
],
"visible": [
{
"$state": "/meta/objects/request/operations/fetch/phase",
"eq": "success"
},
{
"$state": "/objects/request/data/status",
"eq": "pending"
}
]
}
}
Complete document — examples/documents/purchase-approval.json
examples/documents/purchase-approval.json
{
"envelopeVersion": 1,
"ui": {
"root": "app",
"elements": {
"app": {
"type": "PageStack",
"props": {
"name": "Purchase approval"
},
"children": [
"page-review",
"page-done"
]
},
"page-review": {
"type": "Page",
"props": {
"title": "Review",
"background": "mist"
},
"children": [
"loading",
"request-card",
"decision-card",
"already-decided"
]
},
"loading": {
"type": "Text",
"props": {
"content": "Loading request…",
"size": "md",
"tone": "muted",
"align": "left",
"italic": false
},
"children": [],
"visible": {
"$state": "/meta/objects/request/operations/fetch/phase",
"eq": "loading"
}
},
"request-card": {
"type": "Section",
"props": {
"eyebrow": "PURCHASE REQUEST",
"title": null,
"tone": "raised",
"padding": "xl"
},
"children": [
"request-title",
"request-grid",
"request-reason"
],
"visible": {
"$state": "/meta/objects/request/operations/fetch/phase",
"eq": "success"
}
},
"request-title": {
"type": "Heading",
"props": {
"content": {
"$state": "/objects/request/data/title"
},
"level": "1",
"align": "left",
"accent": false
},
"children": []
},
"request-grid": {
"type": "Grid",
"props": {
"columns": 3,
"gap": "md",
"padding": "none",
"minCellWidth": 150
},
"children": [
"cell-id",
"cell-requester",
"cell-amount"
]
},
"cell-id": {
"type": "Value",
"props": {
"label": "Request",
"value": {
"$state": "/objects/request/data/id"
}
},
"children": []
},
"cell-requester": {
"type": "Value",
"props": {
"label": "Requested by",
"value": {
"$state": "/objects/request/data/requester"
}
},
"children": []
},
"cell-amount": {
"type": "Value",
"props": {
"label": "Amount",
"value": {
"$format": "currency",
"value": {
"$state": "/objects/request/data/amount"
},
"currency": "USD"
}
},
"children": []
},
"request-reason": {
"type": "Text",
"props": {
"content": {
"$state": "/objects/request/data/justification"
},
"size": "md",
"tone": "muted",
"align": "left",
"italic": false
},
"children": []
},
"decision-card": {
"type": "Section",
"props": {
"eyebrow": "SIGN-OFF",
"title": "Your decision",
"tone": "outlined",
"padding": "lg"
},
"children": [
"decision",
"decision-approve-note",
"decision-reject-note",
"comment",
"submit",
"submit-error"
],
"visible": [
{
"$state": "/meta/objects/request/operations/fetch/phase",
"eq": "success"
},
{
"$state": "/objects/request/data/status",
"eq": "pending"
}
]
},
"decision-approve-note": {
"type": "Text",
"props": {
"content": "You are approving this request.",
"size": "md",
"tone": "accent",
"align": "left",
"italic": false
},
"children": [],
"visible": {
"$state": "/drafts/decision",
"eq": "approved"
}
},
"decision-reject-note": {
"type": "Text",
"props": {
"content": "You are rejecting this request. Tell the requester why.",
"size": "md",
"tone": "accent",
"align": "left",
"italic": false
},
"children": [],
"visible": {
"$state": "/drafts/decision",
"eq": "rejected"
}
},
"comment": {
"type": "Input",
"props": {
"label": "Comment for the requester",
"placeholder": "Optional when approving",
"inputType": "text",
"lines": 3,
"required": {
"$cond": {
"$state": "/drafts/decision",
"eq": "rejected"
},
"$then": true,
"$else": false
},
"helpText": "Required when you reject. Up to 280 characters.",
"value": {
"$bindState": "/drafts/comment"
},
"error": {
"$state": "/meta/objects/request/operations/update/error/fieldErrors/comment"
}
},
"children": []
},
"submit": {
"type": "Button",
"props": {
"label": "Record decision",
"variant": "outline",
"size": "md",
"disabled": false,
"fullWidth": true,
"busy": {
"$cond": {
"$state": "/meta/objects/request/operations/update/phase",
"eq": "loading"
},
"$then": true,
"$else": false
},
"busyLabel": "Recording…"
},
"children": [],
"on": {
"press": [
{
"action": "update",
"params": {
"object": "request",
"inputs": {
"decision": {
"$state": "/drafts/decision"
},
"comment": {
"$state": "/drafts/comment"
}
}
}
},
{
"action": "goToPage",
"params": {
"page": "page-done"
}
}
]
}
},
"submit-error": {
"type": "Text",
"props": {
"content": {
"$state": "/meta/objects/request/operations/update/error/message"
},
"size": "md",
"tone": "accent",
"align": "left",
"italic": false
},
"children": [],
"visible": {
"$state": "/meta/objects/request/operations/update/phase",
"eq": "error"
}
},
"already-decided": {
"type": "Section",
"props": {
"eyebrow": null,
"title": "Already decided",
"tone": "outlined",
"padding": "lg"
},
"children": [
"already-status",
"already-open"
],
"visible": [
{
"$state": "/meta/objects/request/operations/fetch/phase",
"eq": "success"
},
{
"$state": "/objects/request/data/status",
"neq": "pending"
}
]
},
"already-status": {
"type": "Text",
"props": {
"content": {
"$state": "/objects/request/data/status"
},
"size": "md",
"tone": "accent",
"align": "left",
"italic": false
},
"children": []
},
"already-open": {
"type": "Button",
"props": {
"label": "See the outcome",
"variant": "ghost",
"size": "md",
"disabled": false,
"fullWidth": false
},
"children": [],
"on": {
"press": {
"action": "goToPage",
"params": {
"page": "page-done"
}
}
}
},
"page-done": {
"type": "Page",
"props": {
"title": "Outcome",
"background": "paper"
},
"children": [
"done-heading",
"done-status",
"done-comment",
"done-back"
]
},
"done-heading": {
"type": "Heading",
"props": {
"content": "Decision recorded",
"level": "1",
"align": "left",
"accent": true
},
"children": []
},
"done-status": {
"type": "Text",
"props": {
"content": {
"$state": "/objects/request/data/status"
},
"size": "lg",
"tone": "accent",
"align": "left",
"italic": false
},
"children": []
},
"done-comment": {
"type": "Text",
"props": {
"content": {
"$state": "/objects/request/data/decisionComment"
},
"size": "md",
"tone": "muted",
"align": "left",
"italic": false
},
"children": [],
"visible": {
"$state": "/objects/request/data/decisionComment"
}
},
"done-back": {
"type": "Button",
"props": {
"label": "Back to the request",
"variant": "outline",
"size": "md",
"disabled": false,
"fullWidth": false
},
"children": [],
"on": {
"press": {
"action": "goToPage",
"params": {
"page": "page-review"
}
}
}
},
"decision": {
"type": "Choice",
"props": {
"label": "Decision",
"display": "segmented",
"options": [
{
"value": "approved",
"label": "Approve"
},
{
"value": "rejected",
"label": "Reject"
}
],
"required": true,
"helpText": null,
"value": {
"$bindState": "/drafts/decision"
},
"error": {
"$state": "/meta/objects/request/operations/update/error/fieldErrors/decision"
}
},
"children": []
}
},
"state": {
"requestId": "PR-1042",
"drafts": {
"decision": null,
"comment": ""
}
}
},
"meta": {
"pack": {
"id": "mica.core",
"version": "1.0.0"
}
},
"objects": {
"request": {
"type": "procurement.purchase_request",
"cardinality": "one",
"identity": "id",
"fields": {
"id": {
"kind": "string",
"required": true
},
"title": {
"kind": "string",
"required": true
},
"requester": {
"kind": "string",
"required": true
},
"amount": {
"kind": "number",
"required": true
},
"justification": {
"kind": "string"
},
"status": {
"kind": "string",
"required": true,
"enum": [
"pending",
"approved",
"rejected"
]
},
"decisionComment": {
"kind": "string",
"nullable": true
}
},
"capabilities": {
"fetch": {
"inputs": {
"requestId": {
"kind": "string",
"required": true
}
}
},
"update": {
"inputs": {
"decision": {
"kind": "string",
"required": true,
"enum": [
"approved",
"rejected"
]
},
"comment": {
"kind": "string",
"requiredWhen": {
"$state": "/drafts/decision",
"eq": "rejected"
},
"maxLength": 280
}
}
}
},
"sample": {
"id": "PR-0000",
"title": "Sample request",
"requester": "Sample Person",
"amount": 100,
"justification": "Sample justification",
"status": "pending",
"decisionComment": null
}
}
},
"lifecycle": {
"startup": [
{
"action": "fetch",
"params": {
"object": "request",
"inputs": {
"requestId": {
"$state": "/requestId"
}
}
}
}
]
}
}