Skip to content
This repository was archived by the owner on Nov 4, 2024. It is now read-only.

Commit ced6541

Browse files
authored
feat: api integration for subscription related changes (#282)
1 parent aa3451f commit ced6541

34 files changed

+750
-317
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ LMS_BASE_URL=''
44
CREDENTIALS_BASE_URL=''
55
COMMERCE_COORDINATOR_BASE_URL=''
66
ECOMMERCE_BASE_URL=''
7+
SUBSCRIPTIONS_BASE_URL=''
78
LOGIN_URL=''
89
LOGOUT_URL=''
910
CSRF_TOKEN_API_PATH=''
@@ -20,3 +21,4 @@ LOGO_URL=''
2021
LOGO_TRADEMARK_URL=''
2122
LOGO_WHITE_URL=''
2223
FAVICON_URL=''
24+
ENABLE_B2C_SUBSCRIPTIONS=false

.env.development

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LMS_BASE_URL=http://localhost:18000
55
CREDENTIALS_BASE_URL=http://localhost:18150
66
COMMERCE_COORDINATOR_BASE_URL=http://localhost:8140
77
ECOMMERCE_BASE_URL=http://localhost:18130
8+
SUBSCRIPTIONS_BASE_URL=http://localhost:18750
89
LOGIN_URL=http://localhost:18000/login
910
LOGOUT_URL=http://localhost:18000/login
1011
CSRF_TOKEN_API_PATH=/csrf/api/v1/token
@@ -21,3 +22,4 @@ LOGO_URL=https://edx-cdn.org/v3/default/logo.svg
2122
LOGO_TRADEMARK_URL=https://edx-cdn.org/v3/default/logo-trademark.svg
2223
LOGO_WHITE_URL=https://edx-cdn.org/v3/default/logo-white.svg
2324
FAVICON_URL=https://edx-cdn.org/v3/default/favicon.ico
25+
ENABLE_B2C_SUBSCRIPTIONS=true

.env.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LMS_BASE_URL=http://localhost:18000
55
CREDENTIALS_BASE_URL=http://localhost:18150
66
COMMERCE_COORDINATOR_BASE_URL=http://localhost:8140
77
ECOMMERCE_BASE_URL=http://localhost:18130
8+
SUBSCRIPTIONS_BASE_URL=http://localhost:18750
89
LOGIN_URL=http://localhost:18000/login
910
LOGOUT_URL=http://localhost:18000/login
1011
CSRF_TOKEN_API_PATH=/csrf/api/v1/token
@@ -21,3 +22,4 @@ LOGO_URL=https://edx-cdn.org/v3/default/logo.svg
2122
LOGO_TRADEMARK_URL=https://edx-cdn.org/v3/default/logo-trademark.svg
2223
LOGO_WHITE_URL=https://edx-cdn.org/v3/default/logo-white.svg
2324
FAVICON_URL=https://edx-cdn.org/v3/default/favicon.ico
25+
ENABLE_B2C_SUBSCRIPTIONS=true

package-lock.json

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"redux": "4.2.0",
7070
"redux-logger": "3.0.6",
7171
"redux-saga": "1.1.3",
72+
"redux-saga-routines": "^3.2.3",
7273
"redux-thunk": "2.4.1",
7374
"reselect": "4.1.6",
7475
"universal-cookie": "4.0.4",

src/common/utils.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { call, put } from 'redux-saga/effects';
12
import camelCase from 'lodash.camelcase';
23
import snakeCase from 'lodash.snakecase';
34

@@ -79,3 +80,23 @@ export class AsyncActionType {
7980
return `${this.topic}__${this.name}__RESET`;
8081
}
8182
}
83+
84+
/**
85+
* A higher order helper function to create a redux-saga generator function
86+
*
87+
* it handles the boilerplate of making a call to an API
88+
* and dispatching the appropriate actions.
89+
*/
90+
export function createFetchHandler(routine, apiCall) {
91+
return function* handleFetch() {
92+
try {
93+
yield put(routine.request());
94+
const result = yield call(apiCall);
95+
yield put(routine.success(result));
96+
} catch (error) {
97+
yield put(routine.failure(error));
98+
} finally {
99+
yield put(routine.fulfill());
100+
}
101+
};
102+
}

