Skip to content

Commit

Permalink
Update Help Center Launchpad to use calypso-config import instead of …
Browse files Browse the repository at this point in the history
…window.configData and added try catch (Automattic#72964)

* Update to use config import instead of window.configData and added try catch

* Move getEnvironmentHostname outside HelpCenterLaunchpad component
  • Loading branch information
agrullon95 authored Feb 14, 2023
1 parent 76d815e commit 5b38096
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions packages/help-center/src/components/help-center-launchpad.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable no-restricted-imports */
import { recordTracksEvent } from '@automattic/calypso-analytics';
import config from '@automattic/calypso-config';
import { CircularProgressBar } from '@automattic/components';
import { localizeUrl } from '@automattic/i18n-utils';
import { useSelect } from '@wordpress/data';
Expand All @@ -9,19 +10,23 @@ import { useSelector } from 'react-redux';
import { getSectionName, getSelectedSiteId } from 'calypso/state/ui/selectors';
import { SITE_STORE } from '../stores';

export const HelpCenterLaunchpad = () => {
const getEnvironmentHostname = () => {
const currentEnvironment = window?.configData?.env_id;
const hostname = window?.configData?.hostname ?? 'wordpress.com';
const port = window?.configData?.port;
const getEnvironmentHostname = () => {
try {
const currentEnvironment = config( 'env_id' );
const hostname = config( 'hostname' ) ?? 'wordpress.com';
const port = config( 'port' );
switch ( currentEnvironment ) {
case 'development':
return `http://${ hostname }${ port ? ':' + port : '' }`;
default:
return `https://${ hostname }`;
}
};
} catch ( error ) {
return 'https://wordpress.com';
}
};

export const HelpCenterLaunchpad = () => {
const { __ } = useI18n();
const siteId = useSelector( ( state ) => getSelectedSiteId( state ) );
const site = useSelect( ( select ) => siteId && select( SITE_STORE ).getSite( siteId ) );
Expand All @@ -39,7 +44,7 @@ export const HelpCenterLaunchpad = () => {
} );
};

if ( ! site || ! siteIntent || ! siteSlug || ! window.configData ) {
if ( ! site || ! siteIntent || ! siteSlug ) {
return null;
}
return (
Expand Down

0 comments on commit 5b38096

Please sign in to comment.