diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 399648d1b0f0..a68ac320d956 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -658,22 +658,6 @@ const ROUTES = { route: 'settings/workspaces/:policyID/workflows/auto-reporting-frequency/monthly-offset', getRoute: (policyID: string) => `settings/workspaces/${policyID}/workflows/auto-reporting-frequency/monthly-offset` as const, }, - WORKSPACE_REIMBURSE: { - route: 'settings/workspaces/:policyID/reimburse', - getRoute: (policyID: string) => `settings/workspaces/${policyID}/reimburse` as const, - }, - WORKSPACE_RATE_AND_UNIT: { - route: 'settings/workspaces/:policyID/rateandunit', - getRoute: (policyID: string) => `settings/workspaces/${policyID}/rateandunit` as const, - }, - WORKSPACE_RATE_AND_UNIT_RATE: { - route: 'settings/workspaces/:policyID/rateandunit/rate', - getRoute: (policyID: string) => `settings/workspaces/${policyID}/rateandunit/rate` as const, - }, - WORKSPACE_RATE_AND_UNIT_UNIT: { - route: 'settings/workspaces/:policyID/rateandunit/unit', - getRoute: (policyID: string) => `settings/workspaces/${policyID}/rateandunit/unit` as const, - }, WORKSPACE_INVOICES: { route: 'settings/workspaces/:policyID/invoices', getRoute: (policyID: string) => `settings/workspaces/${policyID}/invoices` as const, diff --git a/src/components/FocusTrap/WIDE_LAYOUT_INACTIVE_SCREENS.ts b/src/components/FocusTrap/WIDE_LAYOUT_INACTIVE_SCREENS.ts index ee3ea9b9e0c6..26094b8299a7 100644 --- a/src/components/FocusTrap/WIDE_LAYOUT_INACTIVE_SCREENS.ts +++ b/src/components/FocusTrap/WIDE_LAYOUT_INACTIVE_SCREENS.ts @@ -21,7 +21,6 @@ const WIDE_LAYOUT_INACTIVE_SCREENS: string[] = [ SCREENS.WORKSPACE.INITIAL, SCREENS.WORKSPACE.PROFILE, SCREENS.WORKSPACE.WORKFLOWS, - SCREENS.WORKSPACE.REIMBURSE, SCREENS.WORKSPACE.INVOICES, SCREENS.WORKSPACE.MEMBERS, SCREENS.WORKSPACE.CATEGORIES, diff --git a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx index c2a30f20ed56..cff94bcb6392 100644 --- a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx +++ b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx @@ -221,9 +221,6 @@ const SettingsModalStackNavigator = createModalStackNavigator require('../../../../pages/settings/Subscription/SubscriptionSize').default, [SCREENS.SETTINGS.SUBSCRIPTION.DISABLE_AUTO_RENEW_SURVEY]: () => require('../../../../pages/settings/Subscription/DisableAutoRenewSurveyPage').default, [SCREENS.SETTINGS.SUBSCRIPTION.REQUEST_EARLY_CANCELLATION]: () => require('../../../../pages/settings/Subscription/RequestEarlyCancellationPage').default, - [SCREENS.WORKSPACE.RATE_AND_UNIT]: () => require('../../../../pages/workspace/reimburse/WorkspaceRateAndUnitPage/InitialPage').default, - [SCREENS.WORKSPACE.RATE_AND_UNIT_RATE]: () => require('../../../../pages/workspace/reimburse/WorkspaceRateAndUnitPage/RatePage').default, - [SCREENS.WORKSPACE.RATE_AND_UNIT_UNIT]: () => require('../../../../pages/workspace/reimburse/WorkspaceRateAndUnitPage/UnitPage').default, [SCREENS.WORKSPACE.INVITE]: () => require('../../../../pages/workspace/WorkspaceInvitePage').default, [SCREENS.WORKSPACE.WORKFLOWS_APPROVALS_NEW]: () => require('../../../../pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsCreatePage').default, [SCREENS.WORKSPACE.WORKFLOWS_APPROVALS_EDIT]: () => require('../../../../pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsEditPage').default, diff --git a/src/libs/Navigation/AppNavigator/Navigators/FullScreenNavigator.tsx b/src/libs/Navigation/AppNavigator/Navigators/FullScreenNavigator.tsx index 5a9da5ed0677..2f513fe804bb 100644 --- a/src/libs/Navigation/AppNavigator/Navigators/FullScreenNavigator.tsx +++ b/src/libs/Navigation/AppNavigator/Navigators/FullScreenNavigator.tsx @@ -19,7 +19,6 @@ type Screens = Partial React.Co const CENTRAL_PANE_WORKSPACE_SCREENS = { [SCREENS.WORKSPACE.PROFILE]: () => require('../../../../pages/workspace/WorkspaceProfilePage').default, [SCREENS.WORKSPACE.WORKFLOWS]: () => require('../../../../pages/workspace/workflows/WorkspaceWorkflowsPage').default, - [SCREENS.WORKSPACE.REIMBURSE]: () => require('../../../../pages/workspace/reimburse/WorkspaceReimbursePage').default, [SCREENS.WORKSPACE.INVOICES]: () => require('../../../../pages/workspace/invoices/WorkspaceInvoicesPage').default, [SCREENS.WORKSPACE.MEMBERS]: () => require('../../../../pages/workspace/WorkspaceMembersPage').default, [SCREENS.WORKSPACE.ACCOUNTING.ROOT]: () => require('../../../../pages/workspace/accounting/PolicyAccountingPage').default, diff --git a/src/libs/Navigation/linkingConfig/FULL_SCREEN_TO_RHP_MAPPING.ts b/src/libs/Navigation/linkingConfig/FULL_SCREEN_TO_RHP_MAPPING.ts index 22db5deaebfb..f7df87890469 100755 --- a/src/libs/Navigation/linkingConfig/FULL_SCREEN_TO_RHP_MAPPING.ts +++ b/src/libs/Navigation/linkingConfig/FULL_SCREEN_TO_RHP_MAPPING.ts @@ -3,7 +3,6 @@ import SCREENS from '@src/SCREENS'; const FULL_SCREEN_TO_RHP_MAPPING: Partial> = { [SCREENS.WORKSPACE.PROFILE]: [SCREENS.WORKSPACE.NAME, SCREENS.WORKSPACE.ADDRESS, SCREENS.WORKSPACE.CURRENCY, SCREENS.WORKSPACE.DESCRIPTION, SCREENS.WORKSPACE.SHARE], - [SCREENS.WORKSPACE.REIMBURSE]: [SCREENS.WORKSPACE.RATE_AND_UNIT, SCREENS.WORKSPACE.RATE_AND_UNIT_RATE, SCREENS.WORKSPACE.RATE_AND_UNIT_UNIT], [SCREENS.WORKSPACE.MEMBERS]: [ SCREENS.WORKSPACE.INVITE, SCREENS.WORKSPACE.INVITE_MESSAGE, diff --git a/src/libs/Navigation/linkingConfig/config.ts b/src/libs/Navigation/linkingConfig/config.ts index 5d9d65a5bb67..92dc38e03f04 100644 --- a/src/libs/Navigation/linkingConfig/config.ts +++ b/src/libs/Navigation/linkingConfig/config.ts @@ -520,15 +520,6 @@ const config: LinkingOptions['config'] = { [SCREENS.WORKSPACE.COMPANY_CARDS_ASSIGN_CARD]: { path: ROUTES.WORKSPACE_COMPANY_CARDS_ASSIGN_CARD.route, }, - [SCREENS.WORKSPACE.RATE_AND_UNIT]: { - path: ROUTES.WORKSPACE_RATE_AND_UNIT.route, - }, - [SCREENS.WORKSPACE.RATE_AND_UNIT_RATE]: { - path: ROUTES.WORKSPACE_RATE_AND_UNIT_RATE.route, - }, - [SCREENS.WORKSPACE.RATE_AND_UNIT_UNIT]: { - path: ROUTES.WORKSPACE_RATE_AND_UNIT_UNIT.route, - }, [SCREENS.WORKSPACE.INVITE]: { path: ROUTES.WORKSPACE_INVITE.route, }, @@ -1095,9 +1086,6 @@ const config: LinkingOptions['config'] = { [SCREENS.WORKSPACE.WORKFLOWS]: { path: ROUTES.WORKSPACE_WORKFLOWS.route, }, - [SCREENS.WORKSPACE.REIMBURSE]: { - path: ROUTES.WORKSPACE_REIMBURSE.route, - }, [SCREENS.WORKSPACE.INVOICES]: { path: ROUTES.WORKSPACE_INVOICES.route, }, diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index 4d9b0539b9d8..14b97e390bf1 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -181,15 +181,6 @@ type SettingsNavigatorParamList = { [SCREENS.WORKSPACE.NAME]: undefined; [SCREENS.WORKSPACE.DESCRIPTION]: undefined; [SCREENS.WORKSPACE.SHARE]: undefined; - [SCREENS.WORKSPACE.RATE_AND_UNIT]: { - policyID: string; - }; - [SCREENS.WORKSPACE.RATE_AND_UNIT_RATE]: { - policyID: string; - }; - [SCREENS.WORKSPACE.RATE_AND_UNIT_UNIT]: { - policyID: string; - }; [SCREENS.WORKSPACE.INVITE]: { policyID: string; }; @@ -1170,9 +1161,6 @@ type FullScreenNavigatorParamList = { [SCREENS.WORKSPACE.WORKFLOWS_AUTO_REPORTING_MONTHLY_OFFSET]: { policyID: string; }; - [SCREENS.WORKSPACE.REIMBURSE]: { - policyID: string; - }; [SCREENS.WORKSPACE.INVOICES]: { policyID: string; }; diff --git a/src/pages/workspace/card/WorkspaceCardCreateAWorkspace.tsx b/src/pages/WorkspaceSwitcherPage/WorkspaceCardCreateAWorkspace.tsx similarity index 100% rename from src/pages/workspace/card/WorkspaceCardCreateAWorkspace.tsx rename to src/pages/WorkspaceSwitcherPage/WorkspaceCardCreateAWorkspace.tsx diff --git a/src/pages/WorkspaceSwitcherPage/index.tsx b/src/pages/WorkspaceSwitcherPage/index.tsx index 6dc5ecce075b..53d40340fa3d 100644 --- a/src/pages/WorkspaceSwitcherPage/index.tsx +++ b/src/pages/WorkspaceSwitcherPage/index.tsx @@ -20,7 +20,7 @@ import {sortWorkspacesBySelected} from '@libs/PolicyUtils'; import * as ReportUtils from '@libs/ReportUtils'; import {getWorkspacesBrickRoads, getWorkspacesUnreadStatuses} from '@libs/WorkspacesSettingsUtils'; import type {BrickRoad} from '@libs/WorkspacesSettingsUtils'; -import WorkspaceCardCreateAWorkspace from '@pages/workspace/card/WorkspaceCardCreateAWorkspace'; +import WorkspaceCardCreateAWorkspace from './WorkspaceCardCreateAWorkspace'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; diff --git a/src/pages/workspace/reimburse/WorkspaceRateAndUnitPage/InitialPage.tsx b/src/pages/workspace/reimburse/WorkspaceRateAndUnitPage/InitialPage.tsx deleted file mode 100644 index 7381d02cb01d..000000000000 --- a/src/pages/workspace/reimburse/WorkspaceRateAndUnitPage/InitialPage.tsx +++ /dev/null @@ -1,158 +0,0 @@ -import {Str} from 'expensify-common'; -import React, {useEffect} from 'react'; -import {View} from 'react-native'; -import type {OnyxEntry} from 'react-native-onyx'; -import {withOnyx} from 'react-native-onyx'; -import FormAlertWithSubmitButton from '@components/FormAlertWithSubmitButton'; -import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; -import OfflineWithFeedback from '@components/OfflineWithFeedback'; -import ScrollView from '@components/ScrollView'; -import useLocalize from '@hooks/useLocalize'; -import useThemeStyles from '@hooks/useThemeStyles'; -import * as CurrencyUtils from '@libs/CurrencyUtils'; -import Navigation from '@libs/Navigation/Navigation'; -import * as PolicyUtils from '@libs/PolicyUtils'; -import {getUnitTranslationKey} from '@libs/WorkspacesSettingsUtils'; -import type {WithPolicyProps} from '@pages/workspace/withPolicy'; -import withPolicy from '@pages/workspace/withPolicy'; -import WorkspacePageWithSections from '@pages/workspace/WorkspacePageWithSections'; -import * as BankAccounts from '@userActions/BankAccounts'; -import * as Policy from '@userActions/Policy/Policy'; -import CONST from '@src/CONST'; -import ONYXKEYS from '@src/ONYXKEYS'; -import ROUTES from '@src/ROUTES'; -import type {ReimbursementAccount, WorkspaceRateAndUnit} from '@src/types/onyx'; -import type {Unit} from '@src/types/onyx/Policy'; -import {isEmptyObject} from '@src/types/utils/EmptyObject'; - -type WorkspaceRateAndUnitPageBaseProps = WithPolicyProps; - -type WorkspaceRateAndUnitOnyxProps = { - workspaceRateAndUnit: OnyxEntry; - // eslint-disable-next-line react/no-unused-prop-types - reimbursementAccount: OnyxEntry; -}; - -type WorkspaceRateAndUnitPageProps = WorkspaceRateAndUnitPageBaseProps & WorkspaceRateAndUnitOnyxProps; - -function WorkspaceRateAndUnitPage(props: WorkspaceRateAndUnitPageProps) { - const styles = useThemeStyles(); - const {translate} = useLocalize(); - - useEffect(() => { - if (props.workspaceRateAndUnit?.policyID === props.policy?.id) { - return; - } - Policy.setPolicyIDForReimburseView(props.policy?.id ?? '-1'); - // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps - }, []); - - useEffect(() => { - const customUnits = props.policy?.customUnits ?? {}; - if (!isEmptyObject(customUnits)) { - return; - } - - BankAccounts.setReimbursementAccountLoading(true); - Policy.openWorkspaceReimburseView(props.policy?.id ?? '-1'); - }, [props]); - - const saveUnitAndRate = (newUnit: Unit, newRate: string) => { - const distanceCustomUnit = PolicyUtils.getCustomUnit(props.policy); - if (!distanceCustomUnit) { - return; - } - const currentCustomUnitRate = Object.values(distanceCustomUnit?.rates ?? {}).find((rate) => rate.name === CONST.CUSTOM_UNITS.DEFAULT_RATE); - const unitID = distanceCustomUnit.customUnitID ?? ''; - const unitName = distanceCustomUnit.name ?? ''; - - const newCustomUnit = { - customUnitID: unitID, - name: unitName, - attributes: {unit: newUnit}, - rates: { - ...currentCustomUnitRate, - rate: parseFloat(newRate), - }, - }; - Policy.updateWorkspaceCustomUnitAndRate(props.policy?.id ?? '-1', distanceCustomUnit, newCustomUnit, props.policy?.lastModified); - }; - - const distanceCustomUnit = PolicyUtils.getCustomUnit(props.policy); - const distanceCustomRate = Object.values(distanceCustomUnit?.rates ?? {}).find((rate) => rate.name === CONST.CUSTOM_UNITS.DEFAULT_RATE); - - const unitValue = props.workspaceRateAndUnit?.unit ?? distanceCustomUnit?.attributes.unit ?? CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES; - const rateValue = props.workspaceRateAndUnit?.rate ?? distanceCustomRate?.rate?.toString() ?? ''; - const unitTitle = Str.recapitalize(translate(getUnitTranslationKey(unitValue))); - - const submit = () => { - saveUnitAndRate(unitValue, rateValue); - Policy.clearOnyxDataForReimburseView(); - Navigation.goBack(); - }; - - return ( - - {() => ( - - - - Policy.clearCustomUnitErrors(props.policy?.id ?? '-1', distanceCustomUnit?.customUnitID ?? '-1', distanceCustomRate?.customUnitRateID ?? '-1')} - > - Navigation.navigate(ROUTES.WORKSPACE_RATE_AND_UNIT_RATE.getRoute(props.policy?.id ?? '-1'))} - shouldShowRightIcon - /> - Navigation.navigate(ROUTES.WORKSPACE_RATE_AND_UNIT_UNIT.getRoute(props.policy?.id ?? '-1'))} - shouldShowRightIcon - /> - - - - - submit()} - enabledWhenOffline - buttonText={translate('common.save')} - containerStyles={[styles.mh0, styles.mt5, styles.flex1, styles.ph5]} - isAlertVisible={false} - /> - - - )} - - ); -} - -WorkspaceRateAndUnitPage.displayName = 'WorkspaceRateAndUnitPage'; - -export default withPolicy( - withOnyx({ - // @ts-expect-error: ONYXKEYS.REIMBURSEMENT_ACCOUNT is conflicting with ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM - reimbursementAccount: { - key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, - }, - workspaceRateAndUnit: { - key: ONYXKEYS.WORKSPACE_RATE_AND_UNIT, - }, - })(WorkspaceRateAndUnitPage), -); diff --git a/src/pages/workspace/reimburse/WorkspaceRateAndUnitPage/RatePage.tsx b/src/pages/workspace/reimburse/WorkspaceRateAndUnitPage/RatePage.tsx deleted file mode 100644 index c8a2b3373230..000000000000 --- a/src/pages/workspace/reimburse/WorkspaceRateAndUnitPage/RatePage.tsx +++ /dev/null @@ -1,106 +0,0 @@ -import React, {useCallback, useEffect, useMemo} from 'react'; -import type {OnyxEntry} from 'react-native-onyx'; -import {withOnyx} from 'react-native-onyx'; -import AmountForm from '@components/AmountForm'; -import FormProvider from '@components/Form/FormProvider'; -import InputWrapperWithRef from '@components/Form/InputWrapper'; -import type {FormOnyxValues} from '@components/Form/types'; -import useLocalize from '@hooks/useLocalize'; -import useThemeStyles from '@hooks/useThemeStyles'; -import Navigation from '@libs/Navigation/Navigation'; -import {validateRateValue} from '@libs/PolicyDistanceRatesUtils'; -import * as PolicyUtils from '@libs/PolicyUtils'; -import type {WithPolicyProps} from '@pages/workspace/withPolicy'; -import withPolicy from '@pages/workspace/withPolicy'; -import WorkspacePageWithSections from '@pages/workspace/WorkspacePageWithSections'; -import * as Policy from '@userActions/Policy/Policy'; -import CONST from '@src/CONST'; -import ONYXKEYS from '@src/ONYXKEYS'; -import ROUTES from '@src/ROUTES'; -import INPUT_IDS from '@src/types/form/WorkspaceRateAndUnitForm'; -import type {WorkspaceRateAndUnit} from '@src/types/onyx'; - -type WorkspaceRatePageBaseProps = WithPolicyProps; - -type WorkspaceRateAndUnitOnyxProps = { - workspaceRateAndUnit: OnyxEntry; -}; - -type WorkspaceRatePageProps = WorkspaceRatePageBaseProps & WorkspaceRateAndUnitOnyxProps; - -function WorkspaceRatePage(props: WorkspaceRatePageProps) { - const styles = useThemeStyles(); - const {translate, toLocaleDigit} = useLocalize(); - const outputCurrency = props.policy?.outputCurrency ?? CONST.CURRENCY.USD; - - useEffect(() => { - if (props.workspaceRateAndUnit?.policyID === props.policy?.id) { - return; - } - Policy.setPolicyIDForReimburseView(props.policy?.id ?? '-1'); - // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps - }, []); - - const submit = (values: FormOnyxValues) => { - const rate = values.rate; - Policy.setRateForReimburseView((parseFloat(rate) * CONST.POLICY.CUSTOM_UNIT_RATE_BASE_OFFSET).toFixed(1)); - Navigation.goBack(ROUTES.WORKSPACE_RATE_AND_UNIT.getRoute(props.policy?.id ?? '-1')); - }; - - const validate = useCallback( - (values: FormOnyxValues) => validateRateValue(values, outputCurrency, toLocaleDigit), - [outputCurrency, toLocaleDigit], - ); - - const defaultValue = useMemo(() => { - const defaultDistanceCustomUnit = PolicyUtils.getCustomUnit(props.policy); - const distanceCustomRate = Object.values(defaultDistanceCustomUnit?.rates ?? {}).find((rate) => rate.name === CONST.CUSTOM_UNITS.DEFAULT_RATE); - return distanceCustomRate?.rate ?? 0; - }, [props.policy]); - - return ( - - {() => ( - - - - )} - - ); -} - -WorkspaceRatePage.displayName = 'WorkspaceRatePage'; - -export default withPolicy( - withOnyx({ - workspaceRateAndUnit: { - key: ONYXKEYS.WORKSPACE_RATE_AND_UNIT, - }, - })(WorkspaceRatePage), -); diff --git a/src/pages/workspace/reimburse/WorkspaceRateAndUnitPage/UnitPage.tsx b/src/pages/workspace/reimburse/WorkspaceRateAndUnitPage/UnitPage.tsx deleted file mode 100644 index 981ad2c81f9b..000000000000 --- a/src/pages/workspace/reimburse/WorkspaceRateAndUnitPage/UnitPage.tsx +++ /dev/null @@ -1,78 +0,0 @@ -import React, {useEffect, useMemo} from 'react'; -import type {OnyxEntry} from 'react-native-onyx'; -import {withOnyx} from 'react-native-onyx'; -import Text from '@components/Text'; -import type {UnitItemType} from '@components/UnitPicker'; -import UnitPicker from '@components/UnitPicker'; -import useLocalize from '@hooks/useLocalize'; -import useThemeStyles from '@hooks/useThemeStyles'; -import Navigation from '@libs/Navigation/Navigation'; -import * as PolicyUtils from '@libs/PolicyUtils'; -import type {WithPolicyProps} from '@pages/workspace/withPolicy'; -import withPolicy from '@pages/workspace/withPolicy'; -import WorkspacePageWithSections from '@pages/workspace/WorkspacePageWithSections'; -import * as Policy from '@userActions/Policy/Policy'; -import CONST from '@src/CONST'; -import ONYXKEYS from '@src/ONYXKEYS'; -import ROUTES from '@src/ROUTES'; -import type {WorkspaceRateAndUnit} from '@src/types/onyx'; - -type WorkspaceUnitPageBaseProps = WithPolicyProps; - -type WorkspaceRateAndUnitOnyxProps = { - workspaceRateAndUnit: OnyxEntry; -}; - -type WorkspaceUnitPageProps = WorkspaceUnitPageBaseProps & WorkspaceRateAndUnitOnyxProps; -function WorkspaceUnitPage(props: WorkspaceUnitPageProps) { - const styles = useThemeStyles(); - const {translate} = useLocalize(); - - useEffect(() => { - if (props.workspaceRateAndUnit?.policyID === props.policy?.id) { - return; - } - Policy.setPolicyIDForReimburseView(props.policy?.id ?? '-1'); - // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps - }, []); - - const updateUnit = (unit: UnitItemType) => { - Policy.setUnitForReimburseView(unit.value); - Navigation.goBack(ROUTES.WORKSPACE_RATE_AND_UNIT.getRoute(props.policy?.id ?? '-1')); - }; - - const defaultValue = useMemo(() => { - const defaultDistanceCustomUnit = PolicyUtils.getCustomUnit(props.policy); - return defaultDistanceCustomUnit?.attributes.unit ?? CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES; - }, [props.policy]); - - return ( - - {() => ( - <> - {translate('workspace.reimburse.trackDistanceChooseUnit')} - - - )} - - ); -} - -WorkspaceUnitPage.displayName = 'WorkspaceUnitPage'; -export default withPolicy( - withOnyx({ - workspaceRateAndUnit: { - key: ONYXKEYS.WORKSPACE_RATE_AND_UNIT, - }, - })(WorkspaceUnitPage), -); diff --git a/src/pages/workspace/reimburse/WorkspaceReimbursePage.tsx b/src/pages/workspace/reimburse/WorkspaceReimbursePage.tsx deleted file mode 100644 index d929ec10748a..000000000000 --- a/src/pages/workspace/reimburse/WorkspaceReimbursePage.tsx +++ /dev/null @@ -1,33 +0,0 @@ -import type {StackScreenProps} from '@react-navigation/stack'; -import React from 'react'; -import useLocalize from '@hooks/useLocalize'; -import type {FullScreenNavigatorParamList} from '@libs/Navigation/types'; -import type {WithPolicyProps} from '@pages/workspace/withPolicy'; -import withPolicy from '@pages/workspace/withPolicy'; -import WorkspacePageWithSections from '@pages/workspace/WorkspacePageWithSections'; -import CONST from '@src/CONST'; -import type SCREENS from '@src/SCREENS'; -import WorkspaceReimburseView from './WorkspaceReimburseView'; - -type WorkspaceReimbursePageProps = WithPolicyProps & StackScreenProps; - -function WorkspaceReimbursePage({route, policy}: WorkspaceReimbursePageProps) { - const {translate} = useLocalize(); - - return ( - - {() => } - - ); -} - -WorkspaceReimbursePage.displayName = 'WorkspaceReimbursePage'; - -export default withPolicy(WorkspaceReimbursePage); diff --git a/src/pages/workspace/reimburse/WorkspaceReimburseSection.tsx b/src/pages/workspace/reimburse/WorkspaceReimburseSection.tsx deleted file mode 100644 index 6c07956e74a7..000000000000 --- a/src/pages/workspace/reimburse/WorkspaceReimburseSection.tsx +++ /dev/null @@ -1,111 +0,0 @@ -import React, {useEffect, useState} from 'react'; -import {ActivityIndicator, View} from 'react-native'; -import type {OnyxEntry} from 'react-native-onyx'; -import ConnectBankAccountButton from '@components/ConnectBankAccountButton'; -import * as Expensicons from '@components/Icon/Expensicons'; -import * as Illustrations from '@components/Icon/Illustrations'; -import Section from '@components/Section'; -import Text from '@components/Text'; -import useLocalize from '@hooks/useLocalize'; -import useNetwork from '@hooks/useNetwork'; -import usePrevious from '@hooks/usePrevious'; -import useTheme from '@hooks/useTheme'; -import useThemeStyles from '@hooks/useThemeStyles'; -import BankAccount from '@libs/models/BankAccount'; -import * as Link from '@userActions/Link'; -import type * as OnyxTypes from '@src/types/onyx'; - -type WorkspaceReimburseSectionProps = { - /** Policy values needed in the component */ - policy: OnyxEntry; - - /** Bank account attached to free plan */ - reimbursementAccount: OnyxEntry; -}; - -function WorkspaceReimburseSection({policy, reimbursementAccount}: WorkspaceReimburseSectionProps) { - const theme = useTheme(); - const styles = useThemeStyles(); - const {translate} = useLocalize(); - const [shouldShowLoadingSpinner, setShouldShowLoadingSpinner] = useState(true); - const achState = reimbursementAccount?.achData?.state ?? ''; - const hasVBA = achState === BankAccount.STATE.OPEN; - const policyId = policy?.id ?? '-1'; - const reimburseReceiptsUrl = `reports?policyID=${policyId}&from=all&type=expense&showStates=Archived&isAdvancedFilterMode=true`; - const isLoading = reimbursementAccount?.isLoading ?? false; - const prevIsLoading = usePrevious(isLoading); - const {isOffline} = useNetwork(); - - useEffect(() => { - if (prevIsLoading === isLoading) { - return; - } - setShouldShowLoadingSpinner(isLoading); - }, [prevIsLoading, isLoading]); - - if (isOffline) { - return ( -
- - {`${translate('common.youAppearToBeOffline')} ${translate('common.thisFeatureRequiresInternet')}`} - -
- ); - } - - if (shouldShowLoadingSpinner) { - return ( - - - - ); - } - - return hasVBA ? ( -
Link.openOldDotLink(reimburseReceiptsUrl), - icon: Expensicons.Bank, - shouldShowRightIcon: true, - iconRight: Expensicons.NewWindow, - wrapperStyle: [styles.cardMenuItem], - link: () => Link.buildOldDotURL(reimburseReceiptsUrl), - }, - ]} - > - - {translate('workspace.reimburse.fastReimbursementsVBACopy')} - -
- ) : ( -
- - {translate('workspace.reimburse.unlockNoVBACopy')} - - -
- ); -} - -WorkspaceReimburseSection.displayName = 'WorkspaceReimburseSection'; - -export default WorkspaceReimburseSection; diff --git a/src/pages/workspace/reimburse/WorkspaceReimburseView.tsx b/src/pages/workspace/reimburse/WorkspaceReimburseView.tsx deleted file mode 100644 index 8cfd6ee07207..000000000000 --- a/src/pages/workspace/reimburse/WorkspaceReimburseView.tsx +++ /dev/null @@ -1,150 +0,0 @@ -import React, {useCallback, useEffect, useState} from 'react'; -import {View} from 'react-native'; -import {withOnyx} from 'react-native-onyx'; -import type {OnyxEntry} from 'react-native-onyx'; -import CopyTextToClipboard from '@components/CopyTextToClipboard'; -import * as Expensicons from '@components/Icon/Expensicons'; -import * as Illustrations from '@components/Icon/Illustrations'; -import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; -import OfflineWithFeedback from '@components/OfflineWithFeedback'; -import Section from '@components/Section'; -import Text from '@components/Text'; -import useLocalize from '@hooks/useLocalize'; -import useNetwork from '@hooks/useNetwork'; -import useResponsiveLayout from '@hooks/useResponsiveLayout'; -import useThemeStyles from '@hooks/useThemeStyles'; -import Navigation from '@libs/Navigation/Navigation'; -import * as PolicyUtils from '@libs/PolicyUtils'; -import * as BankAccounts from '@userActions/BankAccounts'; -import * as Link from '@userActions/Link'; -import * as Policy from '@userActions/Policy/Policy'; -import CONST from '@src/CONST'; -import ONYXKEYS from '@src/ONYXKEYS'; -import ROUTES from '@src/ROUTES'; -import type * as OnyxTypes from '@src/types/onyx'; -import type {Unit} from '@src/types/onyx/Policy'; -import WorkspaceReimburseSection from './WorkspaceReimburseSection'; - -type WorkspaceReimburseViewOnyxProps = { - /** Bank account attached to free plan */ - reimbursementAccount: OnyxEntry; -}; - -type WorkspaceReimburseViewProps = WorkspaceReimburseViewOnyxProps & { - /** Policy values needed in the component */ - policy: OnyxEntry; -}; - -function WorkspaceReimburseView({policy, reimbursementAccount}: WorkspaceReimburseViewProps) { - const styles = useThemeStyles(); - const [currentRatePerUnit, setCurrentRatePerUnit] = useState(''); - const {shouldUseNarrowLayout} = useResponsiveLayout(); - const viewAllReceiptsUrl = `expenses?policyIDList=${policy?.id ?? '-1'}&billableReimbursable=reimbursable&submitterEmail=%2B%2B`; - const distanceCustomUnit = PolicyUtils.getCustomUnit(policy); - const distanceCustomRate = Object.values(distanceCustomUnit?.rates ?? {}).find((rate) => rate.name === CONST.CUSTOM_UNITS.DEFAULT_RATE); - const {translate, toLocaleDigit} = useLocalize(); - const {isOffline} = useNetwork(); - - const getUnitLabel = useCallback((value: Unit): string => translate(`common.${value}`), [translate]); - - const getCurrentRatePerUnitLabel = useCallback(() => { - const customUnitRate = Object.values(distanceCustomUnit?.rates ?? {}).find((rate) => rate && rate.name === CONST.CUSTOM_UNITS.DEFAULT_RATE); - const currentUnit = getUnitLabel(distanceCustomUnit?.attributes.unit ?? CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES); - const currentRate = PolicyUtils.getUnitRateValue(toLocaleDigit, customUnitRate); - const perWord = translate('common.per'); - - return `${currentRate} ${perWord} ${currentUnit}`; - }, [translate, distanceCustomUnit, toLocaleDigit, getUnitLabel]); - - const fetchData = useCallback(() => { - // Instead of setting the reimbursement account loading within the optimistic data of the API command, use a separate action so that the Onyx value is updated right away. - // openWorkspaceReimburseView uses API.read which will not make the request until all WRITE requests in the sequential queue have finished responding, so there would be a delay in - // updating Onyx with the optimistic data. - BankAccounts.setReimbursementAccountLoading(true); - Policy.openWorkspaceReimburseView(policy?.id ?? '-1'); - }, [policy?.id]); - - useEffect(() => { - if (isOffline) { - return; - } - fetchData(); - }, [isOffline, fetchData]); - - useEffect(() => { - setCurrentRatePerUnit(getCurrentRatePerUnitLabel()); - }, [policy?.customUnits, getCurrentRatePerUnitLabel]); - - return ( - -
Link.openOldDotLink(viewAllReceiptsUrl), - icon: Expensicons.Receipt, - shouldShowRightIcon: true, - iconRight: Expensicons.NewWindow, - wrapperStyle: styles.cardMenuItem, - link: () => Link.buildOldDotURL(viewAllReceiptsUrl), - }, - ]} - > - - - {translate('workspace.reimburse.captureNoVBACopyBeforeEmail')} - - {translate('workspace.reimburse.captureNoVBACopyAfterEmail')} - - -
- -
- - {translate('workspace.reimburse.trackDistanceCopy')} - - { - Policy.setPolicyIDForReimburseView(policy?.id ?? '-1'); - Navigation.navigate(ROUTES.WORKSPACE_RATE_AND_UNIT.getRoute(policy?.id ?? '-1')); - }} - wrapperStyle={[styles.sectionMenuItemTopDescription, styles.mt3]} - brickRoadIndicator={(distanceCustomUnit?.errors ?? distanceCustomRate?.errors) && CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR} - /> - - -
- - -
- ); -} - -WorkspaceReimburseView.displayName = 'WorkspaceReimburseView'; - -export default withOnyx({ - // @ts-expect-error: ONYXKEYS.REIMBURSEMENT_ACCOUNT is conflicting with ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM - reimbursementAccount: { - key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, - }, -})(WorkspaceReimburseView);