Skip to content

Commit

Permalink
Merge pull request Expensify#26373 from Expensify/vit-makeMerchantNon…
Browse files Browse the repository at this point in the history
…Empty

Disallow empty merchant field
  • Loading branch information
stitesExpensify authored Aug 31, 2023
2 parents c9c1f47 + 537a6ab commit 84706e7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/pages/EditRequestMerchantPage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {useRef} from 'react';
import React, {useCallback, useRef} from 'react';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import _ from 'underscore';
import TextInput from '../components/TextInput';
import ScreenWrapper from '../components/ScreenWrapper';
import HeaderWithBackButton from '../components/HeaderWithBackButton';
Expand All @@ -22,6 +23,17 @@ const propTypes = {
function EditRequestMerchantPage({defaultMerchant, onSubmit}) {
const {translate} = useLocalize();
const merchantInputRef = useRef(null);

const validate = useCallback((value) => {
const errors = {};

if (_.isEmpty(value.merchant)) {
errors.merchant = 'common.error.fieldRequired';
}

return errors;
}, []);

return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
Expand All @@ -36,6 +48,7 @@ function EditRequestMerchantPage({defaultMerchant, onSubmit}) {
style={[styles.flexGrow1, styles.ph5]}
formID={ONYXKEYS.FORMS.MONEY_REQUEST_MERCHANT_FORM}
onSubmit={onSubmit}
validate={validate}
submitButtonText={translate('common.save')}
enabledWhenOffline
>
Expand Down
13 changes: 12 additions & 1 deletion src/pages/iou/MoneyRequestMerchantPage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useEffect, useRef} from 'react';
import React, {useCallback, useEffect, useRef} from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import PropTypes from 'prop-types';
Expand Down Expand Up @@ -67,6 +67,16 @@ function MoneyRequestMerchantPage({iou, route}) {
Navigation.goBack(ROUTES.getMoneyRequestConfirmationRoute(iouType, reportID));
}

const validate = useCallback((value) => {
const errors = {};

if (_.isEmpty(value.moneyRequestMerchant)) {
errors.moneyRequestMerchant = 'common.error.fieldRequired';
}

return errors;
}, []);

/**
* Sets the money request comment by saving it to Onyx.
*
Expand All @@ -92,6 +102,7 @@ function MoneyRequestMerchantPage({iou, route}) {
style={[styles.flexGrow1, styles.ph5]}
formID={ONYXKEYS.FORMS.MONEY_REQUEST_MERCHANT_FORM}
onSubmit={(value) => updateMerchant(value)}
validate={validate}
submitButtonText={translate('common.save')}
enabledWhenOffline
>
Expand Down

0 comments on commit 84706e7

Please sign in to comment.