Fix content tab redirection on campaign creation

This commit is contained in:
Kailash Nadh 2018-11-28 14:17:02 +05:30
parent c24c19b120
commit ca19b50126
3 changed files with 39 additions and 23 deletions

View File

@ -128,9 +128,12 @@ class Editor extends React.PureComponent {
modules={ this.quillModules } modules={ this.quillModules }
defaultValue={ this.props.record.body } defaultValue={ this.props.record.body }
ref={ (o) => { ref={ (o) => {
if(o) { if(!o) {
this.setState({ quill: o }) return
} }
this.setState({ quill: o })
document.querySelector(".ql-editor").focus()
}} }}
onChange={ () => { onChange={ () => {
if(!this.state.quill) { if(!this.state.quill) {
@ -218,10 +221,7 @@ class TheFormDef extends React.PureComponent {
message: "Campaign created", message: "Campaign created",
description: `"${values["name"]}" created` }) description: `"${values["name"]}" created` })
this.props.route.history.push(cs.Routes.ViewCampaign.replace(":id", resp.data.data.id)) this.props.route.history.push(cs.Routes.ViewCampaign.replace(":id", resp.data.data.id) + "#content")
this.props.fetchRecord(resp.data.data.id)
this.props.setCurrentTab("content")
this.setState({ loading: false })
}).catch(e => { }).catch(e => {
notification["error"]({ placement: cs.MsgPosition, message: "Error", description: e.message }) notification["error"]({ placement: cs.MsgPosition, message: "Error", description: e.message })
this.setState({ loading: false }) this.setState({ loading: false })
@ -428,6 +428,11 @@ class Campaign extends React.PureComponent {
} else { } else {
this.setState({ loading: false }) this.setState({ loading: false })
} }
// Content tab?
if(document.location.hash === "#content") {
this.setCurrentTab("content")
}
} }
fetchRecord = (id) => { fetchRecord = (id) => {
@ -498,6 +503,8 @@ class Campaign extends React.PureComponent {
</Spin> </Spin>
</Tabs.TabPane> </Tabs.TabPane>
<Tabs.TabPane tab="Content" disabled={ this.state.record.id ? false : true } key="content"> <Tabs.TabPane tab="Content" disabled={ this.state.record.id ? false : true } key="content">
{ this.state.record.id &&
<div>
<Editor { ...this.props } <Editor { ...this.props }
ref={ (e) => { ref={ (e) => {
// Take the editor's reference and save it in the state // Take the editor's reference and save it in the state
@ -514,6 +521,11 @@ class Campaign extends React.PureComponent {
<div className="content-actions"> <div className="content-actions">
<p><Button icon="search" onClick={() => this.handlePreview(this.state.record)}>Preview</Button></p> <p><Button icon="search" onClick={() => this.handlePreview(this.state.record)}>Preview</Button></p>
</div> </div>
</div>
}
{ !this.state.record.id &&
<Spin className="empty-spinner"></Spin>
}
</Tabs.TabPane> </Tabs.TabPane>
</Tabs> </Tabs>

View File

@ -30,7 +30,7 @@ class ModalPreview extends React.PureComponent {
onOk={ this.props.onCancel }> onOk={ this.props.onCancel }>
<div className="preview-iframe-container"> <div className="preview-iframe-container">
<Spin className="preview-iframe-spinner"></Spin> <Spin className="preview-iframe-spinner"></Spin>
<iframe key="xxxxxxxxx" onLoad={() => { <iframe key="preview-iframe" onLoad={() => {
// If state is used to manage the spinner, it causes // If state is used to manage the spinner, it causes
// the iframe to re-render and reload everything. // the iframe to re-render and reload everything.
// Hack the spinner away from the DOM directly instead. // Hack the spinner away from the DOM directly instead.

View File

@ -40,6 +40,10 @@ hr {
display: none; display: none;
} }
.empty-spinner {
padding: 30px !important;
}
/* Layout */ /* Layout */
body { body {
margin: 0; margin: 0;