@swan-io/shared-business 11.1.2 → 11.1.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swan-io/shared-business",
|
|
3
|
-
"version": "11.1.
|
|
3
|
+
"version": "11.1.3",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=20.9.0",
|
|
6
6
|
"pnpm": "9.9.0"
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
],
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@swan-io/lake": "11.1.
|
|
29
|
+
"@swan-io/lake": "11.1.3"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@formatjs/intl": "^2.10.9",
|
|
@@ -53,6 +53,6 @@
|
|
|
53
53
|
"@types/uuid": "^10.0.0",
|
|
54
54
|
"jsdom": "^25.0.1",
|
|
55
55
|
"vitest": "^2.1.3",
|
|
56
|
-
"@swan-io/lake": "11.1.
|
|
56
|
+
"@swan-io/lake": "11.1.3"
|
|
57
57
|
}
|
|
58
58
|
}
|
|
@@ -9,6 +9,7 @@ import { breakpoints, colors } from "@swan-io/lake/src/constants/design";
|
|
|
9
9
|
import { useResponsive } from "@swan-io/lake/src/hooks/useResponsive";
|
|
10
10
|
import { isNotNullish, isNullish } from "@swan-io/lake/src/utils/nullish";
|
|
11
11
|
import { useForm } from "@swan-io/use-form";
|
|
12
|
+
import { useRef } from "react";
|
|
12
13
|
import { StyleSheet, View } from "react-native";
|
|
13
14
|
import { match } from "ts-pattern";
|
|
14
15
|
import { extractDate, formatExtractedDate } from "../utils/date";
|
|
@@ -58,7 +59,13 @@ const order = match(getMostLikelyUserCountry().cca2)
|
|
|
58
59
|
.otherwise(() => "DMY");
|
|
59
60
|
export const InlineDatePicker = ({ value, label, readOnly = false, onValueChange, validate = () => undefined, error: externalError, style, }) => {
|
|
60
61
|
const { desktop } = useResponsive(breakpoints.small);
|
|
61
|
-
|
|
62
|
+
// We can't rely on blurred, since 3 inputs / select are mapped on
|
|
63
|
+
// 1 field. The first onBlur update the field internal state from
|
|
64
|
+
// not blurred -> blurred, then when the second input is blurred,
|
|
65
|
+
// validate will not be triggered again since the field has already
|
|
66
|
+
// blurred = true
|
|
67
|
+
const touched = useRef(new Set());
|
|
68
|
+
const { Field, validateField } = useForm({
|
|
62
69
|
date: {
|
|
63
70
|
initialValue: isNotNullish(value) ? extractDate(value) : undefined,
|
|
64
71
|
sanitize: date => isNotNullish(date)
|
|
@@ -68,7 +75,7 @@ export const InlineDatePicker = ({ value, label, readOnly = false, onValueChange
|
|
|
68
75
|
year: date.year.trim(),
|
|
69
76
|
}
|
|
70
77
|
: undefined,
|
|
71
|
-
strategy: "
|
|
78
|
+
strategy: "onSubmit",
|
|
72
79
|
validate: date => {
|
|
73
80
|
const errorMessage = validate(date);
|
|
74
81
|
if (isNullish(errorMessage) && isNotNullish(date)) {
|
|
@@ -81,9 +88,17 @@ export const InlineDatePicker = ({ value, label, readOnly = false, onValueChange
|
|
|
81
88
|
},
|
|
82
89
|
},
|
|
83
90
|
});
|
|
84
|
-
|
|
91
|
+
const validateDate = () => {
|
|
92
|
+
if (touched.current.has("day") && touched.current.has("month") && touched.current.has("year")) {
|
|
93
|
+
validateField("date");
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
return (_jsx(View, { style: [styles.container, style], children: _jsx(Field, { name: "date", children: ({ error, onChange, value }) => (_jsx(LakeLabel, { label: label, render: id => {
|
|
85
97
|
var _a;
|
|
86
|
-
const day = (_jsx(View, { style: desktop ? styles.day : styles.dayMobile, children: _jsx(LakeTextInput, { id: id, readOnly: readOnly, style: (isNotNullish(error) || isNotNullish(externalError)) && styles.error, placeholder: t("datePicker.day"), value: (_a = value === null || value === void 0 ? void 0 : value.day) !== null && _a !== void 0 ? _a : undefined, onBlur:
|
|
98
|
+
const day = (_jsx(View, { style: desktop ? styles.day : styles.dayMobile, children: _jsx(LakeTextInput, { id: id, readOnly: readOnly, style: (isNotNullish(error) || isNotNullish(externalError)) && styles.error, placeholder: t("datePicker.day"), value: (_a = value === null || value === void 0 ? void 0 : value.day) !== null && _a !== void 0 ? _a : undefined, onBlur: () => {
|
|
99
|
+
touched.current.add("day");
|
|
100
|
+
validateDate();
|
|
101
|
+
}, hideErrors: true, onChangeText: day => {
|
|
87
102
|
var _a, _b;
|
|
88
103
|
onChange({
|
|
89
104
|
day,
|
|
@@ -93,13 +108,18 @@ export const InlineDatePicker = ({ value, label, readOnly = false, onValueChange
|
|
|
93
108
|
}, pattern: "[0-9]", maxLength: 2, autoComplete: "bday-day" }) }));
|
|
94
109
|
const month = (_jsx(LakeSelect, { value: (value === null || value === void 0 ? void 0 : value.month) === "" ? undefined : value === null || value === void 0 ? void 0 : value.month, style: (isNotNullish(error) || isNotNullish(externalError)) && styles.error, readOnly: readOnly, placeholder: t("datePicker.month"), hideErrors: true, items: months, onValueChange: month => {
|
|
95
110
|
var _a, _b;
|
|
111
|
+
touched.current.add("month");
|
|
112
|
+
validateDate();
|
|
96
113
|
onChange({
|
|
97
114
|
day: (_a = value === null || value === void 0 ? void 0 : value.day) !== null && _a !== void 0 ? _a : "",
|
|
98
115
|
month,
|
|
99
116
|
year: (_b = value === null || value === void 0 ? void 0 : value.year) !== null && _b !== void 0 ? _b : "",
|
|
100
117
|
});
|
|
101
118
|
} }));
|
|
102
|
-
const year = (_jsx(View, { style: desktop ? styles.year : styles.yearMobile, children: _jsx(LakeTextInput, { value: value === null || value === void 0 ? void 0 : value.year, style: (isNotNullish(error) || isNotNullish(externalError)) && styles.error, readOnly: readOnly, placeholder: t("datePicker.year"), onBlur:
|
|
119
|
+
const year = (_jsx(View, { style: desktop ? styles.year : styles.yearMobile, children: _jsx(LakeTextInput, { value: value === null || value === void 0 ? void 0 : value.year, style: (isNotNullish(error) || isNotNullish(externalError)) && styles.error, readOnly: readOnly, placeholder: t("datePicker.year"), onBlur: () => {
|
|
120
|
+
touched.current.add("year");
|
|
121
|
+
validateDate();
|
|
122
|
+
}, hideErrors: true, onChangeText: year => {
|
|
103
123
|
var _a, _b;
|
|
104
124
|
return onChange({
|
|
105
125
|
day: (_a = value === null || value === void 0 ? void 0 : value.day) !== null && _a !== void 0 ? _a : "",
|