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

Race fix attempt 2 #4436

Merged
merged 1 commit into from
Aug 6, 2021
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
8 changes: 7 additions & 1 deletion src/pages/home/HeaderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,23 @@ const propTypes = {
}).isRequired,

/** Personal details of all the users */
personalDetails: PropTypes.objectOf(participantPropTypes).isRequired,
personalDetails: PropTypes.objectOf(participantPropTypes),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing required because these throw unnecessary errors as onyx takes a while to load in these variables. I think all async variables should just be defined as not required.


...windowDimensionsPropTypes,
...withLocalizePropTypes,
};

const defaultProps = {
personalDetails: {},
report: null,
};

const HeaderView = (props) => {
// Waiting until ONYX variables are loaded before displaying the component
if (_.isEmpty(props.personalDetails)) {
return null;
}

const participants = lodashGet(props.report, 'participants', []);
const isMultipleParticipant = participants.length > 1;
const displayNamesWithTooltips = _.map(
Expand Down
3 changes: 2 additions & 1 deletion src/pages/home/report/ParticipantLocalTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import withLocalize, {withLocalizePropTypes} from '../../../components/withLocal
import {participantPropTypes} from '../sidebar/optionPropTypes';
import ExpensiText from '../../../components/Text';
import Timers from '../../../libs/Timers';
import CONST from '../../../CONST';

const propTypes = {
/** Personal details of the participant */
Expand Down Expand Up @@ -40,7 +41,7 @@ class ParticipantLocalTime extends PureComponent {
}

getParticipantLocalTime() {
const reportRecipientTimezone = lodashGet(this.props.participant, 'timezone', {});
const reportRecipientTimezone = lodashGet(this.props.participant, 'timezone', CONST.DEFAULT_TIME_ZONE);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

setting a proper default because if we use {} as default then it will fail 3 lines down for currentUserDay and throw an error.

moment.locale(this.props.preferredLocale);
const reportRecipientDay = moment().tz(reportRecipientTimezone.selected).format('dddd');
const currentUserDay = moment().tz(this.props.currentUserTimezone.selected).format('dddd');
Expand Down
15 changes: 11 additions & 4 deletions src/pages/home/report/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ const propTypes = {
}),

/** The personal details of the person who is logged in */
myPersonalDetails: PropTypes.shape(currentUserPersonalDetailsPropsTypes).isRequired,
myPersonalDetails: PropTypes.shape(currentUserPersonalDetailsPropsTypes),

/** Personal details of all the users */
personalDetails: PropTypes.objectOf(participantPropTypes).isRequired,
personalDetails: PropTypes.objectOf(participantPropTypes),

/** The report currently being looked at */
report: PropTypes.shape({
Expand Down Expand Up @@ -123,6 +123,8 @@ const defaultProps = {
reportActions: {},
network: {isOffline: false},
blockedFromConcierge: {},
personalDetails: {},
myPersonalDetails: {},
};

class ReportActionCompose extends React.Component {
Expand Down Expand Up @@ -421,14 +423,19 @@ class ReportActionCompose extends React.Component {
}

render() {
// Waiting until ONYX variables are loaded before displaying the component
if (_.isEmpty(this.props.personalDetails) || _.isEmpty(this.props.myPersonalDetails)) {
return null;
}

// eslint-disable-next-line no-unused-vars
const reportParticipants = lodashGet(this.props.report, 'participants', []);
const hasMultipleParticipants = reportParticipants.length > 1;
const hasChronosParticipant = _.contains(reportParticipants, CONST.EMAIL.CHRONOS);
const hasConciergeParticipant = _.contains(reportParticipants, CONST.EMAIL.CONCIERGE);
const reportRecipient = this.props.personalDetails[reportParticipants[0]];
const currentUserTimezone = lodashGet(this.props.myPersonalDetails, 'timezone', {});
const reportRecipientTimezone = lodashGet(reportRecipient, 'timezone', {});
const currentUserTimezone = lodashGet(this.props.myPersonalDetails, 'timezone', CONST.DEFAULT_TIME_ZONE);
const reportRecipientTimezone = lodashGet(reportRecipient, 'timezone', CONST.DEFAULT_TIME_ZONE);
const shouldShowReportRecipientLocalTime = !hasConciergeParticipant
&& !hasChronosParticipant
&& !hasMultipleParticipants
Expand Down
4 changes: 2 additions & 2 deletions src/pages/home/sidebar/SidebarLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ class SidebarLinks extends React.Component {
}

render() {
// Wait until the reports are actually loaded before displaying the LHN
if (!this.props.initialReportDataLoaded) {
// Wait until the reports and personalDetails are actually loaded before displaying the LHN
if (!this.props.initialReportDataLoaded || _.isEmpty(this.props.personalDetails)) {
return null;
}

Expand Down