Skip to content

Support ticket intake

A customer describes a problem once, picks a priority, optionally asks for a call back, and submits. The host’s helpdesk creates the ticket and issues its number, and the micro-app moves to a confirmation page that shows it.

  • Press Submit ticket with the form empty. Nothing is sent: each required input shows is required but missing under its field.
  • Enter a subject of fewer than five characters, or an email without a domain, and submit again — the declaration’s minLength and pattern rules block it.
  • Press Call me back (it stays pressed while a call is wanted). A phone field appears with its Required marker, and submitting without it is refused.
  • Fill everything in but keep the description short. This time the host refuses — the stand-in helpdesk wants at least 20 characters — and its message appears in the same place.
  • Submit a valid ticket with Urgent priority. You land on the confirmation page with the new ticket number.

One declared object with a create capability

Section titled “One declared object with a create capability”

The document declares a ticket of host type helpdesk.ticket. It only ever creates one, so create is its sole capability, and the fields list what the confirmation page reads back:

{
"ticket": {
"type": "helpdesk.ticket",
"cardinality": "one",
"identity": "id",
"fields": {
"id": {
"kind": "string",
"required": true
},
"subject": {
"kind": "string",
"required": true
},
"priority": {
"kind": "string",
"required": true,
"enum": [
"normal",
"urgent"
]
},
"status": {
"kind": "string",
"required": true,
"enum": [
"open",
"pending",
"solved"
]
}
},
"capabilities": {
"create": {
"inputs": {
"email": {
"kind": "string",
"required": true,
"format": "email",
"pattern": "^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$"
},
"subject": {
"kind": "string",
"required": true,
"minLength": 5,
"maxLength": 80
},
"description": {
"kind": "string",
"required": true,
"maxLength": 2000
},
"priority": {
"kind": "string",
"required": true,
"enum": [
"normal",
"urgent"
]
},
"callbackPhone": {
"kind": "string",
"requiredWhen": {
"$state": "/drafts/wantsCallback",
"eq": true
},
"pattern": "^[0-9+() -]{7,20}$"
}
}
}
},
"sample": {
"id": "T-1001",
"subject": "Invoices page shows an error",
"priority": "normal",
"status": "open"
}
}
}

The draft the form edits is ordinary document state:

{
"state": {
"drafts": {
"ticket": {
"email": "",
"subject": "",
"description": "",
"priority": "normal",
"callbackPhone": ""
},
"wantsCallback": false
}
}
}

Each Input binds to a draft field with $bindState, and its error reads that input’s field error, which shows under the field only while there is one:

{
"subject": {
"type": "Input",
"props": {
"label": "Subject",
"placeholder": "Invoices page shows an error",
"inputType": "text",
"required": true,
"helpText": "5–80 characters",
"value": {
"$bindState": "/drafts/ticket/subject"
},
"error": {
"$state": "/meta/objects/ticket/operations/create/error/fieldErrors/subject"
}
},
"children": []
}
}

Priority is a segmented Choice whose options are the declared input’s enum values, bound to the draft. Asking for a call is a Toggle with display: "button" bound to /drafts/wantsCallback: one element, pressed while a call is wanted. See offer a fixed list of options.

The callback toggle writes /drafts/wantsCallback. The phone Input is visible, and marked required, under the same condition the callbackPhone input’s requiredWhen uses, so what the person sees and what Mica enforces agree:

{
"phone": {
"type": "Input",
"props": {
"label": "Callback phone",
"placeholder": "+1 555 0100",
"inputType": "text",
"required": {
"$cond": {
"$state": "/drafts/wantsCallback",
"eq": true
},
"$then": true,
"$else": false
},
"helpText": null,
"value": {
"$bindState": "/drafts/ticket/callbackPhone"
},
"error": {
"$state": "/meta/objects/ticket/operations/create/error/fieldErrors/callbackPhone"
}
},
"children": [],
"visible": {
"$state": "/drafts/wantsCallback",
"eq": true
}
}
}

The submit button runs two actions. create rejects when anything fails, so goToPage only runs after the host has created the ticket. While the create is loading the button is busy: it shows Sending… and ignores presses:

