@swan-io/shared-business 13.7.8 → 13.7.9

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": "13.7.8",
3
+ "version": "13.7.9",
4
4
  "engines": {
5
5
  "node": ">22.12.0"
6
6
  },
@@ -25,7 +25,7 @@
25
25
  ],
26
26
  "license": "MIT",
27
27
  "peerDependencies": {
28
- "@swan-io/lake": "13.7.8"
28
+ "@swan-io/lake": "13.7.9"
29
29
  },
30
30
  "dependencies": {
31
31
  "@formatjs/intl": "^4.1.2",
@@ -50,6 +50,6 @@
50
50
  "@types/react-dom": "^19.2.3",
51
51
  "@types/react-native": "^0.72.8",
52
52
  "type-fest": "^5.4.3",
53
- "@swan-io/lake": "13.7.8"
53
+ "@swan-io/lake": "13.7.9"
54
54
  }
55
55
  }
@@ -36,7 +36,11 @@ type Props<Purpose extends string> = {
36
36
  status: SupportingDocumentCollectionStatus;
37
37
  generateUpload: (input: UploadInput<Purpose>) => Future<Result<UploadOutputWithId<UploadOutput>, unknown>>;
38
38
  documents: Document<Purpose>[];
39
- requiredDocumentPurposes: Purpose[];
39
+ requiredDocumentPurposes: Record<Purpose, {
40
+ label: string;
41
+ description: string;
42
+ purposeDetails?: string;
43
+ }>;
40
44
  uploadFile?: (config: UploadFileInput<UploadOutput>) => Future<Result<Response<string>, NetworkError | TimeoutError>>;
41
45
  onChange?: (documents: Document<Purpose>[]) => void;
42
46
  onRemoveFile?: (file: SwanFile) => Future<Result<unknown, unknown>>;
@@ -45,10 +49,6 @@ type Props<Purpose extends string> = {
45
49
  readOnly?: boolean;
46
50
  getPurposeMetadata?: (purose: Purpose) => PurposeMetadata | undefined;
47
51
  readonlyDocumentPurposes?: Purpose[];
48
- purposeLabelOverrides?: Partial<Record<Purpose, string>>;
49
- purposeDescriptionLabelOverrides?: Partial<Record<Purpose, string>>;
50
52
  };
51
- export declare const getSupportingDocumentPurposeLabel: (purpose: string) => string;
52
- export declare const getSupportingDocumentPurposeDescriptionLabel: (purpose: string) => string;
53
- export declare const SupportingDocumentCollection: <Purpose extends string>({ ref, documents, generateUpload, uploadFile, requiredDocumentPurposes, templateLanguage, status, onChange, onRemoveFile, showIds, readOnly, getPurposeMetadata, readonlyDocumentPurposes, purposeLabelOverrides, purposeDescriptionLabelOverrides, }: Props<Purpose>) => import("react/jsx-runtime").JSX.Element;
53
+ export declare const SupportingDocumentCollection: <Purpose extends string>({ ref, documents, generateUpload, uploadFile, requiredDocumentPurposes, templateLanguage, status, onChange, onRemoveFile, showIds, readOnly, getPurposeMetadata, readonlyDocumentPurposes, }: Props<Purpose>) => import("react/jsx-runtime").JSX.Element;
54
54
  export {};
@@ -15,7 +15,7 @@ import { badStatusToError, Request } from "@swan-io/request";
15
15
  import { Fragment, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
16
16
  import { StyleSheet } from "react-native";
17
17
  import { match } from "ts-pattern";
18
- import { isTranslationKey, locale, t } from "../utils/i18n";
18
+ import { locale, t } from "../utils/i18n";
19
19
  import { FilesUploader } from "./FilesUploader";
20
20
  import { LakeModal } from "./LakeModal";
21
21
  const ACCEPTED_FORMATS = ["application/pdf", "image/png", "image/jpeg", "image/heic"];
@@ -42,22 +42,14 @@ const getSupportLink = (language) => match(language)
42
42
  .with("es", () => "https://support.swan.io/hc/en-150/articles/22544703221021--Proof-of-registration-for-Spanish-companies")
43
43
  .with("nl", () => "https://support.swan.io/hc/en-150/articles/22543228421277--Proof-of-registration-for-Dutch-companies")
44
44
  .otherwise(() => "https://support.swan.io/hc/en-150/articles/22620756787869-Proof-of-company-registration");
45
- export const getSupportingDocumentPurposeLabel = (purpose) => {
46
- const key = `supportingDocuments.purpose.${purpose}`;
47
- return isTranslationKey(key) ? t(key) : purpose;
48
- };
49
- export const getSupportingDocumentPurposeDescriptionLabel = (purpose) => {
50
- const key = `supportingDocuments.purpose.${purpose}.description`;
51
- return isTranslationKey(key) ? t(key) : "";
52
- };
53
- export const SupportingDocumentCollection = ({ ref, documents, generateUpload, uploadFile, requiredDocumentPurposes, templateLanguage = locale.language, status, onChange, onRemoveFile, showIds = false, readOnly = false, getPurposeMetadata, readonlyDocumentPurposes = [], purposeLabelOverrides, purposeDescriptionLabelOverrides, }) => {
45
+ export const SupportingDocumentCollection = ({ ref, documents, generateUpload, uploadFile, requiredDocumentPurposes, templateLanguage = locale.language, status, onChange, onRemoveFile, showIds = false, readOnly = false, getPurposeMetadata, readonlyDocumentPurposes = [], }) => {
54
46
  const [showPowerOfAttorneyModal, setShowPowerOfAttorneyModal] = useState(false);
55
47
  const [showSwornStatementModal, setShowSwornStatementModal] = useState(false);
56
48
  const [currentMetadata, setCurrentMetadata] = useState(undefined);
57
49
  const [addedDocuments, setAddedDocuments] = useState([]);
58
50
  const orderedDocumentPurposes = useMemo(() => {
59
51
  // Get all purposes to display: the required ones and the ones that have at least a document
60
- const allPurposes = new Set(requiredDocumentPurposes);
52
+ const allPurposes = new Set(Object.keys(requiredDocumentPurposes));
61
53
  const allDocuments = [...addedDocuments, ...documents];
62
54
  allDocuments.forEach(document => allPurposes.add(document.purpose));
63
55
  const documentsByPurpose = new Map([...allPurposes].map(purpose => {
@@ -66,7 +58,7 @@ export const SupportingDocumentCollection = ({ ref, documents, generateUpload, u
66
58
  }));
67
59
  // Map purposes to their priorities (lower priority comes first)
68
60
  // We precompute it to avoid running on each `sort` callback call
69
- const allRequiredPurposes = new Set(requiredDocumentPurposes);
61
+ const allRequiredPurposes = new Set(Object.keys(requiredDocumentPurposes));
70
62
  // Indices:
71
63
  // -> 0: documents aren't empty and all validated
72
64
  // -> 1: purpose is required
@@ -129,10 +121,9 @@ export const SupportingDocumentCollection = ({ ref, documents, generateUpload, u
129
121
  return true;
130
122
  });
131
123
  return (_jsxs(Form, { children: [showableDocumentPurposes.map(({ purpose, files, areAllDocumentsValidated, isRequired }) => {
132
- var _a, _b;
124
+ var _a;
133
125
  const metadata = getPurposeMetadata === null || getPurposeMetadata === void 0 ? void 0 : getPurposeMetadata(purpose);
134
- const label = (_a = purposeDescriptionLabelOverrides === null || purposeDescriptionLabelOverrides === void 0 ? void 0 : purposeDescriptionLabelOverrides[purpose]) !== null && _a !== void 0 ? _a : getSupportingDocumentPurposeDescriptionLabel(purpose);
135
- return (_jsxs(Fragment, { children: [_jsx(LakeLabel, { label: (_b = purposeLabelOverrides === null || purposeLabelOverrides === void 0 ? void 0 : purposeLabelOverrides[purpose]) !== null && _b !== void 0 ? _b : getSupportingDocumentPurposeLabel(purpose), description: label, render: () => (_jsxs(_Fragment, { children: [_jsxs(Box, { direction: "row", children: [_jsx(Box, { direction: "row", children: isNotNullish(metadata) ? (purpose === "CompanyRegistration" ? (_jsxs(_Fragment, { children: [_jsx(LakeButton, { size: "small", mode: "secondary", icon: "question-circle-regular", onPress: () => window.open(getSupportLink(locale.language)), ariaLabel: t("supportingDocuments.help.howToSendAGoodDocument"), children: t("supportingDocuments.help.howToSendAGoodDocument") }), _jsx(Space, { width: 8 })] })) : (_jsxs(_Fragment, { children: [_jsx(Help, { type: "button", label: metadata.title, onPress: () => setCurrentMetadata(metadata) }), _jsx(Space, { width: 8 })] }))) : (match(purpose)
126
+ return (_jsxs(Fragment, { children: [_jsx(LakeLabel, { label: requiredDocumentPurposes[purpose].label, description: (_a = requiredDocumentPurposes[purpose].purposeDetails) !== null && _a !== void 0 ? _a : requiredDocumentPurposes[purpose].description, render: () => (_jsxs(_Fragment, { children: [_jsxs(Box, { direction: "row", children: [_jsx(Box, { direction: "row", children: isNotNullish(metadata) ? (purpose === "CompanyRegistration" ? (_jsxs(_Fragment, { children: [_jsx(LakeButton, { size: "small", mode: "secondary", icon: "question-circle-regular", onPress: () => window.open(getSupportLink(locale.language)), ariaLabel: t("supportingDocuments.help.howToSendAGoodDocument"), children: t("supportingDocuments.help.howToSendAGoodDocument") }), _jsx(Space, { width: 8 })] })) : (_jsxs(_Fragment, { children: [_jsx(Help, { type: "button", label: metadata.title, onPress: () => setCurrentMetadata(metadata) }), _jsx(Space, { width: 8 })] }))) : (match(purpose)
136
127
  .with("CompanyRegistration", () => (_jsx(LakeButton, { size: "small", mode: "secondary", icon: "question-circle-regular", onPress: () => window.open(getSupportLink(locale.language)), ariaLabel: t("supportingDocuments.help.howToSendAGoodDocument"), children: t("supportingDocuments.help.howToSendAGoodDocument") })))
137
128
  .otherwise(() => null)) }), match(purpose)
138
129
  .with("PowerOfAttorney", () => (_jsx(Help, { type: "button", icon: "arrow-down-filled", label: t("supportingDocuments.help.downloadTemplate"), onPress: () => setShowPowerOfAttorneyModal(true) })))