Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/components/MoneyRequestConfirmationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
setMoneyRequestTaxRate,
setSplitShares,
} from '@libs/actions/IOU';
import {isCategoryDescriptionRequired} from '@libs/CategoryUtils';
import {convertToBackendAmount, convertToDisplayString, convertToDisplayStringWithoutCurrency, getCurrencyDecimals} from '@libs/CurrencyUtils';
import DistanceRequestUtils from '@libs/DistanceRequestUtils';
import {calculateAmount, insertTagIntoTransactionTagsString, isMovingTransactionFromTrackExpense as isMovingTransactionFromTrackExpenseUtil} from '@libs/IOUUtils';
Expand Down Expand Up @@ -406,6 +407,11 @@ function MoneyRequestConfirmationList({

const isCategoryRequired = !!policy?.requiresCategory && !isTypeInvoice;

const isDescriptionRequired = useMemo(
() => isCategoryDescriptionRequired(policyCategories, iouCategory, policy?.areRulesEnabled),
[iouCategory, policyCategories, policy?.areRulesEnabled],
);

useEffect(() => {
if (shouldDisplayFieldError && didConfirmSplit) {
setFormError('iou.error.genericSmartscanFailureMessage');
Expand Down Expand Up @@ -1131,6 +1137,7 @@ function MoneyRequestConfirmationList({
iouIsReimbursable={iouIsReimbursable}
onToggleReimbursable={onToggleReimbursable}
isReceiptEditable={isReceiptEditable}
isDescriptionRequired={isDescriptionRequired}
/>
);

Expand Down
5 changes: 5 additions & 0 deletions src/components/MoneyRequestConfirmationListFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ type MoneyRequestConfirmationListFooterProps = {

/** Flag indicating if the IOU is reimbursable */
iouIsReimbursable: boolean;

/** Flag indicating if the description is required */
isDescriptionRequired: boolean;
};

function MoneyRequestConfirmationListFooter({
Expand Down Expand Up @@ -258,6 +261,7 @@ function MoneyRequestConfirmationListFooter({
iouIsReimbursable,
onToggleReimbursable,
isReceiptEditable = false,
isDescriptionRequired = false,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB: Can we set up this flag within this components instead of taking a prop? Not a blocker because I assume that required adding a lot of additional useOnyx calls to this file.

}: MoneyRequestConfirmationListFooterProps) {
const styles = useThemeStyles();
const {translate, toLocaleDigit, localeCompare} = useLocalize();
Expand Down Expand Up @@ -455,6 +459,7 @@ function MoneyRequestConfirmationListFooter({
disabled={didConfirm}
interactive={!isReadOnly}
numberOfLinesTitle={2}
rightLabel={isDescriptionRequired ? translate('common.required') : ''}
/>
</MentionReportContext.Provider>
</ShowContextMenuContext.Provider>
Expand Down
8 changes: 8 additions & 0 deletions src/libs/CategoryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ function isCategoryMissing(category: string | undefined): boolean {
return emptyCategories.includes(category ?? '');
}

function isCategoryDescriptionRequired(policyCategories: PolicyCategories | undefined, category: string | undefined, areRulesEnabled: boolean | undefined): boolean {
if (!policyCategories || !category || !areRulesEnabled) {
return false;
}
return !!policyCategories[category]?.areCommentsRequired;
}

function getDecodedCategoryName(categoryName: string) {
return Str.htmlDecode(categoryName);
}
Expand All @@ -116,5 +123,6 @@ export {
updateCategoryInMccGroup,
getEnabledCategoriesCount,
isCategoryMissing,
isCategoryDescriptionRequired,
getDecodedCategoryName,
};
4 changes: 3 additions & 1 deletion src/pages/iou/SplitExpenseEditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import usePolicy from '@hooks/usePolicy';
import usePrevious from '@hooks/usePrevious';
import useThemeStyles from '@hooks/useThemeStyles';
import {removeSplitExpenseField, updateSplitExpenseField} from '@libs/actions/IOU';
import {getDecodedCategoryName} from '@libs/CategoryUtils';
import {getDecodedCategoryName, isCategoryDescriptionRequired} from '@libs/CategoryUtils';
import {convertToDisplayString} from '@libs/CurrencyUtils';
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import Navigation from '@libs/Navigation/Navigation';
Expand Down Expand Up @@ -71,6 +71,7 @@ function SplitExpenseEditPage({route}: SplitExpensePageProps) {

const isCategoryRequired = !!policy?.requiresCategory;
const reportName = getReportName(report, policy);
const isDescriptionRequired = isCategoryDescriptionRequired(policyCategories, splitExpenseDraftTransactionDetails?.category, policy?.areRulesEnabled);

const shouldShowTags = !!policy?.areTagsEnabled && !!(transactionTag || hasEnabledTags(policyTagLists));
const tagVisibility = useMemo(
Expand Down Expand Up @@ -118,6 +119,7 @@ function SplitExpenseEditPage({route}: SplitExpensePageProps) {
style={[styles.moneyRequestMenuItem]}
titleWrapperStyle={styles.flex1}
numberOfLinesTitle={2}
rightLabel={isDescriptionRequired ? translate('common.required') : ''}
/>
{shouldShowCategory && (
<MenuItemWithTopDescription
Expand Down
24 changes: 23 additions & 1 deletion src/pages/iou/request/step/IOURequestStepDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ import useAutoFocusInput from '@hooks/useAutoFocusInput';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import usePolicy from '@hooks/usePolicy';
import usePolicyForMovingExpenses from '@hooks/usePolicyForMovingExpenses';
import useRestartOnReceiptFailure from '@hooks/useRestartOnReceiptFailure';
import useShowNotFoundPageInIOUStep from '@hooks/useShowNotFoundPageInIOUStep';
import useThemeStyles from '@hooks/useThemeStyles';
import {isCategoryDescriptionRequired} from '@libs/CategoryUtils';
import {addErrorMessage} from '@libs/ErrorUtils';
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import {shouldUseTransactionDraft} from '@libs/IOUUtils';
import Navigation from '@libs/Navigation/Navigation';
import Parser from '@libs/Parser';
Expand Down Expand Up @@ -46,6 +49,7 @@ function IOURequestStepDescription({
const policy = usePolicy(report?.policyID);
const [splitDraftTransaction] = useOnyx(`${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${transactionID}`, {canBeMissing: true});
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${report?.policyID}`, {canBeMissing: true});

const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${report?.policyID}`, {canBeMissing: true});

const styles = useThemeStyles();
Expand All @@ -67,6 +71,20 @@ function IOURequestStepDescription({
const isSavedRef = useRef(false);
useRestartOnReceiptFailure(transaction, reportID, iouType, action);

const {policyForMovingExpensesID} = usePolicyForMovingExpenses();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this policy for moving expenses thing? Why don't we use the policy directly?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB: Oh I see, it's kind of a fall back. Still, I would like to learn more about why this is needed.


const [transactionDraft] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${getNonEmptyStringOnyxID(transaction?.transactionID)}`, {canBeMissing: true});

const movingExpensesPolicy = usePolicy(policyForMovingExpensesID);
const [movingExpensesPolicyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyForMovingExpensesID}`, {canBeMissing: true});

const isDescriptionRequired = useMemo(() => {
const categoriesToUse = policyCategories ?? movingExpensesPolicyCategories;
const policyToUse = policy ?? movingExpensesPolicy;

return isCategoryDescriptionRequired(categoriesToUse, transaction?.category ?? transactionDraft?.category, policyToUse?.areRulesEnabled);
}, [policyCategories, movingExpensesPolicyCategories, transaction?.category, transactionDraft?.category, policy, movingExpensesPolicy]);

/**
* @returns - An object containing the errors for each inputID
*/
Expand All @@ -82,9 +100,13 @@ function IOURequestStepDescription({
);
}

if (isDescriptionRequired && !values.moneyRequestComment) {
addErrorMessage(errors, INPUT_IDS.MONEY_REQUEST_COMMENT, translate('common.error.fieldRequired'));
}
Comment on lines +103 to +105

@gijoe0295 gijoe0295 May 25, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not block submission without required description to align with required category/tag cases. Only block when missing merchant. This was also C+ concern here #73725 (comment) that was not resolved.

See Slack discussion in this issue #88707 for details.


return errors;
},
[translate],
[isDescriptionRequired, translate],
);

const navigateBack = () => {
Expand Down
85 changes: 84 additions & 1 deletion tests/unit/CategoryUtilsTest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {isCategoryMissing} from '@libs/CategoryUtils';
import {isCategoryDescriptionRequired, isCategoryMissing} from '@libs/CategoryUtils';
import type {PolicyCategories} from '@src/types/onyx';

describe(`isMissingCategory`, () => {
it('returns true if category is undefined', () => {
Expand All @@ -19,3 +20,85 @@ describe(`isMissingCategory`, () => {
expect(isCategoryMissing('Meals')).toBe(false);
});
});

describe('isCategoryDescriptionRequired', () => {
const mockPolicyCategories: PolicyCategories = {
Travel: {
areCommentsRequired: true,
enabled: true,
name: 'Travel',
pendingAction: null,
},
Meals: {
areCommentsRequired: false,
enabled: true,
name: 'Meals',
pendingAction: null,
},
Office: {
areCommentsRequired: true,
enabled: false,
name: 'Office',
pendingAction: null,
},
};

it('returns false when policyCategories is undefined', () => {
expect(isCategoryDescriptionRequired(undefined, 'Travel', true)).toBe(false);
});

it('returns false when category is undefined', () => {
expect(isCategoryDescriptionRequired(mockPolicyCategories, undefined, true)).toBe(false);
});

it('returns false when category is empty string', () => {
expect(isCategoryDescriptionRequired(mockPolicyCategories, '', true)).toBe(false);
});

it('returns false when areRulesEnabled is undefined', () => {
expect(isCategoryDescriptionRequired(mockPolicyCategories, 'Travel', undefined)).toBe(false);
});

it('returns false when areRulesEnabled is false', () => {
expect(isCategoryDescriptionRequired(mockPolicyCategories, 'Travel', false)).toBe(false);
});

it('returns true when category has areCommentsRequired set to true and rules are enabled', () => {
expect(isCategoryDescriptionRequired(mockPolicyCategories, 'Travel', true)).toBe(true);
});

it('returns false when category has areCommentsRequired set to false even if rules are enabled', () => {
expect(isCategoryDescriptionRequired(mockPolicyCategories, 'Meals', true)).toBe(false);
});

it('returns true when category has areCommentsRequired set to true regardless of enabled status', () => {
expect(isCategoryDescriptionRequired(mockPolicyCategories, 'Office', true)).toBe(true);
});
Comment on lines +74 to +76

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB: The name of this test makes it sound like areRulesEnabled should be false, but it's true.


it('returns false when category does not exist in policyCategories', () => {
expect(isCategoryDescriptionRequired(mockPolicyCategories, 'NonExistentCategory', true)).toBe(false);
});

it('returns false when all parameters are valid but areCommentsRequired is falsy', () => {
const categoriesWithFalsyComments: PolicyCategories = {
TestCategory: {
areCommentsRequired: false,
enabled: true,
name: 'TestCategory',
pendingAction: null,
},
};
expect(isCategoryDescriptionRequired(categoriesWithFalsyComments, 'TestCategory', true)).toBe(false);
});

it('handles edge case with undefined areCommentsRequired', () => {
const categoriesWithUndefinedComments: PolicyCategories = {
TestCategory: {
enabled: true,
name: 'TestCategory',
pendingAction: null,
},
};
expect(isCategoryDescriptionRequired(categoriesWithUndefinedComments, 'TestCategory', true)).toBe(false);
});
});
Loading