-
Notifications
You must be signed in to change notification settings - Fork 2k
/
index.jsx
73 lines (62 loc) · 1.8 KB
/
index.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* Fixed notice about upcoming support closures
*
* @format
*/
/**
* External dependencies
*/
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import i18n, { localize } from 'i18n-calypso';
/**
* Internal dependencies
*/
import FormSectionHeading from 'components/forms/form-section-heading';
import olarkStore from 'lib/olark-store';
import { title, upcoming, closed } from './messages';
const Notice = localize( ( { translate, closedFrom, closedTo, reason } ) => (
<div className="chat-closure-notice">
<FormSectionHeading>
{ title( { translate, closedFrom, closedTo, reason } ) }
</FormSectionHeading>
<div>
{ i18n.moment().isBefore( closedFrom )
? upcoming( { translate, closedFrom, closedTo, reason } )
: closed( { translate, closedFrom, closedTo, reason } ) }
</div>
</div>
) );
export default class ChatClosureNotice extends Component {
constructor( props ) {
super( props );
this.state = { olark: olarkStore.get() };
}
componentDidMount() {
this.updateOlarkState();
olarkStore.on( 'change', this.updateOlarkState );
}
componentWillUnmount() {
olarkStore.removeListener( 'change', this.updateOlarkState );
}
updateOlarkState = () => {
this.setState( { olark: olarkStore.get() } );
};
render() {
const closedFrom = i18n.moment( this.props.from );
const closedTo = i18n.moment( this.props.to );
// Don't show notice if user isn't eligible for chat
if ( ! this.state.olark.isUserEligible ) {
return null;
}
// Closure period is over, don't show any notice
if ( i18n.moment().isAfter( closedTo ) ) {
return null;
}
return <Notice reason={ this.props.reason } closedFrom={ closedFrom } closedTo={ closedTo } />;
}
}
ChatClosureNotice.propTypes = {
from: PropTypes.string.isRequired,
to: PropTypes.string.isRequired,
};