@swan-io/shared-business 7.4.5 → 7.4.6

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": "7.4.5",
3
+ "version": "7.4.6",
4
4
  "engines": {
5
5
  "node": ">=18.0.0",
6
6
  "yarn": "^1.22.0"
@@ -7,6 +7,7 @@ type Props<T> = {
7
7
  getId?: (item: T) => unknown;
8
8
  onChange: (value: T) => void;
9
9
  disabled?: boolean;
10
+ tile?: boolean;
10
11
  };
11
- export declare const ChoicePicker: <T>({ items, getId, large, renderItem, value, disabled, onChange, }: Props<T>) => import("react/jsx-runtime").JSX.Element;
12
+ export declare const ChoicePicker: <T>({ tile, items, getId, large, renderItem, value, disabled, onChange, }: Props<T>) => import("react/jsx-runtime").JSX.Element;
12
13
  export {};
@@ -102,7 +102,7 @@ const styles = StyleSheet.create({
102
102
  },
103
103
  });
104
104
  const identity = (x) => x;
105
- export const ChoicePicker = ({ items, getId = identity, large = false, renderItem, value, disabled = false, onChange, }) => {
105
+ export const ChoicePicker = ({ tile = true, items, getId = identity, large = false, renderItem, value, disabled = false, onChange, }) => {
106
106
  const containerRef = useRef(null);
107
107
  const { desktop } = useResponsive(breakpoints.medium);
108
108
  const [mobilePosition, setMobilePosition] = useState("start");
@@ -191,5 +191,8 @@ export const ChoicePicker = ({ items, getId = identity, large = false, renderIte
191
191
  large && styles.itemLarge,
192
192
  !desktop && styles.itemSmallViewport,
193
193
  !desktop && { width: `${100 / items.length}%` },
194
- ], onPress: () => onChange(item), children: ({ hovered }) => (_jsx(Tile, { hovered: hovered, selected: value != null && getId(item) === getId(value), flexGrow: 1, children: _jsxs(View, { style: styles.tileContents, children: [_jsx(View, { style: styles.tileRenderedContents, children: renderItem(item) }), desktop && (_jsxs(_Fragment, { children: [_jsx(Space, { height: 24 }), _jsx(LakeRadio, { value: value != null && getId(item) === getId(value) })] }))] }) })) }, String(index)))) }) }), !desktop && (_jsx(LakeButton, { icon: "chevron-left-filled", mode: "secondary", forceBackground: true, onPress: onPressPrevious, disabled: mobilePosition === "start" || disabled, style: styles.leftButton, ariaLabel: t("common.previous") })), !desktop && (_jsx(LakeButton, { icon: "chevron-right-filled", mode: "secondary", forceBackground: true, onPress: onPressNext, disabled: mobilePosition === "end" || disabled, style: styles.rightButton, ariaLabel: t("common.next") }))] }));
194
+ ], onPress: () => onChange(item), children: ({ hovered }) => {
195
+ const tileContent = (_jsxs(View, { style: styles.tileContents, children: [_jsx(View, { style: styles.tileRenderedContents, children: renderItem(item) }), desktop && (_jsxs(_Fragment, { children: [_jsx(Space, { height: 24 }), _jsx(LakeRadio, { value: value != null && getId(item) === getId(value) })] }))] }));
196
+ return tile ? (_jsx(Tile, { hovered: hovered, selected: value != null && getId(item) === getId(value), flexGrow: 1, children: tileContent })) : (tileContent);
197
+ } }, String(index)))) }) }), !desktop && (_jsx(LakeButton, { icon: "chevron-left-filled", mode: "secondary", forceBackground: true, onPress: onPressPrevious, disabled: mobilePosition === "start" || disabled, style: styles.leftButton, ariaLabel: t("common.previous") })), !desktop && (_jsx(LakeButton, { icon: "chevron-right-filled", mode: "secondary", forceBackground: true, onPress: onPressNext, disabled: mobilePosition === "end" || disabled, style: styles.rightButton, ariaLabel: t("common.next") }))] }));
195
198
  };
@@ -1,6 +1,7 @@
1
1
  import { Future, Result } from "@swan-io/boxed";
2
+ import { NetworkError, Response, TimeoutError } from "@swan-io/request";
2
3
  import { ForwardedRef, Ref } from "react";
3
- import { UploadOutputWithId } from "../hooks/useFilesUploader";
4
+ import { UploadFileInput, UploadOutputWithId } from "../hooks/useFilesUploader";
4
5
  import { SwanFile } from "../utils/SwanFile";
