|
| 1 | +import React, {useCallback, useMemo} from 'react'; |
| 2 | +import {View} from 'react-native'; |
| 3 | +import type {ValueOf} from 'type-fest'; |
| 4 | +import RadioListItem from '@components/SelectionList/RadioListItem'; |
| 5 | +import type {ListItem} from '@components/SelectionList/types'; |
| 6 | +import SelectionScreen from '@components/SelectionScreen'; |
| 7 | +import type {SelectorType} from '@components/SelectionScreen'; |
| 8 | +import Text from '@components/Text'; |
| 9 | +import useLocalize from '@hooks/useLocalize'; |
| 10 | +import useThemeStyles from '@hooks/useThemeStyles'; |
| 11 | +import Navigation from '@navigation/Navigation'; |
| 12 | +import type {WithPolicyConnectionsProps} from '@pages/workspace/withPolicyConnections'; |
| 13 | +import withPolicyConnections from '@pages/workspace/withPolicyConnections'; |
| 14 | +import CONST from '@src/CONST'; |
| 15 | +import ROUTES from '@src/ROUTES'; |
| 16 | + |
| 17 | +type MenuListItem = ListItem & { |
| 18 | + value: ValueOf<typeof CONST.NETSUITE_ACCOUNTING_METHODS>; |
| 19 | +}; |
| 20 | + |
| 21 | +function NetSuiteAccountingMethodPage({policy}: WithPolicyConnectionsProps) { |
| 22 | + const {translate} = useLocalize(); |
| 23 | + const policyID = policy?.id ?? '-1'; |
| 24 | + const styles = useThemeStyles(); |
| 25 | + const config = policy?.connections?.netsuite.options.config; |
| 26 | + const accountingMehtod = config?.accountingMehtod ?? CONST.NETSUITE_ACCOUNTING_METHODS.CASH; |
| 27 | + const data: MenuListItem[] = Object.values(CONST.NETSUITE_ACCOUNTING_METHODS).map((accountingMehtodType) => ({ |
| 28 | + value: accountingMehtodType, |
| 29 | + text: translate(`workspace.netsuite.advancedConfig.accountingMethods.values.${accountingMehtodType}`), |
| 30 | + alternateText: translate(`workspace.netsuite.advancedConfig.accountingMethods.alternateText.${accountingMehtodType}`), |
| 31 | + keyForList: accountingMehtodType, |
| 32 | + isSelected: accountingMehtod === accountingMehtodType, |
| 33 | + })); |
| 34 | + |
| 35 | + const headerContent = useMemo( |
| 36 | + () => ( |
| 37 | + <View> |
| 38 | + <Text style={[styles.ph5, styles.pb5]}>{translate('workspace.netsuite.advancedConfig.accountingMethods.description')}</Text> |
| 39 | + </View> |
| 40 | + ), |
| 41 | + [translate, styles.pb5, styles.ph5], |
| 42 | + ); |
| 43 | + |
| 44 | + const selectExpenseReportApprovalLevel = useCallback( |
| 45 | + (row: MenuListItem) => { |
| 46 | + // if (row.value !== config?.syncOptions.exportReportsTo) { |
| 47 | + // Connections.updateNetSuiteExportReportsTo(policyID, row.value, config?.syncOptions.exportReportsTo ?? CONST.NETSUITE_REPORTS_APPROVAL_LEVEL.REPORTS_APPROVED_NONE); |
| 48 | + // } |
| 49 | + Navigation.goBack(ROUTES.POLICY_ACCOUNTING_NETSUITE_AUTO_SYNC.getRoute(policyID)); |
| 50 | + }, |
| 51 | + [config?.syncOptions.exportReportsTo, policyID], |
| 52 | + ); |
| 53 | + |
| 54 | + return ( |
| 55 | + <SelectionScreen |
| 56 | + displayName={NetSuiteAccountingMethodPage.displayName} |
| 57 | + title="workspace.netsuite.advancedConfig.accountingMethods.label" |
| 58 | + headerContent={headerContent} |
| 59 | + sections={[{data}]} |
| 60 | + listItem={RadioListItem} |
| 61 | + onSelectRow={(selection: SelectorType) => selectExpenseReportApprovalLevel(selection as MenuListItem)} |
| 62 | + initiallyFocusedOptionKey={data.find((mode) => mode.isSelected)?.keyForList} |
| 63 | + policyID={policyID} |
| 64 | + accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN]} |
| 65 | + featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED} |
| 66 | + onBackButtonPress={() => Navigation.goBack(ROUTES.POLICY_ACCOUNTING_NETSUITE_AUTO_SYNC.getRoute(policyID))} |
| 67 | + connectionName={CONST.POLICY.CONNECTIONS.NAME.NETSUITE} |
| 68 | + /> |
| 69 | + ); |
| 70 | +} |
| 71 | + |
| 72 | +NetSuiteAccountingMethodPage.displayName = 'NetSuiteExpenseReportApprovalLevelSelectPage'; |
| 73 | + |
| 74 | +export default withPolicyConnections(NetSuiteAccountingMethodPage); |
0 commit comments