Skip to content

Commit c81f00e

Browse files
committed
Extract Error from login component
1 parent 740d85e commit c81f00e

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

app/components/Error/Error.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react';
2+
3+
const Error = ({error}) => (
4+
error ?
5+
<div className="notification is-danger">
6+
{error}
7+
</div> : null
8+
);
9+
export default Error;

app/components/Login/LoginComponent.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import { Router } from 'react-router'
33

44
import User from 'services/User';
5+
import ErrorComponent from 'components/Error/Error';
56

67
class LoginComponent extends React.Component{
78
constructor(props, context) {
@@ -37,13 +38,6 @@ class LoginComponent extends React.Component{
3738
}
3839

3940
render() {
40-
let error = <span></span>;
41-
if (this.state.error) {
42-
error = <div className="notification is-danger">
43-
<button className="delete" onClick={this.handleDeleteMessage}></button>
44-
{this.state.error}
45-
</div>;
46-
}
4741
return (
4842
<section className="hero is-fullheight is-primary">
4943
<div className="hero-body">
@@ -55,7 +49,7 @@ class LoginComponent extends React.Component{
5549
</h1>
5650
<form onSubmit={this.handleSubmit}>
5751
<div className="box">
58-
{error}
52+
<ErrorComponent error={this.state.error} />
5953
<label className="label">Username</label>
6054
<p className="control">
6155
<input

0 commit comments

Comments
 (0)