@swan-io/shared-business 18.5.0 → 18.6.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/FraudReport/CardDetailsStep.d.ts +7 -0
- package/src/components/FraudReport/CardDetailsStep.js +46 -0
- 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/VictimStep.d.ts +3 -1
- package/src/components/FraudReport/VictimStep.js +38 -5
- package/src/components/LakeModal.js +1 -1
- package/src/hooks/__tests__/useFraudReportFlow.test.js +108 -20
- package/src/hooks/useFraudReportFlow.js +12 -7
- package/src/locales/de.json +62 -8
- package/src/locales/en.json +55 -1
- package/src/locales/es.json +55 -1
- package/src/locales/fi.json +55 -1
- package/src/locales/fr.json +55 -1
- package/src/locales/it.json +55 -1
- package/src/locales/nl.json +55 -1
- package/src/locales/pt.json +55 -1
- 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.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 +171 -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 +3 -1
- package/src/utils/__tests__/fraudReport.rejections.test.js +11 -19
- package/src/utils/__tests__/fraudReport.resume.test.js +17 -3
- package/src/utils/__tests__/fraudReport.toInput.test.js +84 -30
- package/src/utils/__tests__/fraudReport.transactions.test.js +11 -1
- package/src/utils/__tests__/fraudReport.victim.test.js +27 -1
- package/src/utils/__tests__/validation.test.js +69 -2
- package/src/utils/fraudReport/card.d.ts +11 -0
- package/src/utils/fraudReport/card.js +15 -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 +18 -0
- package/src/utils/fraudReport/picker.js +49 -0
- package/src/utils/fraudReport/pickerFilters.d.ts +26 -0
- package/src/utils/fraudReport/pickerFilters.js +62 -0
- package/src/utils/fraudReport/prefill.js +5 -3
- package/src/utils/fraudReport/rejections.d.ts +0 -1
- package/src/utils/fraudReport/rejections.js +2 -6
- package/src/utils/fraudReport/resume.js +3 -3
- package/src/utils/fraudReport/toInput.d.ts +5 -3
- package/src/utils/fraudReport/toInput.js +20 -22
- package/src/utils/fraudReport/transactions.d.ts +2 -0
- package/src/utils/fraudReport/transactions.js +4 -0
- 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 +14 -7
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box } from "@swan-io/lake/src/components/Box";
|
|
3
|
+
import { Icon } from "@swan-io/lake/src/components/Icon";
|
|
4
|
+
import { LakeButton } from "@swan-io/lake/src/components/LakeButton";
|
|
5
|
+
import { LakeCheckbox } from "@swan-io/lake/src/components/LakeCheckbox";
|
|
6
|
+
import { LakeText } from "@swan-io/lake/src/components/LakeText";
|
|
7
|
+
import { LakeTextInput } from "@swan-io/lake/src/components/LakeTextInput";
|
|
8
|
+
import { Popover } from "@swan-io/lake/src/components/Popover";
|
|
9
|
+
import { Pressable } from "@swan-io/lake/src/components/Pressable";
|
|
10
|
+
import { Space } from "@swan-io/lake/src/components/Space";
|
|
11
|
+
import { colors, radii, spacings } from "@swan-io/lake/src/constants/design";
|
|
12
|
+
import { useDebounce } from "@swan-io/lake/src/hooks/useDebounce";
|
|
13
|
+
import dayjs from "dayjs";
|
|
14
|
+
import { useCallback, useEffect, useId, useRef, useState } from "react";
|
|
15
|
+
import { StyleSheet, View } from "react-native";
|
|
16
|
+
import { match } from "ts-pattern";
|
|
17
|
+
import { PICKER_DATE_FORMAT, parseAmountFilter, pickerFilterTypes, togglePickerFilterType, validateFromDate, validateToDate, } from "../../utils/fraudReport/pickerFilters";
|
|
18
|
+
import { locale, t } from "../../utils/i18n";
|
|
19
|
+
import { DatePickerModal } from "../DatePicker";
|
|
20
|
+
import { getPaymentMethodLabel } from "./TransactionRows";
|
|
21
|
+
const SEARCH_DEBOUNCE = 500;
|
|
22
|
+
const SEARCH_WIDTH = 350;
|
|
23
|
+
const SEARCH_MIN_WIDTH = 200;
|
|
24
|
+
const styles = StyleSheet.create({
|
|
25
|
+
largeBar: {
|
|
26
|
+
gap: 16,
|
|
27
|
+
},
|
|
28
|
+
smallBar: {
|
|
29
|
+
gap: 12,
|
|
30
|
+
},
|
|
31
|
+
chips: {
|
|
32
|
+
gap: 8,
|
|
33
|
+
},
|
|
34
|
+
chip: {
|
|
35
|
+
alignItems: "center",
|
|
36
|
+
borderColor: colors.gray[200],
|
|
37
|
+
borderRadius: radii[8],
|
|
38
|
+
borderStyle: "dashed",
|
|
39
|
+
borderWidth: 1,
|
|
40
|
+
flexDirection: "row",
|
|
41
|
+
height: 28,
|
|
42
|
+
overflow: "hidden",
|
|
43
|
+
},
|
|
44
|
+
chipWithValue: {
|
|
45
|
+
borderStyle: "solid",
|
|
46
|
+
},
|
|
47
|
+
chipClear: {
|
|
48
|
+
paddingLeft: spacings[8],
|
|
49
|
+
paddingRight: spacings[4],
|
|
50
|
+
paddingVertical: spacings[4],
|
|
51
|
+
},
|
|
52
|
+
chipButton: {
|
|
53
|
+
alignItems: "center",
|
|
54
|
+
alignSelf: "stretch",
|
|
55
|
+
flexDirection: "row",
|
|
56
|
+
gap: 2,
|
|
57
|
+
paddingHorizontal: spacings[8],
|
|
58
|
+
transitionDuration: "150ms",
|
|
59
|
+
transitionProperty: "background-color",
|
|
60
|
+
},
|
|
61
|
+
chipButtonWithValue: {
|
|
62
|
+
paddingLeft: 0,
|
|
63
|
+
},
|
|
64
|
+
chipButtonHovered: {
|
|
65
|
+
backgroundColor: colors.gray[50],
|
|
66
|
+
},
|
|
67
|
+
chipButtonPressed: {
|
|
68
|
+
backgroundColor: colors.gray[100],
|
|
69
|
+
},
|
|
70
|
+
chipSeparator: {
|
|
71
|
+
backgroundColor: colors.gray[100],
|
|
72
|
+
height: 16,
|
|
73
|
+
marginHorizontal: spacings[8],
|
|
74
|
+
width: 1,
|
|
75
|
+
},
|
|
76
|
+
chipValue: {
|
|
77
|
+
maxWidth: 150,
|
|
78
|
+
},
|
|
79
|
+
popover: {
|
|
80
|
+
padding: spacings[20],
|
|
81
|
+
},
|
|
82
|
+
list: {
|
|
83
|
+
minWidth: 200,
|
|
84
|
+
paddingVertical: spacings[12],
|
|
85
|
+
},
|
|
86
|
+
listItem: {
|
|
87
|
+
alignItems: "center",
|
|
88
|
+
flexDirection: "row",
|
|
89
|
+
height: spacings[32],
|
|
90
|
+
paddingHorizontal: spacings[20],
|
|
91
|
+
transitionDuration: "150ms",
|
|
92
|
+
transitionProperty: "background-color",
|
|
93
|
+
},
|
|
94
|
+
listItemHovered: {
|
|
95
|
+
backgroundColor: colors.gray[50],
|
|
96
|
+
},
|
|
97
|
+
search: {
|
|
98
|
+
// The search takes the room the chips leave, between its two widths: the chips wrap only
|
|
99
|
+
// once it is at its smallest.
|
|
100
|
+
flexBasis: SEARCH_MIN_WIDTH,
|
|
101
|
+
flexGrow: 1,
|
|
102
|
+
flexShrink: 0,
|
|
103
|
+
marginLeft: "auto",
|
|
104
|
+
maxWidth: SEARCH_WIDTH,
|
|
105
|
+
},
|
|
106
|
+
searchClear: {
|
|
107
|
+
borderRadius: radii[4],
|
|
108
|
+
padding: spacings[8],
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
const FilterChip = ({ ref, label, value, expanded, popoverId, onPress, onClear }) => {
|
|
112
|
+
const hasValue = value != null;
|
|
113
|
+
const buttonRef = useRef(null);
|
|
114
|
+
return (_jsxs(View, { ref: ref, style: [styles.chip, hasValue && styles.chipWithValue], children: [hasValue ? (_jsx(Pressable, { role: "button", "aria-label": t("fraudReport.picker.filters.clear", { filter: label }), style: styles.chipClear, onPress: () => {
|
|
115
|
+
var _a;
|
|
116
|
+
// The clear button goes away: the focus stays on the chip.
|
|
117
|
+
(_a = buttonRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
118
|
+
onClear();
|
|
119
|
+
}, children: _jsx(Icon, { name: "dismiss-circle-regular", size: 16, color: colors.gray[600] }) })) : null, _jsxs(Pressable, { ref: buttonRef, role: "button", "aria-haspopup": "dialog", "aria-expanded": expanded, "aria-controls": expanded ? popoverId : undefined, style: ({ hovered, pressed }) => [
|
|
120
|
+
styles.chipButton,
|
|
121
|
+
hasValue && styles.chipButtonWithValue,
|
|
122
|
+
hovered && styles.chipButtonHovered,
|
|
123
|
+
pressed && styles.chipButtonPressed,
|
|
124
|
+
], onPress: onPress, children: [hasValue ? null : _jsx(Icon, { name: "add-circle-regular", size: 16, color: colors.gray[600] }), _jsx(LakeText, { variant: "smallMedium", color: colors.gray[700], userSelect: "none", children: label }), hasValue ? (_jsxs(_Fragment, { children: [_jsx(View, { style: styles.chipSeparator }), _jsx(LakeText, { variant: "smallMedium", color: colors.current[600], numberOfLines: 1, userSelect: "none", style: styles.chipValue, children: value })] })) : null] })] }));
|
|
125
|
+
};
|
|
126
|
+
const toDisplayDate = (date) => dayjs.utc(date, PICKER_DATE_FORMAT, true).format(locale.dateFormat);
|
|
127
|
+
// An invalid date stays invalid, so the validator rejects it.
|
|
128
|
+
const fromDisplayDate = (date) => {
|
|
129
|
+
const parsed = dayjs.utc(date, locale.dateFormat, true);
|
|
130
|
+
return parsed.isValid() ? parsed.format(PICKER_DATE_FORMAT) : "";
|
|
131
|
+
};
|
|
132
|
+
const fromPickerDate = ({ year, month, day }) => dayjs.utc().year(year).month(month).date(day).format(PICKER_DATE_FORMAT);
|
|
133
|
+
const getDateError = (error) => match(error)
|
|
134
|
+
.with("InvalidDate", () => t("validation.invalidDate"))
|
|
135
|
+
.with("StartAfterEnd", () => t("fraudReport.picker.filters.startAfterEnd"))
|
|
136
|
+
.with(undefined, () => undefined)
|
|
137
|
+
.exhaustive();
|
|
138
|
+
const DateFilter = ({ label, value, visible, validate, onChange, onOpen, onClose, }) => {
|
|
139
|
+
const displayed = value == null ? undefined : toDisplayDate(value);
|
|
140
|
+
return (_jsxs(_Fragment, { children: [_jsx(FilterChip, { label: label, value: displayed, expanded: visible, onPress: onOpen, onClear: () => onChange(undefined) }), _jsx(DatePickerModal
|
|
141
|
+
// Its input keeps the last date it was given: a cleared filter starts empty again.
|
|
142
|
+
, { visible: visible, format: locale.dateFormat, firstWeekDay: "monday", label: label, cancelLabel: t("common.cancel"), confirmLabel: t("fraudReport.picker.filters.apply"), value: displayed, isSelectable: date => validate(fromPickerDate(date)) == null,
|
|
143
|
+
// Applying an empty date changes nothing.
|
|
144
|
+
validate: date => (date === "" ? undefined : getDateError(validate(fromDisplayDate(date)))), onChange: date => onChange(fromDisplayDate(date)), onDismiss: onClose }, displayed !== null && displayed !== void 0 ? displayed : "")] }));
|
|
145
|
+
};
|
|
146
|
+
const AmountFilter = ({ label, value, visible, onChange, onOpen, onClose, }) => {
|
|
147
|
+
const ref = useRef(null);
|
|
148
|
+
const popoverId = useId();
|
|
149
|
+
const [text, setText] = useState(value !== null && value !== void 0 ? value : "");
|
|
150
|
+
const [invalid, setInvalid] = useState(false);
|
|
151
|
+
const open = () => {
|
|
152
|
+
setText(value !== null && value !== void 0 ? value : "");
|
|
153
|
+
setInvalid(false);
|
|
154
|
+
onOpen();
|
|
155
|
+
};
|
|
156
|
+
const submit = () => {
|
|
157
|
+
const parsed = parseAmountFilter(text);
|
|
158
|
+
if ("error" in parsed) {
|
|
159
|
+
return setInvalid(true);
|
|
160
|
+
}
|
|
161
|
+
onChange(parsed.amount);
|
|
162
|
+
onClose();
|
|
163
|
+
};
|
|
164
|
+
return (_jsxs(_Fragment, { children: [_jsx(FilterChip, { ref: ref, label: label, value: value, expanded: visible, popoverId: popoverId, onPress: open, onClear: () => onChange(undefined) }), _jsx(Popover, { id: popoverId, label: label, placement: "left", referenceRef: ref, visible: visible, onDismiss: onClose, children: _jsxs(View, { style: styles.popover, children: [_jsx(LakeTextInput, { "aria-label": label, placeholder: label, inputMode: "decimal", value: text, error: invalid ? t("fraudReport.picker.filters.invalidAmount") : undefined, onChangeText: value => {
|
|
165
|
+
setText(value);
|
|
166
|
+
setInvalid(false);
|
|
167
|
+
}, onSubmitEditing: submit }), _jsx(Space, { height: 8 }), _jsx(LakeButton, { color: "current", size: "small", onPress: submit, children: t("fraudReport.picker.filters.apply") })] }) })] }));
|
|
168
|
+
};
|
|
169
|
+
const TypesFilter = ({ label, value, visible, onChange, onOpen, onClose, }) => {
|
|
170
|
+
const ref = useRef(null);
|
|
171
|
+
const popoverId = useId();
|
|
172
|
+
const selected = value !== null && value !== void 0 ? value : [];
|
|
173
|
+
return (_jsxs(_Fragment, { children: [_jsx(FilterChip, { ref: ref, label: label, value: selected.length === 0 ? undefined : selected.map(getPaymentMethodLabel).join(", "), expanded: visible, popoverId: popoverId, onPress: onOpen, onClear: () => onChange(undefined) }), _jsx(Popover, { id: popoverId, label: label, placement: "left", referenceRef: ref, visible: visible, onDismiss: onClose, children: _jsx(View, { role: "group", "aria-label": label, style: styles.list, children: pickerFilterTypes.map(type => {
|
|
174
|
+
const checked = selected.includes(type);
|
|
175
|
+
return (_jsxs(Pressable, { role: "checkbox", "aria-checked": checked, style: ({ hovered }) => [styles.listItem, hovered && styles.listItemHovered], onPress: () => onChange(togglePickerFilterType(selected, type)), children: [_jsx(LakeCheckbox, { value: checked }), _jsx(Space, { width: 12 }), _jsx(LakeText, { variant: "smallRegular", color: colors.gray[900], userSelect: "none", children: getPaymentMethodLabel(type) })] }, type));
|
|
176
|
+
}) }) })] }));
|
|
177
|
+
};
|
|
178
|
+
const SearchFilter = ({ initialValue, large, onChange, }) => {
|
|
179
|
+
const [text, setText] = useState(initialValue);
|
|
180
|
+
const cancel = useRef(undefined);
|
|
181
|
+
// A search comes late: it has to reach the callback of the latest render, which holds the
|
|
182
|
+
// filters changed in the meantime.
|
|
183
|
+
const latestOnChange = useRef(onChange);
|
|
184
|
+
useEffect(() => {
|
|
185
|
+
latestOnChange.current = onChange;
|
|
186
|
+
});
|
|
187
|
+
const debounced = useDebounce(useCallback((value) => latestOnChange.current(value), []), SEARCH_DEBOUNCE);
|
|
188
|
+
// A search still waiting when the picker closes is dropped.
|
|
189
|
+
useEffect(() => () => { var _a; return (_a = cancel.current) === null || _a === void 0 ? void 0 : _a.call(cancel); }, []);
|
|
190
|
+
const change = (value) => {
|
|
191
|
+
setText(value);
|
|
192
|
+
cancel.current = debounced(value);
|
|
193
|
+
};
|
|
194
|
+
const clear = () => {
|
|
195
|
+
var _a;
|
|
196
|
+
(_a = cancel.current) === null || _a === void 0 ? void 0 : _a.call(cancel);
|
|
197
|
+
setText("");
|
|
198
|
+
onChange("");
|
|
199
|
+
};
|
|
200
|
+
return (_jsx(View, { style: large ? styles.search : undefined, children: _jsx(LakeTextInput, { "aria-label": t("fraudReport.picker.search"), placeholder: t("fraudReport.picker.search"), icon: "search-filled", inputMode: "search", hideErrors: true, value: text, onChangeText: change, renderEnd: () => text === "" ? null : (_jsx(Pressable, { role: "button", "aria-label": t("fraudReport.picker.clearSearch"), style: styles.searchClear, onPress: clear, children: _jsx(Icon, { name: "dismiss-filled", size: 12, color: colors.gray[600] }) })) }) }));
|
|
201
|
+
};
|
|
202
|
+
export const TransactionPickerFilters = ({ filters, large, onChange }) => {
|
|
203
|
+
var _a;
|
|
204
|
+
const [open, setOpen] = useState();
|
|
205
|
+
const close = () => setOpen(undefined);
|
|
206
|
+
const chips = (_jsxs(Box, { direction: "row", wrap: "wrap", alignItems: "center", shrink: 1, style: styles.chips, children: [_jsx(DateFilter, { label: t("fraudReport.picker.filters.startDate"), value: filters.fromDate, visible: open === "fromDate", validate: date => validateFromDate(date, filters.toDate), onChange: fromDate => onChange({ fromDate }), onOpen: () => setOpen("fromDate"), onClose: close }), _jsx(DateFilter, { label: t("fraudReport.picker.filters.endDate"), value: filters.toDate, visible: open === "toDate", validate: date => validateToDate(date, filters.fromDate), onChange: toDate => onChange({ toDate }), onOpen: () => setOpen("toDate"), onClose: close }), _jsx(AmountFilter, { label: t("fraudReport.transactions.amount"), value: filters.amount, visible: open === "amount", onChange: amount => onChange({ amount }), onOpen: () => setOpen("amount"), onClose: close }), _jsx(TypesFilter, { label: t("fraudReport.transactions.paymentMethod"), value: filters.types, visible: open === "types", onChange: types => onChange({ types }), onOpen: () => setOpen("types"), onClose: close })] }));
|
|
207
|
+
const search = (_jsx(SearchFilter, { initialValue: (_a = filters.search) !== null && _a !== void 0 ? _a : "", large: large, onChange: value => onChange({ search: value }) }));
|
|
208
|
+
// One tree and one order for both layouts, the search placed by the direction alone: the
|
|
209
|
+
// picker measures its width after its first render, and a search being typed must keep its
|
|
210
|
+
// text and its focus through the change of layout. The cost: on a small screen the search
|
|
211
|
+
// shows first but comes after the chips for the keyboard and screen readers.
|
|
212
|
+
return (_jsxs(Box, { direction: large ? "row" : "columnReverse", alignItems: large ? "center" : "stretch", style: large ? styles.largeBar : styles.smallBar, children: [chips, search] }));
|
|
213
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FraudReportTransaction, FraudReportTransactionType } from "../../utils/fraudReport/types";
|
|
2
|
+
export declare const getPaymentMethodLabel: (type: FraudReportTransactionType) => string;
|
|
3
|
+
export declare const formatTransactionDate: ({ executionDate }: FraudReportTransaction) => string;
|
|
4
|
+
export declare const formatTransactionAmount: ({ amount }: FraudReportTransaction) => string;
|
|
5
|
+
export declare const TransactionsTotals: ({ transactions, overLimit, }: {
|
|
6
|
+
transactions: FraudReportTransaction[];
|
|
7
|
+
overLimit?: boolean;
|
|
8
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { LakeText } from "@swan-io/lake/src/components/LakeText";
|
|
3
|
+
import { Space } from "@swan-io/lake/src/components/Space";
|
|
4
|
+
import { colors } from "@swan-io/lake/src/constants/design";
|
|
5
|
+
import dayjs from "dayjs";
|
|
6
|
+
import { match } from "ts-pattern";
|
|
7
|
+
import { getTransactionsTotal } from "../../utils/fraudReport/transactions";
|
|
8
|
+
import { formatCurrencySymbol, formatNestedMessage, locale, t } from "../../utils/i18n";
|
|
9
|
+
export const getPaymentMethodLabel = (type) => match(type)
|
|
10
|
+
.with("CardOutDebit", () => t("fraudReport.transactions.paymentMethod.card"))
|
|
11
|
+
.with("SepaCreditTransferOut", () => t("fraudReport.transactions.paymentMethod.sepaCreditTransfer"))
|
|
12
|
+
.with("SepaInstantCreditTransferOut", () => t("fraudReport.transactions.paymentMethod.sepaInstantCreditTransfer"))
|
|
13
|
+
.with("InternationalCreditTransferOut", () => t("fraudReport.transactions.paymentMethod.internationalCreditTransfer"))
|
|
14
|
+
.with("InternalCreditTransferOut", () => t("fraudReport.transactions.paymentMethod.internalCreditTransfer"))
|
|
15
|
+
.exhaustive();
|
|
16
|
+
export const formatTransactionDate = ({ executionDate }) => dayjs(executionDate).format(locale.dateFormat);
|
|
17
|
+
export const formatTransactionAmount = ({ amount }) => formatCurrencySymbol(Number(amount.value), amount.currency);
|
|
18
|
+
const highlightWith = (color) => (chunks) => (_jsx(LakeText, { variant: "medium", color: color, children: chunks }));
|
|
19
|
+
// Both dark enough for AAA contrast on a modal's background as well as on a tile.
|
|
20
|
+
const highlight = highlightWith(colors.current[600]);
|
|
21
|
+
const negativeHighlight = highlightWith(colors.negative[700]);
|
|
22
|
+
// The total and the count of a selection. The parent lays them out in a row or a column.
|
|
23
|
+
export const TransactionsTotals = ({ transactions, overLimit = false, }) => {
|
|
24
|
+
const total = getTransactionsTotal(transactions);
|
|
25
|
+
return (_jsxs(_Fragment, { children: [_jsx(LakeText, { color: colors.gray[700], children: formatNestedMessage("fraudReport.transactions.total", {
|
|
26
|
+
amount: formatCurrencySymbol(total.value, total.currency),
|
|
27
|
+
highlight,
|
|
28
|
+
}) }), _jsx(Space, { width: 32, height: 8 }), _jsx(LakeText, { color: colors.gray[700], children: formatNestedMessage("fraudReport.transactions.selectedCount", {
|
|
29
|
+
count: transactions.length,
|
|
30
|
+
highlight: overLimit ? negativeHighlight : highlight,
|
|
31
|
+
}) })] }));
|
|
32
|
+
};
|
|
@@ -9,22 +9,11 @@ import { Space } from "@swan-io/lake/src/components/Space";
|
|
|
9
9
|
import { Tag } from "@swan-io/lake/src/components/Tag";
|
|
10
10
|
import { Tile, TileFullWidthContent } from "@swan-io/lake/src/components/Tile";
|
|
11
11
|
import { backgroundColor, colors } from "@swan-io/lake/src/constants/design";
|
|
12
|
-
import dayjs from "dayjs";
|
|
13
12
|
import { useEffect, useRef, useState } from "react";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import { formatCurrencySymbol, formatNestedMessage, locale, t } from "../../utils/i18n";
|
|
13
|
+
import { removeDuplicateTransactions } from "../../utils/fraudReport/transactions";
|
|
14
|
+
import { t } from "../../utils/i18n";
|
|
17
15
|
import { FraudReportFooter, useFraudReportSmallLayout, } from "./FraudReportLayout";
|
|
18
|
-
|
|
19
|
-
.with("CardOutDebit", () => t("fraudReport.transactions.paymentMethod.card"))
|
|
20
|
-
.with("SepaCreditTransferOut", () => t("fraudReport.transactions.paymentMethod.sepaCreditTransfer"))
|
|
21
|
-
.with("SepaInstantCreditTransferOut", () => t("fraudReport.transactions.paymentMethod.sepaInstantCreditTransfer"))
|
|
22
|
-
.with("InternationalCreditTransferOut", () => t("fraudReport.transactions.paymentMethod.internationalCreditTransfer"))
|
|
23
|
-
.with("InternalCreditTransferOut", () => t("fraudReport.transactions.paymentMethod.internalCreditTransfer"))
|
|
24
|
-
.exhaustive();
|
|
25
|
-
const highlight = (chunks) => (_jsx(LakeText, { variant: "medium", color: colors.current[500], children: chunks }));
|
|
26
|
-
const formatDate = ({ executionDate }) => dayjs(executionDate).format(locale.dateFormat);
|
|
27
|
-
const formatAmount = ({ amount }) => formatCurrencySymbol(Number(amount.value), amount.currency);
|
|
16
|
+
import { formatTransactionAmount, formatTransactionDate, getPaymentMethodLabel, TransactionsTotals, } from "./TransactionRows";
|
|
28
17
|
const removeColumn = {
|
|
29
18
|
id: "remove",
|
|
30
19
|
width: 56,
|
|
@@ -32,8 +21,8 @@ const removeColumn = {
|
|
|
32
21
|
renderTitle: () => null,
|
|
33
22
|
renderCell: ({ item, extraInfo: { disabled, onRemove, setRemoveButton } }) => (_jsx(Cell, { align: "right", children: _jsx(LakeButton, { ref: element => setRemoveButton(item.id, element), mode: "tertiary", size: "small", color: "negative", icon: "subtract-circle-regular", disabled: disabled, ariaLabel: t("fraudReport.transactions.remove", {
|
|
34
23
|
counterparty: item.counterparty,
|
|
35
|
-
amount:
|
|
36
|
-
date:
|
|
24
|
+
amount: formatTransactionAmount(item),
|
|
25
|
+
date: formatTransactionDate(item),
|
|
37
26
|
}), onPress: () => onRemove(item.id) }) })),
|
|
38
27
|
};
|
|
39
28
|
const columns = [
|
|
@@ -42,7 +31,7 @@ const columns = [
|
|
|
42
31
|
width: 120,
|
|
43
32
|
title: t("fraudReport.transactions.date"),
|
|
44
33
|
renderTitle: ({ title }) => _jsx(HeaderCell, { text: title }),
|
|
45
|
-
renderCell: ({ item }) => _jsx(TextCell, { text:
|
|
34
|
+
renderCell: ({ item }) => _jsx(TextCell, { text: formatTransactionDate(item) }),
|
|
46
35
|
},
|
|
47
36
|
{
|
|
48
37
|
id: "counterparty",
|
|
@@ -56,7 +45,7 @@ const columns = [
|
|
|
56
45
|
width: 130,
|
|
57
46
|
title: t("fraudReport.transactions.amount"),
|
|
58
47
|
renderTitle: ({ title }) => _jsx(HeaderCell, { text: title }),
|
|
59
|
-
renderCell: ({ item }) => _jsx(TextCell, { text:
|
|
48
|
+
renderCell: ({ item }) => _jsx(TextCell, { text: formatTransactionAmount(item) }),
|
|
60
49
|
},
|
|
61
50
|
{
|
|
62
51
|
id: "paymentMethod",
|
|
@@ -80,7 +69,7 @@ const smallColumns = [
|
|
|
80
69
|
width: "grow",
|
|
81
70
|
title: "",
|
|
82
71
|
renderTitle: () => null,
|
|
83
|
-
renderCell: ({ item }) => (_jsxs(Cell, { direction: "column", children: [_jsx(LakeText, { numberOfLines: 1, color: colors.gray[700], children: item.counterparty }), _jsx(LakeText, { variant: "medium", color: colors.gray[900], children:
|
|
72
|
+
renderCell: ({ item }) => (_jsxs(Cell, { direction: "column", children: [_jsx(LakeText, { numberOfLines: 1, color: colors.gray[700], children: item.counterparty }), _jsx(LakeText, { variant: "medium", color: colors.gray[900], children: formatTransactionAmount(item) })] })),
|
|
84
73
|
},
|
|
85
74
|
removeColumn,
|
|
86
75
|
];
|
|
@@ -106,16 +95,9 @@ export const TransactionsStep = ({ values, onNext, onPrevious, loading, renderPi
|
|
|
106
95
|
setFocusAfterRemove({ id: (_b = next === null || next === void 0 ? void 0 : next.id) !== null && _b !== void 0 ? _b : null });
|
|
107
96
|
setTransactions(transactions.filter(item => item.id !== id));
|
|
108
97
|
};
|
|
109
|
-
const total = getTransactionsTotal(transactions);
|
|
110
98
|
const empty = transactions.length === 0;
|
|
111
99
|
const selectButton = (_jsx(LakeButton, { ref: selectButtonRef, size: small ? "large" : "small", grow: small, mode: "secondary", icon: "add-circle-regular", disabled: loading, onPress: () => setPickerVisible(true), children: t("fraudReport.transactions.select") }));
|
|
112
|
-
return (_jsxs(_Fragment, { children: [_jsx(Tile, { title: t("fraudReport.transactions.title"), description: t("fraudReport.transactions.description"), children:
|
|
113
|
-
amount: formatCurrencySymbol(total.value, total.currency),
|
|
114
|
-
highlight,
|
|
115
|
-
}) }), _jsx(Space, { width: 32, height: 8 }), _jsx(LakeText, { color: colors.gray[700], children: formatNestedMessage("fraudReport.transactions.selectedCount", {
|
|
116
|
-
count: transactions.length,
|
|
117
|
-
highlight,
|
|
118
|
-
}) })] }) }), _jsx(Space, { height: 24 }), _jsxs(Tile, { title: _jsxs(_Fragment, { children: [t("fraudReport.transactions.listTitle"), _jsx(Space, { width: 8 }), _jsx(Tag, { color: empty ? "negative" : "gray", children: String(transactions.length) })] }), headerEnd: small ? undefined : selectButton, children: [empty ? (_jsx(EmptyView, { icon: "lake-inbox-empty", borderedIcon: true, title: t("fraudReport.transactions.emptyTitle"), subtitle: small ? undefined : t("fraudReport.transactions.emptySubtitle") })) : (_jsx(TileFullWidthContent, { children: _jsx(PlainListView, { data: transactions, keyExtractor: ({ id }) => id, extraInfo: {
|
|
100
|
+
return (_jsxs(_Fragment, { children: [_jsx(Tile, { title: t("fraudReport.transactions.title"), description: t("fraudReport.transactions.description"), children: _jsx(Box, { direction: small ? "column" : "row", children: _jsx(TransactionsTotals, { transactions: transactions }) }) }), _jsx(Space, { height: 24 }), _jsxs(Tile, { title: _jsxs(_Fragment, { children: [t("fraudReport.transactions.listTitle"), _jsx(Space, { width: 8 }), _jsx(Tag, { color: empty ? "negative" : "gray", children: String(transactions.length) })] }), headerEnd: small ? undefined : selectButton, children: [empty ? (_jsx(EmptyView, { icon: "lake-inbox-empty", borderedIcon: true, title: t("fraudReport.transactions.emptyTitle"), subtitle: small ? undefined : t("fraudReport.transactions.emptySubtitle") })) : (_jsx(TileFullWidthContent, { children: _jsx(PlainListView, { data: transactions, keyExtractor: ({ id }) => id, extraInfo: {
|
|
119
101
|
disabled: loading === true,
|
|
120
102
|
onRemove: removeTransaction,
|
|
121
103
|
setRemoveButton: (id, element) => {
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Option } from "@bloodyowl/boxed";
|
|
2
|
+
import type { FraudReportTransaction } from "../../utils/fraudReport/types";
|
|
2
3
|
import { FraudReportAccountMembership } from "../../utils/fraudReport/victim";
|
|
3
4
|
import { FraudReportStepProps } from "./FraudReportLayout";
|
|
4
5
|
type Props = FraudReportStepProps<"victimAccountMembershipId"> & {
|
|
6
|
+
transactions: FraudReportTransaction[];
|
|
5
7
|
currentAccountMembership: Option<FraudReportAccountMembership>;
|
|
6
8
|
accountMemberships: FraudReportAccountMembership[];
|
|
7
9
|
};
|
|
8
|
-
export declare const VictimStep: ({ currentAccountMembership, accountMemberships, values, onNext, }: Props) => import("react").JSX.Element;
|
|
10
|
+
export declare const VictimStep: ({ currentAccountMembership, accountMemberships, transactions, values, onNext, }: Props) => import("react").JSX.Element;
|
|
9
11
|
export {};
|
|
@@ -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
|
};
|
|
@@ -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 });
|