{
"submit": {
"type": "Button",
"props": {
"label": "Submit ticket",
"variant": "solid",
"size": "md",
"disabled": false,
"fullWidth": true,
"busy": {
"$cond": {
"$state": "/meta/objects/ticket/operations/create/phase",
"eq": "loading"
},
"$then": true,
"$else": false
},
"busyLabel": "Sending…"
},
"children": [],
"on": {
"press": [
{
"action": "create",
"params": {
"object": "ticket",
"inputs": {
"email": {
"$state": "/drafts/ticket/email"
},
"subject": {
"$state": "/drafts/ticket/subject"
},
"description": {
"$state": "/drafts/ticket/description"
},
"priority": {
"$state": "/drafts/ticket/priority"
},
"callbackPhone": {
"$state": "/drafts/ticket/callbackPhone"
}
}
}
},
{
"action": "goToPage",
"params": {
"page": "page-received"
}
}
]
}
}
}

The confirmation page reads the new record: /objects/ticket/data/id is the number the host issued.

Complete document — examples/documents/support-ticket.json
examples/documents/support-ticket.json
{
"envelopeVersion": 1,
"ui": {
"root": "app",
"elements": {
"app": {
"type": "PageStack",
"props": {
"name": "Support ticket intake"
},
"children": [
"page-new",
"page-received"
]
},
"page-new": {
"type": "Page",
"props": {
"title": "New ticket",
"background": "mist"
},
"children": [
"intro",
"form"
]
},
"intro": {
"type": "Stack",
"props": {
"direction": "vertical",
"gap": "sm",
"align": "stretch",
"justify": "start",
"wrap": false,
"padding": "none",
"surface": null
},
"children": [
"intro-heading",
"intro-copy"
]
},
"intro-heading": {
"type": "Heading",
"props": {
"content": "How can we help?",
"level": "1",
"align": "left",
"accent": true
},
"children": []
},
"intro-copy": {
"type": "Text",
"props": {
"content": "Describe the problem once. The support team sees everything you enter here.",
"size": "lg",
"tone": "muted",
"align": "left",
"italic": false
},
"children": []
},
"form": {
"type": "Section",
"props": {
"eyebrow": "NEW TICKET",
"title": "Your request",
"tone": "raised",
"padding": "lg"
},
"children": [
"email",
"subject",
"description",
"priority",
"priority-urgent-note",
"callback",
"phone",
"submit",
"submit-error"
]
},
"email": {
"type": "Input",
"props": {
"label": "Work email",
"placeholder": "name@company.example",
"inputType": "email",
"required": true,
"helpText": null,
"value": {
"$bindState": "/drafts/ticket/email"
},
"error": {
"$state": "/meta/objects/ticket/operations/create/error/fieldErrors/email"
}
},
"children": []
},
"subject": {
"type": "Input",
"props": {
"label": "Subject",
"placeholder": "Invoices page shows an error",
"inputType": "text",
"required": true,
"helpText": "5–80 characters",
"value": {
"$bindState": "/drafts/ticket/subject"
},
"error": {
"$state": "/meta/objects/ticket/operations/create/error/fieldErrors/subject"
}
},
"children": []
},
"description": {
"type": "Input",
"props": {
"label": "What happened?",
"placeholder": "Steps, error messages, what you expected",
"inputType": "text",
"lines": 4,
"required": true,
"helpText": null,
"value": {
"$bindState": "/drafts/ticket/description"
},
"error": {
"$state": "/meta/objects/ticket/operations/create/error/fieldErrors/description"
}
},
"children": []
},
"priority-urgent-note": {
"type": "Text",
"props": {
"content": "Urgent tickets page the on-call engineer.",
"size": "sm",
"tone": "accent",
"align": "left",
"italic": false
},
"children": [],
"visible": {
"$state": "/drafts/ticket/priority",
"eq": "urgent"
}
},
"phone": {
"type": "Input",
"props": {
"label": "Callback phone",
"placeholder": "+1 555 0100",
"inputType": "text",
"required": {
"$cond": {
"$state": "/drafts/wantsCallback",
"eq": true
},
"$then": true,
"$else": false
},
"helpText": null,
"value": {
"$bindState": "/drafts/ticket/callbackPhone"
},
"error": {
"$state": "/meta/objects/ticket/operations/create/error/fieldErrors/callbackPhone"
}
},
"children": [],
"visible": {
"$state": "/drafts/wantsCallback",
"eq": true
}
},
"submit": {
"type": "Button",
"props": {
"label": "Submit ticket",
"variant": "solid",
"size": "md",
"disabled": false,
"fullWidth": true,
"busy": {
"$cond": {
"$state": "/meta/objects/ticket/operations/create/phase",
"eq": "loading"
},
"$then": true,
"$else": false
},
"busyLabel": "Sending…"
},
"children": [],
"on": {
"press": [
{
"action": "create",
"params": {
"object": "ticket",
"inputs": {
"email": {
"$state": "/drafts/ticket/email"
},
"subject": {
"$state": "/drafts/ticket/subject"
},
"description": {
"$state": "/drafts/ticket/description"
},
"priority": {
"$state": "/drafts/ticket/priority"
},
"callbackPhone": {
"$state": "/drafts/ticket/callbackPhone"
}
}
}
},
{
"action": "goToPage",
"params": {
"page": "page-received"
}
}
]
}
},
"submit-error": {
"type": "Text",
"props": {
"content": {
"$state": "/meta/objects/ticket/operations/create/error/message"
},
"size": "md",
"tone": "accent",
"align": "left",
"italic": false
},
"children": [],
"visible": {
"$state": "/meta/objects/ticket/operations/create/phase",
"eq": "error"
}
},
"page-received": {
"type": "Page",
"props": {
"title": "Received",
"background": "paper"
},
"children": [
"received"
]
},
"received": {
"type": "Section",
"props": {
"eyebrow": "TICKET RECEIVED",
"title": null,
"tone": "outlined",
"padding": "xl"
},
"children": [
"received-heading",
"received-id",
"received-subject",
"received-urgent",
"received-again"
]
},
"received-heading": {
"type": "Heading",
"props": {
"content": "We're on it",
"level": "1",
"align": "left",
"accent": true
},
"children": []
},
"received-id": {
"type": "Text",
"props": {
"content": {
"$state": "/objects/ticket/data/id"
},
"size": "lg",
"tone": "accent",
"align": "left",
"italic": false
},
"children": []
},
"received-subject": {
"type": "Text",
"props": {
"content": {
"$state": "/objects/ticket/data/subject"
},
"size": "md",
"tone": "muted",
"align": "left",
"italic": false
},
"children": []
},
"received-urgent": {
"type": "Text",
"props": {
"content": "The on-call engineer has been paged.",
"size": "md",
"tone": "muted",
"align": "left",
"italic": false
},
"children": [],
"visible": {
"$state": "/objects/ticket/data/priority",
"eq": "urgent"
}
},
"received-again": {
"type": "Button",
"props": {
"label": "File another ticket",
"variant": "outline",
"size": "md",
"disabled": false,
"fullWidth": false
},
"children": [],
"on": {
"press": {
"action": "goToPage",
"params": {
"page": "page-new"
}
}
}
},
"priority": {
"type": "Choice",
"props": {
"label": "Priority",
"display": "segmented",
"options": [
{
"value": "normal",
"label": "Normal"
},
{
"value": "urgent",
"label": "Urgent — work is blocked"
}
],
"required": true,
"helpText": null,
"value": {
"$bindState": "/drafts/ticket/priority"
},
"error": {
"$state": "/meta/objects/ticket/operations/create/error/fieldErrors/priority"
}
},
"children": []
},
"callback": {
"type": "Toggle",
"props": {
"label": "Call me back",
"display": "button",
"required": false,
"helpText": null,
"value": {
"$bindState": "/drafts/wantsCallback"
}
},
"children": []
}
},
"state": {
"drafts": {
"ticket": {
"email": "",
"subject": "",
"description": "",
"priority": "normal",
"callbackPhone": ""
},
"wantsCallback": false
}
}
},
"meta": {
"pack": {
"id": "mica.core",
"version": "1.0.0"
}
},
"objects": {
"ticket": {
"type": "helpdesk.ticket",
"cardinality": "one",
"identity": "id",
"fields": {
"id": {
"kind": "string",
"required": true
},
"subject": {
"kind": "string",
"required": true
},
"priority": {
"kind": "string",
"required": true,
"enum": [
"normal",
"urgent"
]
},
"status": {
"kind": "string",
"required": true,
"enum": [
"open",
"pending",
"solved"
]
}
},
"capabilities": {
"create": {
"inputs": {
"email": {
"kind": "string",
"required": true,
"format": "email",
"pattern": "^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$"
},
"subject": {
"kind": "string",
"required": true,
"minLength": 5,
"maxLength": 80
},
"description": {
"kind": "string",
"required": true,
"maxLength": 2000
},
"priority": {
"kind": "string",
"required": true,
"enum": [
"normal",
"urgent"
]
},
"callbackPhone": {
"kind": "string",
"requiredWhen": {
"$state": "/drafts/wantsCallback",
"eq": true
},
"pattern": "^[0-9+() -]{7,20}$"
}
}
}
},
"sample": {
"id": "T-1001",
"subject": "Invoices page shows an error",
"priority": "normal",
"status": "open"
}
}
}
}