UNPKG

3.94 kBJavaScriptView Raw
1import React from 'react';
2import { modes } from '../data/constants';
3import EmailSubOrGiftArticle from './email-sub-or-gift-article';
4import EmailSubOnlyArticle from './email-sub-only-article';
5import EmailFreeArticle from './email-free-article';
6
7export default class extends React.Component {
8
9 constructor (props) {
10 super(props)
11 }
12
13 componentWillMount () {
14 this.setState(this.props.store.getState())
15 this.storeUnsubscribe = this.props.store.subscribe(() => this.setState(this.props.store.getState()))
16 }
17
18 componentWillUnmount () {
19 this.storeUnsubscribe()
20 }
21
22 render () {
23 const actions = this.props.actions
24 const dispatch = this.props.dispatch
25
26 if (this.state.mode === modes.GIFT_OR_SUB) {
27 return (
28 <EmailSubOrGiftArticle
29 isReady={this.state.isReady}
30 isOpen={this.props.isTop ? this.state.isOpenTop : this.state.isOpenBottom}
31 isGift={this.state.isGift}
32 onIsGiftChange={isGift => dispatch(actions.isGiftChange(isGift))}
33 credit={this.state.credit}
34 monthlyAllowance={this.state.monthlyAllowance}
35 emailAddresses={this.state.emailAddresses}
36 emailAddressErrors={this.state.emailAddressErrors}
37 onEmailAddressChange={(index, value) => dispatch(actions.emailAddressChange(index, value))}
38 onAddEmailAddress={() => dispatch(actions.addEmailAddress())}
39 onRemoveEmailAddress={index => dispatch(actions.removeEmailAddress(index))}
40 customMessage={this.props.customMessage}
41 image={this.state.imageUrl}
42 messageText={this.state.messageText}
43 onMessageTyping={(value) => dispatch(actions.messageTextChange(value))}
44 messageLength={this.state.messageLength}
45 onSend={() => dispatch(actions.validateThenSend())}
46 isSending={this.state.isSending}
47 onClose={() => dispatch(this.props.isTop ? actions.closeTop() : actions.closeBottom())}
48 />
49 )
50 } else if (this.state.mode === modes.SUB_ONLY) {
51 return (
52 <EmailSubOnlyArticle
53 isReady={this.state.isReady}
54 isOpen={this.props.isTop ? this.state.isOpenTop : this.state.isOpenBottom}
55 emailAddresses={this.state.emailAddresses}
56 emailAddressErrors={this.state.emailAddressErrors}
57 onEmailAddressChange={(index, value) => dispatch(actions.emailAddressChange(index, value))}
58 onAddEmailAddress={() => dispatch(actions.addEmailAddress())}
59 onRemoveEmailAddress={index => dispatch(actions.removeEmailAddress(index))}
60 customMessage={this.props.customMessage}
61 image={this.state.imageUrl}
62 messageText={this.state.messageText}
63 onMessageTyping={(value) => dispatch(actions.messageTextChange(value))}
64 messageLength={this.state.messageLength}
65 onSend={() => dispatch(actions.validateThenSend())}
66 isSending={this.state.isSending}
67 onClose={() => dispatch(this.props.isTop ? actions.closeTop() : actions.closeBottom())}
68 />
69 )
70 } else if (this.state.mode === modes.FREE) {
71 return (
72 <EmailFreeArticle
73 isReady={this.state.isReady}
74 isOpen={this.props.isTop ? this.state.isOpenTop : this.state.isOpenBottom}
75 emailAddresses={this.state.emailAddresses}
76 emailAddressErrors={this.state.emailAddressErrors}
77 onEmailAddressChange={(index, value) => dispatch(actions.emailAddressChange(index, value))}
78 onAddEmailAddress={() => dispatch(actions.addEmailAddress())}
79 onRemoveEmailAddress={index => dispatch(actions.removeEmailAddress(index))}
80 customMessage={this.props.customMessage}
81 image={this.state.imageUrl}
82 messageText={this.state.messageText}
83 onMessageTyping={(value) => dispatch(actions.messageTextChange(value))}
84 messageLength={this.state.messageLength}
85 onSend={() => dispatch(actions.validateThenSend())}
86 isSending={this.state.isSending}
87 onClose={() => dispatch(this.props.isTop ? actions.closeTop() : actions.closeBottom())}
88 />
89 )
90 }
91 }
92}