@swan-io/shared-business 7.0.5 → 7.0.7
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
|
@@ -27,6 +27,7 @@ type Props<Purpose extends string> = {
|
|
|
27
27
|
onRemoveFile?: (file: SwanFile) => Future<Result<unknown, unknown>>;
|
|
28
28
|
templateLanguage?: string;
|
|
29
29
|
showIds?: boolean;
|
|
30
|
+
readOnly?: boolean;
|
|
30
31
|
};
|
|
31
32
|
export declare const getSupportingDocumentPurposeLabel: (purpose: string) => string;
|
|
32
33
|
export declare const getSupportingDocumentPurposeDescriptionLabel: (purpose: string) => string;
|
|
@@ -34,7 +35,7 @@ export type SupportingDocumentCollectionRef<Purpose extends string> = {
|
|
|
34
35
|
areAllRequiredDocumentsFilled: () => boolean;
|
|
35
36
|
addDocument: (document: Document<Purpose>) => void;
|
|
36
37
|
};
|
|
37
|
-
export declare const SupportingDocumentCollectionWithRef: <Purpose extends string>({ documents, generateUpload, requiredDocumentPurposes, templateLanguage, status, onRemoveFile, showIds, }: Props<Purpose>, ref: Ref<SupportingDocumentCollectionRef<Purpose>>) => import("react/jsx-runtime").JSX.Element;
|
|
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;
|
|
38
39
|
export declare const SupportingDocumentCollection: <I extends string>(props: Props<I> & {
|
|
39
40
|
ref?: ForwardedRef<SupportingDocumentCollectionRef<I>>;
|
|
40
41
|
}) => ReturnType<typeof SupportingDocumentCollectionWithRef>;
|
|
@@ -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, }, ref) => {
|
|
51
|
+
export const SupportingDocumentCollectionWithRef = ({ documents, generateUpload, 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([]);
|
|
@@ -118,7 +118,15 @@ export const SupportingDocumentCollectionWithRef = ({ documents, generateUpload,
|
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
}, [addedDocuments]);
|
|
121
|
-
return (_jsxs(Form, { children: [orderedDocumentPurposes
|
|
121
|
+
return (_jsxs(Form, { children: [orderedDocumentPurposes
|
|
122
|
+
.filter(({ files }) => {
|
|
123
|
+
// Completely hide the purpose section if empty and no action is available
|
|
124
|
+
if (readOnly && files.length === 0) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
return true;
|
|
128
|
+
})
|
|
129
|
+
.map(({ purpose, files, areAllDocumentsValidated, isRequired }) => {
|
|
122
130
|
return (_jsxs(Fragment, { children: [_jsx(LakeLabel, { label: getSupportingDocumentPurposeLabel(purpose), help: match(purpose)
|
|
123
131
|
.with("PowerOfAttorney", () => (_jsx(Help, { type: "button", label: t("supportingDocuments.help.whatIsThis"), onPress: () => setShowPowerOfAttorneyModal(true) })))
|
|
124
132
|
.with("SwornStatement", () => (_jsx(Help, { type: "button", label: t("supportingDocuments.help.whatIsThis"), onPress: () => setShowSwornStatementModal(true) })))
|
|
@@ -128,7 +136,7 @@ export const SupportingDocumentCollectionWithRef = ({ documents, generateUpload,
|
|
|
128
136
|
}), render: () => (_jsx(FilesUploader, { ref: ref => (filesUploaderRefByPurpose.current[purpose] = ref),
|
|
129
137
|
// Only allow uploading is the Supporting Document Collection awaits for docs
|
|
130
138
|
// and that the specific purpose isn't already fully validated
|
|
131
|
-
canUpload: 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
|
+
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 }) => {
|
|
132
140
|
const body = new FormData();
|
|
133
141
|
upload.fields.forEach(({ key, value }) => body.append(key, value));
|
|
134
142
|
body.append("file", file);
|
|
@@ -141,7 +149,7 @@ export const SupportingDocumentCollectionWithRef = ({ documents, generateUpload,
|
|
|
141
149
|
}).mapOkToResult(badStatusToError);
|
|
142
150
|
}, formatAndSizeDescription: t("supportingDocuments.documentTypes", {
|
|
143
151
|
maxSizeMB: 20000000 / 1000000,
|
|
144
|
-
}), onRemoveFile: onRemoveFile, onChange: files => {
|
|
152
|
+
}), onRemoveFile: readOnly ? undefined : onRemoveFile, onChange: files => {
|
|
145
153
|
if (isRequired) {
|
|
146
154
|
filesByRequiredPurpose.current.set(purpose, files);
|
|
147
155
|
}
|