2017-12-21 22:08:54 +01:00
|
|
|
import React from 'react';
|
|
|
|
import ModalError from 'modal/modalError';
|
|
|
|
import ModalAuthFailure from 'modal/modalAuthFailure';
|
|
|
|
import ModalDownloading from 'modal/modalDownloading';
|
2017-12-08 11:08:50 +01:00
|
|
|
import ModalAutoUpdateDownloaded from "modal/modalAutoUpdateDownloaded";
|
2018-01-16 06:38:23 +01:00
|
|
|
import ModalAutoUpdateConfirm from "modal/modalAutoUpdateDownloaded";
|
2017-12-21 22:08:54 +01:00
|
|
|
import ModalUpgrade from 'modal/modalUpgrade';
|
|
|
|
import ModalWelcome from 'modal/modalWelcome';
|
|
|
|
import ModalFirstReward from 'modal/modalFirstReward';
|
|
|
|
import ModalRewardApprovalRequired from 'modal/modalRewardApprovalRequired';
|
|
|
|
import ModalCreditIntro from 'modal/modalCreditIntro';
|
|
|
|
import ModalRemoveFile from 'modal/modalRemoveFile';
|
|
|
|
import ModalTransactionFailed from 'modal/modalTransactionFailed';
|
|
|
|
import ModalFileTimeout from 'modal/modalFileTimeout';
|
|
|
|
import ModalAffirmPurchase from 'modal/modalAffirmPurchase';
|
|
|
|
import ModalRevokeClaim from 'modal/modalRevokeClaim';
|
|
|
|
import ModalEmailCollection from '../modalEmailCollection';
|
|
|
|
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,
|
2017-12-07 19:07:30 +01:00
|
|
|
this.checkShowEmail,
|
2017-08-26 05:21:26 +02:00
|
|
|
this.checkShowCreditIntro,
|
2017-12-21 22:08:54 +01:00
|
|
|
].reduce((acc, func) => (!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 &&
|
2017-12-21 22:08:54 +01:00
|
|
|
(transitionModal != this.state.lastTransitionModal || page != this.state.lastTransitionPage)
|
2017-08-26 05:21:26 +02:00
|
|
|
) {
|
|
|
|
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-12-21 22:08:54 +01: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-12-07 19:07:30 +01:00
|
|
|
checkShowEmail(props) {
|
2017-12-21 22:08:54 +01:00
|
|
|
const { isEmailCollectionAcknowledged, isVerificationCandidate, user } = props;
|
2017-08-21 05:06:26 +02:00
|
|
|
if (
|
2017-12-07 19:07:30 +01:00
|
|
|
!isEmailCollectionAcknowledged &&
|
|
|
|
isVerificationCandidate &&
|
2017-08-21 05:06:26 +02:00
|
|
|
user &&
|
2017-12-07 19:07:30 +01:00
|
|
|
!user.has_verified_email
|
2017-08-21 05:06:26 +02:00
|
|
|
) {
|
2017-12-07 19:07:30 +01:00
|
|
|
return modals.EMAIL_COLLECTION;
|
2017-08-18 19:09:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-07 19:07:30 +01:00
|
|
|
checkShowCreditIntro(props) {
|
|
|
|
const { balance, page, isCreditIntroAcknowledged } = props;
|
2017-08-26 05:21:26 +02:00
|
|
|
|
2017-12-07 19:07:30 +01:00
|
|
|
if (
|
|
|
|
balance <= 0 &&
|
|
|
|
!isCreditIntroAcknowledged &&
|
2017-12-21 22:08:54 +01:00
|
|
|
(['send', 'publish'].includes(page) || this.isPaidShowPage(props))
|
2017-12-07 19:07:30 +01:00
|
|
|
) {
|
2017-08-26 05:21:26 +02:00
|
|
|
return modals.INSUFFICIENT_CREDITS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
isPaidShowPage(props) {
|
|
|
|
const { page, showPageCost } = props;
|
2017-12-21 22:08:54 +01:00
|
|
|
return page === 'show' && showPageCost > 0;
|
2017-08-26 05:21:26 +02:00
|
|
|
}
|
|
|
|
|
2017-08-18 19:09:40 +02:00
|
|
|
render() {
|
2018-01-17 11:50:02 +01:00
|
|
|
const { modal, modalsAllowed, 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-12-08 11:08:50 +01:00
|
|
|
case modals.AUTO_UPDATE_DOWNLOADED:
|
|
|
|
return <ModalAutoUpdateDownloaded {...modalProps} />;
|
2018-01-16 06:38:23 +01:00
|
|
|
case modals.AUTO_UPDATE_CONFIRM:
|
|
|
|
return <ModalAutoUpdateConfirm {...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-12-07 19:07:30 +01:00
|
|
|
return <ModalCreditIntro {...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-31 06:15:13 +02:00
|
|
|
case modals.TRANSACTION_FAILED:
|
2017-09-08 05:15:05 +02:00
|
|
|
return <ModalTransactionFailed {...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-10-27 21:42:54 +02:00
|
|
|
case modals.CONFIRM_CLAIM_REVOKE:
|
|
|
|
return <ModalRevokeClaim {...modalProps} />;
|
2017-12-07 19:07:30 +01:00
|
|
|
case modals.EMAIL_COLLECTION:
|
|
|
|
return <ModalEmailCollection {...modalProps} />;
|
2017-08-18 19:09:40 +02:00
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ModalRouter;
|