@colisweb/rescript-toolkit 5.20.4 → 5.21.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.
- package/package.json +1 -1
- package/src/form/ReSchema.res +10 -6
- package/src/request/Request.res +45 -0
package/package.json
CHANGED
package/src/form/ReSchema.res
CHANGED
|
@@ -26,7 +26,7 @@ module Make = (Lenses: Lenses) => {
|
|
|
26
26
|
|
|
27
27
|
module Validation = {
|
|
28
28
|
type rec t =
|
|
29
|
-
| Email({field: Lenses.field<string>, error: option<string>}): t
|
|
29
|
+
| Email({field: Lenses.field<string>, isOptional: bool, error: option<string>}): t
|
|
30
30
|
| Phone({field: Lenses.field<string>, error: option<string>}): t
|
|
31
31
|
| Password({
|
|
32
32
|
field: Lenses.field<string>,
|
|
@@ -91,7 +91,7 @@ module Make = (Lenses: Lenses) => {
|
|
|
91
91
|
|
|
92
92
|
let false_ = (~error=?, field) => [False({field, error})]
|
|
93
93
|
|
|
94
|
-
let email = (~error=?, field) => [Email({field, error})]
|
|
94
|
+
let email = (~error=?, ~isOptional=false, field) => [Email({field, isOptional, error})]
|
|
95
95
|
let phone = (~error=?, field) => [Phone({field, error})]
|
|
96
96
|
let password = (~error=?, ~login=?, field) => [Password({field, ?login, error})]
|
|
97
97
|
let optionalPassword = (~error=?, ~login=?, field) => [OptionalPassword({field, ?login, error})]
|
|
@@ -204,13 +204,17 @@ module Make = (Lenses: Lenses) => {
|
|
|
204
204
|
? Valid
|
|
205
205
|
: Error(error->Belt.Option.getWithDefault(i18n.floatMax(~value, ~max))),
|
|
206
206
|
)
|
|
207
|
-
| Validation.Email({field, error}) =>
|
|
207
|
+
| Validation.Email({field, isOptional, error}) =>
|
|
208
208
|
let value = Lenses.get(values, field)
|
|
209
209
|
(
|
|
210
210
|
Field(field),
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
211
|
+
switch value {
|
|
212
|
+
| "" if isOptional => Valid
|
|
213
|
+
| value =>
|
|
214
|
+
Js.Re.test_(ReSchemaRegExp.email, value)
|
|
215
|
+
? Valid
|
|
216
|
+
: Error(error->Belt.Option.getWithDefault(i18n.email(~value)))
|
|
217
|
+
},
|
|
214
218
|
)
|
|
215
219
|
| Validation.Phone({field, error}) =>
|
|
216
220
|
let value = Lenses.get(values, field)
|
package/src/request/Request.res
CHANGED
|
@@ -284,3 +284,48 @@ let mutateWithParams = (
|
|
|
284
284
|
revalidate,
|
|
285
285
|
)
|
|
286
286
|
}
|
|
287
|
+
|
|
288
|
+
module FetchAndRender = {
|
|
289
|
+
@react.component
|
|
290
|
+
let make = (
|
|
291
|
+
type argument response err,
|
|
292
|
+
~config: module(Config with
|
|
293
|
+
type argument = argument
|
|
294
|
+
and type response = response
|
|
295
|
+
and type error = err
|
|
296
|
+
),
|
|
297
|
+
~argument,
|
|
298
|
+
~children,
|
|
299
|
+
) => {
|
|
300
|
+
let (data, _, _) = useFetcher(config, Some(argument))
|
|
301
|
+
|
|
302
|
+
children(data)
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
module FetchAndRenderWithSuspense = {
|
|
307
|
+
@react.component
|
|
308
|
+
let make = (
|
|
309
|
+
type argument response err,
|
|
310
|
+
~config: module(Config with
|
|
311
|
+
type argument = argument
|
|
312
|
+
and type response = response
|
|
313
|
+
and type error = err
|
|
314
|
+
),
|
|
315
|
+
~argument,
|
|
316
|
+
~children,
|
|
317
|
+
~fallback=?,
|
|
318
|
+
~fallbackRender,
|
|
319
|
+
) => {
|
|
320
|
+
<Toolkit.Ui.ErrorBoundary
|
|
321
|
+
fallbackRender={({error}) => {
|
|
322
|
+
let module(C) = config
|
|
323
|
+
let apiError: error<C.error> = error->Obj.magic
|
|
324
|
+
fallbackRender(apiError)
|
|
325
|
+
}}>
|
|
326
|
+
<React.Suspense fallback={fallback->Option.getWithDefault(<Toolkit.Ui.SpinnerFullScreen />)}>
|
|
327
|
+
<FetchAndRender config argument> {data => children(data)} </FetchAndRender>
|
|
328
|
+
</React.Suspense>
|
|
329
|
+
</Toolkit.Ui.ErrorBoundary>
|
|
330
|
+
}
|
|
331
|
+
}
|