-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathQuickbooksOutOfPocketExpenseConfigurationPage.tsx
114 lines (107 loc) · 6 KB
/
QuickbooksOutOfPocketExpenseConfigurationPage.tsx
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
102
103
104
105
106
107
108
109
110
111
112
113
114
import React, {useMemo} from 'react';
import type {ValueOf} from 'type-fest';
import ConnectionLayout from '@components/ConnectionLayout';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import * as PolicyUtils from '@libs/PolicyUtils';
import Navigation from '@navigation/Navigation';
import type {WithPolicyConnectionsProps} from '@pages/workspace/withPolicyConnections';
import withPolicyConnections from '@pages/workspace/withPolicyConnections';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import type {PendingAction} from '@src/types/onyx/OnyxCommon';
type QBOSectionType = {
title?: string;
description?: string;
onPress: () => void;
errorText?: string;
hintText?: string;
subscribedSettings: string[];
pendingAction?: PendingAction;
brickRoadIndicator?: ValueOf<typeof CONST.BRICK_ROAD_INDICATOR_STATUS>;
};
const account = [CONST.QUICKBOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT];
const accountOrExportDestination = [CONST.QUICKBOOKS_CONFIG.REIMBURSABLE_EXPENSES_EXPORT_DESTINATION, CONST.QUICKBOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT];
function QuickbooksOutOfPocketExpenseConfigurationPage({policy}: WithPolicyConnectionsProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const policyID = policy?.id ?? '-1';
const qboConfig = policy?.connections?.quickbooksOnline?.config;
const isLocationEnabled = !!(qboConfig?.syncLocations && qboConfig?.syncLocations !== CONST.INTEGRATION_ENTITY_MAP_TYPES.NONE);
const isTaxesEnabled = !!qboConfig?.syncTax;
const [exportHintText, accountDescription] = useMemo(() => {
let hintText: string | undefined;
let description: string | undefined;
switch (qboConfig?.reimbursableExpensesExportDestination) {
case CONST.QUICKBOOKS_REIMBURSABLE_ACCOUNT_TYPE.CHECK:
hintText = isLocationEnabled ? undefined : translate('workspace.qbo.exportCheckDescription');
description = translate('workspace.qbo.bankAccount');
break;
case CONST.QUICKBOOKS_REIMBURSABLE_ACCOUNT_TYPE.JOURNAL_ENTRY:
hintText = isTaxesEnabled ? undefined : translate('workspace.qbo.exportJournalEntryDescription');
description = translate('workspace.qbo.account');
break;
case CONST.QUICKBOOKS_REIMBURSABLE_ACCOUNT_TYPE.VENDOR_BILL:
hintText = isLocationEnabled ? undefined : translate('workspace.qbo.exportVendorBillDescription');
description = translate('workspace.qbo.accountsPayable');
break;
default:
break;
}
return [hintText, description];
}, [translate, qboConfig?.reimbursableExpensesExportDestination, isLocationEnabled, isTaxesEnabled]);
const sections: QBOSectionType[] = [
{
title: qboConfig?.reimbursableExpensesExportDestination ? translate(`workspace.qbo.accounts.${qboConfig?.reimbursableExpensesExportDestination}`) : undefined,
description: translate('workspace.accounting.exportAs'),
onPress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_EXPORT_OUT_OF_POCKET_EXPENSES_SELECT.getRoute(policyID)),
hintText: exportHintText,
subscribedSettings: accountOrExportDestination,
pendingAction: PolicyUtils.settingsPendingAction(accountOrExportDestination, qboConfig?.pendingFields),
brickRoadIndicator: PolicyUtils.areSettingsInErrorFields(accountOrExportDestination, qboConfig?.errorFields) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined,
},
{
title: qboConfig?.reimbursableExpensesAccount?.name ?? translate('workspace.qbo.notConfigured'),
description: accountDescription,
onPress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_EXPORT_OUT_OF_POCKET_EXPENSES_ACCOUNT_SELECT.getRoute(policyID)),
subscribedSettings: account,
pendingAction: PolicyUtils.settingsPendingAction(account, qboConfig?.pendingFields),
brickRoadIndicator: PolicyUtils.areSettingsInErrorFields(account, qboConfig?.errorFields) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined,
},
];
return (
<ConnectionLayout
displayName={QuickbooksOutOfPocketExpenseConfigurationPage.displayName}
headerTitle="workspace.accounting.exportOutOfPocket"
title="workspace.qbo.exportOutOfPocketExpensesDescription"
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN]}
policyID={policyID}
featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED}
contentContainerStyle={styles.pb2}
titleStyle={styles.ph5}
connectionName={CONST.POLICY.CONNECTIONS.NAME.QBO}
onBackButtonPress={() => Navigation.goBack(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_EXPORT.getRoute(policyID))}
>
{sections.map((section, index) => (
<OfflineWithFeedback
pendingAction={section.pendingAction}
// eslint-disable-next-line react/no-array-index-key
key={index}
>
<MenuItemWithTopDescription
title={section.title}
description={section.description}
onPress={section.onPress}
shouldShowRightIcon
brickRoadIndicator={section.brickRoadIndicator}
hintText={section.hintText}
/>
</OfflineWithFeedback>
))}
</ConnectionLayout>
);
}
QuickbooksOutOfPocketExpenseConfigurationPage.displayName = 'QuickbooksExportOutOfPocketExpensesPage';
export default withPolicyConnections(QuickbooksOutOfPocketExpenseConfigurationPage);