Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PON-219: Manage Subscriptions Url #288

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
APP_READY,
initialize,
subscribe,
getConfig,
mergeConfig,
} from '@edx/frontend-platform';

Expand All @@ -19,6 +20,7 @@ import messages from './i18n';
import configureStore from './store';
import NotFoundPage from './components/NotFoundPage';
import { OrdersAndSubscriptionsPage } from './orders-and-subscriptions';
import { ManageSubscriptionsPage } from './subscriptions';

import './index.scss';

Expand Down Expand Up @@ -47,6 +49,12 @@ subscribe(APP_READY, () => {
<Header />
<main>
<Switch>
{getConfig().ENABLE_B2C_SUBSCRIPTIONS === 'true' ? (
<Route
path="/manage-subscriptions"
component={ManageSubscriptionsPage}
/>
) : null}
<Route path="/orders" component={OrdersAndSubscriptionsPage} />
<Route path="/notfound" component={NotFoundPage} />
<Route path="*" component={NotFoundPage} />
Expand Down
29 changes: 29 additions & 0 deletions src/subscriptions/ManageSubscriptionsPage.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React, { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';

import NotFoundPage from '../components/NotFoundPage';
import { PageLoading } from '../common';
import { fetchStripeCustomerPortalURL } from './actions';
import { subscriptionsSelector } from './selectors';

const ManageSubscriptionsPage = () => {
const dispatch = useDispatch();
const { stripeCustomerPortalURL, stripeError } = useSelector(
subscriptionsSelector,
);

useEffect(() => {
dispatch(fetchStripeCustomerPortalURL());
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(() => {
if (stripeCustomerPortalURL) {
window.location.href = stripeCustomerPortalURL;
}
}, [stripeCustomerPortalURL]);

return stripeError ? <NotFoundPage /> : <PageLoading />;
};

export default ManageSubscriptionsPage;
28 changes: 28 additions & 0 deletions src/subscriptions/ManageSubscriptionsPage.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* eslint-disable global-require */
import React from 'react';
import renderer from 'react-test-renderer';
import { Provider } from 'react-redux';
import { IntlProvider } from '@edx/frontend-platform/i18n';
import configureMockStore from 'redux-mock-store';

import ManageSubscriptionsPage from './ManageSubscriptionsPage';

const mockStore = configureMockStore();
const storeMocks = require('../store/__mocks__/mockStore');

describe('<ManageSubscriptions />', () => {
describe('Renders correctly in various states', () => {
it('renders when url is fetched correctly', () => {
const tree = renderer
.create(
<IntlProvider locale="en">
<Provider store={mockStore(storeMocks)}>
<ManageSubscriptionsPage />
</Provider>
</IntlProvider>,
)
.toJSON();
expect(tree).toMatchSnapshot();
});
});
});
10 changes: 6 additions & 4 deletions src/subscriptions/SubscriptionUpsell.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import { useMediaQuery } from 'react-responsive';

import { FormattedMessage } from '@edx/frontend-platform/i18n';
import { Alert, Badge, Button } from '@edx/paragon';
import { Search } from '@edx/paragon/icons';

const SubscriptionUpsell = () => (
<Alert
className="bg-light-200"
actions={[
<Button className="text-nowrap" iconBefore={Search}>
<Button className="text-nowrap">
<FormattedMessage
id="ecommerce.order.history.subscription.upsell.button"
defaultMessage="Explore subscription options"
Expand All @@ -32,14 +31,17 @@ const SubscriptionUpsell = () => (
</Badge>
<FormattedMessage
id="ecommerce.order.history.subscription.upsell.heading"
defaultMessage="Monthly program subscriptions now available"
defaultMessage="Monthly program subscriptions {emDash} more flexible, more affordable"
description="Heading for subscription upsell"
values={{
emDash: <>&mdash;</>,
}}
/>
</Alert.Heading>
<FormattedMessage
tagName="p"
id="ecommerce.order.history.subscription.upsell.message"
defaultMessage="An easier way to access popular programs with more control over how much you spend. Starting at {minSubscriptionPrice} per month after a {trialLength}-day free trial. Cancel anytime."
defaultMessage="Now available for many popular programs, affordable monthly subscription pricing can help you manage your budget more effectively. Subscriptions start at {minSubscriptionPrice}/month USD per program, after a {trialLength}-day full access free trial. Cancel at any time."
description="Message body for subscription upsell"
values={{
minSubscriptionPrice: '$39',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<ManageSubscriptions /> Renders correctly in various states renders when url is fetched correctly 1`] = `
<div>
<div
className="d-flex justify-content-center align-items-center flex-column"
style={
Object {
"height": "50vh",
}
}
>
<div
className="spinner-border text-primary"
role="status"
/>
</div>
</div>
`;
2 changes: 2 additions & 0 deletions src/subscriptions/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Subscriptions from './Subscriptions';
import ManageSubscriptionsPage from './ManageSubscriptionsPage';
import { fetchSubscriptions } from './actions';
import reducer from './reducer';
import saga from './saga';
Expand All @@ -10,4 +11,5 @@ export {
reducer,
saga,
storeName,
ManageSubscriptionsPage,
};