-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mod: code review
- Loading branch information
Showing
6 changed files
with
153 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
.errPage { | ||
width: 100%; | ||
height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
background-color: #fff; | ||
.errImg { | ||
width: 436px; | ||
margin-bottom: 20px; | ||
} | ||
.errText { | ||
font-weight: 400; | ||
font-size: 24px; | ||
line-height: 34px; | ||
margin-bottom: 8px; | ||
} | ||
.errTip { | ||
font-weight: 400; | ||
font-size: 12px; | ||
line-height: 17px; | ||
color: #595959; | ||
margin-bottom: 18px; | ||
} | ||
.btns { | ||
margin-bottom: 50px; | ||
button:not(:last-child) { | ||
margin-right: 15px; | ||
} | ||
} | ||
|
||
.errContainer { | ||
max-width: 1180px; | ||
padding: 18px 30px; | ||
background: #FFFFFF; | ||
box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.25); | ||
.header { | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
margin-bottom: 20px; | ||
} | ||
.errMsg { | ||
max-height: 400px; | ||
color: #B00000; | ||
overflow: auto; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React from 'react'; | ||
import errorImg from '@app/static/images/errorBoundary.png'; | ||
import intl from 'react-intl-universal'; | ||
import { CopyToClipboard } from 'react-copy-to-clipboard'; | ||
import { Button, message } from 'antd'; | ||
import { withRouter, RouteComponentProps } from 'react-router-dom'; | ||
import styles from './index.module.less'; | ||
|
||
interface IProps extends RouteComponentProps {} | ||
interface IState { | ||
errInfo: string; | ||
} | ||
class ErrorBoundary extends React.PureComponent<IProps, IState> { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
errInfo: null, | ||
}; | ||
} | ||
componentDidCatch(_error, errorInfo) { | ||
this.setState({ | ||
errInfo: errorInfo.componentStack, | ||
}); | ||
} | ||
componentDidUpdate(prevProps: Readonly<IProps>): void { | ||
if(prevProps.location.pathname !== this.props.location.pathname) { | ||
this.setState({ | ||
errInfo: null, | ||
}); | ||
} | ||
} | ||
|
||
handleCopy = () => { | ||
message.success(intl.get('common.copySuccess')); | ||
}; | ||
|
||
render() { | ||
const { errInfo } = this.state; | ||
if(!errInfo) return this.props.children; | ||
return <div className={styles.errPage}> | ||
<img src={errorImg} className={styles.errImg} /> | ||
<p className={styles.errText}>{intl.get('warning.crashPage')}</p> | ||
<p className={styles.errTip}>{intl.get('warning.crashPageTip')}</p> | ||
<div className={styles.btns}> | ||
<Button type="primary" onClick={() => window.location.reload()}>{intl.get('warning.refreshPage')}</Button> | ||
<Button onClick={() => window.open(intl.get('link.forumHref'), '_blank')}>{intl.get('warning.contactStaff')}</Button> | ||
</div> | ||
<div className={styles.errContainer}> | ||
<div className={styles.header}> | ||
<span>{intl.get('warning.errorMessage')}</span> | ||
<CopyToClipboard key={1} text={errInfo} onCopy={this.handleCopy}> | ||
<Button>{intl.get('common.copy')}</Button> | ||
</CopyToClipboard> | ||
</div> | ||
<p className={styles.errMsg}>{errInfo.toString()}</p> | ||
</div> | ||
</div>; | ||
} | ||
} | ||
|
||
export default withRouter(ErrorBoundary); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.