fix(client): move all user fetching to learn
This commit is contained in:
committed by
mrugesh
parent
ebe9c468e3
commit
f48952c3e6
@@ -1,6 +1,15 @@
|
||||
import React, { Fragment } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { createSelector } from 'reselect';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
import { Loader } from '../../components/helpers';
|
||||
import {
|
||||
userSelector,
|
||||
userFetchStateSelector,
|
||||
isSignedInSelector
|
||||
} from '../../redux';
|
||||
import createRedirect from '../../components/createRedirect';
|
||||
import DonateModal from '../Donation';
|
||||
|
||||
import 'prismjs/themes/prism.css';
|
||||
@@ -9,7 +18,33 @@ import './prism-night.css';
|
||||
import 'react-reflex/styles.css';
|
||||
import './learn.css';
|
||||
|
||||
function LearnLayout({ children }) {
|
||||
const mapStateToProps = createSelector(
|
||||
userFetchStateSelector,
|
||||
isSignedInSelector,
|
||||
userSelector,
|
||||
(fetchState, isSignedIn, user) => ({
|
||||
fetchState,
|
||||
isSignedIn,
|
||||
user
|
||||
})
|
||||
);
|
||||
|
||||
const RedirectAcceptPrivacyTerm = createRedirect('/accept-privacy-terms');
|
||||
|
||||
function LearnLayout({
|
||||
fetchState: { pending, complete },
|
||||
isSignedIn,
|
||||
user: { acceptedPrivacyTerms },
|
||||
children
|
||||
}) {
|
||||
if (pending && !complete) {
|
||||
return <Loader fullScreen={true} />;
|
||||
}
|
||||
|
||||
if (isSignedIn && !acceptedPrivacyTerms) {
|
||||
return <RedirectAcceptPrivacyTerm />;
|
||||
}
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
<main id='learn-app-wrapper'>{children}</main>
|
||||
@@ -19,6 +54,17 @@ function LearnLayout({ children }) {
|
||||
}
|
||||
|
||||
LearnLayout.displayName = 'LearnLayout';
|
||||
LearnLayout.propTypes = { children: PropTypes.any };
|
||||
LearnLayout.propTypes = {
|
||||
children: PropTypes.any,
|
||||
fetchState: PropTypes.shape({
|
||||
pending: PropTypes.bool,
|
||||
complete: PropTypes.bool,
|
||||
errored: PropTypes.bool
|
||||
}),
|
||||
isSignedIn: PropTypes.bool,
|
||||
user: PropTypes.shape({
|
||||
acceptedPrivacyTerms: PropTypes.bool
|
||||
})
|
||||
};
|
||||
|
||||
export default LearnLayout;
|
||||
export default connect(mapStateToProps)(LearnLayout);
|
||||
|
@@ -16,7 +16,9 @@ describe('<Welcome />', () => {
|
||||
const shallow = new ShallowRenderer();
|
||||
shallow.render(<LearnPage {...loggedInProps} />);
|
||||
const result = shallow.getRenderOutput();
|
||||
expect(result.type.displayName === 'LearnLayout').toBeTruthy();
|
||||
expect(
|
||||
result.type.WrappedComponent.displayName === 'LearnLayout'
|
||||
).toBeTruthy();
|
||||
});
|
||||
|
||||
it('has a header', () => {
|
||||
|
@@ -32,14 +32,6 @@ function Welcome({ name }) {
|
||||
</blockquote>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row>
|
||||
<Col sm={10} smOffset={1} xs={12}>
|
||||
<Spacer />
|
||||
<h2 className='text-center medium-heading'>
|
||||
What would you like to do today?
|
||||
</h2>
|
||||
</Col>
|
||||
</Row>
|
||||
</Fragment>
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user