-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Expand file tree
/
Copy pathuseConfirmationCtaText.ts
More file actions
101 lines (82 loc) · 3.04 KB
/
Copy pathuseConfirmationCtaText.ts
File metadata and controls
101 lines (82 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import type {DropdownOption} from '@components/ButtonWithDropdownMenu/types';
import useLocalize from '@hooks/useLocalize';
import {hasInvoicingDetails} from '@userActions/Policy/Policy';
import type {IOUType} from '@src/CONST';
import type * as OnyxTypes from '@src/types/onyx';
import type {OnyxEntry} from 'react-native-onyx';
type UseConfirmationCtaTextParams = {
/** Number of expenses being created on confirm (drives bulk copy) */
expensesNumber: number;
/** Whether the current IOU type is invoice */
isTypeInvoice: boolean;
/** Whether the current IOU type is track-expense */
isTypeTrackExpense: boolean;
/** Whether the current IOU type is split */
isTypeSplit: boolean;
/** Whether the current IOU type is request */
isTypeRequest: boolean;
/** Total IOU amount */
iouAmount: number;
/** IOU type being confirmed (used as the dropdown option `value`) */
iouType: IOUType;
/** Policy the IOU belongs to, used to detect missing invoice company info */
policy: OnyxEntry<OnyxTypes.Policy>;
/** Pre-formatted amount string (with currency symbol) */
formattedAmount: string;
/** Path or remote ID of an attached receipt */
receiptPath: string | number;
/** Whether the distance request route is still pending */
isDistanceRequestWithPendingRoute: boolean;
/** Whether the transaction is a per-diem request */
isPerDiemRequest: boolean;
};
/**
* Computes the primary confirm button label for the Money Request confirmation flow.
*
* Picks between create / split / invoice / next variants based on the IOU type,
* bulk-expense count, and amount, returning a single-entry DropdownOption array shaped
* for the ButtonWithDropdownMenu consumer.
*/
function useConfirmationCtaText({
expensesNumber,
isTypeInvoice,
isTypeTrackExpense,
isTypeSplit,
isTypeRequest,
iouAmount,
iouType,
policy,
formattedAmount,
receiptPath,
isDistanceRequestWithPendingRoute,
isPerDiemRequest,
}: UseConfirmationCtaTextParams): Array<DropdownOption<string>> {
const {translate} = useLocalize();
let text;
if (expensesNumber > 1) {
text = translate('iou.createExpenses', expensesNumber);
} else if (isTypeInvoice) {
if (hasInvoicingDetails(policy)) {
text = translate('iou.sendInvoice', formattedAmount);
} else {
text = translate('common.next');
}
} else if (isTypeTrackExpense) {
text = translate('iou.createExpense');
} else if (isTypeSplit && iouAmount === 0) {
text = translate('iou.splitExpense');
} else if ((receiptPath && isTypeRequest) || isDistanceRequestWithPendingRoute || isPerDiemRequest) {
text = translate('iou.createExpense');
} else if (isTypeSplit) {
text = translate('iou.splitExpense');
} else {
text = translate('iou.createExpense');
}
return [
{
text: text[0].toUpperCase() + text.slice(1),
value: iouType,
},
];
}
export default useConfirmationCtaText;