Skip to content

Commit fcc71f4

Browse files
committed
the add project form now cancels with the correct return path
1 parent 035e081 commit fcc71f4

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/layouts/ProjectSubLayout.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import AuthenticationLayout from '../projects/authentication/AuthenticationLayou
88
import DatabaseHome from '../projects/database/DatabaseHome'
99
import DatabaseLayout from '../projects/database/DatabaseLayout'
1010

11-
const ProjectSubLayout = ({ match }) => {
11+
const ProjectSubLayout = ({ match, pathname }) => {
1212
const [project, setProject] = useState(false)
1313
const { projectId } = match.params
1414

@@ -30,7 +30,9 @@ const ProjectSubLayout = ({ match }) => {
3030
<nav className="project-nav horizontal-spacing" style={{ color: 'white' }}>
3131
<span className="text-light-tint">{project.name}</span>
3232
<span> : </span>
33-
<Link to="/projects/add" className="text-light-tint">
33+
<Link
34+
to={{ pathname: '/projects/add', state: { cancelPathname: location.pathname } }}
35+
className="text-light-tint">
3436
Add Project
3537
</Link>
3638
</nav>

src/projects/AddProject.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useState } from 'react'
22
import { Link, Prompt } from 'react-router-dom'
33
import Card from '../ui/Card'
44

5-
const AddProject = () => {
5+
const AddProject = ({ location }) => {
66
const [formIsDirty, setFormIsDirty] = useState(false)
77

88
function handleSubmit(e) {
@@ -16,9 +16,9 @@ const AddProject = () => {
1616
<input onChange={() => setFormIsDirty(true)} type="text" placeholder="Project Name" required />
1717
<footer className="horizontal-spacing">
1818
<button type="submit" className="button">
19-
Add Project.
19+
Add Project
2020
</button>
21-
<Link to="/projects">Cancel</Link>
21+
<Link to={(location.state && location.state.cancelPathname) || '/projects'}>Cancel</Link>
2222
</footer>
2323
</form>
2424
</Card>

0 commit comments

Comments
 (0)