next-safe-form 1.0.1 → 1.0.3
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.
- package/README.md +23 -12
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -88,29 +88,40 @@ useActionForm();
|
|
|
88
88
|
```ts
|
|
89
89
|
export async function loginAction(_, formData: FormData) {
|
|
90
90
|
const data = Object.fromEntries(formData);
|
|
91
|
+
const { success, error } = await someValidationFunction(data);
|
|
91
92
|
|
|
92
93
|
// Example validation error
|
|
93
|
-
if (!
|
|
94
|
-
|
|
95
|
-
success: false,
|
|
96
|
-
error: { email: "Email is required" },
|
|
97
|
-
type: "fields",
|
|
98
|
-
};
|
|
99
|
-
}
|
|
94
|
+
if (!success || error) {
|
|
95
|
+
const fields = extractZodError(error);
|
|
100
96
|
|
|
101
|
-
// Example server error
|
|
102
|
-
if (data.email !== "test@test.com") {
|
|
103
97
|
return {
|
|
104
98
|
success: false,
|
|
105
|
-
|
|
106
|
-
|
|
99
|
+
data,
|
|
100
|
+
error: {
|
|
101
|
+
type: "fields",
|
|
102
|
+
fields,
|
|
103
|
+
message: "Données invalides",
|
|
104
|
+
},
|
|
107
105
|
};
|
|
108
106
|
}
|
|
109
107
|
|
|
108
|
+
// Example server error
|
|
110
109
|
return {
|
|
111
|
-
success:
|
|
110
|
+
success: false,
|
|
112
111
|
data,
|
|
112
|
+
error: {
|
|
113
|
+
type: "server",
|
|
114
|
+
message: "Identifiant incorrect",
|
|
115
|
+
},
|
|
113
116
|
};
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
success: true,
|
|
120
|
+
data: {
|
|
121
|
+
phone: "",
|
|
122
|
+
password: ""
|
|
123
|
+
}
|
|
124
|
+
};
|
|
114
125
|
}
|
|
115
126
|
```
|
|
116
127
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-safe-form",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Simplify React 19 Server Actions forms in Next.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -32,6 +32,9 @@
|
|
|
32
32
|
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
33
33
|
"publish": "npm publish",
|
|
34
34
|
"publish-public": "npm publish --access public",
|
|
35
|
-
"publish-private": "npm publish --access restricted"
|
|
35
|
+
"publish-private": "npm publish --access restricted",
|
|
36
|
+
"patch": "npm version patch && npm publish --access public",
|
|
37
|
+
"minor": "npm version minor && npm publish --access public",
|
|
38
|
+
"major": "npm version major && npm publish --access public"
|
|
36
39
|
}
|
|
37
|
-
}
|
|
40
|
+
}
|