@colisweb/rescript-toolkit 5.35.7 → 5.37.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colisweb/rescript-toolkit",
3
- "version": "5.35.7",
3
+ "version": "5.37.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "clean": "rescript clean",
@@ -77,6 +77,12 @@ module Make = (Lenses: Lenses) => {
77
77
  error: option<string>,
78
78
  }): t
79
79
  | ArrayNonEmpty({field: Lenses.field<array<'a>>, error: option<string>}): t
80
+ | ForbiddenCharaters({
81
+ field: Lenses.field<string>,
82
+ characters: array<string>,
83
+ optionalPredicate?: Lenses.state => bool,
84
+ error: option<string>,
85
+ }): t
80
86
 
81
87
  type schema = array<t>
82
88
 
@@ -124,6 +130,9 @@ module Make = (Lenses: Lenses) => {
124
130
  let nonEmpty = (~error=?, ~optionalPredicate=?, field) => [
125
131
  StringNonEmpty({field, ?optionalPredicate, error}),
126
132
  ]
133
+ let forbiddenCharacters = (~error=?, ~optionalPredicate=?, ~characters, field) => [
134
+ ForbiddenCharaters({field, ?optionalPredicate, characters, error}),
135
+ ]
127
136
 
128
137
  let string = (~min=?, ~minError=?, ~max=?, ~maxError=?, field) => {
129
138
  mergeValidators([
@@ -389,6 +398,19 @@ module Make = (Lenses: Lenses) => {
389
398
  : Valid,
390
399
  )
391
400
  }
401
+ | Validation.ForbiddenCharaters({field, error, characters} as props) => {
402
+ let value = Lenses.get(values, field)
403
+ let isOptional = props.optionalPredicate->Option.mapWithDefault(false, fn => fn(values))
404
+
405
+ (
406
+ Field(field),
407
+ isOptional
408
+ ? Valid
409
+ : characters->Array.some(char => value->Js.String2.includes(char))
410
+ ? Error(error->Option.getWithDefault(i18n.invalidCharacter(characters)))
411
+ : Valid,
412
+ )
413
+ }
392
414
  }
393
415
 
394
416
  let getFieldValidator = (~validators, ~fieldName) =>
@@ -414,6 +436,7 @@ module Make = (Lenses: Lenses) => {
414
436
  | Validation.ArrayNonEmpty({field}) => Field(field) == fieldName
415
437
  | Validation.CustomNestedSchema2({field}) => Field(field) == fieldName
416
438
  | Validation.Phone({field}) => Field(field) == fieldName
439
+ | Validation.ForbiddenCharaters({field}) => Field(field) == fieldName
417
440
  }
418
441
  )
419
442
 
@@ -440,6 +463,7 @@ module Make = (Lenses: Lenses) => {
440
463
  | Validation.CustomNestedSchema2({field}) => Field(field) == fieldName
441
464
  | Validation.OptionNonEmpty({field}) => Field(field) == fieldName
442
465
  | Validation.ArrayNonEmpty({field}) => Field(field) == fieldName
466
+ | Validation.ForbiddenCharaters({field}) => Field(field) == fieldName
443
467
  }
444
468
  )
445
469
 
@@ -13,6 +13,7 @@ type t = {
13
13
  phone: string,
14
14
  passwordTooShort: string,
15
15
  passwordCantContainLogin: string,
16
+ invalidCharacter: array<string> => string,
16
17
  }
17
18
 
18
19
  let default = {
@@ -37,4 +38,8 @@ let default = {
37
38
  phone: "Format du numéro invalide. Ex : +33612345678",
38
39
  passwordTooShort: "Le mot de passe doit contenir au moins 10 caractères, avoir au moins 1 minuscule, 1 majuscule et un chiffre.",
39
40
  passwordCantContainLogin: "Le mot de passe ne peut pas contenir l'identifiant.",
41
+ invalidCharacter: characters =>
42
+ `Ce champ contient un caractère non autorisé parmi cette liste: ${characters->Js.Array2.joinWith(
43
+ " ",
44
+ )}`,
40
45
  }
@@ -124,6 +124,7 @@ module Make = (Config: Config) => {
124
124
  | Validation.CustomNestedSchema2({field}) => (Field(field), Pristine)
125
125
  | Validation.OptionNonEmpty({field}) => (Field(field), Pristine)
126
126
  | Validation.ArrayNonEmpty({field}) => (Field(field), Pristine)
127
+ | Validation.ForbiddenCharaters({field}) => (Field(field), Pristine)
127
128
  }
128
129
  )
129
130
  }
@@ -322,6 +322,11 @@ let mutateWithParams = (
322
322
  }
323
323
 
324
324
  module FetchAndRender = {
325
+ type childrenParams<'argument, 'data> = {
326
+ data: 'data,
327
+ reload: unit => Promise.t<result<bool, Js.Promise.error>>,
328
+ isLoading: bool,
329
+ }
325
330
  @react.component
326
331
  let make = (
327
332
  type argument response err,
@@ -332,11 +337,11 @@ module FetchAndRender = {
332
337
  ),
333
338
  ~argument,
334
339
  ~options=?,
335
- ~children,
340
+ ~children: childrenParams<argument, response> => React.element,
336
341
  ) => {
337
- let (data, _, _) = useFetcher(~options?, config, Some(argument))
342
+ let (data, isLoading, reload) = useFetcher(~options?, config, Some(argument))
338
343
 
339
- children(data)
344
+ children({data, reload, isLoading})
340
345
  }
341
346
  }
342
347
 
@@ -350,7 +355,7 @@ module FetchAndRenderWithSuspense = {
350
355
  and type error = err
351
356
  ),
352
357
  ~argument,
353
- ~children,
358
+ ~children: FetchAndRender.childrenParams<argument, response> => React.element,
354
359
  ~fallback=?,
355
360
  ~options=?,
356
361
  ~fallbackRender,