aboutsummaryrefslogtreecommitdiffstats
path: root/code/frontend/src/models/internal
diff options
context:
space:
mode:
Diffstat (limited to 'code/frontend/src/models/internal')
-rw-r--r--code/frontend/src/models/internal/FormError.ts24
-rw-r--r--code/frontend/src/models/internal/IForm.ts15
-rw-r--r--code/frontend/src/models/internal/KnownProblem.ts10
3 files changed, 49 insertions, 0 deletions
diff --git a/code/frontend/src/models/internal/FormError.ts b/code/frontend/src/models/internal/FormError.ts
new file mode 100644
index 0000000..f6d8978
--- /dev/null
+++ b/code/frontend/src/models/internal/FormError.ts
@@ -0,0 +1,24 @@
+import type { KnownProblem } from "./KnownProblem";
+
+export class FormError {
+ title: string;
+ subtitle: string;
+ constructor(title: string = "", subtitle: string = "") {
+ this.title = title;
+ this.title = subtitle;
+ }
+
+ set(title: string = "", subtitle: string = "") {
+ this.title = title;
+ this.subtitle = subtitle;
+ }
+
+ set_from_known_problem(knownProblem: KnownProblem) {
+ this.title = knownProblem.title ?? "";
+ this.subtitle = knownProblem.subtitle ?? "";
+ }
+
+ has_error() {
+ return this.title?.length > 0 || this.subtitle?.length > 0;
+ }
+} \ No newline at end of file
diff --git a/code/frontend/src/models/internal/IForm.ts b/code/frontend/src/models/internal/IForm.ts
new file mode 100644
index 0000000..c14b770
--- /dev/null
+++ b/code/frontend/src/models/internal/IForm.ts
@@ -0,0 +1,15 @@
+import type { FormError } from "./FormError";
+
+export interface IForm {
+ fields: Record<string, IFormField>;
+ error: FormError;
+ get_payload: Function;
+ submit_async: Function;
+ isLoading: boolean;
+ showError: boolean;
+}
+
+export interface IFormField {
+ value: any;
+ errors: Array<string>;
+}
diff --git a/code/frontend/src/models/internal/KnownProblem.ts b/code/frontend/src/models/internal/KnownProblem.ts
new file mode 100644
index 0000000..b6923d9
--- /dev/null
+++ b/code/frontend/src/models/internal/KnownProblem.ts
@@ -0,0 +1,10 @@
+export type KnownProblem = {
+ title: string,
+ subtitle: string,
+ errors: Record<string, string[]>,
+ traceId: string,
+}
+
+export function is_known_problem(response: Response): boolean {
+ return response.headers.has("X-IsKnownProblem");
+} \ No newline at end of file