5
6
  export type Document<Purpose extends string> = {
6
7
  purpose: Purpose;
@@ -23,6 +24,7 @@ type Props<Purpose extends string> = {
23
24
  generateUpload: (input: UploadInput<Purpose>) => Future<Result<UploadOutputWithId<UploadOutput>, unknown>>;
24
25
  documents: Document<Purpose>[];
25
26
  requiredDocumentPurposes: Purpose[];
27
+ uploadFile?: (config: UploadFileInput<UploadOutput>) => Future<Result<Response<string>, NetworkError | TimeoutError>>;
26
28
  onChange?: (documents: Document<Purpose>[]) => void;
27
29
  onRemoveFile?: (file: SwanFile) => Future<Result<unknown, unknown>>;
28
30
  templateLanguage?: string;
@@ -35,7 +37,7 @@ export type SupportingDocumentCollectionRef<Purpose extends string> = {
35
37
  areAllRequiredDocumentsFilled: () => boolean;
36
38
  addDocument: (document: Document<Purpose>) => void;
37
39
  };
38
- export declare const SupportingDocumentCollectionWithRef: <Purpose extends string>({ documents, generateUpload, requiredDocumentPurposes, templateLanguage, status, onRemoveFile, showIds, readOnly, }: Props<Purpose>, ref: Ref<SupportingDocumentCollectionRef<Purpose>>) => import("react/jsx-runtime").JSX.Element;
40
+ export declare const SupportingDocumentCollectionWithRef: <Purpose extends string>({ documents, generateUpload, uploadFile, requiredDocumentPurposes, templateLanguage, status, onRemoveFile, showIds, readOnly, }: Props<Purpose>, ref: Ref<SupportingDocumentCollectionRef<Purpose>>) => import("react/jsx-runtime").JSX.Element;
39
41
  export declare const SupportingDocumentCollection: <I extends string>(props: Props<I> & {
40
42
  ref?: ForwardedRef<SupportingDocumentCollectionRef<I>>;
41
43
  }) => ReturnType<typeof SupportingDocumentCollectionWithRef>;
@@ -6,7 +6,7 @@ import { LakeLabel } from "@swan-io/lake/src/components/LakeLabel";
6
6
  import { LakeText } from "@swan-io/lake/src/components/LakeText";
7
7
  import { LakeTooltip } from "@swan-io/lake/src/components/LakeTooltip";
8
8
  import { Space } from "@swan-io/lake/src/components/Space";
9
- import { isNotNullishOrEmpty } from "@swan-io/lake/src/utils/nullish";
9
+ import { isNotNullish, isNotNullishOrEmpty } from "@swan-io/lake/src/utils/nullish";
10
10
  import { Request, badStatusToError } from "@swan-io/request";
11
11
  import { Fragment, forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState, } from "react";
12
12
  import { StyleSheet } from "react-native";
@@ -48,7 +48,7 @@ export const getSupportingDocumentPurposeDescriptionLabel = (purpose) => {
48
48
  return "";
49
49
  }
50
50
  };
51
- export const SupportingDocumentCollectionWithRef = ({ documents, generateUpload, requiredDocumentPurposes, templateLanguage = locale.language, status, onRemoveFile, showIds = false, readOnly = false, }, ref) => {
51
+ export const SupportingDocumentCollectionWithRef = ({ documents, generateUpload, uploadFile, requiredDocumentPurposes, templateLanguage = locale.language, status, onRemoveFile, showIds = false, readOnly = false, }, ref) => {
52
52
  const [showPowerOfAttorneyModal, setShowPowerOfAttorneyModal] = useState(false);
53
53
  const [showSwornStatementModal, setShowSwornStatementModal] = useState(false);
54
54
  const [addedDocuments, setAddedDocuments] = useState([]);
@@ -135,18 +135,20 @@ export const SupportingDocumentCollectionWithRef = ({ documents, generateUpload,
135
135
  }), render: () => (_jsx(FilesUploader, { ref: ref => (filesUploaderRefByPurpose.current[purpose] = ref),
136
136
  // Only allow uploading is the Supporting Document Collection awaits for docs
137
137
  // and that the specific purpose isn't already fully validated
138
- canUpload: !readOnly && status === "WaitingForDocument" && !areAllDocumentsValidated, accept: ACCEPTED_FORMATS, maxSize: 20000000, icon: "document-regular", initialFiles: files, generateUpload: generateUpload, getUploadConfig: file => ({ fileName: file.name, purpose }), uploadFile: ({ upload, file, onLoadStart, onProgress }) => {
139
- const body = new FormData();
140
- upload.fields.forEach(({ key, value }) => body.append(key, value));
141
- body.append("file", file);
142
- return Request.make({
143
- url: upload.url,
144
- method: "POST",
145
- onLoadStart,
146
- onProgress,
147
- body,
148
- }).mapOkToResult(badStatusToError);
149
- }, formatAndSizeDescription: t("supportingDocuments.documentTypes", {
138
+ canUpload: !readOnly && status === "WaitingForDocument" && !areAllDocumentsValidated, accept: ACCEPTED_FORMATS, maxSize: 20000000, icon: "document-regular", initialFiles: files, generateUpload: generateUpload, getUploadConfig: file => ({ fileName: file.name, purpose }), uploadFile: isNotNullish(uploadFile)
139
+ ? uploadFile
140
+ : ({ upload, file, onLoadStart, onProgress }) => {
141
+ const body = new FormData();
142
+ upload.fields.forEach(({ key, value }) => body.append(key, value));
143
+ body.append("file", file);
144
+ return Request.make({
145
+ url: upload.url,
146
+ method: "POST",
147
+ onLoadStart,
148
+ onProgress,
149
+ body,
150
+ }).mapOkToResult(badStatusToError);
151
+ }, formatAndSizeDescription: t("supportingDocuments.documentTypes", {
150
152
  maxSizeMB: 20000000 / 1000000,
151
153
  }), onRemoveFile: readOnly ? undefined : onRemoveFile, onChange: files => {
152
154
  if (isRequired) {