Skip to content

Commit 821c28a

Browse files
committed
fix: Workspace - Taxes - Can't press Enter on creating tax rate.
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
1 parent 54e5187 commit 821c28a

6 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/components/AmountPicker/AmountSelectorModal.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {useFocusEffect} from '@react-navigation/native';
22
import React, {useCallback, useRef, useState} from 'react';
3-
import {View} from 'react-native';
3+
import {Keyboard, View} from 'react-native';
44
import AmountForm from '@components/AmountForm';
55
import Button from '@components/Button';
66
import HeaderWithBackButton from '@components/HeaderWithBackButton';
@@ -77,7 +77,10 @@ function AmountSelectorModal({value, description = '', onValueSelected, isVisibl
7777
large
7878
pressOnEnter
7979
text={translate('common.save')}
80-
onPress={() => onValueSelected?.(currentValue ?? '')}
80+
onPress={() => {
81+
onValueSelected?.(currentValue ?? '');
82+
Keyboard.dismiss();
83+
}}
8184
style={styles.mh5}
8285
/>
8386
</View>

src/components/Form/FormProvider.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ function FormProvider(
115115
shouldRenderFooterAboveSubmit = false,
116116
shouldUseStrictHtmlTagValidation = false,
117117
shouldPreventDefaultFocusOnPressSubmit = false,
118+
enterKeyEventListenerPriority = 1,
118119
...rest
119120
}: FormProviderProps,
120121
forwardedRef: ForwardedRef<FormRef>,
@@ -459,6 +460,7 @@ function FormProvider(
459460
enabledWhenOffline={enabledWhenOffline}
460461
shouldRenderFooterAboveSubmit={shouldRenderFooterAboveSubmit}
461462
shouldPreventDefaultFocusOnPressSubmit={shouldPreventDefaultFocusOnPressSubmit}
463+
enterKeyEventListenerPriority={enterKeyEventListenerPriority}
462464
>
463465
{typeof children === 'function' ? children({inputValues}) : children}
464466
</FormWrapper>

src/components/Form/FormWrapper.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ function FormWrapper({
9494
shouldSubmitButtonBlendOpacity = false,
9595
shouldPreventDefaultFocusOnPressSubmit = false,
9696
onScroll = () => {},
97+
enterKeyEventListenerPriority = 1,
9798
}: FormWrapperProps) {
9899
const styles = useThemeStyles();
99100
const formRef = useRef<RNScrollView>(null);
@@ -179,7 +180,7 @@ function FormWrapper({
179180
enabledWhenOffline={enabledWhenOffline}
180181
isSubmitActionDangerous={isSubmitActionDangerous}
181182
disablePressOnEnter={disablePressOnEnter}
182-
enterKeyEventListenerPriority={1}
183+
enterKeyEventListenerPriority={enterKeyEventListenerPriority}
183184
shouldRenderFooterAboveSubmit={shouldRenderFooterAboveSubmit}
184185
shouldBlendOpacity={shouldSubmitButtonBlendOpacity}
185186
shouldPreventDefaultFocusOnPress={shouldPreventDefaultFocusOnPressSubmit}
@@ -212,6 +213,7 @@ function FormWrapper({
212213
submitFlexEnabled,
213214
shouldRenderFooterAboveSubmit,
214215
shouldPreventDefaultFocusOnPressSubmit,
216+
enterKeyEventListenerPriority,
215217
],
216218
);
217219

src/components/Form/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ type FormProps<TFormID extends OnyxFormKey = OnyxFormKey> = {
173173
* If `true`, the form will smoothly scroll to the bottom after interactions have completed.
174174
*/
175175
shouldScrollToEnd?: boolean;
176+
177+
/** The priority to assign the enter key event listener to buttons. 0 is the highest priority. */
178+
enterKeyEventListenerPriority?: number;
176179
};
177180

178181
type FormRef<TFormID extends OnyxFormKey = OnyxFormKey> = {

src/components/TextPicker/TextSelectorModal.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ function TextSelectorModal({
142142
enabledWhenOffline
143143
shouldHideFixErrorsAlert
144144
addBottomSafeAreaPadding
145+
enterKeyEventListenerPriority={0}
145146
>
146147
<View style={styles.pb4}>{!!subtitle && <Text style={[styles.sidebarLinkText, styles.optionAlternateText]}>{subtitle}</Text>}</View>
147148
<InputWrapper

src/pages/workspace/taxes/WorkspaceCreateTaxPage.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import ScreenWrapper from '@components/ScreenWrapper';
1010
import Text from '@components/Text';
1111
import TextPicker from '@components/TextPicker';
1212
import useLocalize from '@hooks/useLocalize';
13-
import useOnyx from '@hooks/useOnyx';
1413
import useThemeStyles from '@hooks/useThemeStyles';
1514
import {createPolicyTax, getNextTaxCode, getTaxValueWithPercentage, validateTaxName, validateTaxValue} from '@libs/actions/TaxRate';
1615
import Navigation from '@libs/Navigation/Navigation';
@@ -37,7 +36,6 @@ function WorkspaceCreateTaxPage({
3736
}: WorkspaceCreateTaxPageProps) {
3837
const styles = useThemeStyles();
3938
const {translate} = useLocalize();
40-
const [modal] = useOnyx(ONYXKEYS.MODAL, {canBeMissing: true});
4139

4240
const submitForm = useCallback(
4341
({value, ...values}: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_NEW_TAX_FORM>) => {
@@ -90,7 +88,6 @@ function WorkspaceCreateTaxPage({
9088
submitButtonText={translate('common.save')}
9189
enabledWhenOffline
9290
shouldValidateOnBlur={false}
93-
disablePressOnEnter={!!modal?.isVisible}
9491
addBottomSafeAreaPadding
9592
>
9693
<View style={styles.mhn5}>

0 commit comments

Comments
 (0)