Skip to content

Commit

Permalink
feat: use learner portal hostname config variable (#79)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: requires the presence of ENTERPRISE_LEARNER_PORTAL_HOSTNAME env var to properly generate learner portal urls
  • Loading branch information
christopappas authored Mar 2, 2020
1 parent 295293c commit ab1a30c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/enterprise/getLearnerPortalLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,24 @@ const cacheLinks = (userId, links) => {
const fetchLearnerPortalLinks = async (userId) => {
const httpClient = getAuthenticatedHttpClient();
const enterpriseApiUrl = `${getConfig().LMS_BASE_URL}/enterprise/api/v1/enterprise-customer/`;
const enterpriseLearnerPortalHostname = process.env.ENTERPRISE_LEARNER_PORTAL_HOSTNAME;
if (!enterpriseLearnerPortalHostname) {
return [];
}

try {
const { data } = await httpClient.get(enterpriseApiUrl);
const enterpriseCustomers = data.results.map(customer => ({
name: customer.name,
isEnabled: customer.enable_learner_portal,
hostname: customer.learner_portal_hostname,
slug: customer.slug,
}));

const links = enterpriseCustomers
.filter(({ isEnabled, hostname }) => isEnabled && hostname)
.map(({ name, hostname }) => ({
.filter(({ isEnabled, slug }) => isEnabled && slug)
.map(({ name, slug }) => ({
title: name,
url: `https://${hostname}`,
url: `https://${enterpriseLearnerPortalHostname}/${slug}`,
}));

cacheLinks(userId, links);
Expand Down

0 comments on commit ab1a30c

Please sign in to comment.