Skip to content

Commit

Permalink
feat: add manage subscriptions url
Browse files Browse the repository at this point in the history
  • Loading branch information
NawfalAhmed committed May 16, 2023
1 parent ced6541 commit 9702a05
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
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
28 changes: 28 additions & 0 deletions src/subscriptions/ManageSubscriptionsPage.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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, stripeLoading } = useSelector(
subscriptionsSelector,
);

useEffect(() => {
dispatch(fetchStripeCustomerPortalURL());
}, []);

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

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

export default ManageSubscriptionsPage;
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,
};

0 comments on commit 9702a05

Please sign in to comment.