Skip to content

Commit

Permalink
create util function
Browse files Browse the repository at this point in the history
  • Loading branch information
tienifr committed Feb 6, 2024
1 parent 2a6819a commit 76a2811
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/components/LocalePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {withOnyx} from 'react-native-onyx';
import useLocalize from '@hooks/useLocalize';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import FormUtils from '@libs/FormUtils';
import * as App from '@userActions/App';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -34,7 +35,7 @@ function LocalePicker({account, preferredLocale = CONST.LOCALES.DEFAULT, size =
keyForList: language,
isSelected: preferredLocale === language,
}));
const shouldDisablePicker = account?.isLoading && account.loadingForm === (account.requiresTwoFactorAuth ? CONST.FORMS.VALIDATE_TFA_CODE_FORM : CONST.FORMS.VALIDATE_CODE_FORM);
const shouldDisablePicker = FormUtils.isValidateCodeFormSubmitting(account ?? {});

return (
<Picker
Expand Down
7 changes: 6 additions & 1 deletion src/libs/FormUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import type {OnyxFormKeyWithoutDraft} from '@components/Form/types';
import CONST from '@src/CONST';
import type {Account} from '@src/types/onyx';

const isValidateCodeFormSubmitting = (account: Account) =>
account.isLoading && account.loadingForm === (account.requiresTwoFactorAuth ? CONST.FORMS.VALIDATE_TFA_CODE_FORM : CONST.FORMS.VALIDATE_CODE_FORM);

function getDraftKey(formID: OnyxFormKeyWithoutDraft): `${OnyxFormKeyWithoutDraft}Draft` {
return `${formID}Draft`;
}

export default {getDraftKey};
export default {getDraftKey, isValidateCodeFormSubmitting};
4 changes: 2 additions & 2 deletions src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
import canFocusInputOnScreenFocus from '@libs/canFocusInputOnScreenFocus';
import compose from '@libs/compose';
import * as ErrorUtils from '@libs/ErrorUtils';
import FormUtils from '@libs/FormUtils';
import * as ValidationUtils from '@libs/ValidationUtils';
import ChangeExpensifyLoginLink from '@pages/signin/ChangeExpensifyLoginLink';
import Terms from '@pages/signin/Terms';
Expand Down Expand Up @@ -105,8 +106,7 @@ function BaseValidateCodeForm(props) {
const hasError = Boolean(props.account) && !_.isEmpty(props.account.errors) && !needToClearError;
const isLoadingResendValidationForm = props.account.loadingForm === CONST.FORMS.RESEND_VALIDATE_CODE_FORM;
const shouldDisableResendValidateCode = props.network.isOffline || props.account.isLoading;
const isValidateCodeFormSubmitting =
props.account.isLoading && props.account.loadingForm === (props.account.requiresTwoFactorAuth ? CONST.FORMS.VALIDATE_TFA_CODE_FORM : CONST.FORMS.VALIDATE_CODE_FORM);
const isValidateCodeFormSubmitting = FormUtils.isValidateCodeFormSubmitting(props.account);

useEffect(() => {
if (!(inputValidateCodeRef.current && hasError && (props.session.autoAuthState === CONST.AUTO_AUTH_STATE.FAILED || props.account.isLoading))) {
Expand Down

0 comments on commit 76a2811

Please sign in to comment.