import fs from 'fs';
import temp from 'temp';
import { shell } from 'electron';
import { React, PropTypes, RegExpUtils } from 'mailspring-exports';
const FormErrorMessage = props => {
const { message, log, empty } = props;
if (!message) {
return
{empty}
;
}
let rawLogLink = false;
if (log && log.length > 0) {
const onViewLog = () => {
const logPath = temp.path({ suffix: '.log' });
fs.writeFileSync(logPath, log);
shell.openItem(logPath);
};
rawLogLink = (
View Log
);
}
const linkMatch = RegExpUtils.urlRegex({ matchEntireString: false }).exec(message);
if (linkMatch) {
const link = linkMatch[0];
return (
{message.substr(0, linkMatch.index)}
{link}
{message.substr(linkMatch.index + link.length)}
{rawLogLink}
);
}
return (
{message}
{rawLogLink}
);
};
FormErrorMessage.propTypes = {
empty: PropTypes.string,
message: PropTypes.string,
};
export default FormErrorMessage;