From 1ad61dcdc2b5d292e27ecb6663dd8bf4506e83fb Mon Sep 17 00:00:00 2001 From: Michal Muzyk Date: Mon, 6 May 2024 16:07:27 +0200 Subject: [PATCH] fix: restore picker done button --- .../reimburse/WorkspaceRateAndUnitPage.tsx | 158 ------------------ src/styles/index.ts | 5 + 2 files changed, 5 insertions(+), 158 deletions(-) delete mode 100644 src/pages/workspace/reimburse/WorkspaceRateAndUnitPage.tsx diff --git a/src/pages/workspace/reimburse/WorkspaceRateAndUnitPage.tsx b/src/pages/workspace/reimburse/WorkspaceRateAndUnitPage.tsx deleted file mode 100644 index 8fef5f4dc6f9..000000000000 --- a/src/pages/workspace/reimburse/WorkspaceRateAndUnitPage.tsx +++ /dev/null @@ -1,158 +0,0 @@ -import type {StackScreenProps} from '@react-navigation/stack'; -import React, {useEffect} from 'react'; -import {Keyboard, View} from 'react-native'; -import FormProvider from '@components/Form/FormProvider'; -import InputWrapper from '@components/Form/InputWrapper'; -import type {FormOnyxValues} from '@components/Form/types'; -import OfflineWithFeedback from '@components/OfflineWithFeedback'; -import Picker from '@components/Picker'; -import TextInput from '@components/TextInput'; -import useLocalize from '@hooks/useLocalize'; -import useThemeStyles from '@hooks/useThemeStyles'; -import * as CurrencyUtils from '@libs/CurrencyUtils'; -import getPermittedDecimalSeparator from '@libs/getPermittedDecimalSeparator'; -import Navigation from '@libs/Navigation/Navigation'; -import type {SettingsNavigatorParamList} from '@libs/Navigation/types'; -import * as NumberUtils from '@libs/NumberUtils'; -import * as PolicyUtils from '@libs/PolicyUtils'; -import withPolicy from '@pages/workspace/withPolicy'; -import type {WithPolicyProps} from '@pages/workspace/withPolicy'; -import WorkspacePageWithSections from '@pages/workspace/WorkspacePageWithSections'; -import * as BankAccounts from '@userActions/BankAccounts'; -import * as Policy from '@userActions/Policy'; -import CONST from '@src/CONST'; -import type {TranslationPaths} from '@src/languages/types'; -import ONYXKEYS from '@src/ONYXKEYS'; -import ROUTES from '@src/ROUTES'; -import type SCREENS from '@src/SCREENS'; -import type {Unit} from '@src/types/onyx/Policy'; - -type WorkspaceRateAndUnitPageProps = WithPolicyProps & StackScreenProps; - -type ValidationError = {rate?: TranslationPaths | undefined}; - -function WorkspaceRateAndUnitPage({policy, route}: WorkspaceRateAndUnitPageProps) { - const {translate, toLocaleDigit} = useLocalize(); - const styles = useThemeStyles(); - - useEffect(() => { - if ((policy?.customUnits ?? []).length !== 0) { - return; - } - - BankAccounts.setReimbursementAccountLoading(true); - Policy.openWorkspaceReimburseView(policy?.id ?? ''); - }, [policy?.customUnits, policy?.id]); - - const unitItems = [ - {label: translate('common.kilometers'), value: CONST.CUSTOM_UNITS.DISTANCE_UNIT_KILOMETERS}, - {label: translate('common.miles'), value: CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES}, - ]; - - const saveUnitAndRate = (unit: Unit, rate: string) => { - const distanceCustomUnit = Object.values(policy?.customUnits ?? {}).find((customUnit) => customUnit.name === CONST.CUSTOM_UNITS.NAME_DISTANCE); - if (!distanceCustomUnit) { - return; - } - const currentCustomUnitRate = Object.values(distanceCustomUnit?.rates ?? {}).find((r) => r.name === CONST.CUSTOM_UNITS.DEFAULT_RATE); - const unitID = distanceCustomUnit.customUnitID ?? ''; - const unitName = distanceCustomUnit.name ?? ''; - const rateNumValue = PolicyUtils.getNumericValue(rate, toLocaleDigit); - - const newCustomUnit: Policy.NewCustomUnit = { - customUnitID: unitID, - name: unitName, - attributes: {unit}, - rates: { - ...currentCustomUnitRate, - rate: Number(rateNumValue) * CONST.POLICY.CUSTOM_UNIT_RATE_BASE_OFFSET, - }, - }; - - Policy.updateWorkspaceCustomUnitAndRate(policy?.id ?? '', distanceCustomUnit, newCustomUnit, policy?.lastModified); - }; - - const submit = (values: FormOnyxValues) => { - saveUnitAndRate(values.unit as Unit, values.rate); - Keyboard.dismiss(); - Navigation.goBack(ROUTES.WORKSPACE_REIMBURSE.getRoute(policy?.id ?? '')); - }; - - const validate = (values: FormOnyxValues): ValidationError => { - const errors: ValidationError = {}; - const decimalSeparator = toLocaleDigit('.'); - const outputCurrency = policy?.outputCurrency ?? CONST.CURRENCY.USD; - // Allow one more decimal place for accuracy - const rateValueRegex = RegExp(String.raw`^-?\d{0,8}([${getPermittedDecimalSeparator(decimalSeparator)}]\d{1,${CurrencyUtils.getCurrencyDecimals(outputCurrency) + 1}})?$`, 'i'); - if (!rateValueRegex.test(values.rate) || values.rate === '') { - errors.rate = 'workspace.reimburse.invalidRateError'; - } else if (NumberUtils.parseFloatAnyLocale(values.rate) <= 0) { - errors.rate = 'workspace.reimburse.lowRateError'; - } - return errors; - }; - - const distanceCustomUnit = Object.values(policy?.customUnits ?? {}).find((unit) => unit.name === CONST.CUSTOM_UNITS.NAME_DISTANCE); - const distanceCustomRate = Object.values(distanceCustomUnit?.rates ?? {}).find((rate) => rate.name === CONST.CUSTOM_UNITS.DEFAULT_RATE); - - return ( - - {() => ( - - Policy.clearCustomUnitErrors(policy?.id ?? '', distanceCustomUnit?.customUnitID ?? '', distanceCustomRate?.customUnitRateID ?? '')} - > - - - - - - - - )} - - ); -} - -WorkspaceRateAndUnitPage.displayName = 'WorkspaceRateAndUnitPage'; - -export default withPolicy(WorkspaceRateAndUnitPage); diff --git a/src/styles/index.ts b/src/styles/index.ts index 54a72bee54eb..419cc5a3fd4a 100644 --- a/src/styles/index.ts +++ b/src/styles/index.ts @@ -799,6 +799,7 @@ const styles = (theme: ThemeColors) => fontSize: 17, }, modalViewMiddle: { + position: 'relative', backgroundColor: theme.border, borderTopWidth: 0, }, @@ -841,6 +842,10 @@ const styles = (theme: ThemeColors) => width: variables.iconSizeExtraSmall, height: variables.iconSizeExtraSmall, }, + chevronContainer: { + pointerEvents: 'none', + opacity: 0, + }, } satisfies CustomPickerStyle), badge: {