src/index.jsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
APP_READY,
1010
initialize,
1111
subscribe,
12+
mergeConfig,
1213
} from '@edx/frontend-platform';
1314

1415
import Header from '@edx/frontend-component-header';
@@ -21,7 +22,26 @@ import { OrdersAndSubscriptionsPage } from './orders-and-subscriptions';
2122

2223
import './index.scss';
2324

25+
/**
26+
* TEMPORARY
27+
*
28+
* Until we add the following keys in frontend-platform,
29+
* use mergeConfig to join it with the rest of the config items
30+
* (so we don't need to get it separately from process.env).
31+
* After we add the keys to frontend-platform, this mergeConfig can go away
32+
*/
33+
mergeConfig({
34+
COMMERCE_COORDINATOR_BASE_URL: process.env.COMMERCE_COORDINATOR_BASE_URL,
35+
ENABLE_B2C_SUBSCRIPTIONS: process.env.ENABLE_B2C_SUBSCRIPTIONS,
36+
SUBSCRIPTIONS_BASE_URL: process.env.SUBSCRIPTIONS_BASE_URL,
37+
SUPPORT_URL: process.env.SUPPORT_URL,
38+
});
39+
2440
subscribe(APP_READY, () => {
41+
if (process.env.NODE_ENV === 'development') {
42+
global.analytics?.debug();
43+
}
44+
2545
ReactDOM.render(
2646
<AppProvider store={configureStore()}>
2747
<Header />
@@ -39,7 +59,12 @@ subscribe(APP_READY, () => {
3959
});
4060

4161
subscribe(APP_INIT_ERROR, (error) => {
42-
ReactDOM.render(<IntlProvider locale="en"><ErrorPage message={error.message} /></IntlProvider>, document.getElementById('root'));
62+
ReactDOM.render(
63+
<IntlProvider locale="en">
64+
<ErrorPage message={error.message} />
65+
</IntlProvider>,
66+
document.getElementById('root'),
67+
);
4368
});
4469

4570
initialize({

src/order-history/OrderHistoryPage.jsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ class OrderHistoryPage extends React.Component {
2727
this.handlePageSelect = this.handlePageSelect.bind(this);
2828
}
2929

30-
componentDidMount() {
31-
// TODO: We should fetch based on the route (ex: /orders/list/page/1)
32-
this.props.fetchOrders(1);
33-
}
34-
3530
handlePageSelect(page) {
3631
// TODO: We should update the url and trigger this fetching based on the route
3732
this.props.fetchOrders(page);
@@ -203,7 +198,9 @@ class OrderHistoryPage extends React.Component {
203198
</>
204199
) : null}
205200
{loaded && !hasOrders ? this.renderEmptyMessage() : null}
206-
{loading ? this.renderLoading() : null}
201+
{loading && !this.props.isB2CSubsEnabled
202+
? this.renderLoading()
203+
: null}
207204
</div>
208205
</section>
209206
);

src/order-history/OrderHistoryPage.test.jsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import configureMockStore from 'redux-mock-store';
88
import ConnectedOrderHistoryPage from './OrderHistoryPage';
99

1010
const mockStore = configureMockStore();
11-
const storeMocks = {
12-
ordersLoaded: require('./__mocks__/ordersLoaded.mockStore'),
13-
};
11+
const storeMocks = require('../store/__mocks__/mockStore');
12+
1413
const requiredOrderHistoryPageProps = {
1514
isB2CSubsEnabled: false,
1615
fetchOrders: () => {},
@@ -30,7 +29,7 @@ describe('<OrderHistoryPage />', () => {
3029
const tree = renderer
3130
.create((
3231
<IntlProvider locale="en">
33-
<Provider store={mockStore(storeMocks.ordersLoaded)}>
32+
<Provider store={mockStore(storeMocks)}>
3433
<ConnectedOrderHistoryPage {...requiredOrderHistoryPageProps} />
3534
</Provider>
3635
</IntlProvider>

src/order-history/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import OrderHistoryPage from './OrderHistoryPage';
2+
import { fetchOrders } from './actions';
23
import reducer from './reducer';
34
import saga from './saga';
45
import { storeName } from './selectors';
56

67
export default OrderHistoryPage;
7-
export { reducer, saga, storeName };
8+
export {
9+
fetchOrders,
10+
reducer,
11+
saga,
12+
storeName,
13+
};

0 commit comments

Comments
 (0)