Skip to content

Commit 8936a73

Browse files
committed
refactor: use config for the env variables
1 parent 9c123fb commit 8936a73

File tree

4 files changed

+78
-22
lines changed

4 files changed

+78
-22
lines changed

.env.development

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
ABOUT_US_URL=
1+
ABOUT_US_URL=null
22
ACCESS_TOKEN_COOKIE_NAME=edx-jwt-cookie-header-payload
3-
ACCESSIBILITY_URL=
3+
ACCESSIBILITY_URL=null
44
BASE_URL=localhost:8080
5-
CONTACT_URL=
5+
CONTACT_URL=null
66
CREDENTIALS_BASE_URL=http://localhost:18150
77
CSRF_TOKEN_API_PATH=/csrf/api/v1/token
88
ECOMMERCE_BASE_URL=http://localhost:18130
9-
HONOR_CODE_URL=
9+
HONOR_CODE_URL=null
1010
LANGUAGE_PREFERENCE_COOKIE_NAME=openedx-language-preference
1111
LMS_BASE_URL=http://localhost:18000
1212
LOGIN_URL=http://localhost:18000/login
@@ -16,14 +16,14 @@ TERMS_OF_SERVICE_URL=null
1616
PRIVACY_POLICY_URL=null
1717
SUPPORT_EMAIL=null
1818
STUDIO_BASE_URL=http://localhost:18010
19-
TRADEMARK_TEXT=
19+
TRADEMARK_TEXT=''
2020
ORDER_HISTORY_URL=localhost:1996/orders
2121
REFRESH_ACCESS_TOKEN_ENDPOINT=http://localhost:18000/login_refresh
2222
SEGMENT_KEY=null
2323
SHOW_LOGO=true
2424
SITE_NAME=Open edX
25-
SUPPORT_CENTER_TEXT=
26-
SUPPORT_CENTER_URL=
25+
SUPPORT_CENTER_TEXT=''
26+
SUPPORT_CENTER_URL=null
2727
USER_INFO_COOKIE_NAME=edx-user-info
2828
LOGO_ALT_TEXT="Open edX Logo"
2929
LOGO_URL=https://edx-cdn.org/v3/default/logo.svg

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ This component requires that the following environment variable be set by the co
4545

4646
Optional Environment Variables
4747
=====================
48-
Apart from the required environment variables, this component also supports the following optional environment variable. These variables add the ability to display
49-
custom legal links in the footer. Optional Environment Variables can also be set by the consuming micro-frontend
48+
Apart from the required environment variables, this component also supports the following optional environment variables. These variables add the ability to display
49+
custom legal links in the footer. Optional environment variables can also be set by the consuming micro-frontend.
5050

5151
* ``ABOUT_US_URL`` - About Us page URL.
5252
* ``ACCESSIBILITY_URL`` - Accessibility page URL.

src/components/Footer.jsx

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import _ from 'lodash';
23
import PropTypes from 'prop-types';
34
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
45
import { sendTrackEvent } from '@edx/frontend-platform/analytics';
@@ -7,12 +8,29 @@ import { AppContext } from '@edx/frontend-platform/react';
78

89
import messages from './Footer.messages';
910
import LanguageSelector from './LanguageSelector';
11+
import {APP_CONFIG_INITIALIZED, mergeConfig, subscribe, getConfig} from "@edx/frontend-platform";
1012

1113
ensureConfig([
1214
'LMS_BASE_URL',
1315
'LOGO_TRADEMARK_URL',
1416
], 'Footer component');
1517

18+
subscribe(APP_CONFIG_INITIALIZED, () => {
19+
mergeConfig({
20+
ABOUT_US_URL: process.env.ABOUT_US_URL,
21+
ACCESSIBILITY_URL: process.env.ACCESSIBILITY_URL,
22+
CONTACT_URL: process.env.CONTACT_URL,
23+
HONOR_CODE_URL: process.env.HONOR_CODE_URL,
24+
LOGO_ALT_TEXT: process.env.LOGO_ALT_TEXT,
25+
PRIVACY_POLICY_URL: process.env.PRIVACY_POLICY_URL,
26+
SHOW_LOGO: process.env.SHOW_LOGO,
27+
SUPPORT_CENTER_TEXT: process.env.SUPPORT_CENTER_TEXT,
28+
SUPPORT_CENTER_URL: process.env.SUPPORT_CENTER_URL,
29+
TERMS_OF_SERVICE_URL: process.env.TERMS_OF_SERVICE_URL,
30+
TRADEMARK_TEXT: process.env.TRADEMARK_TEXT,
31+
}, 'Footer additional config');
32+
});
33+
1634
const EVENT_NAMES = {
1735
FOOTER_LINK: 'edx.bi.footer.link',
1836
};
@@ -34,7 +52,7 @@ class SiteFooter extends React.Component {
3452
}
3553

3654
renderLinkIfExists(value, text) {
37-
return value && <li><a href={value}>{text}</a></li>;
55+
return !_.isEmpty(value) && <li><a href={value}>{text}</a></li>;
3856
}
3957

