import React from 'react' import { connect } from 'react-redux' import { bindActionCreators } from 'redux' import Admin from './../admin' import { copyWebinar } from '../actions/index' interface WebinarCopyPropsType { copyWebinar: any; errors: string[]; webinar: any; } interface WebinarCopyStateType { fetching: boolean; webinar: { name: string, url: string }; errors: string[]; } class WebinarCopy extends React.Component { constructor(props) { super(props); this.state = { fetching: false, webinar: { name: "", url: "" }, errors: [] } } changeFieldArgs() { return { thing: "webinar", errorsArray: this.state.errors } } clickSave() { this.setState({ fetching: true }); this.props.copyWebinar({ oldWebinarId: window.location.pathname.split("/")[3], newWebinar: this.state.webinar }).then(() => { window.location.href = `/admin/webinars/${this.props.webinar.id}`; }, () => { this.setState({ fetching: false, errors: this.props.errors }); }); } render() { return(
{ Admin.renderSpinner(this.state.fetching) } { Admin.renderGrayedOut(this.state.fetching) }

New Name (Internal)

{ Admin.renderModalFieldError(this.state.errors, Admin.errors.name) }

New Url

{ Admin.renderModalFieldError(this.state.errors, Admin.errors.url) }
Copy
) } componentDidUpdate() { Admin.resetNiceSelect({ selector: '#webinar-new select', func: Admin.changeField.bind(this, this.changeFieldArgs()) }); } } const mapStateToProps = (reducers, props) => { return reducers.standardReducer; }; function mapDispatchToProps(dispatch) { return bindActionCreators({ copyWebinar }, dispatch); } export default connect(mapStateToProps, mapDispatchToProps)(WebinarCopy);