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
11 changes: 0 additions & 11 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
type MemberChangeMessageElement = MessageTextElement | MemberChangeMessageUserMentionElement | MemberChangeMessageRoomReferenceElement;

let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 60 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand All @@ -69,7 +69,7 @@
});

let allReports: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 72 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -78,14 +78,14 @@
});

let isNetworkOffline = false;
Onyx.connect({

Check warning on line 81 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NETWORK,
callback: (val) => (isNetworkOffline = val?.isOffline ?? false),
});

let currentUserAccountID: number | undefined;
let currentEmail = '';
Onyx.connect({

Check warning on line 88 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, value is undefined
Expand All @@ -99,7 +99,7 @@
});

let privatePersonalDetails: PrivatePersonalDetails | undefined;
Onyx.connect({

Check warning on line 102 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
callback: (personalDetails) => {
privatePersonalDetails = personalDetails;
Expand Down Expand Up @@ -3071,16 +3071,6 @@
return !wasByCurrentUser && wasCreatedOffline && !(action.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD || action.isOptimisticAction);
}

function getReportActionFromExpensifyCard(cardID: number) {
return Object.values(allReportActions ?? {})
.map((reportActions) => Object.values(reportActions ?? {}))
.flat()
.find((reportAction) => {
const cardIssuedActionOriginalMessage = isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.CARD_ISSUED_VIRTUAL) ? getOriginalMessage(reportAction) : undefined;
return cardIssuedActionOriginalMessage?.cardID === cardID;
});
}

function getIntegrationSyncFailedMessage(action: OnyxEntry<ReportAction>, policyID?: string, shouldShowOldDotLink = false): string {
const {label, errorMessage} = getOriginalMessage(action as ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.INTEGRATION_SYNC_FAILED>) ?? {label: '', errorMessage: ''};

Expand Down Expand Up @@ -3283,7 +3273,6 @@
getReopenedMessage,
getLeaveRoomMessage,
getRetractedMessage,
getReportActionFromExpensifyCard,
isReopenedAction,
isRetractedAction,
getIntegrationSyncFailedMessage,
Expand Down
13 changes: 0 additions & 13 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@
const parsedReportActionMessageCache: Record<string, string> = {};

let conciergeReportID: OnyxEntry<string>;
Onyx.connect({

Check warning on line 925 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.CONCIERGE_REPORT_ID,
callback: (value) => {
conciergeReportID = value;
Expand All @@ -930,7 +930,7 @@
});

const defaultAvatarBuildingIconTestID = 'SvgDefaultAvatarBuilding Icon';
Onyx.connect({

Check warning on line 933 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, val is undefined
Expand All @@ -948,7 +948,7 @@
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
let allPersonalDetailLogins: string[];
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({

Check warning on line 951 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
if (currentUserAccountID) {
Expand All @@ -960,14 +960,14 @@
});

let allReportsDraft: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 963 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_DRAFT,
waitForCollectionCallback: true,
callback: (value) => (allReportsDraft = value),
});

let allPolicies: OnyxCollection<Policy>;
Onyx.connect({

Check warning on line 970 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => (allPolicies = value),
Expand Down Expand Up @@ -11470,18 +11470,6 @@
};
}

function findReportIDForAction(action?: ReportAction): string | undefined {
if (!allReportActions || !action?.reportActionID) {
return undefined;
}

return Object.keys(allReportActions)
.find((reportActionsKey) => {
const reportActions = allReportActions?.[reportActionsKey];
return !!reportActions && !isEmptyObject(reportActions[action.reportActionID]);
})
?.replace(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}`, '');
}
function canRejectReportAction(report: Report, policy?: Policy): boolean {
if (!Permissions.isBetaEnabled(CONST.BETAS.NEWDOT_REJECT, allBetas)) {
return false;
Expand Down Expand Up @@ -12109,7 +12097,6 @@
generateReportAttributes,
getReportPersonalDetailsParticipants,
isAllowedToSubmitDraftExpenseReport,
findReportIDForAction,
isWorkspaceEligibleForReportChange,
pushTransactionViolationsOnyxData,
navigateOnDeleteExpense,
Expand Down
26 changes: 0 additions & 26 deletions src/libs/actions/Card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import {READ_COMMANDS, SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs
import * as ErrorUtils from '@libs/ErrorUtils';
import * as NetworkStore from '@libs/Network/NetworkStore';
import * as PolicyUtils from '@libs/PolicyUtils';
import {getReportActionFromExpensifyCard} from '@libs/ReportActionsUtils';
import {findReportIDForAction} from '@libs/ReportUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Card, CompanyCardFeed} from '@src/types/onyx';
Expand Down Expand Up @@ -634,8 +632,6 @@ function updateExpensifyCardLimitType(workspaceAccountID: number, cardID: number
function deactivateCard(workspaceAccountID: number, card?: Card) {
const authToken = NetworkStore.getAuthToken();
const cardID = card?.cardID ?? CONST.DEFAULT_NUMBER_ID;
const reportAction = getReportActionFromExpensifyCard(cardID);
const reportID = findReportIDForAction(reportAction) ?? reportAction?.reportID;

if (!authToken) {
return;
Expand Down Expand Up @@ -681,28 +677,6 @@ function deactivateCard(workspaceAccountID: number, card?: Card) {
},
];

if (reportAction?.reportActionID && reportID) {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
value: {
[reportAction.reportActionID]: {
...reportAction,
originalMessage: {
cardID: null,
},
},
},
});
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportAction.reportID}`,
value: {
[reportAction.reportActionID]: reportAction,
},
});
}

const parameters: CardDeactivateParams = {
authToken,
cardID,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useCallback, useEffect, useState} from 'react';
import {View} from 'react-native';
import {InteractionManager, View} from 'react-native';
import ExpensifyCardImage from '@assets/images/expensify-card.svg';
import Badge from '@components/Badge';
import ConfirmModal from '@components/ConfirmModal';
Expand Down Expand Up @@ -57,7 +57,6 @@ function WorkspaceExpensifyCardDetailsPage({route}: WorkspaceExpensifyCardDetail
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
const {isSmallScreenWidth} = useResponsiveLayout();
const styles = useThemeStyles();
const [isDeleted, setIsDeleted] = useState(false);

const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {canBeMissing: false});
const [cardFeeds] = useCardFeeds(policyID);
Expand All @@ -79,24 +78,15 @@ function WorkspaceExpensifyCardDetailsPage({route}: WorkspaceExpensifyCardDetail
openCardDetailsPage(Number(cardID));
}, [cardID]);

useEffect(() => {
if (!isDeleted) {
return;
}
return () => {
deactivateCardAction(defaultFundID, card);
};
}, [isDeleted, defaultFundID, card]);

const {isOffline} = useNetwork({onReconnect: fetchCardDetails});

useEffect(() => fetchCardDetails(), [fetchCardDetails]);

const deactivateCard = () => {
setIsDeleted(true);
setIsDeactivateModalVisible(false);
requestAnimationFrame(() => {
Navigation.goBack();
Navigation.goBack();
InteractionManager.runAfterInteractions(() => {
deactivateCardAction(defaultFundID, card);
});
};

Expand Down
Loading