Skip to content
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

feat: [Auth Violations] Support isDismissed on newDot to hide violations. #54455

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6463ecf
feat: [Auth Violations] Support isDismissed on newDot to hide violati…
Krishna2323 Dec 23, 2024
6166bb7
Merge branch 'main' into krishna2323/issue/53398
Krishna2323 Jan 5, 2025
2a179a2
fix eslint.
Krishna2323 Jan 5, 2025
cd59a56
fix eslint.
Krishna2323 Jan 5, 2025
5682ae0
fix eslint.
Krishna2323 Jan 5, 2025
1016065
fix eslint.
Krishna2323 Jan 6, 2025
a2d0da6
fix ESLint.
Krishna2323 Jan 6, 2025
ee414e3
fix ESLint.
Krishna2323 Jan 6, 2025
82877a6
Merge branch 'Expensify:main' into krishna2323/issue/53398
Krishna2323 Jan 9, 2025
18f9c6f
fix ESlint issues.
Krishna2323 Jan 9, 2025
40c5559
fix ESlint issues.
Krishna2323 Jan 9, 2025
3f4dd02
Merge branch 'main' into krishna2323/issue/53398
Krishna2323 Jan 13, 2025
7eb5639
Merge branch 'Expensify:main' into krishna2323/issue/53398
Krishna2323 Jan 14, 2025
593f497
fix ESlint.
Krishna2323 Jan 15, 2025
825c4be
fix ESlint.
Krishna2323 Jan 15, 2025
969623b
Merge branch 'main' into krishna2323/issue/53398
Krishna2323 Jan 15, 2025
486acb5
revert unnecessary changes.
Krishna2323 Jan 15, 2025
0a0cbc3
fix ESLint.
Krishna2323 Jan 15, 2025
55f73fa
fix ESLint.
Krishna2323 Jan 15, 2025
a5194c8
minor update.
Krishna2323 Jan 15, 2025
332efdf
fix merge conflicts.
Krishna2323 Jan 16, 2025
1ef4be5
minor import fix.
Krishna2323 Jan 16, 2025
afe362c
Merge branch 'main' into krishna2323/issue/53398
Krishna2323 Jan 16, 2025
6abedea
remove duplicate imports.
Krishna2323 Jan 16, 2025
05747b2
minor fix.
Krishna2323 Jan 16, 2025
d870956
fix typescript issue.
Krishna2323 Jan 16, 2025
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
13 changes: 8 additions & 5 deletions src/components/BrokenConnectionDescription.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import React from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import {isInstantSubmitEnabled, isPolicyAdmin as isPolicyAdminPolicyUtils} from '@libs/PolicyUtils';
import {isCurrentUserSubmitter, isProcessingReport, isReportApproved, isReportManuallyReimbursed} from '@libs/ReportUtils';
import {getTransactionViolations} from '@libs/TransactionUtils';
import Navigation from '@navigation/Navigation';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Policy, Report} from '@src/types/onyx';
import TextLink from './TextLink';

