Skip to content

Commit

Permalink
Merge pull request #40868 from koko57/fix/40749-validation-for-splits
Browse files Browse the repository at this point in the history
fix: fix validation for split bill
  • Loading branch information
robertjchen authored Apr 26, 2024
2 parents 42d4ed7 + 96817be commit 951c7b3
Showing 1 changed file with 7 additions and 23 deletions.
30 changes: 7 additions & 23 deletions src/components/MoneyRequestConfirmationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,6 @@ function MoneyRequestConfirmationList({
const [didConfirm, setDidConfirm] = useState(false);
const [didConfirmSplit, setDidConfirmSplit] = useState(false);

const [merchantError, setMerchantError] = useState(false);

const [isAttachmentInvalid, setIsAttachmentInvalid] = useState(false);

const navigateBack = () => {
Expand All @@ -322,19 +320,9 @@ function MoneyRequestConfirmationList({
const isMerchantEmpty = !iouMerchant || iouMerchant === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT;
const isMerchantRequired = isPolicyExpenseChat && !isScanRequest && shouldShowMerchant;

const isCategoryRequired = canUseViolations && !!policy?.requiresCategory;
const shouldDisplayMerchantError = isMerchantRequired && (shouldDisplayFieldError || formError === 'iou.error.invalidMerchant') && isMerchantEmpty;

useEffect(() => {
if ((!isMerchantRequired && isMerchantEmpty) || !merchantError) {
return;
}
if (!isMerchantEmpty && merchantError) {
setMerchantError(false);
if (formError === 'iou.error.invalidMerchant') {
setFormError('');
}
}
}, [formError, isMerchantEmpty, merchantError, isMerchantRequired]);
const isCategoryRequired = canUseViolations && !!policy?.requiresCategory;

useEffect(() => {
if (shouldDisplayFieldError && hasSmartScanFailed) {
Expand All @@ -345,13 +333,9 @@ function MoneyRequestConfirmationList({
setFormError('iou.error.genericSmartscanFailureMessage');
return;
}
if (merchantError) {
setFormError('iou.error.invalidMerchant');
return;
}
// reset the form error whenever the screen gains or loses focus
setFormError('');
}, [isFocused, transaction, shouldDisplayFieldError, hasSmartScanFailed, didConfirmSplit, isMerchantRequired, merchantError]);
}, [isFocused, transaction, shouldDisplayFieldError, hasSmartScanFailed, didConfirmSplit]);

useEffect(() => {
if (!shouldCalculateDistanceAmount) {
Expand Down Expand Up @@ -577,8 +561,8 @@ function MoneyRequestConfirmationList({
if (selectedParticipants.length === 0) {
return;
}
if ((isMerchantRequired && isMerchantEmpty) || (shouldDisplayFieldError && TransactionUtils.isMerchantMissing(transaction ?? null))) {
setMerchantError(true);
if (!isEditingSplitBill && isMerchantRequired && (isMerchantEmpty || (shouldDisplayFieldError && TransactionUtils.isMerchantMissing(transaction ?? null)))) {
setFormError('iou.error.invalidMerchant');
return;
}
if (iouCategory.length > CONST.API_TRANSACTION_CATEGORY_MAX_LENGTH) {
Expand Down Expand Up @@ -805,8 +789,8 @@ function MoneyRequestConfirmationList({
}}
disabled={didConfirm}
interactive={!isReadOnly}
brickRoadIndicator={merchantError ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
error={merchantError ? translate('common.error.fieldRequired') : ''}
brickRoadIndicator={shouldDisplayMerchantError ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
error={shouldDisplayMerchantError ? translate('common.error.fieldRequired') : ''}
rightLabel={isMerchantRequired ? translate('common.required') : ''}
/>
),
Expand Down

0 comments on commit 951c7b3

Please sign in to comment.