Skip to content

Commit

Permalink
Remove unnecessary banner from dashboard.
Browse files Browse the repository at this point in the history
  • Loading branch information
taliaedX committed Mar 5, 2021
1 parent 527fb6c commit 7a2546f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 23 deletions.
2 changes: 2 additions & 0 deletions src/components/course/CoursePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import React from 'react';

import Course from './Course';
import AuthenticatedUserSubsidyPage from '../app/AuthenticatedUserSubsidyPage';
import OffersAlert from '../enterprise-user-subsidy/OffersAlert';

export default function CoursePage() {
return (
<AuthenticatedUserSubsidyPage>
<OffersAlert />
<Course />
</AuthenticatedUserSubsidyPage>
);
Expand Down
17 changes: 6 additions & 11 deletions src/components/enterprise-user-subsidy/OffersAlert.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React from 'react';
import PropTypes from 'prop-types';
import React, { useContext } from 'react';

import { Alert, Container } from '@edx/paragon';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faInfoCircle } from '@fortawesome/free-solid-svg-icons';
import { UserSubsidyContext } from '.';

export const getOffersText = (number) => `You have ${number} course redemption voucher${number > 1 ? 's' : ''} left to use.`;
export const getOffersText = (number) => `You have ${number} enrollment codes${number > 1 ? 's' : ''} left to use.`;

const OffersAlert = ({ offers }) => {
if (!offers.offersCount) {
const OffersAlert = () => {
const { offers } = useContext(UserSubsidyContext);
if (!offers?.offersCount) {
return null;
}
return (
Expand All @@ -21,10 +22,4 @@ const OffersAlert = ({ offers }) => {
);
};

OffersAlert.propTypes = {
offers: PropTypes.shape({
offersCount: PropTypes.number.isRequired,
}).isRequired,
};

export default OffersAlert;
2 changes: 0 additions & 2 deletions src/components/enterprise-user-subsidy/UserSubsidyAlerts.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useContext } from 'react';
import { AppContext } from '@edx/frontend-platform/react';
import { UserSubsidyContext } from '.';
import OffersAlert from './OffersAlert';
import SubscriptionSubsidy from './SubscriptionSubsidy';

const UserSubsidyAlerts = () => {
Expand All @@ -10,7 +9,6 @@ const UserSubsidyAlerts = () => {

return (
<>
{offers && <OffersAlert offers={offers} />}
{/**
* SubscriptionSubsidy takes care of redirecting the user to `/${enterpriseConfig.slug}`
* if their organization has a subscription plan but they don't have appropriate access
Expand Down
39 changes: 29 additions & 10 deletions src/components/enterprise-user-subsidy/tests/OffersAlert.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,39 @@ import { screen, render } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';

import OffersAlert, { getOffersText } from '../OffersAlert';
import { UserSubsidyContext } from '..';

describe('<OffersAlert />', () => {
const offers = {
loading: false,
offers: [],
offersCount: 3,
};
/* eslint-disable react/prop-types */
const OffersAlertWithContext = ({
subsidyContext = {},
}) => (
<UserSubsidyContext.Provider value={subsidyContext}>
<OffersAlert />
</UserSubsidyContext.Provider>
);
/* eslint-enable react/prop-types */

describe('<OffersAlert />', () => {
it('renders an alert when loading is complete and there are offers', () => {
render(<OffersAlert offers={offers} />);
expect(screen.queryByText(getOffersText(offers.offersCount))).toBeInTheDocument();
const subsidyContext = {
offers: {
loading: false,
offers: [],
offersCount: 3,
},
};
render(<OffersAlertWithContext subsidyContext={subsidyContext} />);
expect(screen.queryByText(getOffersText(subsidyContext.offers.offersCount))).toBeInTheDocument();
});
it('does not render an alert if there are no offers', () => {
render(<OffersAlert offers={{ ...offers, offersCount: 0 }} />);
expect(screen.queryByText(getOffersText(offers.offersCount))).not.toBeInTheDocument();
const subsidyContext = {
offers: {
loading: false,
offers: [],
offersCount: 0,
},
};
render(<OffersAlertWithContext subsidyContext={subsidyContext} />);
expect(screen.queryByText(getOffersText(subsidyContext.offers.offersCount))).not.toBeInTheDocument();
});
});
2 changes: 2 additions & 0 deletions src/components/search/SearchPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import React from 'react';
import { SearchData } from '@edx/frontend-enterprise';
import Search from './Search';
import AuthenticatedUserSubsidyPage from '../app/AuthenticatedUserSubsidyPage';
import OffersAlert from '../enterprise-user-subsidy/OffersAlert';

const SearchPage = () => (
<AuthenticatedUserSubsidyPage>
<OffersAlert />
<SearchData>
<Search />
</SearchData>
Expand Down

0 comments on commit 7a2546f

Please sign in to comment.