import React, { Component } from 'react'; import { getLearnerPortalLinks } from '@edx/frontend-enterprise'; import { StatusAlert } from '@edx/paragon'; import apiClient from '../apiClient'; const LOCAL_STORAGE_KEY = 'has-viewed-enterprise-learner-portal-banner'; function getAlertHtml(learnerPortalLinks) { let html = ''; for (let i = 0; i < learnerPortalLinks.length; i += 1) { const link = learnerPortalLinks[i]; html += `
${link.title} has a dedicated page where you can see all of your sponsored courses. Go to your learner portal.
`; } return html; } function setViewedBanner() { window.localStorage.setItem(LOCAL_STORAGE_KEY, true); } function hasViewedBanner() { return window.localStorage.getItem(LOCAL_STORAGE_KEY) != null; } class EnterpriseLearnerPortalBanner extends Component { constructor(props) { super(props); this.onClose = this.onClose.bind(this); this.state = { open: false, alertHtml: '', }; } componentDidMount() { if (!hasViewedBanner()) { getLearnerPortalLinks(apiClient).then((learnerPortalLinks) => { this.setState({ open: true, alertHtml: getAlertHtml(learnerPortalLinks), }); }); } } onClose() { this.setState({ open: false }); setViewedBanner(); } render() { const { alertHtml, open } = this.state; if (open && alertHtml) { return (
)} onClose={this.onClose} />
); } return null; } } export { EnterpriseLearnerPortalBanner }; // eslint-disable-line import/prefer-default-export