Repository navigation
72031 fix required description by category #73725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d03429d
b3d7c6c
b9d9aec
bfceb31
9cc0dd7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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'; | ||
|
|
@@ -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(); | ||
|
|
@@ -67,6 +71,20 @@ function IOURequestStepDescription({ | |
| const isSavedRef = useRef(false); | ||
| useRestartOnReceiptFailure(transaction, reportID, iouType, action); | ||
|
|
||
| const {policyForMovingExpensesID} = usePolicyForMovingExpenses(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| */ | ||
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = () => { | ||
|
|
||
| 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', () => { | ||
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NAB: The name of this test makes it sound like |
||
|
|
||
| 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); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
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.