Fix starting and performing steps: send the workflow id under the name the server expects

This commit is contained in:
Yashas C 2026-11-05 06:40:17 +00:00 committed by Zino Studio
parent e60fcc8af3
commit 4d3f4ae2b5
3 changed files with 27 additions and 6 deletions

19
src/api.ts Normal file
View File

@ -0,0 +1,19 @@
import type { ZinoClient } from './zino-sdk'
// The SDK's start/perform helpers send `workflow_id`; the runtime API reads
// `workflow_uuid`. These calls go through the SDK's client with the right body.
export interface StepResult { instance_id?: string | number; success?: boolean }
export function startProcess(client: ZinoClient, workflowId: string, activityId: string, data: Record<string, unknown>) {
return client.request<StepResult>('POST', '/start', { workflow_uuid: workflowId, activity_id: activityId, data })
}
export function performStep(client: ZinoClient, workflowId: string, instanceId: string, activityId: string, data: Record<string, unknown>) {
const n = Number(instanceId)
return client.request<StepResult>('POST', '/activity', {
workflow_uuid: workflowId,
instance_id: Number.isFinite(n) ? n : instanceId,
activity_id: activityId,
data,
})
}

View File

@ -3,6 +3,7 @@ import { useQuery, useZino } from '../zino-sdk'
import { DETAIL_VIEW_IDS, FIELD_DEFS, STEPS, SYSTEM_KEYS, type StepDef } from '../config' import { DETAIL_VIEW_IDS, FIELD_DEFS, STEPS, SYSTEM_KEYS, type StepDef } from '../config'
import { ErrorBox, Loading, PageTitle, btnPrimary, btnSecondary, formatValue } from '../components/ui' import { ErrorBox, Loading, PageTitle, btnPrimary, btnSecondary, formatValue } from '../components/ui'
import { useState } from 'react' import { useState } from 'react'
import { performStep } from '../api'
import { useMutation, useQueryClient } from '../zino-sdk' import { useMutation, useQueryClient } from '../zino-sdk'
import { WORKFLOW_IDS } from '../config' import { WORKFLOW_IDS } from '../config'
@ -14,7 +15,7 @@ function canPerform(step: StepDef, roles: string[]) {
export default function RecordPage() { export default function RecordPage() {
const { id = '' } = useParams() const { id = '' } = useParams()
const { views, user, workflows } = useZino() const { views, user, client } = useZino()
const qc = useQueryClient() const qc = useQueryClient()
const [done, setDone] = useState<string | null>(null) const [done, setDone] = useState<string | null>(null)
const q = useQuery({ const q = useQuery({
@ -22,7 +23,7 @@ export default function RecordPage() {
queryFn: () => views.getDetailView(DETAIL_VIEW_IDS.REGISTRATION_DETAILS, id), queryFn: () => views.getDetailView(DETAIL_VIEW_IDS.REGISTRATION_DETAILS, id),
}) })
const quick = useMutation({ const quick = useMutation({
mutationFn: (step: StepDef) => workflows.performActivity(WORKFLOW_IDS.TRUCK_ONBOARDING, id, step.id, {}), mutationFn: (step: StepDef) => performStep(client, WORKFLOW_IDS.TRUCK_ONBOARDING, id, step.id, {}),
onSuccess: (_r, step) => { setDone(step.name); qc.invalidateQueries({ queryKey: ['detailview'] }); qc.invalidateQueries({ queryKey: ['recordview'] }) }, onSuccess: (_r, step) => { setDone(step.name); qc.invalidateQueries({ queryKey: ['detailview'] }); qc.invalidateQueries({ queryKey: ['recordview'] }) },
}) })

View File

@ -1,6 +1,7 @@
import { useState, type FormEvent } from 'react' import { useState, type FormEvent } from 'react'
import { useNavigate, useParams } from 'react-router-dom' import { useNavigate, useParams } from 'react-router-dom'
import { useMutation, useQueryClient, useZino } from '../zino-sdk' import { useMutation, useQueryClient, useZino } from '../zino-sdk'
import { performStep, startProcess } from '../api'
import { FILE_ALLOWED_TYPES, INIT_STEP, WORKFLOW_IDS, fieldDef, stepById, type FieldDef } from '../config' import { FILE_ALLOWED_TYPES, INIT_STEP, WORKFLOW_IDS, fieldDef, stepById, type FieldDef } from '../config'
import { ErrorBox, PageTitle, btnPrimary, btnSecondary, inputCls } from '../components/ui' import { ErrorBox, PageTitle, btnPrimary, btnSecondary, inputCls } from '../components/ui'
@ -27,7 +28,7 @@ export default function StepFormPage({ start }: { start?: boolean }) {
const params = useParams() const params = useParams()
const step = start ? INIT_STEP : stepById(params.stepId ?? '') const step = start ? INIT_STEP : stepById(params.stepId ?? '')
const instanceId = start ? undefined : params.id const instanceId = start ? undefined : params.id
const { workflows } = useZino() const { client } = useZino()
const qc = useQueryClient() const qc = useQueryClient()
const nav = useNavigate() const nav = useNavigate()
const [values, setValues] = useState<Record<string, Val>>({}) const [values, setValues] = useState<Record<string, Val>>({})
@ -35,11 +36,11 @@ export default function StepFormPage({ start }: { start?: boolean }) {
const submit = useMutation({ const submit = useMutation({
mutationFn: (data: Record<string, Val>) => start mutationFn: (data: Record<string, Val>) => start
? workflows.startWorkflow(WORKFLOW_IDS.TRUCK_ONBOARDING, step!.id, data) ? startProcess(client, WORKFLOW_IDS.TRUCK_ONBOARDING, step!.id, data)
: workflows.performActivity(WORKFLOW_IDS.TRUCK_ONBOARDING, instanceId!, step!.id, data), : performStep(client, WORKFLOW_IDS.TRUCK_ONBOARDING, instanceId!, step!.id, data),
onSuccess: (r) => { onSuccess: (r) => {
qc.invalidateQueries({ queryKey: ['recordview'] }); qc.invalidateQueries({ queryKey: ['detailview'] }) qc.invalidateQueries({ queryKey: ['recordview'] }); qc.invalidateQueries({ queryKey: ['detailview'] })
nav(`/records/${encodeURIComponent(r.instance_id || instanceId || '')}`) nav(`/records/${encodeURIComponent(String(r.instance_id ?? instanceId ?? ''))}`)
}, },
}) })
if (!step) return <ErrorBox error={{ message: 'Unknown step' }} /> if (!step) return <ErrorBox error={{ message: 'Unknown step' }} />