@swan-io/shared-business 18.5.0 → 18.7.0
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 +3 -3
- package/src/components/BirthdatePicker.d.ts +3 -1
- package/src/components/BirthdatePicker.js +2 -2
- package/src/components/FileInput.js +25 -10
- package/src/components/FileTile.d.ts +4 -3
- package/src/components/FileTile.js +14 -7
- package/src/components/FilesUploader.js +12 -4
- package/src/components/FraudReport/CardDetailsStep.d.ts +7 -0
- package/src/components/FraudReport/CardDetailsStep.js +46 -0
- package/src/components/FraudReport/DocumentsStep.d.ts +13 -0
- package/src/components/FraudReport/DocumentsStep.js +49 -0
- package/src/components/FraudReport/FraudReportLayout.d.ts +2 -1
- package/src/components/FraudReport/FraudReportLayout.js +2 -2
- package/src/components/FraudReport/FraudsterDetailsStep.d.ts +7 -0
- package/src/components/FraudReport/FraudsterDetailsStep.js +56 -0
- package/src/components/FraudReport/IntroStep.js +5 -1
- package/src/components/FraudReport/TransactionPicker.d.ts +13 -0
- package/src/components/FraudReport/TransactionPicker.js +213 -0
- package/src/components/FraudReport/TransactionPickerFilters.d.ts +8 -0
- package/src/components/FraudReport/TransactionPickerFilters.js +213 -0
- package/src/components/FraudReport/TransactionRows.d.ts +8 -0
- package/src/components/FraudReport/TransactionRows.js +32 -0
- package/src/components/FraudReport/TransactionsStep.js +9 -27
- package/src/components/FraudReport/TransferDetailsStep.d.ts +7 -0
- package/src/components/FraudReport/TransferDetailsStep.js +25 -0
- package/src/components/FraudReport/VictimStep.d.ts +3 -1
- package/src/components/FraudReport/VictimStep.js +38 -5
- package/src/components/LakeModal.js +1 -1
- package/src/components/SupportingDocumentCollection.d.ts +1 -0
- package/src/components/SupportingDocumentCollection.js +13 -14
- package/src/hooks/__tests__/useFilesUploader.test.d.ts +1 -0
- package/src/hooks/__tests__/useFilesUploader.test.js +101 -0
- package/src/hooks/__tests__/useFraudReportFlow.test.js +108 -20
- package/src/hooks/useFilesUploader.d.ts +2 -1
- package/src/hooks/useFilesUploader.js +28 -9
- package/src/hooks/useFraudReportFlow.js +12 -7
- package/src/locales/de.json +84 -8
- package/src/locales/en.json +77 -1
- package/src/locales/es.json +77 -1
- package/src/locales/fi.json +77 -1
- package/src/locales/fr.json +77 -1
- package/src/locales/it.json +77 -1
- package/src/locales/nl.json +77 -1
- package/src/locales/pt.json +77 -1
- package/src/utils/SwanFile.d.ts +2 -0
- package/src/utils/__tests__/fraudReport.card.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.card.test.js +39 -0
- package/src/utils/__tests__/fraudReport.documents.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.documents.test.js +61 -0
- package/src/utils/__tests__/fraudReport.fraudster.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.fraudster.test.js +35 -0
- package/src/utils/__tests__/fraudReport.messages.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.messages.test.js +28 -0
- package/src/utils/__tests__/fraudReport.picker.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.picker.test.js +186 -0
- package/src/utils/__tests__/fraudReport.pickerFilters.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.pickerFilters.test.js +144 -0
- package/src/utils/__tests__/fraudReport.prefill.test.js +7 -1
- package/src/utils/__tests__/fraudReport.rejections.test.js +11 -19
- package/src/utils/__tests__/fraudReport.resume.test.js +19 -4
- package/src/utils/__tests__/fraudReport.toInput.test.js +160 -40
- package/src/utils/__tests__/fraudReport.transactions.test.js +11 -1
- package/src/utils/__tests__/fraudReport.transfer.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.transfer.test.js +31 -0
- package/src/utils/__tests__/fraudReport.victim.test.js +27 -1
- package/src/utils/__tests__/validation.test.js +81 -7
- package/src/utils/fraudReport/card.d.ts +11 -0
- package/src/utils/fraudReport/card.js +15 -0
- package/src/utils/fraudReport/documents.d.ts +9 -0
- package/src/utils/fraudReport/documents.js +18 -0
- package/src/utils/fraudReport/fakeApi.js +1 -1
- package/src/utils/fraudReport/fraudster.d.ts +10 -0
- package/src/utils/fraudReport/fraudster.js +11 -0
- package/src/utils/fraudReport/messages.d.ts +4 -0
- package/src/utils/fraudReport/messages.js +7 -0
- package/src/utils/fraudReport/picker.d.ts +19 -0
- package/src/utils/fraudReport/picker.js +50 -0
- package/src/utils/fraudReport/pickerFilters.d.ts +26 -0
- package/src/utils/fraudReport/pickerFilters.js +62 -0
- package/src/utils/fraudReport/prefill.d.ts +1 -1
- package/src/utils/fraudReport/prefill.js +6 -3
- package/src/utils/fraudReport/rejections.d.ts +0 -1
- package/src/utils/fraudReport/rejections.js +2 -6
- package/src/utils/fraudReport/resume.js +4 -4
- package/src/utils/fraudReport/toInput.d.ts +6 -3
- package/src/utils/fraudReport/toInput.js +41 -24
- package/src/utils/fraudReport/transactions.d.ts +2 -0
- package/src/utils/fraudReport/transactions.js +4 -0
- package/src/utils/fraudReport/transfer.d.ts +6 -0
- package/src/utils/fraudReport/transfer.js +8 -0
- package/src/utils/fraudReport/types.d.ts +1 -1
- package/src/utils/fraudReport/validation.d.ts +1 -1
- package/src/utils/fraudReport/validation.js +4 -0
- package/src/utils/fraudReport/victim.d.ts +11 -0
- package/src/utils/fraudReport/victim.js +9 -0
- package/src/utils/validation.d.ts +2 -0
- package/src/utils/validation.js +15 -8
|
@@ -9,10 +9,12 @@ import { RadioGroup } from "@swan-io/lake/src/components/RadioGroup";
|
|
|
9
9
|
import { Space } from "@swan-io/lake/src/components/Space";
|
|
10
10
|
import { Tile } from "@swan-io/lake/src/components/Tile";
|
|
11
11
|
import { colors } from "@swan-io/lake/src/constants/design";
|
|
12
|
+
import { isNullishOrEmpty } from "@swan-io/lake/src/utils/nullish";
|
|
12
13
|
import { useState } from "react";
|
|
13
14
|
import { StyleSheet, View } from "react-native";
|
|
14
|
-
import { getInitialVictimChoice, getOtherAccountMemberships, getSelectedAccountMembershipId, getVictimAccountMembershipId, } from "../../utils/fraudReport/victim";
|
|
15
|
+
import { getInitialVictimChoice, getOtherAccountMemberships, getSelectedAccountMembershipId, getVictimAccountMembershipId, getVictimChange, } from "../../utils/fraudReport/victim";
|
|
15
16
|
import { formatNestedMessage, t } from "../../utils/i18n";
|
|
17
|
+
import { ConfirmModal } from "../ConfirmModal";
|
|
16
18
|
import { FraudReportFooter, useFraudReportSmallLayout, } from "./FraudReportLayout";
|
|
17
19
|
const styles = StyleSheet.create({
|
|
18
20
|
column: {
|
|
@@ -20,8 +22,9 @@ const styles = StyleSheet.create({
|
|
|
20
22
|
flexGrow: 1,
|
|
21
23
|
},
|
|
22
24
|
});
|
|
23
|
-
export const VictimStep = ({ currentAccountMembership, accountMemberships, values, onNext, }) => {
|
|
25
|
+
export const VictimStep = ({ currentAccountMembership, accountMemberships, transactions, values, onNext, }) => {
|
|
24
26
|
const small = useFraudReportSmallLayout();
|
|
27
|
+
const [confirmVisible, setConfirmVisible] = useState(false);
|
|
25
28
|
const [choice, setChoice] = useState(() => getInitialVictimChoice({
|
|
26
29
|
currentAccountMembership,
|
|
27
30
|
victimAccountMembershipId: values.victimAccountMembershipId,
|
|
@@ -43,13 +46,43 @@ export const VictimStep = ({ currentAccountMembership, accountMemberships, value
|
|
|
43
46
|
const memberItems = getOtherAccountMemberships({
|
|
44
47
|
currentAccountMembership,
|
|
45
48
|
accountMemberships,
|
|
46
|
-
}).map(({ id, name }) => ({
|
|
47
|
-
|
|
49
|
+
}).map(({ id, name, phoneNumber }) => ({
|
|
50
|
+
name,
|
|
51
|
+
value: id,
|
|
52
|
+
phoneNumber,
|
|
53
|
+
searchTerms: isNullishOrEmpty(phoneNumber)
|
|
54
|
+
? undefined
|
|
55
|
+
: [phoneNumber, phoneNumber.replace(/\s/g, "")],
|
|
56
|
+
}));
|
|
57
|
+
const memberPicker = (_jsx(LakeLabel, { label: t("fraudReport.victim.memberLabel"), help: small || currentAccountMembership.isNone() ? undefined : (_jsx(InformationTooltip, { text: t("fraudReport.victim.memberHelp"), focusable: true })), render: id => (_jsx(LakeSelect, { id: id, items: memberItems, hasSearch: true, searchPlaceholder: t("fraudReport.victim.searchMember"), renderItem: (item, isSelected) => (_jsxs(Box, { direction: "column", children: [_jsx(LakeText, { color: isSelected ? colors.gray[800] : colors.gray[900], numberOfLines: 1, children: item.name }), isNullishOrEmpty(item.phoneNumber) ? null : (_jsx(LakeText, { variant: "smallRegular", color: colors.gray[600], children: item.phoneNumber }))] })), value: selectedId.toUndefined(), onValueChange: value => setChoice(previous => ({ ...previous, selectedId: Option.Some(value) })) })) }));
|
|
48
58
|
return (_jsxs(_Fragment, { children: [_jsx(Tile, { title: t("fraudReport.victim.title"), description: t("fraudReport.victim.description"), children: currentAccountMembership.match({
|
|
49
59
|
None: () => memberPicker,
|
|
50
60
|
Some: current => (_jsxs(Box, { direction: small ? "column" : "row", children: [_jsxs(View, { style: !small && styles.column, children: [_jsx(LakeLabel, { type: "radioGroup", label: t("fraudReport.victim.forYourself"), render: () => (_jsx(RadioGroup, { direction: small ? "column" : "row", hideErrors: true, items: answerItems, value: choice.answer.toUndefined(), onValueChange: answer => setChoice(previous => ({ ...previous, answer: Option.Some(answer) })) })) }), choice.answer.toUndefined() === "Myself" ? (_jsxs(_Fragment, { children: [_jsx(Space, { height: 40 }), _jsx(LakeText, { variant: "medium", color: colors.gray[700], children: formatNestedMessage("fraudReport.victim.reportingFor", {
|
|
51
61
|
name: current.name,
|
|
52
62
|
highlight: chunks => (_jsx(LakeText, { variant: "medium", color: colors.current[500], children: chunks })),
|
|
53
63
|
}) })] })) : null] }), choice.answer.toUndefined() === "SomeoneElse" ? (_jsxs(_Fragment, { children: [_jsx(Space, { width: 24, height: 24 }), _jsx(View, { style: !small && styles.column, children: memberPicker })] })) : null] })),
|
|
54
|
-
}) }), _jsx(FraudReportFooter, { nextDisabled: victim.isNone(), onNext: () => victim.tapSome(victimAccountMembershipId =>
|
|
64
|
+
}) }), _jsx(FraudReportFooter, { nextDisabled: victim.isNone(), onNext: () => victim.tapSome(victimAccountMembershipId => {
|
|
65
|
+
const { removed } = getVictimChange({
|
|
66
|
+
transactions,
|
|
67
|
+
previousVictimAccountMembershipId: values.victimAccountMembershipId,
|
|
68
|
+
victimAccountMembershipId,
|
|
69
|
+
});
|
|
70
|
+
if (removed.length > 0) {
|
|
71
|
+
setConfirmVisible(true);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
onNext({ victimAccountMembershipId });
|
|
75
|
+
}
|
|
76
|
+
}) }), _jsx(ConfirmModal, { visible: confirmVisible, icon: "warning-regular", color: "warning", title: t("fraudReport.victim.changeTitle"), message: transactions.some(({ rail }) => rail === "Transfer")
|
|
77
|
+
? t("fraudReport.victim.changeMessage")
|
|
78
|
+
: t("fraudReport.victim.changeMessageCardsOnly"), confirmText: t("fraudReport.victim.changeConfirm"), onCancel: () => {
|
|
79
|
+
setConfirmVisible(false);
|
|
80
|
+
setChoice(getInitialVictimChoice({
|
|
81
|
+
currentAccountMembership,
|
|
82
|
+
victimAccountMembershipId: values.victimAccountMembershipId,
|
|
83
|
+
}));
|
|
84
|
+
}, onConfirm: () => {
|
|
85
|
+
setConfirmVisible(false);
|
|
86
|
+
victim.tapSome(victimAccountMembershipId => onNext({ victimAccountMembershipId }));
|
|
87
|
+
} })] }));
|
|
55
88
|
};
|
|
@@ -137,5 +137,5 @@ export const LakeModal = ({ visible, icon, title, color = "current", children, m
|
|
|
137
137
|
if (rootElement == null) {
|
|
138
138
|
return null;
|
|
139
139
|
}
|
|
140
|
-
return (_jsx(Portal, { container: rootElement, children: _jsxs(View, { role: "dialog", "aria-modal": true, "aria-hidden": !visible, "aria-labelledby": visible && title != null ? titleId : undefined, style: [styles.container, !visible && styles.inert], children: [_jsx(TransitionView, { style: styles.fill, enter: styles.overlayEnter, leave: styles.overlayLeave, children: visible ? _jsx(View, { style: styles.overlay }) : null }), _jsx(Suspendable, { fallback: _jsx(LoadingView, { color: backgroundColor.accented, delay: 0 }), children: _jsx(TransitionView, { style: styles.fill, enter: styles.modalEnter, leave: styles.modalLeave, children: visible ? (_jsx(ResponsiveContainer, { style: styles.root, breakpoint: breakpoints.tiny, children: ({ large, small }) => (_jsx(FocusTrap, { autoFocus: true, focusLock: true, returnFocus: true, onEscapeKey: onPressClose, style: styles.trap, children: _jsxs(ScrollView, { style: styles.modalContainer, contentContainerStyle: large ? styles.modalContentContainer : styles.modalContentContainerSmall, children: [onPressClose != null ? (_jsx(Pressable, { onPress: onPressClose, style: styles.pressableOverlay })) : null, _jsxs(View, {
|
|
140
|
+
return (_jsx(Portal, { container: rootElement, children: _jsxs(View, { role: "dialog", "aria-modal": true, "aria-hidden": !visible, "aria-labelledby": visible && title != null ? titleId : undefined, style: [styles.container, !visible && styles.inert], children: [_jsx(TransitionView, { style: styles.fill, enter: styles.overlayEnter, leave: styles.overlayLeave, children: visible ? _jsx(View, { style: styles.overlay }) : null }), _jsx(Suspendable, { fallback: _jsx(LoadingView, { color: backgroundColor.accented, delay: 0 }), children: _jsx(TransitionView, { style: styles.fill, enter: styles.modalEnter, leave: styles.modalLeave, children: visible ? (_jsx(ResponsiveContainer, { style: styles.root, breakpoint: breakpoints.tiny, children: ({ large, small }) => (_jsx(FocusTrap, { autoFocus: true, focusLock: true, returnFocus: true, onEscapeKey: onPressClose, style: styles.trap, children: _jsxs(ScrollView, { style: styles.modalContainer, contentContainerStyle: large ? styles.modalContentContainer : styles.modalContentContainerSmall, children: [onPressClose != null ? (_jsx(Pressable, { onPress: onPressClose, style: styles.pressableOverlay })) : null, _jsxs(View, { style: [large ? styles.modal : styles.modalSmall, { maxWidth }], children: [_jsxs(View, { style: styles.modalHeader, children: [_jsxs(View, { style: styles.modalIconTitle, children: [icon != null ? (_jsx(Icon, { name: icon, size: large ? 40 : 32, color: colors[color][500] })) : null, icon != null && title != null ? _jsx(Space, { height: 12 }) : null, title != null ? (_jsxs(_Fragment, { children: [_jsx(LakeHeading, { id: titleId, level: 2, variant: "h3", children: title }), _jsx(Space, { height: 12 })] })) : null] }), onPressClose != null ? (_jsx(LakeButton, { style: styles.closeButton, mode: "tertiary", onPress: onPressClose, icon: "lake-close", ariaLabel: t("common.close") })) : null] }), typeof children === "function" ? children({ large, small }) : children] })] }) })) })) : null }) })] }) }));
|
|
141
141
|
};
|
|
@@ -28,6 +28,7 @@ export type UploadOutput = {
|
|
|
28
28
|
value: string;
|
|
29
29
|
}[];
|
|
30
30
|
};
|
|
31
|
+
export declare const uploadSupportingDocumentFile: ({ upload, file, onProgress, }: UploadFileInput<UploadOutput>) => Future<Result<Response<string>, import("@bloodyowl/request").BadStatusError | NetworkError | TimeoutError>>;
|
|
31
32
|
type SupportingDocumentCollectionStatus = "WaitingForDocument" | "PendingReview" | "Approved" | "Canceled" | "Rejected";
|
|
32
33
|
type PurposeMetadata = {
|
|
33
34
|
title: string;
|
|
@@ -31,6 +31,18 @@ export const toDocumentPurposes = (requiredPurposes) => {
|
|
|
31
31
|
});
|
|
32
32
|
return Object.fromEntries(entries);
|
|
33
33
|
};
|
|
34
|
+
export const uploadSupportingDocumentFile = ({ upload, file, onProgress, }) => {
|
|
35
|
+
const body = new FormData();
|
|
36
|
+
upload.fields.forEach(({ key, value }) => body.append(key, value));
|
|
37
|
+
body.append("file", file);
|
|
38
|
+
setTimeout(() => onProgress(0.8), 100);
|
|
39
|
+
return Request.make({
|
|
40
|
+
url: upload.url,
|
|
41
|
+
method: "POST",
|
|
42
|
+
body,
|
|
43
|
+
type: "text",
|
|
44
|
+
}).mapOkToResult(badStatusToError);
|
|
45
|
+
};
|
|
34
46
|
const styles = StyleSheet.create({
|
|
35
47
|
button: { opacity: 1 },
|
|
36
48
|
buttonWithDefaultCursor: { opacity: 1, cursor: "default" },
|
|
@@ -127,20 +139,7 @@ export const SupportingDocumentCollection = ({ ref, documents, generateUpload, u
|
|
|
127
139
|
canUpload: !readonlyDocumentPurposes.includes(purpose) &&
|
|
128
140
|
!readOnly &&
|
|
129
141
|
status === "WaitingForDocument" &&
|
|
130
|
-
!areAllDocumentsValidated, accept: ACCEPTED_FORMATS, maxSize: 20000000, icon: "document-regular", initialFiles: files, generateUpload: generateUpload, getUploadConfig: file => ({ fileName: file.name, purpose }), uploadFile:
|
|
131
|
-
? uploadFile
|
|
132
|
-
: ({ upload, file, onProgress }) => {
|
|
133
|
-
const body = new FormData();
|
|
134
|
-
upload.fields.forEach(({ key, value }) => body.append(key, value));
|
|
135
|
-
body.append("file", file);
|
|
136
|
-
setTimeout(() => onProgress(0.8), 100);
|
|
137
|
-
return Request.make({
|
|
138
|
-
url: upload.url,
|
|
139
|
-
method: "POST",
|
|
140
|
-
body,
|
|
141
|
-
type: "text",
|
|
142
|
-
}).mapOkToResult(badStatusToError);
|
|
143
|
-
}, formatAndSizeDescription: t("supportingDocuments.documentTypes", {
|
|
142
|
+
!areAllDocumentsValidated, accept: ACCEPTED_FORMATS, maxSize: 20000000, icon: "document-regular", initialFiles: files, generateUpload: generateUpload, getUploadConfig: file => ({ fileName: file.name, purpose }), uploadFile: uploadFile !== null && uploadFile !== void 0 ? uploadFile : uploadSupportingDocumentFile, formatAndSizeDescription: t("supportingDocuments.documentTypes", {
|
|
144
143
|
maxSizeMB: 20000000 / 1000000,
|
|
145
144
|
}), onRemoveFile: readOnly ? undefined : onRemoveFile, onChange: files => {
|
|
146
145
|
if (isRequired) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Future, Result } from "@bloodyowl/boxed";
|
|
2
|
+
import { act, renderHook } from "@testing-library/react";
|
|
3
|
+
import { describe, expect, test, vi } from "vitest";
|
|
4
|
+
import { useFilesUploader } from "../useFilesUploader";
|
|
5
|
+
const pdf = (name) => new File(["file"], name, { type: "application/pdf" });
|
|
6
|
+
const uploaded = (id, name) => ({
|
|
7
|
+
id,
|
|
8
|
+
name,
|
|
9
|
+
statusInfo: { status: "Uploaded" },
|
|
10
|
+
});
|
|
11
|
+
const generated = (id) => Future.value(Result.Ok({ id, upload: "" }));
|
|
12
|
+
const failure = () => Future.value(Result.Error("network"));
|
|
13
|
+
const render = ({ initialFiles = [], generateUpload = vi.fn(() => generated("server")), uploadFile = vi.fn(() => Future.value(Result.Ok(undefined))), }) => renderHook(() => useFilesUploader({
|
|
14
|
+
initialFiles,
|
|
15
|
+
generateUpload,
|
|
16
|
+
uploadFile,
|
|
17
|
+
}));
|
|
18
|
+
const statuses = (files) => files.map(({ name, statusInfo }) => `${name} ${statusInfo.status}`);
|
|
19
|
+
describe("useFilesUploader", () => {
|
|
20
|
+
test("shows a file as uploading before generateUpload answers, then keeps its place", () => {
|
|
21
|
+
let answer = () => { };
|
|
22
|
+
const { result } = render({
|
|
23
|
+
initialFiles: [uploaded("saved", "saved.pdf")],
|
|
24
|
+
generateUpload: () => Future.make(resolve => {
|
|
25
|
+
answer = resolve;
|
|
26
|
+
}),
|
|
27
|
+
});
|
|
28
|
+
act(() => {
|
|
29
|
+
result.current.upload({ fileName: "report.pdf" }, pdf("report.pdf"));
|
|
30
|
+
});
|
|
31
|
+
expect(statuses(result.current.files)).toEqual(["saved.pdf Uploaded", "report.pdf Uploading"]);
|
|
32
|
+
act(() => answer(Result.Ok({ id: "server", upload: "" })));
|
|
33
|
+
expect(result.current.files).toEqual([
|
|
34
|
+
uploaded("saved", "saved.pdf"),
|
|
35
|
+
uploaded("server", "report.pdf"),
|
|
36
|
+
]);
|
|
37
|
+
});
|
|
38
|
+
test("keeps a file whose upload couldn't start, and retries it", () => {
|
|
39
|
+
const generateUpload = vi
|
|
40
|
+
.fn(() => generated("server"))
|
|
41
|
+
.mockImplementationOnce(failure);
|
|
42
|
+
const { result } = render({ generateUpload });
|
|
43
|
+
act(() => {
|
|
44
|
+
result.current.upload({ fileName: "report.pdf" }, pdf("report.pdf"));
|
|
45
|
+
});
|
|
46
|
+
expect(statuses(result.current.files)).toEqual(["report.pdf UploadFailed"]);
|
|
47
|
+
act(() => { var _a; var _b; return result.current.retry((_b = (_a = result.current.files[0]) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : ""); });
|
|
48
|
+
expect(result.current.files).toEqual([uploaded("server", "report.pdf")]);
|
|
49
|
+
expect(generateUpload).toHaveBeenCalledTimes(2);
|
|
50
|
+
});
|
|
51
|
+
test("keeps a file whose upload failed, with the ID generateUpload gave", () => {
|
|
52
|
+
const uploadFile = vi
|
|
53
|
+
.fn(() => Future.value(Result.Ok(undefined)))
|
|
54
|
+
.mockImplementationOnce(failure);
|
|
55
|
+
const { result } = render({ uploadFile });
|
|
56
|
+
act(() => {
|
|
57
|
+
result.current.upload({ fileName: "report.pdf" }, pdf("report.pdf"));
|
|
58
|
+
});
|
|
59
|
+
expect(result.current.files).toEqual([
|
|
60
|
+
{ id: "server", name: "report.pdf", statusInfo: { status: "UploadFailed" } },
|
|
61
|
+
]);
|
|
62
|
+
});
|
|
63
|
+
test("retries a failed file in its place in the list", () => {
|
|
64
|
+
const uploadFile = vi
|
|
65
|
+
.fn(() => Future.value(Result.Ok(undefined)))
|
|
66
|
+
.mockImplementationOnce(failure);
|
|
67
|
+
let nextId = 0;
|
|
68
|
+
const { result } = render({
|
|
69
|
+
initialFiles: [uploaded("saved", "saved.pdf")],
|
|
70
|
+
generateUpload: () => generated(`server-${++nextId}`),
|
|
71
|
+
uploadFile,
|
|
72
|
+
});
|
|
73
|
+
act(() => {
|
|
74
|
+
result.current.upload({ fileName: "report.pdf" }, pdf("report.pdf"));
|
|
75
|
+
});
|
|
76
|
+
act(() => {
|
|
77
|
+
result.current.upload({ fileName: "later.pdf" }, pdf("later.pdf"));
|
|
78
|
+
});
|
|
79
|
+
expect(statuses(result.current.files)).toEqual([
|
|
80
|
+
"saved.pdf Uploaded",
|
|
81
|
+
"report.pdf UploadFailed",
|
|
82
|
+
"later.pdf Uploaded",
|
|
83
|
+
]);
|
|
84
|
+
act(() => result.current.retry("server-1"));
|
|
85
|
+
expect(statuses(result.current.files)).toEqual([
|
|
86
|
+
"saved.pdf Uploaded",
|
|
87
|
+
"report.pdf Uploaded",
|
|
88
|
+
"later.pdf Uploaded",
|
|
89
|
+
]);
|
|
90
|
+
});
|
|
91
|
+
test("replaces a listed file when generateUpload gives its ID again", () => {
|
|
92
|
+
const { result } = render({
|
|
93
|
+
initialFiles: [uploaded("document", "old.pdf")],
|
|
94
|
+
generateUpload: () => generated("document"),
|
|
95
|
+
});
|
|
96
|
+
act(() => {
|
|
97
|
+
result.current.upload({ fileName: "new.pdf" }, pdf("new.pdf"));
|
|
98
|
+
});
|
|
99
|
+
expect(result.current.files).toEqual([uploaded("document", "new.pdf")]);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
@@ -71,6 +71,12 @@ const startReport = (flow, { victim, transactions }) => {
|
|
|
71
71
|
flow.next({ victimAccountMembershipId: victim });
|
|
72
72
|
flow.next({ transactions });
|
|
73
73
|
};
|
|
74
|
+
const goBackTo = (flow, step) => {
|
|
75
|
+
for (let index = 0; index < 10 && flow.result.current.step !== step; index++) {
|
|
76
|
+
flow.previous();
|
|
77
|
+
}
|
|
78
|
+
expect(flow.result.current.step).toBe(step);
|
|
79
|
+
};
|
|
74
80
|
afterEach(() => {
|
|
75
81
|
vi.useRealTimers();
|
|
76
82
|
});
|
|
@@ -256,21 +262,105 @@ describe("victim", () => {
|
|
|
256
262
|
expect(flow.result.current.disputeCaseId.isSome()).toBe(true);
|
|
257
263
|
expect(flow.result.current).not.toHaveProperty("victimAccountMembershipId");
|
|
258
264
|
});
|
|
259
|
-
test("
|
|
265
|
+
test("changes the victim once the draft exists, without the previous victim's card transactions", () => {
|
|
260
266
|
const flow = setup();
|
|
261
|
-
startReport(flow, { victim: "member-
|
|
267
|
+
startReport(flow, { victim: "member-1", transactions: [card, transfer] });
|
|
262
268
|
flow.previous();
|
|
263
269
|
flow.previous();
|
|
264
270
|
expect(flow.result.current.step).toBe("Victim");
|
|
271
|
+
flow.next({ victimAccountMembershipId: "member-2" });
|
|
272
|
+
expect(flow.result.current.step).toBe("Transactions");
|
|
265
273
|
expect(flow.result.current.values.victimAccountMembershipId).toBe("member-2");
|
|
266
|
-
flow.
|
|
274
|
+
expect(flow.result.current.values.transactions).toEqual([transfer]);
|
|
275
|
+
expect(flow.callNames()).toEqual(["draft"]);
|
|
267
276
|
flow.next({ transactions: [transfer] });
|
|
268
|
-
expect(flow.result.current.
|
|
277
|
+
expect(flow.result.current.error.isNone()).toBe(true);
|
|
269
278
|
expect(flow.calls.at(-1)).toEqual({
|
|
270
279
|
name: "update",
|
|
271
|
-
input: expect.objectContaining({
|
|
280
|
+
input: expect.objectContaining({
|
|
281
|
+
transactionIds: ["transfer-1"],
|
|
282
|
+
victimAccountMembershipId: "member-2",
|
|
283
|
+
}),
|
|
272
284
|
});
|
|
273
285
|
});
|
|
286
|
+
test("leaves no transaction selected when the previous victim only had card transactions", () => {
|
|
287
|
+
const flow = setup();
|
|
288
|
+
startReport(flow, { victim: "member-1", transactions: [card] });
|
|
289
|
+
flow.previous();
|
|
290
|
+
flow.previous();
|
|
291
|
+
flow.next({ victimAccountMembershipId: "member-2" });
|
|
292
|
+
expect(flow.result.current.step).toBe("Transactions");
|
|
293
|
+
expect(flow.result.current.values.transactions).toEqual([]);
|
|
294
|
+
expect(flow.callNames()).toEqual(["draft"]);
|
|
295
|
+
});
|
|
296
|
+
test("clears the previous victim's card answers when the victim changes", () => {
|
|
297
|
+
const flow = setup();
|
|
298
|
+
startReport(flow, { victim: "member-1", transactions: [card, transfer] });
|
|
299
|
+
flow.next(incident);
|
|
300
|
+
flow.next({ isLostOrStolen: true, lostOrStolenNoticedAt: "2026-11-01" });
|
|
301
|
+
goBackTo(flow, "Victim");
|
|
302
|
+
flow.next({ victimAccountMembershipId: "member-2" });
|
|
303
|
+
expect(flow.result.current.values).toMatchObject(incident);
|
|
304
|
+
expect(flow.result.current.values.isLostOrStolen).toBeUndefined();
|
|
305
|
+
expect(flow.result.current.values.lostOrStolenNoticedAt).toBeUndefined();
|
|
306
|
+
});
|
|
307
|
+
test("clears the previous victim's card answers when the victim changes with only transfers selected", () => {
|
|
308
|
+
const flow = setup();
|
|
309
|
+
startReport(flow, { victim: "member-1", transactions: [card, transfer] });
|
|
310
|
+
flow.next(incident);
|
|
311
|
+
flow.next({ isLostOrStolen: true, lostOrStolenNoticedAt: "2026-11-01" });
|
|
312
|
+
goBackTo(flow, "Transactions");
|
|
313
|
+
flow.next({ transactions: [transfer] });
|
|
314
|
+
goBackTo(flow, "Victim");
|
|
315
|
+
flow.next({ victimAccountMembershipId: "member-2" });
|
|
316
|
+
expect(flow.result.current.values.transactions).toEqual([transfer]);
|
|
317
|
+
expect(flow.result.current.values.isLostOrStolen).toBeUndefined();
|
|
318
|
+
expect(flow.result.current.values.lostOrStolenNoticedAt).toBeUndefined();
|
|
319
|
+
});
|
|
320
|
+
test("sends the new victim's card without the previous victim's card answers", () => {
|
|
321
|
+
const flow = setup({
|
|
322
|
+
transactions: [
|
|
323
|
+
...seededTransactions(),
|
|
324
|
+
{
|
|
325
|
+
id: "card-2",
|
|
326
|
+
accountId: "account-1",
|
|
327
|
+
type: "CardOutDebit",
|
|
328
|
+
cardholderAccountMembershipId: "member-2",
|
|
329
|
+
},
|
|
330
|
+
],
|
|
331
|
+
});
|
|
332
|
+
startReport(flow, { victim: "member-1", transactions: [card] });
|
|
333
|
+
flow.next(incident);
|
|
334
|
+
flow.next({
|
|
335
|
+
isLostOrStolen: true,
|
|
336
|
+
lostOrStolenNoticedAt: "2026-11-01",
|
|
337
|
+
hasContactedMerchant: true,
|
|
338
|
+
hasFiledPoliceComplaint: true,
|
|
339
|
+
});
|
|
340
|
+
goBackTo(flow, "Victim");
|
|
341
|
+
flow.next({ victimAccountMembershipId: "member-2" });
|
|
342
|
+
flow.next({ transactions: [createFakeTransaction("card-2", "CardOutDebit")] });
|
|
343
|
+
expect(flow.calls.at(-1)).toEqual({
|
|
344
|
+
name: "update",
|
|
345
|
+
input: expect.objectContaining({
|
|
346
|
+
transactionIds: ["card-2"],
|
|
347
|
+
fraudDetails: expect.objectContaining({ hasFiledPoliceComplaint: true }),
|
|
348
|
+
fraudCardDetails: {
|
|
349
|
+
isLostOrStolen: null,
|
|
350
|
+
lostOrStolenNoticedAt: null,
|
|
351
|
+
hasContactedMerchant: null,
|
|
352
|
+
},
|
|
353
|
+
}),
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
test("keeps the selection when the victim stays the same", () => {
|
|
357
|
+
const flow = setup();
|
|
358
|
+
startReport(flow, { victim: "member-1", transactions: [card, transfer] });
|
|
359
|
+
flow.previous();
|
|
360
|
+
flow.previous();
|
|
361
|
+
flow.next({ victimAccountMembershipId: "member-1" });
|
|
362
|
+
expect(flow.result.current.values.transactions).toEqual([card, transfer]);
|
|
363
|
+
});
|
|
274
364
|
test("sends the victim on a transfer-only case", () => {
|
|
275
365
|
const flow = setup();
|
|
276
366
|
startReport(flow, { victim: "member-2", transactions: [transfer] });
|
|
@@ -494,21 +584,6 @@ describe("rejections", () => {
|
|
|
494
584
|
},
|
|
495
585
|
rejection: { __typename: "DisputeCaseTransactionsAlreadyReportedRejection" },
|
|
496
586
|
},
|
|
497
|
-
{
|
|
498
|
-
name: "the victim isn't found once the draft exists",
|
|
499
|
-
config: {
|
|
500
|
-
transactions: [
|
|
501
|
-
...seededTransactions(),
|
|
502
|
-
{ id: "transfer-2", accountId: "account-2", type: "SepaCreditTransferOut" },
|
|
503
|
-
],
|
|
504
|
-
},
|
|
505
|
-
run: flow => {
|
|
506
|
-
startReport(flow, { victim: "member-2", transactions: [transfer] });
|
|
507
|
-
flow.previous();
|
|
508
|
-
flow.next({ transactions: [createFakeTransaction("transfer-2", "SepaCreditTransferOut")] });
|
|
509
|
-
},
|
|
510
|
-
rejection: { __typename: "AccountMembershipNotFoundRejection" },
|
|
511
|
-
},
|
|
512
587
|
{
|
|
513
588
|
name: "the case isn't found",
|
|
514
589
|
run: flow => {
|
|
@@ -528,6 +603,19 @@ describe("rejections", () => {
|
|
|
528
603
|
expect(flow.result.current.step).toBe("Rejected");
|
|
529
604
|
expectRejection(flow, rejection);
|
|
530
605
|
});
|
|
606
|
+
test("goes back to the victim step when the victim isn't found once the draft exists", () => {
|
|
607
|
+
const flow = setup({
|
|
608
|
+
transactions: [
|
|
609
|
+
...seededTransactions(),
|
|
610
|
+
{ id: "transfer-2", accountId: "account-2", type: "SepaCreditTransferOut" },
|
|
611
|
+
],
|
|
612
|
+
});
|
|
613
|
+
startReport(flow, { victim: "member-2", transactions: [transfer] });
|
|
614
|
+
flow.previous();
|
|
615
|
+
flow.next({ transactions: [createFakeTransaction("transfer-2", "SepaCreditTransferOut")] });
|
|
616
|
+
expect(flow.result.current.step).toBe("Victim");
|
|
617
|
+
expectRejection(flow, { __typename: "AccountMembershipNotFoundRejection" });
|
|
618
|
+
});
|
|
531
619
|
test("ends the report on the rejected step when the draft expired", () => {
|
|
532
620
|
let date = new Date("2026-11-26T10:00:00.000Z");
|
|
533
621
|
const flow = setup({ now: () => date });
|
|
@@ -18,7 +18,8 @@ export type Config<UploadInput, UploadOutput, GenerateUploadError, UploadFileErr
|
|
|
18
18
|
};
|
|
19
19
|
export declare const useFilesUploader: <UploadInput, UploadOutput, GenerateUploadError, UploadFileError>(config: Config<UploadInput, UploadOutput, GenerateUploadError, UploadFileError>) => {
|
|
20
20
|
files: SwanFile[];
|
|
21
|
-
upload: (uploadInput: UploadInput, file: File) => Future<Result<unknown, GenerateUploadError | UploadFileError>>;
|
|
21
|
+
upload: (uploadInput: UploadInput, file: File, placeholderId?: string) => Future<Result<unknown, GenerateUploadError | UploadFileError>>;
|
|
22
22
|
remove: (id: string) => void;
|
|
23
|
+
retry: (id: string) => void;
|
|
23
24
|
add: (fileToAdd: SwanFile) => void;
|
|
24
25
|
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { useCallback, useState } from "react";
|
|
1
|
+
import { useCallback, useRef, useState } from "react";
|
|
2
|
+
import { v4 as uuid } from "uuid";
|
|
2
3
|
export const useFilesUploader = (config) => {
|
|
3
4
|
const [files, setFiles] = useState(config.initialFiles);
|
|
5
|
+
const failedUploads = useRef(new Map());
|
|
4
6
|
const add = useCallback((fileToAdd) => {
|
|
5
7
|
setFiles(files => {
|
|
6
8
|
if (files.some(item => item.id === fileToAdd.id)) {
|
|
@@ -11,23 +13,31 @@ export const useFilesUploader = (config) => {
|
|
|
11
13
|
}
|
|
12
14
|
});
|
|
13
15
|
}, []);
|
|
14
|
-
const
|
|
16
|
+
const setFailed = useCallback((id, uploadInput, file) => {
|
|
17
|
+
failedUploads.current.set(id, { uploadInput, file });
|
|
18
|
+
add({ id, name: file.name, statusInfo: { status: "UploadFailed" } });
|
|
19
|
+
}, [add]);
|
|
20
|
+
const upload = useCallback((uploadInput, file, placeholderId = uuid()) => {
|
|
21
|
+
add({ id: placeholderId, name: file.name, statusInfo: { status: "Uploading", progress: 0 } });
|
|
15
22
|
return config
|
|
16
23
|
.generateUpload(uploadInput)
|
|
17
24
|
.tapError(error => {
|
|
18
25
|
if (config.onError != null) {
|
|
19
26
|
config.onError(error);
|
|
20
27
|
}
|
|
28
|
+
setFailed(placeholderId, uploadInput, file);
|
|
21
29
|
})
|
|
22
30
|
.flatMapOk(({ upload, id }) => {
|
|
23
|
-
setFiles(files =>
|
|
24
|
-
|
|
25
|
-
{
|
|
31
|
+
setFiles(files => {
|
|
32
|
+
const uploadingFile = {
|
|
26
33
|
id,
|
|
27
34
|
statusInfo: { status: "Uploading", progress: 0 },
|
|
28
35
|
name: file.name,
|
|
29
|
-
}
|
|
30
|
-
|
|
36
|
+
};
|
|
37
|
+
return files
|
|
38
|
+
.filter(file => file.id !== id || file.id === placeholderId)
|
|
39
|
+
.map(file => (file.id === placeholderId ? uploadingFile : file));
|
|
40
|
+
});
|
|
31
41
|
const onProgress = (progress) => {
|
|
32
42
|
setFiles(files => files.map(file => {
|
|
33
43
|
// A late progress report (upload is faster than fake progress bar)
|
|
@@ -63,17 +73,26 @@ export const useFilesUploader = (config) => {
|
|
|
63
73
|
if (config.onError != null) {
|
|
64
74
|
config.onError(error);
|
|
65
75
|
}
|
|
66
|
-
|
|
76
|
+
setFailed(id, uploadInput, file);
|
|
67
77
|
});
|
|
68
78
|
});
|
|
69
|
-
}, [config]);
|
|
79
|
+
}, [add, config, setFailed]);
|
|
70
80
|
const remove = useCallback((id) => {
|
|
81
|
+
failedUploads.current.delete(id);
|
|
71
82
|
setFiles(files => files.filter(file => file.id !== id));
|
|
72
83
|
}, []);
|
|
84
|
+
const retry = useCallback((id) => {
|
|
85
|
+
const failedUpload = failedUploads.current.get(id);
|
|
86
|
+
if (failedUpload != null) {
|
|
87
|
+
failedUploads.current.delete(id);
|
|
88
|
+
upload(failedUpload.uploadInput, failedUpload.file, id);
|
|
89
|
+
}
|
|
90
|
+
}, [upload]);
|
|
73
91
|
return {
|
|
74
92
|
files,
|
|
75
93
|
upload,
|
|
76
94
|
remove,
|
|
95
|
+
retry,
|
|
77
96
|
add,
|
|
78
97
|
};
|
|
79
98
|
};
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { AsyncData, Option } from "@bloodyowl/boxed";
|
|
2
2
|
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
3
3
|
import { match } from "ts-pattern";
|
|
4
|
+
import { emptyCardAnswers } from "../utils/fraudReport/card";
|
|
4
5
|
import { toFormValues } from "../utils/fraudReport/prefill";
|
|
5
6
|
import { getRejectionStep } from "../utils/fraudReport/rejections";
|
|
6
7
|
import { getResumeStep } from "../utils/fraudReport/resume";
|
|
7
8
|
import { getDetailsSteps } from "../utils/fraudReport/stepper";
|
|
8
9
|
import { toDraftInput, toTransactionIds, toUpdateInput, } from "../utils/fraudReport/toInput";
|
|
9
10
|
import { fraudReportSteps, } from "../utils/fraudReport/types";
|
|
11
|
+
import { getVictimChange } from "../utils/fraudReport/victim";
|
|
10
12
|
const initialState = {
|
|
11
13
|
step: "Intro",
|
|
12
14
|
values: { transactions: [] },
|
|
@@ -25,7 +27,6 @@ const getErrorChange = (state, values, error) => {
|
|
|
25
27
|
const step = match(error)
|
|
26
28
|
.returnType()
|
|
27
29
|
.with({ kind: "rejection" }, ({ rejection }) => getRejectionStep(rejection, {
|
|
28
|
-
hasDraft: state.savedCase.isSome(),
|
|
29
30
|
detailsSteps: getDetailsSteps(values),
|
|
30
31
|
}))
|
|
31
32
|
.with({ kind: "error" }, () => state.step)
|
|
@@ -90,11 +91,15 @@ export const useFraudReportFlow = ({ api, onExit, resumeFrom, }) => {
|
|
|
90
91
|
(state.step === "Intro" && state.resumable.isLoading())) {
|
|
91
92
|
return;
|
|
92
93
|
}
|
|
93
|
-
const {
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
const merged = { ...state.values, ...input };
|
|
95
|
+
const { changed, kept } = getVictimChange({
|
|
96
|
+
transactions: merged.transactions,
|
|
97
|
+
previousVictimAccountMembershipId: state.values.victimAccountMembershipId,
|
|
98
|
+
victimAccountMembershipId: input.victimAccountMembershipId,
|
|
99
|
+
});
|
|
100
|
+
const values = changed
|
|
101
|
+
? { ...merged, transactions: kept, ...emptyCardAnswers }
|
|
102
|
+
: merged;
|
|
98
103
|
const steps = getSteps(values);
|
|
99
104
|
const nextStep = Option.fromUndefined(steps[steps.indexOf(state.step) + 1]).getOr(state.step);
|
|
100
105
|
const transactionIds = toTransactionIds(values);
|
|
@@ -104,7 +109,7 @@ export const useFraudReportFlow = ({ api, onExit, resumeFrom, }) => {
|
|
|
104
109
|
.with("Transactions", "Incident", "Card", "Transfer", "Fraudster", () => Option.Some(state.savedCase.match({
|
|
105
110
|
None: () => api.draft(toDraftInput(values)),
|
|
106
111
|
Some: savedCase => api.update(toUpdateInput({
|
|
107
|
-
savedCase,
|
|
112
|
+
disputeCaseId: savedCase.id,
|
|
108
113
|
values,
|
|
109
114
|
savedTransactionIds: state.savedTransactionIds,
|
|
110
115
|
})),
|