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
17 changes: 6 additions & 11 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@
import INPUT_IDS from '@src/types/form/NewRoomForm';
import type {
Account,
DismissedProductTraining,
IntroSelected,
InvitedEmailsToAccountIDs,
NewGroupChatDraft,
Expand Down Expand Up @@ -280,7 +279,7 @@
let currentUserAccountID = -1;
let currentUserEmail: string | undefined;

Onyx.connect({

Check warning on line 282 in src/libs/actions/Report.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 @@ -293,13 +292,13 @@
},
});

Onyx.connect({

Check warning on line 295 in src/libs/actions/Report.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),
});

let preferredSkinTone: number = CONST.EMOJI_DEFAULT_SKIN_TONE;
Onyx.connect({

Check warning on line 301 in src/libs/actions/Report.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.PREFERRED_EMOJI_SKIN_TONE,
callback: (value) => {
preferredSkinTone = EmojiUtils.getPreferredSkinToneIndex(value);
Expand All @@ -309,7 +308,7 @@
// map of reportID to all reportActions for that report
const allReportActions: OnyxCollection<ReportActions> = {};

Onyx.connect({

Check warning on line 311 in src/libs/actions/Report.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,
callback: (actions, key) => {
if (!key || !actions) {
Expand All @@ -321,14 +320,14 @@
});

let allTransactionViolations: OnyxCollection<TransactionViolations> = {};
Onyx.connect({

Check warning on line 323 in src/libs/actions/Report.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.TRANSACTION_VIOLATIONS,
waitForCollectionCallback: true,
callback: (value) => (allTransactionViolations = value),
});

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

Check warning on line 330 in src/libs/actions/Report.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 @@ -338,7 +337,7 @@

let isNetworkOffline = false;
let networkStatus: NetworkStatus;
Onyx.connect({

Check warning on line 340 in src/libs/actions/Report.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: (value) => {
isNetworkOffline = value?.isOffline ?? false;
Expand All @@ -347,7 +346,7 @@
});

let allPersonalDetails: OnyxEntry<PersonalDetailsList> = {};
Onyx.connect({

Check warning on line 349 in src/libs/actions/Report.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) => {
allPersonalDetails = value ?? {};
Expand All @@ -355,7 +354,7 @@
});

let account: OnyxEntry<Account> = {};
Onyx.connect({

Check warning on line 357 in src/libs/actions/Report.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.ACCOUNT,
callback: (value) => {
account = value ?? {};
Expand All @@ -363,7 +362,7 @@
});

const draftNoteMap: OnyxCollection<string> = {};
Onyx.connect({

Check warning on line 365 in src/libs/actions/Report.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.PRIVATE_NOTES_DRAFT,
callback: (value, key) => {
if (!key) {
Expand Down Expand Up @@ -418,12 +417,6 @@
callback: (value) => (allReportDraftComments = value),
});

let nvpDismissedProductTraining: OnyxEntry<DismissedProductTraining>;
Onyx.connect({
key: ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING,
callback: (value) => (nvpDismissedProductTraining = value),
});

const allPolicies: OnyxCollection<Policy> = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.POLICY,
Expand Down Expand Up @@ -5673,8 +5666,8 @@
});
}

function navigateToTrainingModal(dismissedProductTrainingNVP: OnyxEntry<DismissedProductTraining>, reportID: string) {
if (dismissedProductTrainingNVP?.[CONST.CHANGE_POLICY_TRAINING_MODAL]) {
function navigateToTrainingModal(isChangePolicyTrainingModalDismissed: boolean, reportID: string) {
if (isChangePolicyTrainingModalDismissed) {
return;
}

Expand Down Expand Up @@ -5965,6 +5958,7 @@
accountID: number,
email: string,
hasViolationsParam: boolean,
isChangePolicyTrainingModalDismissed: boolean,
isASAPSubmitBetaEnabled: boolean,
reportNextStep?: ReportNextStep,
isReportLastVisibleArchived = false,
Expand Down Expand Up @@ -5994,7 +5988,7 @@

// If the dismissedProductTraining.changeReportModal is not set,
// navigate to CHANGE_POLICY_EDUCATIONAL and a backTo param for the report page.
navigateToTrainingModal(nvpDismissedProductTraining, report.reportID);
navigateToTrainingModal(isChangePolicyTrainingModalDismissed, report.reportID);
}

/**
Expand All @@ -6006,6 +6000,7 @@
accountID: number,
email: string,
hasViolationsParam: boolean,
isChangePolicyTrainingModalDismissed: boolean,
isASAPSubmitBetaEnabled: boolean,
employeeList: PolicyEmployeeList | undefined,
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'],
Expand Down Expand Up @@ -6069,7 +6064,7 @@

// If the dismissedProductTraining.changeReportModal is not set,
// navigate to CHANGE_POLICY_EDUCATIONAL and a backTo param for the report page.
navigateToTrainingModal(nvpDismissedProductTraining, report.reportID);
navigateToTrainingModal(isChangePolicyTrainingModalDismissed, report.reportID);
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/pages/ReportChangeWorkspacePage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {useCallback} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import {useSession} from '@components/OnyxListItemProvider';
Expand Down Expand Up @@ -31,12 +32,16 @@ import {
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';
import type {DismissedProductTraining} from '@src/types/onyx';
import NotFoundPage from './ErrorPage/NotFoundPage';
import type {WithReportOrNotFoundProps} from './home/report/withReportOrNotFound';
import withReportOrNotFound from './home/report/withReportOrNotFound';

type ReportChangeWorkspacePageProps = WithReportOrNotFoundProps & PlatformStackScreenProps<ReportChangeWorkspaceNavigatorParamList, typeof SCREENS.REPORT_CHANGE_WORKSPACE.ROOT>;

const changePolicyTrainingModalDismissedSelector = (nvpDismissedProductTraining: OnyxEntry<DismissedProductTraining>): boolean =>
!!nvpDismissedProductTraining?.[CONST.CHANGE_POLICY_TRAINING_MODAL];

function ReportChangeWorkspacePage({report, route}: ReportChangeWorkspacePageProps) {
const reportID = report?.reportID;
const {isOffline} = useNetwork();
Expand All @@ -46,6 +51,7 @@ function ReportChangeWorkspacePage({report, route}: ReportChangeWorkspacePagePro

const [policies, fetchStatus] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: false});
const [reportNextStep] = useOnyx(`${ONYXKEYS.COLLECTION.NEXT_STEP}${reportID}`, {canBeMissing: true});
const [isChangePolicyTrainingModalDismissed = false] = useOnyx(ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING, {canBeMissing: true, selector: changePolicyTrainingModalDismissedSelector});
const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: false});
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true});
const isReportLastVisibleArchived = useReportIsArchived(report?.parentReportID);
Expand Down Expand Up @@ -83,6 +89,7 @@ function ReportChangeWorkspacePage({report, route}: ReportChangeWorkspacePagePro
session?.accountID ?? CONST.DEFAULT_NUMBER_ID,
session?.email ?? '',
hasViolations,
isChangePolicyTrainingModalDismissed,
isASAPSubmitBetaEnabled,
employeeList,
formatPhoneNumber,
Expand All @@ -95,6 +102,7 @@ function ReportChangeWorkspacePage({report, route}: ReportChangeWorkspacePagePro
session?.accountID ?? CONST.DEFAULT_NUMBER_ID,
session?.email ?? '',
hasViolations,
isChangePolicyTrainingModalDismissed,
isASAPSubmitBetaEnabled,
reportNextStep,
isReportLastVisibleArchived,
Expand All @@ -113,6 +121,7 @@ function ReportChangeWorkspacePage({report, route}: ReportChangeWorkspacePagePro
hasViolations,
isASAPSubmitBetaEnabled,
reportNextStep,
isChangePolicyTrainingModalDismissed,
],
);

Expand Down
7 changes: 4 additions & 3 deletions tests/actions/ReportTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2069,7 +2069,7 @@ describe('actions/Report', () => {
await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${newPolicy.id}`, newPolicy);

// When moving to another workspace
Report.changeReportPolicy(expenseReport, newPolicy, 1, '', true, false);
Report.changeReportPolicy(expenseReport, newPolicy, 1, '', true, false, false);
await waitForBatchedUpdates();

// Then the expense report should not be archived anymore
Expand Down Expand Up @@ -2112,7 +2112,7 @@ describe('actions/Report', () => {
await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${newPolicy.id}`, newPolicy);

// When moving to another workspace
Report.changeReportPolicy(expenseReport, newPolicy, 1, '', false, false);
Report.changeReportPolicy(expenseReport, newPolicy, 1, '', false, false, false);
await waitForBatchedUpdates();

// Then the expense report chatReportID and parentReportID should be updated to the new expense chat reportID
Expand Down Expand Up @@ -2159,6 +2159,7 @@ describe('actions/Report', () => {
'',
true,
false,
false,
{
[adminEmail]: {role: CONST.POLICY.ROLE.ADMIN},
},
Expand Down Expand Up @@ -2238,7 +2239,7 @@ describe('actions/Report', () => {
await waitForBatchedUpdates();

// Call changeReportPolicyAndInviteSubmitter
Report.changeReportPolicyAndInviteSubmitter(expenseReport, newPolicy, 1, '', true, false, employeeList, TestHelper.formatPhoneNumber, false);
Report.changeReportPolicyAndInviteSubmitter(expenseReport, newPolicy, 1, '', true, false, false, employeeList, TestHelper.formatPhoneNumber, false);
await waitForBatchedUpdates();

// Simulate network failure
Expand Down
Loading