Skip to content

Commit 1ba97f9

Browse files
timdavishbbmoz
authored andcommitted
Feature/#155313760 - Mary sees error message when she fails to create a project (#175)
* fix(create-project): show error message on fail, prevent page refresh * chore(create-project): redirect to projects on success
1 parent 47314bc commit 1ba97f9

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

client/components/CreateProjectForm/CreateProjectForm.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ class CreateProjectForm extends Component {
3838
this.setState({projectName: event.target.value})
3939
}
4040

41-
async createProject () {
41+
async createProject (event) {
42+
event.preventDefault()
4243
const response = await projectsApiClient.createProject(
4344
this.state.projectName,
4445
this.state.causes,
@@ -47,6 +48,8 @@ class CreateProjectForm extends Component {
4748
)
4849
if (response.status === 500) {
4950
this.setState({error: response.statusText})
51+
} else {
52+
this.context.router.history.push('/profile')
5053
}
5154
}
5255

@@ -101,6 +104,11 @@ class CreateProjectForm extends Component {
101104
Create Project
102105
</Button>
103106

107+
{this.state.error &&
108+
<div className={styles.errorContent}>
109+
{this.state.error}
110+
</div>
111+
}
104112
</form>
105113
)
106114
}
@@ -113,6 +121,10 @@ function mapStateToProps (state) {
113121
}
114122
}
115123

124+
CreateProjectForm.contextTypes = {
125+
router: PropTypes.object
126+
}
127+
116128
CreateProjectForm.propTypes = {
117129
error: PropTypes.string,
118130
handleSubmit: PropTypes.func,

client/components/CreateProjectForm/CreateProjectForm.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,10 @@
2828
grid-column: 1 / 1;
2929
grid-row: 8;
3030
}
31+
32+
.errorContent {
33+
grid-row: 9;
34+
grid-column: 1 / 1;
35+
font-size: 1rem;
36+
color: $errorColor;
37+
}

0 commit comments

Comments
 (0)