forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror-view.js
54 lines (49 loc) · 1.46 KB
/
error-view.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import React from 'react';
import PropTypes from 'prop-types';
export default class ErrorView extends React.Component {
static propTypes = {
title: PropTypes.string,
descriptions: PropTypes.arrayOf(PropTypes.string),
preformatted: PropTypes.bool,
retry: PropTypes.func,
logout: PropTypes.func,
}
static defaultProps = {
title: 'Error',
descriptions: ['An unknown error occurred'],
preformatted: false,
}
render() {
return (
<div className="github-Message">
<div className="github-Message-wrapper">
<h1 className="github-Message-title">{this.props.title}</h1>
{this.props.descriptions.map(this.renderDescription)}
<div className="github-Message-action">
{this.props.retry && (
<button className="github-Message-button btn btn-primary" onClick={this.props.retry}>Try Again</button>
)}
{this.props.logout && (
<button className="github-Message-button btn btn-logout" onClick={this.props.logout}>Logout</button>
)}
</div>
</div>
</div>
);
}
renderDescription = (description, key) => {
if (this.props.preformatted) {
return (
<pre key={key} className="github-Message-description">
{description}
</pre>
);
} else {
return (
<p key={key} className="github-Message-description">
{description}
</p>
);
}
}
}