@atlaskit/profilecard
Version:
A React component to display a card with user information.
43 lines • 1.85 kB
JavaScript
import React, { useEffect } from 'react';
import { FormattedMessage } from 'react-intl-next';
import Button from '@atlaskit/button/new';
import CrossCircleIcon from '@atlaskit/icon/core/cross-circle';
import { Text } from '@atlaskit/primitives/compiled';
import messages from '../../messages';
import { ErrorTitle, ErrorWrapper } from '../../styled/Error';
import { PACKAGE_META_DATA } from '../../util/analytics';
const ErrorMessage = props => {
const errorType = props.errorType || {
reason: 'default'
};
const errorReason = errorType.reason;
const {
fireAnalytics,
reload
} = props;
const hasRetry = !!reload;
useEffect(() => {
fireAnalytics('ui.profilecard.rendered.error', {
hasRetry,
errorType: errorReason,
firedAt: Math.round(performance.now()),
...PACKAGE_META_DATA
});
}, [errorReason, fireAnalytics, hasRetry]);
const errorContent = () => {
if (errorReason === 'NotFound') {
return /*#__PURE__*/React.createElement(ErrorTitle, null, /*#__PURE__*/React.createElement(FormattedMessage, messages.errorUserNotFound));
}
return /*#__PURE__*/React.createElement(ErrorTitle, null, /*#__PURE__*/React.createElement(FormattedMessage, messages.errorGeneric), /*#__PURE__*/React.createElement("br", null), reload && /*#__PURE__*/React.createElement(Text, {
color: "color.text.subtlest"
}, /*#__PURE__*/React.createElement(FormattedMessage, messages.errorRetrySuggestion)));
};
return /*#__PURE__*/React.createElement(ErrorWrapper, {
testId: "profilecard-error"
}, /*#__PURE__*/React.createElement(CrossCircleIcon, {
label: "icon error"
}), errorContent(), reload && /*#__PURE__*/React.createElement(Button, {
onClick: reload
}, /*#__PURE__*/React.createElement(FormattedMessage, messages.errorTryAgain)));
};
export default ErrorMessage;