Repository navigation
feat: add ability to require attendees based on category selection (rework) #79050
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
62314b5
9509674
97d5baf
8de058d
7c8a863
5e6c0a5
4e8a274
452b3bb
f67c42e
1bba24d
cf2e0fb
c869695
586e011
8f17f9e
30dce16
3c44ad3
d5c78e7
c6c68e0
29da283
f8f7196
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 |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ import { | |
| setMoneyRequestTaxRate, | ||
| setSplitShares, | ||
| } from '@libs/actions/IOU'; | ||
| import {getIsMissingAttendeesViolation} from '@libs/AttendeeUtils'; | ||
| import {isCategoryDescriptionRequired} from '@libs/CategoryUtils'; | ||
| import {convertToBackendAmount, convertToDisplayString, convertToDisplayStringWithoutCurrency, getCurrencyDecimals} from '@libs/CurrencyUtils'; | ||
| import DistanceRequestUtils from '@libs/DistanceRequestUtils'; | ||
|
|
@@ -433,11 +434,20 @@ function MoneyRequestConfirmationList({ | |
| setFormError('iou.receiptScanningFailed'); | ||
| return; | ||
| } | ||
| // reset the form error whenever the screen gains or loses focus | ||
| setFormError(''); | ||
|
|
||
| // Reset the form error whenever the screen gains or loses focus | ||
| // but preserve violation-related errors since those represent real validation issues | ||
| // that can only be fixed by changing the underlying data | ||
| if (!formError.startsWith(CONST.VIOLATIONS_PREFIX)) { | ||
| setFormError(''); | ||
| return; | ||
| } | ||
| // Clear missingAttendees violation if user fixed it by changing category or attendees | ||
| const isMissingAttendeesViolation = getIsMissingAttendeesViolation(policyCategories, iouCategory, iouAttendees, currentUserPersonalDetails, policy?.isAttendeeTrackingEnabled); | ||
|
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.
|
||
| if (formError === 'violations.missingAttendees' && !isMissingAttendeesViolation) { | ||
| setFormError(''); | ||
| } | ||
|
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. reverting the above change fixed the problem with the persistent error #79902 |
||
| // eslint-disable-next-line react-hooks/exhaustive-deps -- we don't want this effect to run if it's just setFormError that changes | ||
| }, [isFocused, shouldDisplayFieldError, hasSmartScanFailed, didConfirmSplit]); | ||
| }, [isFocused, shouldDisplayFieldError, hasSmartScanFailed, didConfirmSplit, iouCategory, iouAttendees, policyCategories, currentUserPersonalDetails, policy?.isAttendeeTrackingEnabled]); | ||
|
|
||
| useEffect(() => { | ||
| // We want this effect to run only when the transaction is moving from Self DM to a expense chat | ||
|
|
@@ -928,6 +938,15 @@ function MoneyRequestConfirmationList({ | |
| return; | ||
| } | ||
|
|
||
| // Since invoices are not expense reports that need attendee tracking, this validation should not apply to invoices | ||
| const isMissingAttendeesViolation = | ||
| iouType !== CONST.IOU.TYPE.INVOICE && | ||
| getIsMissingAttendeesViolation(policyCategories, iouCategory, iouAttendees, currentUserPersonalDetails, policy?.isAttendeeTrackingEnabled); | ||
| if (isMissingAttendeesViolation) { | ||
| setFormError('violations.missingAttendees'); | ||
| return; | ||
| } | ||
|
|
||
| if (isPerDiemRequest && (transaction.comment?.customUnit?.subRates ?? []).length === 0) { | ||
| setFormError('iou.error.invalidSubrateLength'); | ||
| return; | ||
|
|
@@ -1001,6 +1020,8 @@ function MoneyRequestConfirmationList({ | |
| showDelegateNoAccessModal, | ||
| iouCategory, | ||
| policyCategories, | ||
| iouAttendees, | ||
| currentUserPersonalDetails, | ||
| ], | ||
| ); | ||
|
|
||
|
|
@@ -1024,6 +1045,10 @@ function MoneyRequestConfirmationList({ | |
| if (isTypeSplit && !shouldShowReadOnlySplits) { | ||
| return debouncedFormError && translate(debouncedFormError); | ||
| } | ||
| // Don't show error at the bottom of the form for missing attendees | ||
| if (formError === 'violations.missingAttendees') { | ||
| return; | ||
| } | ||
| return formError && translate(formError); | ||
| }, [routeError, isTypeSplit, shouldShowReadOnlySplits, debouncedFormError, formError, translate]); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ import useTheme from '@hooks/useTheme'; | |
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import type {TransactionPreviewData} from '@libs/actions/Search'; | ||
| import {handleActionButtonPress as handleActionButtonPressUtil} from '@libs/actions/Search'; | ||
| import {syncMissingAttendeesViolation} from '@libs/AttendeeUtils'; | ||
| import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID'; | ||
| import {isViolationDismissed, mergeProhibitedViolations, shouldShowViolation} from '@libs/TransactionUtils'; | ||
| import variables from '@styles/variables'; | ||
|
|
@@ -29,7 +30,6 @@ import ONYXKEYS from '@src/ONYXKEYS'; | |
| import {isActionLoadingSelector} from '@src/selectors/ReportMetaData'; | ||
| import type {Policy, Report, ReportAction, ReportActions} from '@src/types/onyx'; | ||
| import type {TransactionViolation} from '@src/types/onyx/TransactionViolation'; | ||
| import {isEmptyObject} from '@src/types/utils/EmptyObject'; | ||
| import UserInfoAndActionButtonRow from './UserInfoAndActionButtonRow'; | ||
|
|
||
| function TransactionListItem<TItem extends ListItem>({ | ||
|
|
@@ -63,14 +63,27 @@ function TransactionListItem<TItem extends ListItem>({ | |
|
|
||
| const [isActionLoading] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${transactionItem.reportID}`, {canBeMissing: true, selector: isActionLoadingSelector}); | ||
|
|
||
| // Use active policy (user's current workspace) as fallback for self DM tracking expenses | ||
| // This matches MoneyRequestView's approach via usePolicyForMovingExpenses() | ||
| const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: true}); | ||
| // Use report's policyID as fallback when transaction doesn't have policyID directly | ||
| // Use active policy as final fallback for SelfDM (tracking expenses) | ||
| // NOTE: Using || instead of ?? to treat empty string "" as falsy | ||
| // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing | ||
| const policyID = transactionItem.policyID || snapshotReport?.policyID || activePolicyID; | ||
| const [parentPolicy] = originalUseOnyx(ONYXKEYS.COLLECTION.POLICY, { | ||
| canBeMissing: true, | ||
| selector: (policy) => policy?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`], | ||
| }); | ||
| const snapshotPolicy = useMemo(() => { | ||
| return (snapshot?.data?.[`${ONYXKEYS.COLLECTION.POLICY}${transactionItem.policyID}`] ?? {}) as Policy; | ||
| }, [snapshot, transactionItem.policyID]); | ||
| return (snapshot?.data?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`] ?? {}) as Policy; | ||
| }, [snapshot, policyID]); | ||
| // Fetch policy categories directly from Onyx since they are not included in the search snapshot | ||
| const [policyCategories] = originalUseOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${getNonEmptyStringOnyxID(policyID)}`, {canBeMissing: true}); | ||
| const [lastPaymentMethod] = useOnyx(`${ONYXKEYS.NVP_LAST_PAYMENT_METHOD}`, {canBeMissing: true}); | ||
| const [personalPolicyID] = useOnyx(ONYXKEYS.PERSONAL_POLICY_ID, {canBeMissing: true}); | ||
|
|
||
| const [parentReport] = originalUseOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(transactionItem.reportID)}`, {canBeMissing: true}); | ||
| const [parentPolicy] = originalUseOnyx(`${ONYXKEYS.COLLECTION.POLICY}${getNonEmptyStringOnyxID(transactionItem.policyID)}`, {canBeMissing: true}); | ||
| const [transactionThreadReport] = originalUseOnyx(`${ONYXKEYS.COLLECTION.REPORT}${transactionItem?.reportAction?.childReportID}`, {canBeMissing: true}); | ||
| const [transaction] = originalUseOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${getNonEmptyStringOnyxID(transactionItem.transactionID)}`, {canBeMissing: true}); | ||
| const parentReportActionSelector = useCallback( | ||
|
|
@@ -122,20 +135,34 @@ function TransactionListItem<TItem extends ListItem>({ | |
| transactionItem.shouldShowYearExported, | ||
| ]); | ||
|
|
||
| // Use parentReport/parentPolicy as fallbacks when snapshotReport/snapshotPolicy are empty | ||
| // to fix offline issues where newly created reports aren't in the search snapshot yet | ||
| const reportForViolations = isEmptyObject(snapshotReport) ? parentReport : snapshotReport; | ||
| const policyForViolations = isEmptyObject(snapshotPolicy) ? parentPolicy : snapshotPolicy; | ||
| // Prefer live Onyx policy data over snapshot to ensure fresh policy settings | ||
| // like isAttendeeTrackingEnabled is not missing | ||
| // Use snapshotReport/snapshotPolicy as fallbacks to fix offline issues where | ||
| // newly created reports aren't in the search snapshot yet | ||
| const policyForViolations = parentPolicy ?? snapshotPolicy; | ||
| const reportForViolations = parentReport ?? snapshotReport; | ||
|
|
||
| const transactionViolations = useMemo(() => { | ||
| return mergeProhibitedViolations( | ||
| (violations?.[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionItem.transactionID}`] ?? []).filter( | ||
| (violation: TransactionViolation) => | ||
| !isViolationDismissed(transactionItem, violation, currentUserDetails.email ?? '', currentUserDetails.accountID, reportForViolations, policyForViolations) && | ||
| shouldShowViolation(reportForViolations, policyForViolations, violation.name, currentUserDetails.email ?? '', false, transactionItem), | ||
| ), | ||
| const onyxViolations = (violations?.[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionItem.transactionID}`] ?? []).filter( | ||
| (violation: TransactionViolation) => | ||
| !isViolationDismissed(transactionItem, violation, currentUserDetails.email ?? '', currentUserDetails.accountID, reportForViolations, policyForViolations) && | ||
| shouldShowViolation(reportForViolations, policyForViolations, violation.name, currentUserDetails.email ?? '', false, transactionItem), | ||
| ); | ||
|
|
||
| // Sync missingAttendees violation with current policy category settings (can be removed later when BE handles this) | ||
| // Use live transaction data (attendees, category) to ensure we check against current state, not stale snapshot | ||
| const attendeeOnyxViolations = syncMissingAttendeesViolation( | ||
| onyxViolations, | ||
| policyCategories, | ||
| transaction?.category ?? transactionItem.category ?? '', | ||
| transaction?.comment?.attendees ?? transactionItem.attendees, | ||
|
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.
|
||
| currentUserDetails, | ||
| policyForViolations?.isAttendeeTrackingEnabled ?? false, | ||
| policyForViolations?.type === CONST.POLICY.TYPE.CORPORATE, | ||
| ); | ||
| }, [policyForViolations, reportForViolations, transactionItem, violations, currentUserDetails.email, currentUserDetails.accountID]); | ||
|
|
||
| return mergeProhibitedViolations(attendeeOnyxViolations); | ||
| }, [policyForViolations, reportForViolations, policyCategories, transactionItem, currentUserDetails, violations]); | ||
|
|
||
| const {isDelegateAccessRestricted, showDelegateNoAccessModal} = useContext(DelegateNoAccessContext); | ||
|
|
||
|
|
||
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: Is the trailing period in VIOLATIONS_PREFIX intentional?
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.
Yes, it was either adding it in component like
'${CONST. VIOLATIONS_PREFIX}.'or having it include the dot as part of the constant - this made more sense at the time 😃