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

Share Code URL implementation using Environment URL #21107

Merged
merged 7 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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: 8 additions & 0 deletions src/components/withEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import getComponentDisplayName from '../libs/getComponentDisplayName';
const environmentPropTypes = {
/** The string value representing the current environment */
environment: PropTypes.string.isRequired,

/** The string value representing the URL of the current environment */
environmentURL: PropTypes.string.isRequired,
};

export default function (WrappedComponent) {
Expand All @@ -16,13 +19,17 @@ export default function (WrappedComponent) {

this.state = {
environment: CONST.ENVIRONMENT.PRODUCTION,
environmentURL: CONST.NEW_EXPENSIFY_URL,
};
}

componentDidMount() {
Environment.getEnvironment().then((environment) => {
this.setState({environment});
});
Environment.getEnvironmentURL().then((environmentURL) => {
this.setState({environmentURL})
});
}

render() {
Expand All @@ -32,6 +39,7 @@ export default function (WrappedComponent) {
{...this.props}
ref={this.props.forwardedRef}
environment={this.state.environment}
environmentURL={this.state.environmentURL}
/>
);
}
Expand Down
10 changes: 7 additions & 3 deletions src/pages/ShareCodePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ import CONST from '../CONST';
import ContextMenuItem from '../components/ContextMenuItem';
import * as UserUtils from '../libs/UserUtils';
import ROUTES from '../ROUTES';
import withEnvironment, {environmentPropTypes} from '../components/withEnvironment';
import * as Url from '../libs/Url';

const propTypes = {
/** The report currently being looked at */
report: reportPropTypes,

...withLocalizePropTypes,
...withCurrentUserPersonalDetailsPropTypes,
...environmentPropTypes,
};

const defaultProps = {
Expand All @@ -41,9 +44,10 @@ class ShareCodePage extends React.Component {
const isReport = this.props.report != null && this.props.report.reportID != null;
const subtitle = ReportUtils.getChatRoomSubtitle(this.props.report);

const urlWithTrailingSlash = Url.addTrailingForwardSlash(this.props.environmentURL);
const url = isReport
? `${CONST.NEW_EXPENSIFY_URL}${ROUTES.getReportRoute(this.props.report.reportID)}`
: `${CONST.NEW_EXPENSIFY_URL}${ROUTES.getProfileRoute(this.props.session.accountID)}`;
? `${urlWithTrailingSlash}${ROUTES.getReportRoute(this.props.report.reportID)}`
: `${urlWithTrailingSlash}${ROUTES.getProfileRoute(this.props.session.accountID)}`;

const platform = getPlatform();
const isNative = platform === CONST.PLATFORM.IOS || platform === CONST.PLATFORM.ANDROID;
Expand Down Expand Up @@ -96,4 +100,4 @@ class ShareCodePage extends React.Component {
ShareCodePage.propTypes = propTypes;
ShareCodePage.defaultProps = defaultProps;

export default compose(withLocalize, withCurrentUserPersonalDetails)(ShareCodePage);
export default compose(withEnvironment, withLocalize, withCurrentUserPersonalDetails)(ShareCodePage);