feat: implement immutable form definitions
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
import { apiFetch, apiPath, type ApiSettings } from "@govoplan/core-webui";
|
||||
|
||||
|
||||
export type FormValueType = "text" | "multiline_text" | "integer" | "number" | "boolean" | "date" | "datetime" | "email" | "choice" | "multi_choice" | "object" | "list";
|
||||
|
||||
export type FormFieldDefinition = {
|
||||
key: string;
|
||||
label: string;
|
||||
value_type: FormValueType;
|
||||
required: boolean;
|
||||
help_text?: string | null;
|
||||
options: string[];
|
||||
constraints: Record<string, unknown>;
|
||||
default_value?: unknown;
|
||||
};
|
||||
|
||||
export type FormDefinition = {
|
||||
reference: {
|
||||
kind: "form";
|
||||
owner_module: "forms";
|
||||
object_id: string;
|
||||
tenant_id: string;
|
||||
version: string;
|
||||
};
|
||||
key: string;
|
||||
temporal: {
|
||||
revision: string;
|
||||
valid_from?: string | null;
|
||||
valid_to?: string | null;
|
||||
recorded_at: string;
|
||||
superseded_at?: string | null;
|
||||
change_reason: string;
|
||||
};
|
||||
title: string;
|
||||
description?: string | null;
|
||||
fields: FormFieldDefinition[];
|
||||
publication_state: "draft" | "published" | "retired";
|
||||
allow_drafts: boolean;
|
||||
max_attachments: number;
|
||||
signature_requirement: "none" | "optional" | "required";
|
||||
policy_refs: string[];
|
||||
handoff_kinds: string[];
|
||||
metadata: Record<string, unknown>;
|
||||
};
|
||||
|
||||
export function listFormDefinitions(
|
||||
settings: ApiSettings,
|
||||
options: { query?: string; states?: string[]; offset?: number; limit?: number } = {},
|
||||
signal?: AbortSignal
|
||||
): Promise<{ definitions: FormDefinition[]; total: number }> {
|
||||
return apiFetch(settings, apiPath("/api/v1/forms/definitions", {
|
||||
q: options.query,
|
||||
publication_state: options.states,
|
||||
offset: options.offset ?? 0,
|
||||
limit: options.limit ?? 200
|
||||
}), { signal });
|
||||
}
|
||||
|
||||
export function saveFormDefinition(
|
||||
settings: ApiSettings,
|
||||
definition: FormDefinition,
|
||||
expectedRevision?: string | null
|
||||
): Promise<FormDefinition> {
|
||||
return apiFetch(settings, `/api/v1/forms/definitions/${encodeURIComponent(definition.reference.object_id)}`, {
|
||||
method: "PUT",
|
||||
body: JSON.stringify({
|
||||
definition,
|
||||
expected_revision: expectedRevision ?? null
|
||||
})
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user