// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import $ from 'jquery'; import React from 'react'; import {FormattedMessage} from 'react-intl'; import {Link} from 'react-router/es6'; import {ErrorPageTypes} from 'utils/constants.jsx'; import * as TextFormatting from 'utils/text_formatting.jsx'; import * as Utils from 'utils/utils.jsx'; export default class ErrorPage extends React.Component { static propTypes = { location: React.PropTypes.object.isRequired }; constructor(props) { super(props); this.renderTitle = this.renderTitle.bind(this); this.renderMessage = this.renderMessage.bind(this); this.renderLink = this.renderLink.bind(this); } componentDidMount() { $('body').attr('class', 'sticky error'); } componentWillUnmount() { $('body').attr('class', ''); } linkFilter(link) { return link.startsWith('https://docs.mattermost.com') || link.startsWith('https://forum.mattermost.org'); } renderTitle() { if (this.props.location.query.type === ErrorPageTypes.LOCAL_STORAGE) { return ( ); } if (this.props.location.query.title) { return this.props.location.query.title; } return Utils.localizeMessage('error.generic.title', 'Error'); } renderMessage() { if (this.props.location.query.type === ErrorPageTypes.LOCAL_STORAGE) { return (
); } let message = this.props.location.query.message; if (!message) { message = Utils.localizeMessage('error.generic.message', 'An error has occoured.'); } return
; } renderLink() { let link = this.props.location.query.link; if (link) { link = link.trim(); } else { link = '/'; } if (!link.startsWith('/')) { // Only allow relative links link = '/'; } let linkMessage = this.props.location.query.linkmessage; if (!linkMessage) { linkMessage = Utils.localizeMessage('error.generic.link_message', 'Back to Mattermost'); } return ( {linkMessage} ); } render() { const title = this.renderTitle(); const message = this.renderMessage(); const link = this.renderLink(); return (

{title}

{message} {link}
); } }