@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
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { createElement as _createElement } from "react";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Box } from "@swan-io/lake/src/components/Box";
|
|
4
|
+
import { Cell, CopyableTextCell, HeaderCell, TextCell } from "@swan-io/lake/src/components/Cells";
|
|
5
|
+
import { EmptyView } from "@swan-io/lake/src/components/EmptyView";
|
|
6
|
+
import { Fill } from "@swan-io/lake/src/components/Fill";
|
|
7
|
+
import { LakeAlert } from "@swan-io/lake/src/components/LakeAlert";
|
|
8
|
+
import { LakeButton } from "@swan-io/lake/src/components/LakeButton";
|
|
9
|
+
import { LakeCheckbox } from "@swan-io/lake/src/components/LakeCheckbox";
|
|
10
|
+
import { LakeText } from "@swan-io/lake/src/components/LakeText";
|
|
11
|
+
import { PlainListView } from "@swan-io/lake/src/components/PlainListView";
|
|
12
|
+
import { Pressable } from "@swan-io/lake/src/components/Pressable";
|
|
13
|
+
import { ResponsiveContainer } from "@swan-io/lake/src/components/ResponsiveContainer";
|
|
14
|
+
import { Space } from "@swan-io/lake/src/components/Space";
|
|
15
|
+
import { Tag } from "@swan-io/lake/src/components/Tag";
|
|
16
|
+
import { colors } from "@swan-io/lake/src/constants/design";
|
|
17
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
18
|
+
import { StyleSheet, View } from "react-native";
|
|
19
|
+
import { getTransactionsLimitMessage } from "../../utils/fraudReport/messages";
|
|
20
|
+
import { countPagesWithoutRows, getPickerTransactions, getSelectAllValue, MAX_PAGES_WITHOUT_ROWS, restartPickerPages, toggleAllTransactions, toggleTransaction, } from "../../utils/fraudReport/picker";
|
|
21
|
+
import { hasPickerFilters, isSamePickerFilters, setPickerFilters, } from "../../utils/fraudReport/pickerFilters";
|
|
22
|
+
import { getTransactionsOverLimit, MAX_TRANSACTIONS } from "../../utils/fraudReport/transactions";
|
|
23
|
+
import { t } from "../../utils/i18n";
|
|
24
|
+
import { LakeModal } from "../LakeModal";
|
|
25
|
+
import { TransactionPickerFilters } from "./TransactionPickerFilters";
|
|
26
|
+
import { formatTransactionAmount, formatTransactionDate, getPaymentMethodLabel, TransactionsTotals, } from "./TransactionRows";
|
|
27
|
+
const LOADING_ROWS = 5;
|
|
28
|
+
const HEADER_HEIGHT = 48;
|
|
29
|
+
const MAX_LIST_HEIGHT = 420;
|
|
30
|
+
// Below it the fixed columns leave no room for "Paid to".
|
|
31
|
+
const TABLE_BREAKPOINT = 800;
|
|
32
|
+
const styles = StyleSheet.create({
|
|
33
|
+
checkbox: {
|
|
34
|
+
padding: 4,
|
|
35
|
+
},
|
|
36
|
+
confirm: {
|
|
37
|
+
alignSelf: "stretch",
|
|
38
|
+
},
|
|
39
|
+
loadMore: {
|
|
40
|
+
alignSelf: "center",
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
const CheckboxCell = ({ value, label, onPress, }) => (_jsx(Cell, { children: _jsx(Pressable, { role: "checkbox", "aria-checked": value, "aria-label": label, style: styles.checkbox, onPress: onPress, children: _jsx(LakeCheckbox, { value: value }) }) }));
|
|
44
|
+
const checkboxColumn = {
|
|
45
|
+
id: "checkbox",
|
|
46
|
+
width: 40,
|
|
47
|
+
title: t("fraudReport.picker.selectAll"),
|
|
48
|
+
renderTitle: ({ title, extraInfo: { selectAllValue, onToggleAll } }) => (_jsx(CheckboxCell, { value: selectAllValue, label: title, onPress: onToggleAll })),
|
|
49
|
+
renderCell: ({ item, extraInfo: { selection, onToggle } }) => (_jsx(CheckboxCell, { value: selection.some(({ id }) => id === item.id), label: t("fraudReport.picker.selectTransaction", {
|
|
50
|
+
counterparty: item.counterparty,
|
|
51
|
+
amount: formatTransactionAmount(item),
|
|
52
|
+
date: formatTransactionDate(item),
|
|
53
|
+
}), onPress: () => onToggle(item) })),
|
|
54
|
+
};
|
|
55
|
+
const columns = [
|
|
56
|
+
checkboxColumn,
|
|
57
|
+
{
|
|
58
|
+
id: "date",
|
|
59
|
+
width: 112,
|
|
60
|
+
title: t("fraudReport.transactions.date"),
|
|
61
|
+
renderTitle: ({ title }) => _jsx(HeaderCell, { text: title }),
|
|
62
|
+
renderCell: ({ item }) => _jsx(TextCell, { text: formatTransactionDate(item) }),
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
id: "counterparty",
|
|
66
|
+
width: "grow",
|
|
67
|
+
title: t("fraudReport.transactions.paidTo"),
|
|
68
|
+
renderTitle: ({ title }) => _jsx(HeaderCell, { text: title }),
|
|
69
|
+
renderCell: ({ item }) => _jsx(TextCell, { text: item.counterparty }),
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
id: "amount",
|
|
73
|
+
width: 112,
|
|
74
|
+
title: t("fraudReport.transactions.amount"),
|
|
75
|
+
renderTitle: ({ title }) => _jsx(HeaderCell, { text: title }),
|
|
76
|
+
renderCell: ({ item }) => _jsx(TextCell, { text: formatTransactionAmount(item) }),
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
id: "paymentMethod",
|
|
80
|
+
width: 228,
|
|
81
|
+
title: t("fraudReport.transactions.paymentMethod"),
|
|
82
|
+
renderTitle: ({ title }) => _jsx(HeaderCell, { text: title }),
|
|
83
|
+
renderCell: ({ item }) => (_jsx(Cell, { children: _jsx(Tag, { color: "gray", children: getPaymentMethodLabel(item.type) }) })),
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
id: "transactionId",
|
|
87
|
+
width: 128,
|
|
88
|
+
title: t("fraudReport.transactions.transactionId"),
|
|
89
|
+
renderTitle: ({ title }) => _jsx(HeaderCell, { text: title }),
|
|
90
|
+
renderCell: ({ item }) => (_jsx(CopyableTextCell, { text: item.id, copyWording: t("copyButton.copyTooltip"), copiedWording: t("copyButton.copiedTooltip") })),
|
|
91
|
+
},
|
|
92
|
+
];
|
|
93
|
+
const smallColumns = [
|
|
94
|
+
checkboxColumn,
|
|
95
|
+
{
|
|
96
|
+
id: "summary",
|
|
97
|
+
width: "grow",
|
|
98
|
+
title: "",
|
|
99
|
+
renderTitle: () => null,
|
|
100
|
+
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) })] })),
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
id: "date",
|
|
104
|
+
width: 124,
|
|
105
|
+
title: "",
|
|
106
|
+
renderTitle: () => null,
|
|
107
|
+
renderCell: ({ item }) => (_jsx(TextCell, { align: "right", color: colors.gray[700], text: formatTransactionDate(item) })),
|
|
108
|
+
},
|
|
109
|
+
];
|
|
110
|
+
const TransactionPickerContent = ({ rows, victimAccountMembershipId, selection, loading = false, hasMore = false, large, filters, onFiltersPatch, onEndReached, onSelectionChange, onConfirm, }) => {
|
|
111
|
+
const listed = useMemo(() => getPickerTransactions(rows, victimAccountMembershipId), [rows, victimAccountMembershipId]);
|
|
112
|
+
const [pages, setPages] = useState({
|
|
113
|
+
rowCount: rows.length,
|
|
114
|
+
listedCount: listed.length,
|
|
115
|
+
withoutRows: 0,
|
|
116
|
+
restarted: false,
|
|
117
|
+
});
|
|
118
|
+
// Other filters bring another list: its pages are counted from the start.
|
|
119
|
+
const [countedFilters, setCountedFilters] = useState(filters);
|
|
120
|
+
const base = filters === countedFilters ? pages : restartPickerPages(pages);
|
|
121
|
+
// The user asked for more after a pause: the page it brings starts the count again.
|
|
122
|
+
const [requested, setRequested] = useState(false);
|
|
123
|
+
// The end of a load tells that another list arrived, even with as many rows as the one before.
|
|
124
|
+
const [wasLoading, setWasLoading] = useState(loading);
|
|
125
|
+
const loaded = wasLoading && !loading;
|
|
126
|
+
const counted = countPagesWithoutRows(base, rows.length, listed.length, loaded);
|
|
127
|
+
const currentPages = counted !== base && requested ? { ...counted, withoutRows: 0 } : counted;
|
|
128
|
+
if (loading !== wasLoading) {
|
|
129
|
+
setWasLoading(loading);
|
|
130
|
+
}
|
|
131
|
+
if (currentPages !== pages) {
|
|
132
|
+
setPages(currentPages);
|
|
133
|
+
setCountedFilters(filters);
|
|
134
|
+
setRequested(false);
|
|
135
|
+
}
|
|
136
|
+
// After a few pages with no row for this victim, the user decides whether to keep looking.
|
|
137
|
+
const paused = hasMore && !loading && currentPages.withoutRows >= MAX_PAGES_WITHOUT_ROWS;
|
|
138
|
+
const requesting = requested && hasMore;
|
|
139
|
+
// The whole selection counts, with the transactions that aren't listed.
|
|
140
|
+
const overLimit = getTransactionsOverLimit(selection.length);
|
|
141
|
+
const rowHeight = large ? 56 : 72;
|
|
142
|
+
// A loaded page can hold no row for this victim: more pages may, so it isn't empty yet.
|
|
143
|
+
const waiting = loading || requesting || (hasMore && listed.length === 0 && !paused);
|
|
144
|
+
// The list scrolls inside the modal: it takes its rows' height, up to MAX_LIST_HEIGHT.
|
|
145
|
+
const listHeight = (large && listed.length > 0 ? HEADER_HEIGHT : 0) +
|
|
146
|
+
(listed.length + (waiting ? LOADING_ROWS : 0)) * rowHeight;
|
|
147
|
+
// The list asks for the next page when its end comes into view, once per callback. A new
|
|
148
|
+
// callback after each page makes it ask again while the end is still in view, which happens
|
|
149
|
+
// when a page holds few rows for this victim, or none.
|
|
150
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies(rows.length): see above
|
|
151
|
+
const askForMore = useCallback(() => onEndReached === null || onEndReached === void 0 ? void 0 : onEndReached(), [onEndReached, rows.length]);
|
|
152
|
+
const loadMore = () => {
|
|
153
|
+
setRequested(true);
|
|
154
|
+
onEndReached === null || onEndReached === void 0 ? void 0 : onEndReached();
|
|
155
|
+
};
|
|
156
|
+
return (_jsxs(_Fragment, { children: [_jsx(LakeText, { color: colors.gray[700], children: t("fraudReport.picker.description", { max: MAX_TRANSACTIONS }) }), _jsx(Space, { height: 24 }), overLimit > 0 ? (_jsxs(_Fragment, { children: [_jsx(View, { role: "alert", children: _jsx(LakeAlert, { variant: "error", title: getTransactionsLimitMessage({ toRemove: overLimit }) }) }), _jsx(Space, { height: 24 })] })) : null, onFiltersPatch == null ? null : (_jsxs(_Fragment, { children: [_jsx(TransactionPickerFilters, { filters: filters, large: large, onChange: onFiltersPatch }), _jsx(Space, { height: 24 })] })), listed.length === 0 && !waiting ? (_jsx(EmptyView, { icon: "lake-inbox-empty", borderedIcon: true, title: t(paused
|
|
157
|
+
? "fraudReport.picker.noneYetTitle"
|
|
158
|
+
: hasPickerFilters(filters)
|
|
159
|
+
? "fraudReport.picker.noMatchTitle"
|
|
160
|
+
: "fraudReport.picker.emptyTitle") })) : (_jsx(View, { style: { height: Math.min(MAX_LIST_HEIGHT, listHeight) }, children: _jsx(PlainListView, { data: listed, keyExtractor: ({ id }) => id, extraInfo: {
|
|
161
|
+
selection,
|
|
162
|
+
selectAllValue: getSelectAllValue(selection, listed),
|
|
163
|
+
onToggle: transaction => onSelectionChange(toggleTransaction(selection, transaction)),
|
|
164
|
+
onToggleAll: () => onSelectionChange(toggleAllTransactions(selection, listed)),
|
|
165
|
+
}, columns: columns, smallColumns: smallColumns,
|
|
166
|
+
// The picker already measured its width: the list follows it.
|
|
167
|
+
breakpoint: large ? 0 : Number.POSITIVE_INFINITY, headerHeight: HEADER_HEIGHT, rowHeight: rowHeight,
|
|
168
|
+
// PlainListView counts one group header in its scroll height, even without groups.
|
|
169
|
+
groupHeaderHeight: 0, loading: { isLoading: waiting, count: LOADING_ROWS }, onEndReached: hasMore && !loading && !paused ? askForMore : undefined }) })), paused && !requesting ? (_jsxs(_Fragment, { children: [_jsx(Space, { height: 16 }), _jsx(LakeButton, { mode: "secondary", size: "small", style: styles.loadMore, onPress: loadMore, children: t("fraudReport.picker.loadMore") })] })) : null, _jsx(Space, { height: 24 }), _jsxs(Box, { direction: large ? "row" : "column", alignItems: large ? "center" : "stretch", children: [_jsx(TransactionsTotals, { transactions: selection, overLimit: overLimit > 0 }), _jsx(Fill, { minWidth: 24 }), large ? null : _jsx(Space, { height: 24 }), _jsx(LakeButton, { color: "current", size: large ? "small" : "large", style: large ? undefined : styles.confirm, disabled: overLimit > 0, onPress: onConfirm, children: t("fraudReport.picker.confirm") })] })] }));
|
|
170
|
+
};
|
|
171
|
+
const NO_FILTERS = {};
|
|
172
|
+
export const TransactionPicker = ({ visible, selected, onConfirm, onClose, onFiltersChange, ...props }) => {
|
|
173
|
+
const [selection, setSelection] = useState(selected);
|
|
174
|
+
const [wasVisible, setWasVisible] = useState(visible);
|
|
175
|
+
const [filters, setFilters] = useState(NO_FILTERS);
|
|
176
|
+
const [openCount, setOpenCount] = useState(0);
|
|
177
|
+
// Each opening starts from the step's selection: what was ticked before a close is dropped.
|
|
178
|
+
if (visible !== wasVisible) {
|
|
179
|
+
setWasVisible(visible);
|
|
180
|
+
if (visible) {
|
|
181
|
+
setSelection(selected);
|
|
182
|
+
setFilters(NO_FILTERS);
|
|
183
|
+
setOpenCount(openCount + 1);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// A search can come after the close, while the modal fades out with the content of its last
|
|
187
|
+
// render: only a ref tells it that the picker is closed.
|
|
188
|
+
const open = useRef(visible);
|
|
189
|
+
useEffect(() => {
|
|
190
|
+
open.current = visible;
|
|
191
|
+
}, [visible]);
|
|
192
|
+
const changeFilters = (next) => {
|
|
193
|
+
if (!isSamePickerFilters(filters, next)) {
|
|
194
|
+
setFilters(next);
|
|
195
|
+
onFiltersChange === null || onFiltersChange === void 0 ? void 0 : onFiltersChange(next);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
// The app goes back to the rows without filters, ready for the next opening.
|
|
199
|
+
const leave = (callback) => {
|
|
200
|
+
changeFilters(NO_FILTERS);
|
|
201
|
+
callback();
|
|
202
|
+
};
|
|
203
|
+
return (_jsx(LakeModal, { visible: visible, title: t("fraudReport.picker.title"), maxWidth: 915, onPressClose: () => leave(onClose), children: _jsx(ResponsiveContainer, { breakpoint: TABLE_BREAKPOINT, children: ({ large }) => (_createElement(TransactionPickerContent, { ...props,
|
|
204
|
+
// Each opening starts again: the text typed in the filter bar and the count of
|
|
205
|
+
// pages without rows go.
|
|
206
|
+
key: openCount, large: large, filters: filters, onFiltersPatch: onFiltersChange == null
|
|
207
|
+
? undefined
|
|
208
|
+
: patch => {
|
|
209
|
+
if (open.current) {
|
|
210
|
+
changeFilters(setPickerFilters(filters, patch));
|
|
211
|
+
}
|
|
212
|
+
}, selection: selection, onSelectionChange: setSelection, onConfirm: () => leave(() => onConfirm(selection)) })) }) }));
|
|
213
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FraudReportPickerFilters } from "../../utils/fraudReport/pickerFilters";
|
|
2
|
+
type Props = {
|
|
3
|
+
filters: FraudReportPickerFilters;
|
|
4
|
+
large: boolean;
|
|
5
|
+
onChange: (patch: FraudReportPickerFilters) => void;
|
|
6
|
+
};
|
|
7
|
+
export declare const TransactionPickerFilters: ({ filters, large, onChange }: Props) => import("react").JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -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) => {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { FraudReportStepProps } from "./FraudReportLayout";
|
|
2
|
+
type Props = FraudReportStepProps<"hasContactedBankOrBeneficiary" | "hasFiledPoliceComplaint"> & {
|
|
3
|
+
onPrevious: () => void;
|
|
4
|
+
loading?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare const TransferDetailsStep: ({ values, onNext, onPrevious, loading }: Props) => import("react").JSX.Element;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { LakeLabel } from "@swan-io/lake/src/components/LakeLabel";
|
|
3
|
+
import { MultiSelect } from "@swan-io/lake/src/components/MultiSelect";
|
|
4
|
+
import { Tile } from "@swan-io/lake/src/components/Tile";
|
|
5
|
+
import { useForm } from "@swan-io/use-form";
|
|
6
|
+
import { getTransferActions, toTransferValues, } from "../../utils/fraudReport/transfer";
|
|
7
|
+
import { t } from "../../utils/i18n";
|
|
8
|
+
import { FraudReportFooter } from "./FraudReportLayout";
|
|
9
|
+
export const TransferDetailsStep = ({ values, onNext, onPrevious, loading }) => {
|
|
10
|
+
const { Field, submitForm } = useForm({
|
|
11
|
+
actions: { initialValue: getTransferActions(values) },
|
|
12
|
+
});
|
|
13
|
+
const actionItems = [
|
|
14
|
+
{
|
|
15
|
+
label: t("fraudReport.transfer.action.bankOrBeneficiary"),
|
|
16
|
+
value: "BankOrBeneficiary",
|
|
17
|
+
group: "",
|
|
18
|
+
},
|
|
19
|
+
{ label: t("fraudReport.transfer.action.police"), value: "Police", group: "" },
|
|
20
|
+
];
|
|
21
|
+
const onPressNext = () => submitForm({
|
|
22
|
+
onSuccess: ({ actions }) => onNext(toTransferValues(actions.getOr([]))),
|
|
23
|
+
});
|
|
24
|
+
return (_jsxs(_Fragment, { children: [_jsx(Tile, { title: t("fraudReport.transfer.actionsTitle"), children: _jsx(Field, { name: "actions", children: ({ value, onChange }) => (_jsx(LakeLabel, { label: t("fraudReport.transfer.actionsLabel"), optionalLabel: t("common.optional"), render: id => (_jsx(MultiSelect, { id: id, enableGroups: false, placeholder: t("fraudReport.transfer.actionsPlaceholder"), items: actionItems, values: value, onValueChange: onChange })) })) }) }), _jsx(FraudReportFooter, { onPrevious: onPrevious, onNext: onPressNext, loading: loading })] }));
|
|
25
|
+
};
|
|
@@ -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 {};
|