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

Login via deeplink should open modal in request money #31529

Merged
Changes from 3 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
45 changes: 42 additions & 3 deletions src/pages/EditRequestPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@ import lodashValues from 'lodash/values';
import PropTypes from 'prop-types';
import React, {useEffect, useMemo} from 'react';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
import categoryPropTypes from '@components/categoryPropTypes';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import ScreenWrapper from '@components/ScreenWrapper';
import tagPropTypes from '@components/tagPropTypes';
import transactionPropTypes from '@components/transactionPropTypes';
import withWindowDimensions from '@components/withWindowDimensions';
import compose from '@libs/compose';
import * as CurrencyUtils from '@libs/CurrencyUtils';
import Navigation from '@libs/Navigation/Navigation';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import * as PolicyUtils from '@libs/PolicyUtils';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as ReportUtils from '@libs/ReportUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
import * as IOU from '@userActions/IOU';
import * as Report from '@userActions/Report';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
Expand Down Expand Up @@ -61,6 +66,12 @@ const propTypes = {

/** Transaction that stores the request data */
transaction: transactionPropTypes,

/** Indicates whether the app is loading initial data */
isLoadingReportData: PropTypes.bool,

/** Is the window width narrow, like on a mobile device */
isSmallScreenWidth: PropTypes.bool.isRequired,
};

const defaultProps = {
Expand All @@ -70,11 +81,19 @@ const defaultProps = {
policyTags: {},
parentReportActions: {},
transaction: {},
isLoadingReportData: true,
};

function EditRequestPage({report, route, parentReport, policyCategories, policyTags, parentReportActions, transaction}) {
function EditRequestPage({report, route, parentReport, policyCategories, policyTags, parentReportActions, transaction, isLoadingReportData, isSmallScreenWidth}) {
const parentReportActionID = lodashGet(report, 'parentReportActionID', '0');
const parentReportAction = lodashGet(parentReportActions, parentReportActionID, {});
const parentReportID = lodashGet(report, 'parentReportID', '0');

const isTransactionLoadingRoute = lodashGet(transaction, 'comment.isLoading', false);
const isTransactionLoading = lodashGet(transaction, 'isLoading', false);

const isDataLoading = isLoadingReportData || isTransactionLoading || isTransactionLoadingRoute || _.isEmpty(transaction);
Copy link
Contributor

Choose a reason for hiding this comment

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

For checking if reportData is loaded, is it possible to use WithReportOrNotFound? So that we re-use existing functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we use WithReportOrNotFound, we will show two loading pages one in HOC, and one on this page when OpenReport API is called that will make this page is flickered briefly.


const {
amount: transactionAmount,
currency: transactionCurrency,
Expand Down Expand Up @@ -104,18 +123,34 @@ function EditRequestPage({report, route, parentReport, policyCategories, policyT
// A flag for showing the tags page
const shouldShowTags = isPolicyExpenseChat && (transactionTag || OptionsListUtils.hasEnabledOptions(lodashValues(policyTagList)));

const reportAction = ReportActionsUtils.getReportAction(parentReportID, parentReportActionID);

// For small screen, we don't call openReport API when we go to a sub report page by deeplink
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Where are we calling openReport API separately for big screens?
  2. If the said is true for small screen devices, shouldn't other types of reports be affected by the same? Like Task and edit Task?

Copy link
Contributor Author

@dukenv0307 dukenv0307 Nov 30, 2023

Choose a reason for hiding this comment

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

  1. We are calling openReport API in report screen but when we open a page by deeplink in small screen, LHN is displayed and we don't have access to report screen so openReport API isn't called.

  2. Here we need transation data which is returned in OpenReport API but in Edit Task page we only use report data which is returned in OpenApp API.

// So we need to call openReport here for small screen
useEffect(() => {
if (!isSmallScreenWidth || (!_.isEmpty(report) && !_.isEmpty(reportAction) && !_.isEmpty(transaction))) {
return;
}
Report.openReport(route.params.threadReportID);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isSmallScreenWidth, route.params.threadReportID]);

// Decides whether to allow or disallow editing a money request
useEffect(() => {
// Do not dismiss the modal, when a current user can edit this property of the money request.
if (ReportUtils.canEditFieldOfMoneyRequest(parentReportAction, parentReport.reportID, fieldToEdit)) {
if (isDataLoading || ReportUtils.canEditFieldOfMoneyRequest(parentReportAction, parentReport.reportID, fieldToEdit)) {
return;
}

// Dismiss the modal when a current user cannot edit a money request.
Navigation.isNavigationReady().then(() => {
Navigation.dismissModal();
});
}, [parentReportAction, parentReport.reportID, fieldToEdit]);
}, [parentReportAction, parentReport.reportID, fieldToEdit, isDataLoading]);

if (isDataLoading) {
return <FullScreenLoadingIndicator />;
}

// Update the transaction object and close the modal
function editMoneyRequest(transactionChanges) {
Expand Down Expand Up @@ -272,10 +307,14 @@ EditRequestPage.displayName = 'EditRequestPage';
EditRequestPage.propTypes = propTypes;
EditRequestPage.defaultProps = defaultProps;
export default compose(
withWindowDimensions,
withOnyx({
report: {
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${route.params.threadReportID}`,
},
isLoadingReportData: {
key: ONYXKEYS.IS_LOADING_REPORT_DATA,
},
}),
// eslint-disable-next-line rulesdir/no-multiple-onyx-in-file
withOnyx({
Expand Down
Loading