Experience flow recipes
An app defines ordered pages. Pages emit next(data); useExperience performs their action, stores the result in context, and advances only on success. Each page name must be unique and non-empty. Use static props or props: context => ({ ... }) for reactive data from earlier steps.
Registration, survey, and collection selection
This complete local demo requires no API credentials. It keeps a mock participant and answers in flow context; it does not register an attendee or record a platform survey/quiz response:
<script setup lang="ts">
import {
ThemeWrapper, ExperienceFlow, useExperience, WelcomePage,
RegistrationPage, QuestionPage, CollectionPage, FinalPage,
type CollectionItem,
} from '@gxp-dev/app-ui'
const items: CollectionItem[] = [
{ id: 'portrait', title: 'Portrait', description: 'Create a portrait.' },
{ id: 'poster', title: 'Poster', description: 'Create an event poster.' },
]
const flow = useExperience({
initialContext: { collectionItems: items },
pages: [
{ name: 'welcome', component: WelcomePage, props: { title: 'Create your experience' } },
{ name: 'register', component: RegistrationPage, action: async values => {
// Replace with your registration service; rejection keeps this page active.
return { ...(values as Record<string, unknown>), id: 'demo-participant' }
} },
{ name: 'interests', component: QuestionPage, resultKey: 'interests', props: {
title: 'What interests you?', multiple: true,
options: [{ value: 'design', label: 'Design' }, { value: 'engineering', label: 'Engineering' }],
} },
{ name: 'choose', component: CollectionPage },
{ name: 'final', component: FinalPage, props: { title: 'All set!' } },
],
onComplete: () => console.log('Completed local demo'),
})
</script>
<template>
<ThemeWrapper><ExperienceFlow :flow="flow" /></ThemeWrapper>
</template>
Results are stored at context.registration, context.interests, and context.selectedItem. CollectionPage reads context.collectionItems unless items or contextKey is supplied. An API action can populate collectionItems before the selection step. Normalize collection records into the documented item shape.
Scan, upload, and review
import { useExperience, ScanPage, UploadPage, CollectionPage, FinalPage } from '@gxp-dev/app-ui'
import type { FileSelectedPayload, CollectionItem } from '@gxp-dev/app-ui'
// Your app supplies these operations using its authenticated platform services.
function createCheckInFlow(lookupAttendee: (code: string) => Promise<unknown>,
uploadMedia: (file: FileSelectedPayload) => Promise<CollectionItem[]>) {
return useExperience({ pages: [
{ name: 'scan', component: ScanPage, resultKey: 'attendee',
action: code => lookupAttendee(code as string) },
{ name: 'upload', component: UploadPage, resultKey: 'collectionItems',
props: { acceptImages: true, acceptVideos: false, maxFileSize: 10 * 1024 * 1024 },
action: file => uploadMedia(file as FileSelectedPayload) },
{ name: 'review', component: CollectionPage },
{ name: 'final', component: FinalPage },
] })
}
ScanPage emits a trimmed code and stops its scanner before handoff. UploadPage emits the full processed file only after confirmation. Neither page has a default API action. Distinguish the raw input from the action result: when an action runs, resultKey receives its return value. Save raw data inside your custom action if later pages also need it.
Reactive leaderboard or print job state
import { ref } from 'vue'
import { useExperience, LeaderboardPage, PrintStatusPage, FinalPage } from '@gxp-dev/app-ui'
import type { LeaderboardEntry, PrintJobState } from '@gxp-dev/app-ui'
const scores = ref<LeaderboardEntry[]>([])
const status = ref<PrintJobState>('pending')
const flow = useExperience({ pages: [
{ name: 'scores', component: LeaderboardPage, props: () => ({ entries: scores.value }) },
{ name: 'print', component: PrintStatusPage, props: () => ({ status: status.value, jobId: 'demo-job' }) },
{ name: 'final', component: FinalPage },
] })
Update the refs from your API or realtime subscription, and unsubscribe when the app unmounts. PrintStatusPage waits for completed/cancelled status before offering continuation unless allowSkip is set. Attach @retry and @cancel listeners to ExperienceFlow when this PrintStatusPage is active; the renderer forwards those listeners to the current page through Vue attributes. They are PrintStatusPage events, rather than declared ExperienceFlow events. The host listener calls the authorized job service and updates status; the component does not retry or cancel a backend job by itself. PrintStatusPage contract.
Error handling and retry
<ExperienceFlow :flow="flow">
<template #error="{ error, retry, dismiss }">
<div role="alert" class="rounded-lg bg-card p-6 text-card-foreground">
<p>{{ error.message }}</p>
<button type="button" class="primaryButton" @click="retry">Try again</button>
<button type="button" class="secondaryButton" @click="dismiss">Dismiss</button>
</div>
</template>
</ExperienceFlow>
The built-in error UI also retries. flow.retry() reruns a failed action with the original payload. When a page emits error (for example a LoadingPage task failure/timeout), the renderer's slot retry remounts that page to rerun its task. dismiss clears the error only; it does not rerun work. A separate ErrorPage emits retry for your host's custom recovery route.
Actions should support appropriate retry/idempotency behavior in the service. While an action runs, next/back/goTo cannot move away from its submitting page. Reset invalidates pending results so an old operation cannot populate a new session; it does not cancel the network operation. LoadingPage ignores task completion after unmount and clears its timeout timer after settlement.
Conditional steps and completion
Use when: context => boolean to skip a step. Assign distinct resultKey values for repeated questions or repeated capture steps. onComplete fires once when the final page submits; the final page remains mounted. reset() restores initial context, increments the session revision to remount the first page even without a page-name change, and enables another completion run. Back/goTo clear errors and permit continuation again.
An app-level reset should also clear any persistent media/border singleton state if the flow uses those composables:
import { useMedia, useCameraBorder } from '@gxp-dev/app-ui'
const media = useMedia()
const borders = useCameraBorder()
function startAgain() {
media.resetState()
borders.reset()
flow.reset()
}
See the flow overview, page APIs, and API adapter. Prebuilt pages can be used independently by listening to their emitted events.