4058
render() {
@@ -52,7 +70,7 @@ class SiteFooter extends React.Component {
5270
className="footer d-flex border-top py-3 px-4"
5371
>
5472
<div className="container-fluid d-flex">
55-
{ process.env.SHOW_LOGO
73+
{ getConfig().SHOW_LOGO
5674
&& (
5775
<a
5876
className="d-block"
@@ -62,26 +80,54 @@ class SiteFooter extends React.Component {
6280
<img
6381
style={{ maxHeight: 45 }}
6482
src={logo || config.LOGO_TRADEMARK_URL}
65-
alt={process.env.LOGO_ALT_TEXT || intl.formatMessage(messages['footer.logo.altText'])}
83+
alt={getConfig().LOGO_ALT_TEXT || intl.formatMessage(messages['footer.logo.altText'])}
6684
/>
6785
</a>
6886
)}
6987
<div className="copyright-col">
70-
{process.env.TRADEMARK_TEXT
88+
{getConfig().TRADEMARK_TEXT
7189
&& (
7290
<div className="text-gray-500 small">
73-
{process.env.TRADEMARK_TEXT}
91+
{getConfig().TRADEMARK_TEXT}
7492
</div>
7593
)}
7694
<div>
7795
<ul className="footer-sub-nav">
78-
{this.renderLinkIfExists(process.env.ABOUT_US_URL, 'About Us')}
79-
{this.renderLinkIfExists(process.env.TERMS_OF_SERVICE_URL, 'Terms of Service')}
80-
{this.renderLinkIfExists(process.env.PRIVACY_POLICY_URL, 'Privacy Policy')}
81-
{this.renderLinkIfExists(process.env.HONOR_CODE_URL, 'Honor Code')}
82-
{this.renderLinkIfExists(process.env.CONTACT_URL, 'Contact Us')}
83-
{this.renderLinkIfExists(process.env.ACCESSIBILITY_URL, 'Accessibility')}
84-
{this.renderLinkIfExists(process.env.SUPPORT_CENTER_URL, process.env.SUPPORT_CENTER_TEXT || 'FAQ & Help')}
96+
{
97+
this.renderLinkIfExists(
98+
getConfig().ABOUT_US_URL, intl.formatMessage(messages['footer.edxLinks.aboutUs'])
99+
)
100+
}
101+
{
102+
this.renderLinkIfExists(
103+
getConfig().TERMS_OF_SERVICE_URL, intl.formatMessage(messages['footer.legalLinks.termsOfService'])
104+
)
105+
}
106+
{
107+
this.renderLinkIfExists(
108+
getConfig().PRIVACY_POLICY_URL, intl.formatMessage(messages['footer.legalLinks.privacyPolicy'])
109+
)
110+
}
111+
{
112+
this.renderLinkIfExists(
113+
getConfig().HONOR_CODE_URL, intl.formatMessage(messages['footer.legalLinks.honorCode'])
114+
)
115+
}
116+
{
117+
this.renderLinkIfExists(
118+
getConfig().CONTACT_URL, intl.formatMessage(messages['footer.connectLinks.contact'])
119+
)
120+
}
121+
{
122+
this.renderLinkIfExists(
123+
getConfig().ACCESSIBILITY_URL, intl.formatMessage(messages['footer.legalLinks.a11yPolicy'])
124+
)
125+
}
126+
{
127+
this.renderLinkIfExists(
128+
getConfig().SUPPORT_CENTER_URL, getConfig().SUPPORT_CENTER_TEXT || intl.formatMessage(messages['footer.connectLinks.help'])
129+
)
130+
}
85131
</ul>
86132
</div>
87133
</div>

src/components/Footer.messages.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ const messages = defineMessages({
4141
defaultMessage: 'About',
4242
description: 'The label for the link to the about edX page.',
4343
},
44+
'footer.edxLinks.aboutUs': {
45+
id: 'footer.edxLinks.aboutUs',
46+
defaultMessage: 'About Us',
47+
description: 'The label for the link to the about us page.',
48+
},
4449
'footer.edxLinks.business': {
4550
id: 'footer.edxLinks.business',
4651
defaultMessage: 'edX for Business',
@@ -73,9 +78,14 @@ const messages = defineMessages({
7378
},
7479
'footer.legalLinks.termsOfService': {
7580
id: 'footer.legalLinks.termsOfService',
76-
defaultMessage: 'Terms of Service & Honor Code',
81+
defaultMessage: 'Terms of Service',
7782
description: 'The label for the link to the edX terms of service page.',
7883
},
84+
'footer.legalLinks.honorCode': {
85+
id: 'footer.legalLinks.honorCode',
86+
defaultMessage: 'Honor Code',
87+
description: 'The label for the link to the edX honor code page.',
88+
},
7989
'footer.legalLinks.privacyPolicy': {
8090
id: 'footer.legalLinks.privacyPolicy',
8191
defaultMessage: 'Privacy Policy',

0 commit comments

Comments
 (0)