@azure-net/kit 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { RequestErrors } from '../../delivery/schema/index.js';
|
|
2
2
|
import type { AsyncActionResponse } from '../../index.js';
|
|
3
|
-
export interface FormConfig<FormData
|
|
4
|
-
onSubmit: (formData: Partial<FormData>) => Promise<AsyncActionResponse<Response, FormData>>;
|
|
3
|
+
export interface FormConfig<FormData> {
|
|
5
4
|
initialData?: FormData;
|
|
6
5
|
}
|
|
7
6
|
export interface ActiveForm<FormData, Response> {
|
|
@@ -12,4 +11,4 @@ export interface ActiveForm<FormData, Response> {
|
|
|
12
11
|
pending: boolean;
|
|
13
12
|
dirty: boolean;
|
|
14
13
|
}
|
|
15
|
-
export declare const createActiveForm: <FormData, Response = unknown>(config: FormConfig<FormData
|
|
14
|
+
export declare const createActiveForm: <FormData, Response = unknown>(onSubmit: (formData: Partial<FormData>) => Promise<AsyncActionResponse<Response, FormData>>, config: FormConfig<FormData>) => ActiveForm<FormData, Response>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ObjectUtil } from 'azure-net-tools';
|
|
2
|
-
export const createActiveForm = (config) => {
|
|
2
|
+
export const createActiveForm = (onSubmit, config) => {
|
|
3
3
|
const initial = config.initialData ?? {};
|
|
4
4
|
let formData = $state(ObjectUtil.deepClone(initial));
|
|
5
5
|
let formErrors = $state({});
|
|
@@ -7,7 +7,7 @@ export const createActiveForm = (config) => {
|
|
|
7
7
|
const dirty = $derived(JSON.stringify(formData) !== JSON.stringify(initial));
|
|
8
8
|
const submit = async () => {
|
|
9
9
|
pending = true;
|
|
10
|
-
const result = await
|
|
10
|
+
const result = await onSubmit(formData);
|
|
11
11
|
if (result.error?.fields) {
|
|
12
12
|
formErrors = result.error?.fields;
|
|
13
13
|
}
|