Fix rewards page #274

Merged
6ea86b96 merged 2 commits from fix-rewards-page into master 2017-06-23 16:02:34 +02:00
3 changed files with 80 additions and 58 deletions

View file

@ -16,6 +16,7 @@ export function doAuthenticate() {
type: types.AUTHENTICATION_SUCCESS, type: types.AUTHENTICATION_SUCCESS,
data: { user }, data: { user },
}); });
dispatch(doRewardList());
}) })
.catch(error => { .catch(error => {
dispatch({ dispatch({

View file

@ -7,6 +7,7 @@ import {
selectUserHasEmail, selectUserHasEmail,
selectUserIsVerificationCandidate, selectUserIsVerificationCandidate,
} from "selectors/user"; } from "selectors/user";
import { doRewardList } from "actions/rewards";
import RewardsPage from "./view"; import RewardsPage from "./view";
const select = state => ({ const select = state => ({
@ -17,4 +18,8 @@ const select = state => ({
isVerificationCandidate: selectUserIsVerificationCandidate(state), isVerificationCandidate: selectUserIsVerificationCandidate(state),
}); });
export default connect(select, null)(RewardsPage); const perform = dispatch => ({
fetchRewards: () => dispatch(doRewardList()),
});
export default connect(select, perform)(RewardsPage);

View file

@ -29,14 +29,29 @@ const RewardTile = props => {
); );
}; };
const RewardsPage = props => { class RewardsPage extends React.PureComponent {
componentDidMount() {
this.fetchRewards(this.props);
}
componentWillReceiveProps(nextProps) {
this.fetchRewards(nextProps);
}
fetchRewards(props) {
const { fetching, rewards, fetchRewards } = props;
if (!fetching && Object.keys(rewards).length < 1) fetchRewards();
}
render() {
const { const {
fetching, fetching,
isEligible, isEligible,
isVerificationCandidate, isVerificationCandidate,
hasEmail, hasEmail,
rewards, rewards,
} = props; } = this.props;
let content, let content,
isCard = false; isCard = false;
@ -87,6 +102,7 @@ const RewardsPage = props => {
: content} : content}
</main> </main>
); );
}; }
}
export default RewardsPage; export default RewardsPage;