@swan-io/shared-business 11.1.2 → 11.1.4
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.4",
|
|
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.4"
|
|
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.4"
|
|
57
57
|
}
|
|
58
58
|
}
|
|
@@ -44,6 +44,9 @@ const styles = StyleSheet.create({
|
|
|
44
44
|
borderRadius: 2,
|
|
45
45
|
backgroundColor: colors.current[500],
|
|
46
46
|
},
|
|
47
|
+
id: {
|
|
48
|
+
alignSelf: "flex-start",
|
|
49
|
+
},
|
|
47
50
|
});
|
|
48
51
|
export const FileTile = ({ file: { id, statusInfo, name, url }, showId = false, onRemove, }) => {
|
|
49
52
|
const [isDeleting, setIsDeleting] = useState(false);
|
|
@@ -71,14 +74,14 @@ export const FileTile = ({ file: { id, statusInfo, name, url }, showId = false,
|
|
|
71
74
|
], children: [_jsx(Box, { alignItems: "center", direction: "row", style: styles.content, children: statusInfo.status === "Uploading" ? (_jsxs(_Fragment, { children: [_jsx(LakeText, { numberOfLines: 1, color: colors.gray[700], children: t("fileTile.uploading") }), _jsx(Space, { width: 20 }), _jsx(View, { role: "progressbar", style: styles.progressBar, children: _jsx(View, { style: [styles.progress, { width: `${statusInfo.progress * 100}%` }] }) })] })) : (_jsxs(_Fragment, { children: [statusInfo.status === "Validated" ? (_jsx(Icon, { size: 24, color: colors.positive[500], name: "checkmark-circle-regular" })) : (_jsx(Tag, { icon: getIconNameFromFilename(name), iconSize: 20, color: match(statusInfo)
|
|
72
75
|
.with({ status: P.union("Uploaded", "Pending") }, () => "shakespear")
|
|
73
76
|
.with({ status: "Refused" }, () => "negative")
|
|
74
|
-
.exhaustive() })), _jsx(Space, { width: 16 }), _jsxs(Box, { grow: 1, children: [_jsx(LakeText, { numberOfLines: 1, color: colors.gray[700], style: commonStyles.fill, children: name }), showId ? (_jsx(LakeTooltip, { describedBy: "copy", onHide: () => setVisibleState("copy"), togglableOnFocus: true, content: visibleState === "copy"
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
.exhaustive() })), _jsx(Space, { width: 16 }), _jsxs(Box, { grow: 1, children: [_jsx(LakeText, { numberOfLines: 1, color: colors.gray[700], style: commonStyles.fill, children: name }), showId ? (_jsx(View, { style: styles.id, children: _jsx(LakeTooltip, { describedBy: "copy", onHide: () => setVisibleState("copy"), togglableOnFocus: true, content: visibleState === "copy"
|
|
78
|
+
? t("copyButton.copyTooltip")
|
|
79
|
+
: t("copyButton.copiedTooltip"), children: _jsx(Pressable, { onPress: event => {
|
|
80
|
+
event.stopPropagation();
|
|
81
|
+
event.preventDefault();
|
|
82
|
+
setClipboardText(id);
|
|
83
|
+
setVisibleState("copied");
|
|
84
|
+
}, children: _jsxs(Box, { direction: "row", alignItems: "center", children: [_jsx(LakeText, { numberOfLines: 1, variant: "smallRegular", children: t("fileTile.id", { id }) }), _jsx(Space, { width: 4 }), _jsx(Icon, { size: 14, name: "copy-regular" })] }) }) }) })) : null] }), _jsx(Space, { width: 12 }), isNotNullishOrEmpty(url) && (_jsx(LakeButton, { mode: "tertiary", size: "small", icon: "open-filled", onPress: () => {
|
|
82
85
|
window.open(url, "_blank");
|
|
83
86
|
}, ariaLabel: t("common.open") })), isNotNullish(onRemove) && (_jsx(LakeButton, { mode: "tertiary", size: "small", icon: "delete-regular", color: "negative", onPress: () => setIsDeleteModalVisible(true), ariaLabel: t("common.remove") })), _jsx(LakeModal, { title: t("fileTile.deleteModal.title"), icon: "subtract-circle-regular", visible: isDeleteModalVisible, onPressClose: () => setIsDeleteModalVisible(false), color: "negative", children: _jsx(LakeButtonGroup, { paddingBottom: 0, children: _jsx(LakeButton, { loading: isDeleting, grow: true, color: "negative", onPress: onPressRemove, children: t("fileTile.deleteModal.delete") }) }) })] })) }), match(statusInfo)
|
|
84
87
|
.with({ status: "Pending" }, () => (_jsx(LakeAlert, { anchored: true, title: t("fileTile.status.Pending"), variant: "info" })))
|
|
@@ -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 : "",
|