Skip to content

Commit 0f5803b

Browse files
author
Ives van Hoorne
committed
Different confirm
1 parent 9a54e92 commit 0f5803b

File tree

4 files changed

+38
-9
lines changed

4 files changed

+38
-9
lines changed

src/app/components/ConfirmLink.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// @flow
2+
import React from 'react';
3+
import { Link } from 'react-router-dom';
4+
5+
type Props = {
6+
enabled: boolean,
7+
message: string,
8+
};
9+
10+
export default class ConfirmLink extends React.PureComponent {
11+
props: Props;
12+
confirm = (e: Event) => {
13+
const { enabled, message } = this.props;
14+
15+
if (enabled) {
16+
const yes = confirm(message);
17+
18+
if (!yes) {
19+
e.preventDefault();
20+
e.stopPropagation();
21+
}
22+
}
23+
};
24+
25+
render() {
26+
const { enabled, message, ...props } = this.props;
27+
return <Link onClick={this.confirm} {...props} />;
28+
}
29+
}

src/app/pages/Sandbox/Editor/Content/index.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,6 @@ class EditorPreview extends React.PureComponent {
161161

162162
return (
163163
<FullSize>
164-
<Prompt
165-
when={notSynced}
166-
message={() =>
167-
'You have not saved this sandbox, are you sure you want to navigate away?'}
168-
/>
169164
<Header
170165
sandbox={sandbox}
171166
sandboxActions={sandboxActions}

src/app/pages/Sandbox/Editor/Workspace/Project/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import styled from 'styled-components';
3-
import { Link } from 'react-router-dom';
3+
import ConfirmLink from 'app/components/ConfirmLink';
44
import WorkspaceSubtitle from '../WorkspaceSubtitle';
55
import WorkspaceInputContainer from '../WorkspaceInputContainer';
66
import { sandboxUrl } from '../../../../../utils/url-generator';
@@ -58,7 +58,7 @@ export default class Project extends React.PureComponent {
5858
};
5959

6060
render() {
61-
const { forkedSandbox } = this.props;
61+
const { forkedSandbox, preventTransition } = this.props;
6262
const { title, description } = this.state;
6363
return (
6464
<div>
@@ -88,9 +88,13 @@ export default class Project extends React.PureComponent {
8888
<WorkspaceSubtitle>Forked from</WorkspaceSubtitle>
8989

9090
<Item>
91-
<Link to={sandboxUrl(forkedSandbox)}>
91+
<ConfirmLink
92+
enabled={preventTransition}
93+
message="You have unsaved changes. Are you sure you want to navigate away?"
94+
to={sandboxUrl(forkedSandbox)}
95+
>
9296
{forkedSandbox.title || forkedSandbox.id}
93-
</Link>
97+
</ConfirmLink>
9498
</Item>
9599
</div>}
96100
</div>

src/app/pages/Sandbox/Editor/Workspace/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const Workspace = ({ sandbox, sandboxActions }: Props) => (
4545
title={sandbox.title}
4646
description={sandbox.description}
4747
forkedSandbox={sandbox.forkedFromSandbox}
48+
preventTransition={sandbox.modules.some(m => m.isNotSynced)}
4849
/>
4950
</WorkspaceItem>
5051

0 commit comments

Comments
 (0)