type BrokenConnectionDescriptionProps = {
/** Transaction id of the corresponding report */
transactionID: string | undefined;

/** Current report */
report: OnyxEntry<Report>;

Expand All @@ -26,7 +24,7 @@ type BrokenConnectionDescriptionProps = {
function BrokenConnectionDescription({transactionID, policy, report}: BrokenConnectionDescriptionProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const [transactionViolations] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID ?? CONST.DEFAULT_NUMBER_ID}`);
const transactionViolations = getTransactionViolations(transactionID);

const brokenConnection530Error = transactionViolations?.find((violation) => violation.data?.rterType === CONST.RTER_VIOLATION_TYPES.BROKEN_CARD_CONNECTION_530);
const brokenConnectionError = transactionViolations?.find((violation) => violation.data?.rterType === CONST.RTER_VIOLATION_TYPES.BROKEN_CARD_CONNECTION);
Expand All @@ -46,7 +44,12 @@ function BrokenConnectionDescription({transactionID, policy, report}: BrokenConn
{`${translate('violations.adminBrokenConnectionError')}`}
<TextLink
style={[styles.textLabelSupporting, styles.link]}
onPress={() => Navigation.navigate(ROUTES.WORKSPACE_COMPANY_CARDS.getRoute(policy?.id))}
onPress={() => {
if (!policy?.id) {
return;
}
Navigation.navigate(ROUTES.WORKSPACE_COMPANY_CARDS.getRoute(policy?.id));
}}
>{`${translate('workspace.common.companyCards')}`}</TextLink>
.
</>
Expand Down
17 changes: 8 additions & 9 deletions src/components/MoneyRequestHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import {markAsCash as markAsCashUtil} from '@libs/actions/Transaction';
import Navigation from '@libs/Navigation/Navigation';
import {isPolicyAdmin} from '@libs/PolicyUtils';
import {getOriginalMessage, isMoneyRequestAction} from '@libs/ReportActionsUtils';
Expand All @@ -17,15 +18,14 @@ import {
getTransactionViolations,
hasPendingRTERViolation,
hasReceipt,
isDuplicate as isDuplicateTransactionUtils,
isDuplicate as isDuplicateUtil,
isExpensifyCardTransaction,
isOnHold as isOnHoldTransactionUtils,
isOnHold as isOnHoldUtil,
isPending,
isReceiptBeingScanned,
shouldShowBrokenConnectionViolation as shouldShowBrokenConnectionViolationTransactionUtils,
} from '@libs/TransactionUtils';
import variables from '@styles/variables';
import {markAsCash as markAsCashAction} from '@userActions/Transaction';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
Expand Down Expand Up @@ -60,20 +60,19 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
const {shouldUseNarrowLayout, isSmallScreenWidth} = useResponsiveLayout();
const route = useRoute();
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`);
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID ?? CONST.DEFAULT_NUMBER_ID}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Let us use || instead of ?? as that will help address empty strings as well.

const [transaction] = useOnyx(
`${ONYXKEYS.COLLECTION.TRANSACTION}${
isMoneyRequestAction(parentReportAction) ? getOriginalMessage(parentReportAction)?.IOUTransactionID ?? CONST.DEFAULT_NUMBER_ID : CONST.DEFAULT_NUMBER_ID
}`,
);
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS);
const [dismissedHoldUseExplanation, dismissedHoldUseExplanationResult] = useOnyx(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION, {initialValue: true});
const isLoadingHoldUseExplained = isLoadingOnyxValue(dismissedHoldUseExplanationResult);
const styles = useThemeStyles();
const theme = useTheme();
const {translate} = useLocalize();
const isOnHold = isOnHoldTransactionUtils(transaction);
const isDuplicate = isDuplicateTransactionUtils(transaction?.transactionID);
const isOnHold = isOnHoldUtil(transaction);
const isDuplicate = isDuplicateUtil(transaction?.transactionID);
const reportID = report?.reportID;

const isReportInRHP = route.name === SCREENS.SEARCH.REPORT_RHP;
Expand All @@ -86,7 +85,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
const shouldShowMarkAsCashButton = hasAllPendingRTERViolations || (shouldShowBrokenConnectionViolation && (!isPolicyAdmin(policy) || isCurrentUserSubmitter(parentReport?.reportID)));

const markAsCash = useCallback(() => {
markAsCashAction(transaction?.transactionID, reportID);
markAsCashUtil(transaction?.transactionID, reportID);
}, [reportID, transaction?.transactionID]);

