2017-08-18 19:09:40 +02:00
|
|
|
import React from "react";
|
|
|
|
import ModalError from "modal/modalError";
|
|
|
|
import ModalAuthFailure from "modal/modalAuthFailure";
|
|
|
|
import ModalDownloading from "modal/modalDownloading";
|
|
|
|
import ModalInsufficientCredits from "modal/modalInsufficientCredits";
|
|
|
|
import ModalUpgrade from "modal/modalUpgrade";
|
|
|
|
import ModalWelcome from "modal/modalWelcome";
|
|
|
|
import ModalFirstReward from "modal/modalFirstReward";
|
|
|
|
import * as modals from "constants/modal_types";
|
|
|
|
import ModalCreditIntro from "modal/modalCreditIntro";
|
|
|
|
|
|
|
|
class ModalRouter extends React.PureComponent {
|
|
|
|
componentWillMount() {
|
2017-08-21 05:06:26 +02:00
|
|
|
this.showTransitionModals(this.props);
|
2017-08-18 19:09:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps) {
|
2017-08-21 05:06:26 +02:00
|
|
|
this.showTransitionModals(nextProps);
|
2017-08-18 19:09:40 +02:00
|
|
|
}
|
|
|
|
|
2017-08-21 05:06:26 +02:00
|
|
|
showTransitionModals(props) {
|
|
|
|
const { modal } = props;
|
2017-08-18 19:09:40 +02:00
|
|
|
|
2017-08-21 05:06:26 +02:00
|
|
|
if (modal) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
[
|
|
|
|
this.checkShowWelcome.bind(this),
|
|
|
|
this.checkShowCreditIntro.bind(this),
|
|
|
|
].find(func => func(props));
|
|
|
|
}
|
|
|
|
|
|
|
|
checkShowWelcome(props) {
|
|
|
|
const { isWelcomeAcknowledged, openModal, user } = props;
|
2017-08-18 19:09:40 +02:00
|
|
|
if (
|
|
|
|
!isWelcomeAcknowledged &&
|
|
|
|
user &&
|
|
|
|
!user.is_reward_approved &&
|
|
|
|
!user.is_identity_verified
|
|
|
|
) {
|
2017-08-21 05:06:26 +02:00
|
|
|
openModal(modals.WELCOME);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
checkShowCreditIntro(props) {
|
2017-08-22 23:19:33 +02:00
|
|
|
const {
|
|
|
|
page,
|
|
|
|
isCreditIntroAcknowledged,
|
|
|
|
openModal,
|
|
|
|
user,
|
|
|
|
showPageCost,
|
|
|
|
} = props;
|
2017-08-21 05:06:26 +02:00
|
|
|
|
|
|
|
if (
|
|
|
|
!isCreditIntroAcknowledged &&
|
|
|
|
user &&
|
|
|
|
!user.is_reward_approved &&
|
2017-08-21 05:38:34 +02:00
|
|
|
!user.is_identity_verified &&
|
2017-08-22 23:19:33 +02:00
|
|
|
["rewards", "send", "address", "show", "publish", "wallet"].includes(
|
|
|
|
page
|
|
|
|
) &&
|
|
|
|
(page != "show" || showPageCost > 0)
|
2017-08-21 05:06:26 +02:00
|
|
|
) {
|
|
|
|
openModal(modals.CREDIT_INTRO);
|
|
|
|
return true;
|
2017-08-18 19:09:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { modal } = this.props;
|
|
|
|
|
|
|
|
switch (modal) {
|
|
|
|
case modals.UPGRADE:
|
|
|
|
return <ModalUpgrade />;
|
|
|
|
case modals.DOWNLOADING:
|
|
|
|
return <ModalDownloading />;
|
|
|
|
case modals.ERROR:
|
|
|
|
return <ModalError />;
|
|
|
|
case modals.INSUFFICIENT_CREDITS:
|
|
|
|
return <ModalInsufficientCredits />;
|
|
|
|
case modals.WELCOME:
|
|
|
|
return <ModalWelcome />;
|
|
|
|
case modals.FIRST_REWARD:
|
|
|
|
return <ModalFirstReward />;
|
|
|
|
case modals.AUTHENTICATION_FAILURE:
|
|
|
|
return <ModalAuthFailure />;
|
|
|
|
case modals.CREDIT_INTRO:
|
|
|
|
return <ModalCreditIntro />;
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ModalRouter;
|