lbry-desktop/src/renderer/modal/modalError/view.jsx

71 lines
1.8 KiB
React
Raw Normal View History

2018-09-26 19:48:07 +02:00
// @flow
import React from 'react';
2018-04-18 06:03:01 +02:00
import Native from 'native';
import { ExpandableModal } from 'modal/modal';
2017-04-07 07:15:22 +02:00
2018-09-26 19:48:07 +02:00
type Props = {
error: string | { message: string },
closeModal: () => void,
};
class ModalError extends React.PureComponent<Props> {
2017-04-07 07:15:22 +02:00
render() {
2017-09-08 05:15:05 +02:00
const { closeModal, error } = this.props;
2017-04-07 07:15:22 +02:00
const errorObj = typeof error === 'string' ? { message: error } : error;
2017-05-24 23:53:03 +02:00
2018-04-18 06:03:01 +02:00
const errorKeyLabels = {
connectionString: __('API connection string'),
method: __('Method'),
params: __('Parameters'),
code: __('Error code'),
message: __('Error message'),
data: __('Error data'),
2017-06-06 23:19:12 +02:00
};
2017-06-06 06:21:55 +02:00
2017-06-06 23:19:12 +02:00
const errorInfoList = [];
for (const key of Object.keys(errorObj)) {
const val = typeof errorObj[key] === 'string' ? errorObj[key] : JSON.stringify(errorObj[key]);
2018-04-18 06:03:01 +02:00
const label = errorKeyLabels[key];
2017-06-06 23:19:12 +02:00
errorInfoList.push(
2017-11-24 15:31:05 +01:00
<li key={key}>
2018-09-26 19:48:07 +02:00
<strong>{label}</strong>: {val}
2017-11-24 15:31:05 +01:00
</li>
2017-06-06 23:19:12 +02:00
);
2017-04-07 07:15:22 +02:00
}
2018-09-26 19:48:07 +02:00
const errorInfo = <ul className="error-modal__error-list">{errorInfoList}</ul>;
2017-04-07 07:15:22 +02:00
2017-06-06 23:19:12 +02:00
return (
2017-04-07 07:15:22 +02:00
<ExpandableModal
isOpen
contentLabel={__('Error')}
2018-09-26 19:48:07 +02:00
title={
<React.Fragment>
{__('Error')}{' '}
2018-04-18 06:03:01 +02:00
<img
alt=""
className="error-modal__warning-symbol"
src={Native.imagePath('warning.png')}
/>
2018-09-26 19:48:07 +02:00
</React.Fragment>
}
className="error-modal"
overlayClassName="error-modal-overlay"
onConfirmed={closeModal}
extraContent={errorInfo}
>
<section className="card__content">
2017-06-06 23:19:12 +02:00
<p>
{__(
"We're sorry that LBRY has encountered an error. This has been reported and we will investigate the problem."
)}
</p>
2018-09-26 19:48:07 +02:00
</section>
2017-04-07 07:15:22 +02:00
</ExpandableModal>
2017-06-06 23:19:12 +02:00
);
2017-04-07 07:15:22 +02:00
}
}
2017-07-02 20:23:38 +02:00
export default ModalError;