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";
|
2017-08-26 05:21:26 +02:00
|
|
|
import ModalRewardApprovalRequired from "modal/modalRewardApprovalRequired";
|
2017-08-18 19:09:40 +02:00
|
|
|
import ModalCreditIntro from "modal/modalCreditIntro";
|
2017-09-08 05:15:05 +02:00
|
|
|
import ModalRemoveFile from "modal/modalRemoveFile";
|
2017-08-31 06:15:13 +02:00
|
|
|
import ModalTransactionFailed from "modal/modalTransactionFailed";
|
|
|
|
import ModalInsufficientBalance from "modal/modalInsufficientBalance";
|
2017-09-07 23:18:33 +02:00
|
|
|
import ModalFileTimeout from "modal/modalFileTimeout";
|
|
|
|
import ModalAffirmPurchase from "modal/modalAffirmPurchase";
|
2017-08-31 06:15:13 +02:00
|
|
|
import * as modals from "constants/modal_types";
|
2017-08-18 19:09:40 +02:00
|
|
|
|
|
|
|
class ModalRouter extends React.PureComponent {
|
2017-08-26 05:21:26 +02:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
lastTransitionModal: null,
|
|
|
|
lastTransitionPage: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-08-18 19:09:40 +02:00
|
|
|
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) {
|
2017-09-08 05:15:05 +02:00
|
|
|
const { modal, modalProps, openModal, page } = props;
|
2017-08-18 19:09:40 +02:00
|
|
|
|
2017-08-21 05:06:26 +02:00
|
|
|
if (modal) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-26 05:21:26 +02:00
|
|
|
const transitionModal = [
|
|
|
|
this.checkShowWelcome,
|
|
|
|
this.checkShowCreditIntro,
|
|
|
|
this.checkShowInsufficientCredits,
|
|
|
|
].reduce((acc, func) => {
|
|
|
|
return !acc ? func.bind(this)(props) : acc;
|
|
|
|
}, false);
|
2017-08-18 19:09:40 +02:00
|
|
|
|
2017-08-26 05:21:26 +02:00
|
|
|
if (
|
|
|
|
transitionModal &&
|
|
|
|
(transitionModal != this.state.lastTransitionModal ||
|
|
|
|
page != this.state.lastTransitionPage)
|
|
|
|
) {
|
|
|
|
openModal(transitionModal);
|
|
|
|
this.setState({
|
|
|
|
lastTransitionModal: transitionModal,
|
|
|
|
lastTransitionPage: page,
|
|
|
|
});
|
|
|
|
}
|
2017-08-21 05:06:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
checkShowWelcome(props) {
|
2017-08-26 05:21:26 +02:00
|
|
|
const { isWelcomeAcknowledged, user } = props;
|
2017-08-18 19:09:40 +02:00
|
|
|
if (
|
|
|
|
!isWelcomeAcknowledged &&
|
|
|
|
user &&
|
|
|
|
!user.is_reward_approved &&
|
|
|
|
!user.is_identity_verified
|
|
|
|
) {
|
2017-08-26 05:21:26 +02:00
|
|
|
return modals.WELCOME;
|
2017-08-18 19:09:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-21 05:06:26 +02:00
|
|
|
checkShowCreditIntro(props) {
|
2017-08-26 05:21:26 +02:00
|
|
|
const { page, isCreditIntroAcknowledged, user } = props;
|
2017-08-21 05:06:26 +02:00
|
|
|
|
|
|
|
if (
|
|
|
|
!isCreditIntroAcknowledged &&
|
|
|
|
user &&
|
|
|
|
!user.is_reward_approved &&
|
2017-08-26 05:21:26 +02:00
|
|
|
(["rewards", "send", "receive", "publish", "wallet"].includes(page) ||
|
|
|
|
this.isPaidShowPage(props))
|
2017-08-21 05:06:26 +02:00
|
|
|
) {
|
2017-08-26 05:21:26 +02:00
|
|
|
return modals.CREDIT_INTRO;
|
2017-08-18 19:09:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-26 05:21:26 +02:00
|
|
|
checkShowInsufficientCredits(props) {
|
|
|
|
const { balance, page } = props;
|
|
|
|
|
|
|
|
if (balance <= 0 && ["send", "publish"].includes(page)) {
|
|
|
|
return modals.INSUFFICIENT_CREDITS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
isPaidShowPage(props) {
|
|
|
|
const { page, showPageCost } = props;
|
|
|
|
return page === "show" && showPageCost > 0;
|
|
|
|
}
|
|
|
|
|
2017-08-18 19:09:40 +02:00
|
|
|
render() {
|
2017-09-08 05:15:05 +02:00
|
|
|
const { modal, modalProps } = this.props;
|
2017-08-18 19:09:40 +02:00
|
|
|
|
2017-10-03 23:55:41 +02:00
|
|
|
switch (modal) {
|
2017-08-18 19:09:40 +02:00
|
|
|
case modals.UPGRADE:
|
2017-09-08 05:15:05 +02:00
|
|
|
return <ModalUpgrade {...modalProps} />;
|
2017-08-18 19:09:40 +02:00
|
|
|
case modals.DOWNLOADING:
|
2017-09-08 05:15:05 +02:00
|
|
|
return <ModalDownloading {...modalProps} />;
|
2017-08-18 19:09:40 +02:00
|
|
|
case modals.ERROR:
|
2017-09-08 05:15:05 +02:00
|
|
|
return <ModalError {...modalProps} />;
|
2017-09-07 23:18:33 +02:00
|
|
|
case modals.FILE_TIMEOUT:
|
2017-09-08 05:15:05 +02:00
|
|
|
return <ModalFileTimeout {...modalProps} />;
|
2017-08-18 19:09:40 +02:00
|
|
|
case modals.INSUFFICIENT_CREDITS:
|
2017-09-08 05:15:05 +02:00
|
|
|
return <ModalInsufficientCredits {...modalProps} />;
|
2017-08-18 19:09:40 +02:00
|
|
|
case modals.WELCOME:
|
2017-09-08 05:15:05 +02:00
|
|
|
return <ModalWelcome {...modalProps} />;
|
2017-08-18 19:09:40 +02:00
|
|
|
case modals.FIRST_REWARD:
|
2017-09-08 05:15:05 +02:00
|
|
|
return <ModalFirstReward {...modalProps} />;
|
2017-08-18 19:09:40 +02:00
|
|
|
case modals.AUTHENTICATION_FAILURE:
|
2017-09-08 05:15:05 +02:00
|
|
|
return <ModalAuthFailure {...modalProps} />;
|
2017-08-18 19:09:40 +02:00
|
|
|
case modals.CREDIT_INTRO:
|
2017-09-08 05:15:05 +02:00
|
|
|
return <ModalCreditIntro {...modalProps} />;
|
2017-08-31 06:15:13 +02:00
|
|
|
case modals.TRANSACTION_FAILED:
|
2017-09-08 05:15:05 +02:00
|
|
|
return <ModalTransactionFailed {...modalProps} />;
|
2017-08-31 06:15:13 +02:00
|
|
|
case modals.INSUFFICIENT_BALANCE:
|
2017-09-08 05:15:05 +02:00
|
|
|
return <ModalInsufficientBalance {...modalProps} />;
|
2017-08-26 05:21:26 +02:00
|
|
|
case modals.REWARD_APPROVAL_REQUIRED:
|
2017-09-08 05:15:05 +02:00
|
|
|
return <ModalRewardApprovalRequired {...modalProps} />;
|
2017-09-07 23:18:33 +02:00
|
|
|
case modals.CONFIRM_FILE_REMOVE:
|
2017-09-08 05:15:05 +02:00
|
|
|
return <ModalRemoveFile {...modalProps} />;
|
2017-09-07 23:18:33 +02:00
|
|
|
case modals.AFFIRM_PURCHASE:
|
2017-09-08 05:15:05 +02:00
|
|
|
return <ModalAffirmPurchase {...modalProps} />;
|
2017-08-18 19:09:40 +02:00
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ModalRouter;
|