SPB Git forge

spb/rareindex

Public
54commits 1branches 0releases
7.1 MBsize
maindefault branch
10 days agolast push
TypeScript 61.9% HTML 37.2% SQL 0.7%
682 B · 21 lines typescript
Raw Blame History
1/** Shared shape for server-action results consumed by useActionState forms. */2export interface ActionState {3  ok?: boolean;4  error?: string | null;5  message?: string | null;6  fieldErrors?: Record<string, string>;7  /** arbitrary data returned to the form (e.g. cooldown seconds, QR data URL) */8  data?: Record<string, unknown>;9}1011export const idle: ActionState = { ok: false, error: null };1213export function fieldErrorsFrom(issues: Array<{ path: PropertyKey[]; message: string }>): Record<string, string> {14  const out: Record<string, string> = {};15  for (const i of issues) {16    const k = String(i.path[0] ?? '_');17    if (!out[k]) out[k] = i.message;18  }19  return out;20}21