Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
Merge pull request #625 from metasfresh/dev-620
Browse files Browse the repository at this point in the history
When deleting a newly created document, frontend shall not ask the user if he/she wants to leave the page #620
  • Loading branch information
damianprzygodzki authored Apr 10, 2017
2 parents 0b302f7 + 7eff4d2 commit f72cab5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/components/Container.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Container extends Component {
docActionElem, docStatusData, docNoElement, docNoData,
docSummaryData, dataId, windowType, breadcrumb, references, actions,
showSidelist, siteName, connectionError, noMargin, entity, children,
query, attachments, showIndicator, isDocumentNotSaved, hideHeader
query, attachments, showIndicator, isDocumentNotSaved, hideHeader,
handleDeletedStatus
} = this.props;

return (
Expand All @@ -39,6 +40,7 @@ class Container extends Component {
query={query}
showIndicator={showIndicator}
isDocumentNotSaved={isDocumentNotSaved}
handleDeletedStatus={handleDeletedStatus}
/>
}
{connectionError && <ErrorScreen />}
Expand Down
3 changes: 2 additions & 1 deletion src/components/header/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class Header extends Component {
}

handlePromptSubmitClick = (windowType, docId) => {
const {dispatch} = this.props;
const {dispatch, handleDeletedStatus} = this.props;

this.setState({
prompt: Object.assign({}, this.state.prompt, {
Expand All @@ -182,6 +182,7 @@ class Header extends Component {
}, () => {
dispatch(deleteRequest('window', windowType, null, null, [docId]))
.then(() => {
handleDeletedStatus(true);
dispatch(push('/window/' + windowType));
});
}
Expand Down
13 changes: 11 additions & 2 deletions src/containers/MasterWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class MasterWindow extends Component {

this.state = {
newRow: false,
modalTitle: null
modalTitle: null,
isDeleted: false
}
}

Expand Down Expand Up @@ -53,12 +54,13 @@ class MasterWindow extends Component {

componentWillUnmount() {
const { master, dispatch } = this.props;
const { isDeleted } = this.state;
const {pathname} = this.props.location;
const isDocumentNotSaved =
!master.saveStatus.saved && master.saveStatus.saved !== undefined;
window.removeEventListener('beforeunload', this.confirm);

if(isDocumentNotSaved){
if(isDocumentNotSaved && !isDeleted){
const result = window.confirm('Do you really want to leave?');

if(!result){
Expand Down Expand Up @@ -124,6 +126,12 @@ class MasterWindow extends Component {
})
}

handleDeletedStatus = (param) => {
this.setState({
isDeleted: param
})
}

render() {
const {
master, modal, breadcrumb, references, actions, attachments,
Expand Down Expand Up @@ -169,6 +177,7 @@ class MasterWindow extends Component {
attachments={attachments}
showSidelist={true}
showIndicator={!modal.visible}
handleDeletedStatus={this.handleDeletedStatus}
isDocumentNotSaved={
!master.saveStatus.saved &&
!master.validStatus.initialValue
Expand Down

0 comments on commit f72cab5

Please sign in to comment.