@colisweb/rescript-toolkit 5.48.2 → 5.49.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.48.2",
3
+ "version": "5.49.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "clean": "rescript clean",
@@ -189,6 +189,7 @@ module Make = (Config: Config) => {
189
189
  let use = (
190
190
  ~initialState,
191
191
  ~schema=[]: Validation.schema,
192
+ ~beforeSubmit: option<state => bool>=None,
192
193
  ~onSubmit,
193
194
  ~onSubmitFail=ignore,
194
195
  ~i18n: ReSchemaI18n.t=ReSchemaI18n.default,
@@ -199,7 +200,8 @@ module Make = (Config: Config) => {
199
200
  (state, action) => {
200
201
  switch action {
201
202
  | Submit =>
202
- state.formState == Submitting
203
+ state.formState == Submitting ||
204
+ beforeSubmit->Option.mapWithDefault(false, fn => fn(state))
203
205
  ? NoUpdate
204
206
  : UpdateWithSideEffects(
205
207
  {...state, formState: Submitting},
@@ -12,19 +12,23 @@ let wait = ms =>
12
12
  ->Promise.Js.toResult
13
13
 
14
14
  let durationMinutesToHourMinutesString = (durationMinutes: float, ~separator=":", ()) => {
15
- let hours = (durationMinutes /. 60.)->Js.Math.trunc
16
- let minutes = (durationMinutes -. hours *. 60.)->Js.Math.round
15
+ if durationMinutes === 0. {
16
+ "0h"
17
+ } else {
18
+ let hours = (durationMinutes /. 60.)->Js.Math.trunc
19
+ let minutes = (durationMinutes -. hours *. 60.)->Js.Math.round
17
20
 
18
- let hours = minutes === 60. ? hours +. 1. : hours
19
- let minutes = minutes === 60. ? 0. : minutes
21
+ let hours = minutes === 60. ? hours +. 1. : hours
22
+ let minutes = minutes === 60. ? 0. : minutes
20
23
 
21
- switch (hours, minutes) {
22
- | (0., min) => min->Js.Float.toFixed ++ " min"
23
- | (h, 0.) => h->Js.Float.toFixed ++ " h"
24
- | (h, min) =>
25
- `${h < 10. ? "0" : ""}${h->Js.Float.toFixed}${separator}${min < 10.
26
- ? "0"
27
- : ""}${min->Js.Float.toFixed}`
24
+ switch (hours, minutes) {
25
+ | (0., min) => min->Js.Float.toFixed ++ " min"
26
+ | (h, 0.) => h->Js.Float.toFixed ++ " h"
27
+ | (h, min) =>
28
+ `${h < 10. ? "0" : ""}${h->Js.Float.toFixed}${separator}${min < 10.
29
+ ? "0"
30
+ : ""}${min->Js.Float.toFixed}`
31
+ }
28
32
  }
29
33
  }
30
34