import React from 'react' import { connect } from 'react-redux' import { bindActionCreators } from 'redux' import Modal from 'react-modal' import orderBy from 'lodash/orderBy'; import truncate from 'lodash/truncate'; import Admin from './../admin' import { fetchEntities } from '../actions/index' import NewEntity from './new-entity' const ModalStyles = { overlay: { background: 'rgba(0, 0, 0, 0.50)' }, content: { background: 'white', padding: 0, margin: 'auto', maxWidth: 1000, height: 359 } }; interface WebinarsIndexProps { fetchEntities: any; timeframe: string; webinarTimes: any[]; } interface WebinarsIndexState extends ComponentState { modalOpen: boolean; tab: string; webinars: any[]; } class WebinarsIndex extends React.Component { constructor(props) { super(props); this.state = { fetching: true, webinars: [], modalOpen: false, searchText: '', searchProperty: 'time_parsed', tab: 'Upcoming Live' }; } componentDidMount() { this.props.fetchEntities('webinars').then(() => { this.setState({ fetching: false, webinars: this.props.webinarTimes }); }); } clickNew() { this.setState({ modalOpen: true }); } closeModal() { this.setState({ modalOpen: false }); } filterByTime(webinar) { var duration = (90 * 60 * 1000); switch (this.state.tab) { case 'Upcoming Live': return webinar.webinar_type === 'live' && ((webinar.timestamp * 1000) + duration) > Date.now(); break; case 'Past Live': return webinar.webinar_type === 'live' && ((webinar.timestamp * 1000) + duration) < Date.now(); break; case 'Automated': return webinar.webinar_type === 'automated'; break; default: return null; } } sortByTimestamp(webinar) { return webinar.timestamp; } render() { const { webinars, searchText, searchProperty } = this.state; var filteredWebinars = Admin.filterSearchText(webinars.filter(this.filterByTime.bind(this)), searchText, searchProperty); return(

Webinars

{ Admin.renderTopTabs.call(this, 'webinars', ["Upcoming Live", "Past Live", "Automated"]) } Add Webinar
{ Admin.renderSpinner(this.state.fetching) } { Admin.renderGrayedOut(this.state.fetching) } { orderBy(filteredWebinars, [this.state.searchProperty == 'time_parsed' ? this.sortByTimestamp.bind(this) : Admin.commonSort.bind(this)], [(this.state.searchProperty === 'time_parsed' && this.state.tab === 'Past Live') ? 'desc' : 'asc']).map((webinar, index) => { return( ); }) }
Time
Name
Title
Registrants Chat Pages
{ webinar.time_parsed } { truncate(webinar.name, { length: 53 }) } { truncate(webinar.title, { length: 43 }) } { webinar.registrations }
); } componentDidUpdate() { $('.match-height-layout').matchHeight(); } } const mapStateToProps = (reducers, props) => { return reducers.standardReducer; }; function mapDispatchToProps(dispatch) { return bindActionCreators({ fetchEntities }, dispatch); } export default connect(mapStateToProps, mapDispatchToProps)(WebinarsIndex);