const isScanning = hasReceipt(transaction) && isReceiptBeingScanned(transaction);
Expand Down Expand Up @@ -120,7 +119,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
),
};
}
if (hasPendingRTERViolation(getTransactionViolations(transaction?.transactionID, transactionViolations))) {
if (hasPendingRTERViolation(getTransactionViolations(transaction?.transactionID))) {
return {icon: getStatusIcon(Expensicons.Hourglass), description: translate('iou.pendingMatchWithCreditCardDescription')};
}
if (isScanning) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ function MoneyRequestPreviewContent({
const transactionID = isMoneyRequestAction ? getOriginalMessage(action)?.IOUTransactionID : undefined;
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`);
const [walletTerms] = useOnyx(ONYXKEYS.WALLET_TERMS);
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS);
const [allViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS);
const transactionViolations = getTransactionViolations(transaction?.transactionID);

const sessionAccountID = session?.accountID;
const managerID = iouReport?.managerID ?? CONST.DEFAULT_NUMBER_ID;
Expand Down Expand Up @@ -143,9 +144,9 @@ function MoneyRequestPreviewContent({
const isOnHold = isOnHoldTransactionUtils(transaction);
const isSettlementOrApprovalPartial = !!iouReport?.pendingFields?.partial;
const isPartialHold = isSettlementOrApprovalPartial && isOnHold;
const hasViolations = hasViolationTransactionUtils(transaction?.transactionID, transactionViolations, true);
const hasNoticeTypeViolations = hasNoticeTypeViolationTransactionUtils(transaction?.transactionID, transactionViolations, true) && isPaidGroupPolicy(iouReport);
const hasWarningTypeViolations = hasWarningTypeViolationTransactionUtils(transaction?.transactionID, transactionViolations, true);
const hasViolations = hasViolationTransactionUtils(transaction?.transactionID, allViolations, true);
const hasNoticeTypeViolations = hasNoticeTypeViolationTransactionUtils(transaction?.transactionID, allViolations, true) && isPaidGroupPolicy(iouReport);
const hasWarningTypeViolations = hasWarningTypeViolationTransactionUtils(transaction?.transactionID, allViolations, true);
const hasFieldErrors = hasMissingSmartscanFields(transaction);
const isDistanceRequest = isDistanceRequestTransactionUtils(transaction);
const isFetchingWaypointsFromServer = isFetchingWaypointsFromServerTransactionUtils(transaction);
Expand All @@ -160,11 +161,8 @@ function MoneyRequestPreviewContent({

// Get transaction violations for given transaction id from onyx, find duplicated transactions violations and get duplicates
const allDuplicates = useMemo(
() =>
transactionViolations?.[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction?.transactionID}`]?.find(
(violation) => violation.name === CONST.VIOLATIONS.DUPLICATED_TRANSACTION,
)?.data?.duplicates ?? [],
[transaction?.transactionID, transactionViolations],
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we have to keep transactionID as dependency so that allDuplicates can be updated when it becomes available? Also, I think we can remove transactionViolations and use getTransactionViolations directly.

() => transactionViolations?.find((violation) => violation.name === CONST.VIOLATIONS.DUPLICATED_TRANSACTION)?.data?.duplicates ?? [],
[transactionViolations],
);

// Remove settled transactions from duplicates
Expand Down Expand Up @@ -235,7 +233,7 @@ function MoneyRequestPreviewContent({
}

if (shouldShowRBR && transaction) {
const violations = getTransactionViolations(transaction.transactionID, transactionViolations);
const violations = getTransactionViolations(transaction.transactionID);
if (shouldShowHoldMessage) {
return `${message} ${CONST.DOT_SEPARATOR} ${translate('violations.hold')}`;
}
Expand Down Expand Up @@ -282,7 +280,7 @@ function MoneyRequestPreviewContent({
if (shouldShowBrokenConnectionViolation(transaction ? [transaction.transactionID] : [], iouReport, policy)) {
return {shouldShow: true, messageIcon: Expensicons.Hourglass, messageDescription: translate('violations.brokenConnection530Error')};
}
if (hasPendingUI(transaction, getTransactionViolations(transaction?.transactionID, transactionViolations))) {
if (hasPendingUI(transaction, getTransactionViolations(transaction?.transactionID))) {
return {shouldShow: true, messageIcon: Expensicons.Hourglass, messageDescription: translate('iou.pendingMatchWithCreditCard')};
}
return {shouldShow: false};
Expand Down
Loading
Loading