notify user when abandoning publish; clear form

This commit is contained in:
Travis Eden 2018-10-15 17:11:59 -04:00
parent 593d748bc0
commit 24626bcb02
7 changed files with 39 additions and 16 deletions

View file

@ -0,0 +1 @@
export const SAVE = 'Everything not saved will be lost. Are you sure you want to leave this page?';

View file

@ -12,12 +12,14 @@ import ButtonTertiary from '@components/ButtonTertiary';
import ButtonSecondary from '@components/ButtonSecondary'; import ButtonSecondary from '@components/ButtonSecondary';
import SpaceAround from '@components/SpaceAround'; import SpaceAround from '@components/SpaceAround';
import PublishFinePrint from '@components/PublishFinePrint'; import PublishFinePrint from '@components/PublishFinePrint';
import { SAVE } from '../../constants/confirmation_messages';
class PublishDetails extends React.Component { class PublishDetails extends React.Component {
constructor (props) { constructor (props) {
super(props); super(props);
this.onPublishSubmit = this.onPublishSubmit.bind(this); this.onPublishSubmit = this.onPublishSubmit.bind(this);
this.abandonClaim = this.abandonClaim.bind(this); this.abandonClaim = this.abandonClaim.bind(this);
this.onCancel = this.onCancel.bind(this);
} }
onPublishSubmit () { onPublishSubmit () {
this.props.startPublish(this.props.history); this.props.startPublish(this.props.history);
@ -29,6 +31,16 @@ class PublishDetails extends React.Component {
this.props.abandonClaim({claimData, history}); this.props.abandonClaim({claimData, history});
} }
} }
onCancel () {
const { isUpdate, clearFile, history } = this.props;
if (isUpdate) {
history.push('/');
} else {
if (confirm(SAVE)) {
clearFile();
}
}
}
render () { render () {
const {file, isUpdate, asset} = this.props; const {file, isUpdate, asset} = this.props;
return ( return (
@ -104,7 +116,7 @@ class PublishDetails extends React.Component {
<SpaceAround> <SpaceAround>
<ButtonTertiary <ButtonTertiary
value={'Cancel'} value={'Cancel'}
onClickHandler={this.props.clearFile} onClickHandler={this.onCancel}
/> />
</SpaceAround> </SpaceAround>
</Row> </Row>

View file

@ -1,8 +1,10 @@
import React from 'react'; import React from 'react';
import { withRouter, Prompt } from 'react-router';
import Dropzone from '@containers/Dropzone'; import Dropzone from '@containers/Dropzone';
import PublishPreview from '@components/PublishPreview'; import PublishPreview from '@components/PublishPreview';
import PublishStatus from '@containers/PublishStatus'; import PublishStatus from '@containers/PublishStatus';
import PublishDisabledMessage from '@containers/PublishDisabledMessage'; import PublishDisabledMessage from '@containers/PublishDisabledMessage';
import { SAVE } from '../../constants/confirmation_messages';
class PublishTool extends React.Component { class PublishTool extends React.Component {
render () { render () {
@ -18,7 +20,14 @@ class PublishTool extends React.Component {
<PublishStatus /> <PublishStatus />
); );
} else { } else {
return <PublishPreview isUpdate={isUpdate} />; return (
<React.Fragment>
<Prompt
message={SAVE}
/>
<PublishPreview isUpdate={isUpdate} />
</React.Fragment>
);
} }
} }
return <Dropzone />; return <Dropzone />;
@ -26,4 +35,4 @@ class PublishTool extends React.Component {
} }
}; };
export default PublishTool; export default withRouter(PublishTool);

View file

@ -1,4 +1,5 @@
import React from 'react'; import React from 'react';
import { withRouter } from 'react-router';
import PageLayout from '@components/PageLayout'; import PageLayout from '@components/PageLayout';
import HorizontalSplit from '@components/HorizontalSplit'; import HorizontalSplit from '@components/HorizontalSplit';
import AboutSpeechOverview from '@components/AboutSpeechOverview'; import AboutSpeechOverview from '@components/AboutSpeechOverview';
@ -20,4 +21,4 @@ class AboutPage extends React.Component {
} }
} }
export default AboutPage; export default withRouter(AboutPage);

View file

@ -5,15 +5,15 @@ import PublishTool from '@containers/PublishTool';
class EditPage extends React.Component { class EditPage extends React.Component {
componentDidMount () { componentDidMount () {
const {asset, isUpdate, match, onHandleShowPageUri, clearFile, setUpdateTrue, updateMetadata} = this.props; const {asset, match, onHandleShowPageUri, clearFile, setUpdateTrue, updateMetadata} = this.props;
if (!isUpdate) {
clearFile();
onHandleShowPageUri(match.params); onHandleShowPageUri(match.params);
setUpdateTrue(); setUpdateTrue();
if (asset) { if (asset) {
['title', 'description', 'license', 'nsfw'].forEach(meta => updateMetadata(meta, asset.claimData[meta])); ['title', 'description', 'license', 'nsfw'].forEach(meta => updateMetadata(meta, asset.claimData[meta]));
} }
} }
componentWillUnmount () {
this.props.clearFile();
} }
render () { render () {
const { myChannel, asset } = this.props; const { myChannel, asset } = this.props;

View file

@ -1,5 +1,6 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { onHandleShowHomepage } from '../../actions/show'; import { onHandleShowHomepage } from '../../actions/show';
import { clearFile } from '../../actions/publish';
import View from './view'; import View from './view';
const mapStateToProps = ({ show, site, channel, publish }) => { const mapStateToProps = ({ show, site, channel, publish }) => {
@ -13,6 +14,7 @@ const mapStateToProps = ({ show, site, channel, publish }) => {
const mapDispatchToProps = { const mapDispatchToProps = {
onHandleShowHomepage, onHandleShowHomepage,
clearFile,
}; };
export default connect(mapStateToProps, mapDispatchToProps)(View); export default connect(mapStateToProps, mapDispatchToProps)(View);

View file

@ -4,11 +4,9 @@ import PublishTool from '@containers/PublishTool';
import ContentPageWrapper from '@pages/ContentPageWrapper'; import ContentPageWrapper from '@pages/ContentPageWrapper';
class HomePage extends React.Component { class HomePage extends React.Component {
componentDidMount () { componentWillUnmount () {
if (this.props.isUpdate) {
this.props.clearFile(); this.props.clearFile();
} }
}
render () { render () {
const { homeChannel } = this.props; const { homeChannel } = this.props;
return homeChannel ? ( return homeChannel ? (