2021-04-12 13:32:25 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import PropTypes from "prop-types";
|
|
|
|
|
import classnames from "classnames";
|
|
|
|
|
|
|
|
|
|
import notificationInterface from "interfaces/notification";
|
|
|
|
|
import KolideIcon from "components/icons/KolideIcon";
|
|
|
|
|
import Button from "components/buttons/Button";
|
|
|
|
|
|
|
|
|
|
const baseClass = "flash-message";
|
|
|
|
|
|
|
|
|
|
const FlashMessage = ({
|
|
|
|
|
fullWidth,
|
|
|
|
|
notification,
|
|
|
|
|
onRemoveFlash,
|
|
|
|
|
onUndoActionClick,
|
|
|
|
|
}) => {
|
2016-10-03 17:54:22 +00:00
|
|
|
const { alertType, isVisible, message, undoAction } = notification;
|
2016-12-29 20:27:43 +00:00
|
|
|
const klass = classnames(baseClass, `${baseClass}--${alertType}`, {
|
|
|
|
|
[`${baseClass}--full-width`]: fullWidth,
|
|
|
|
|
});
|
2016-10-03 17:54:22 +00:00
|
|
|
|
2016-10-19 20:22:18 +00:00
|
|
|
if (!isVisible) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-10-03 17:54:22 +00:00
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
const alertIcon =
|
|
|
|
|
alertType === "success" ? "success-check" : "warning-filled";
|
2017-01-05 18:08:19 +00:00
|
|
|
|
2016-10-03 17:54:22 +00:00
|
|
|
return (
|
2016-12-29 20:27:43 +00:00
|
|
|
<div className={klass}>
|
2016-11-03 19:40:54 +00:00
|
|
|
<div className={`${baseClass}__content`}>
|
2020-12-15 02:24:16 +00:00
|
|
|
<KolideIcon name={alertIcon} /> <span>{message}</span>
|
2021-04-12 13:32:25 +00:00
|
|
|
{undoAction && (
|
2017-01-05 18:08:19 +00:00
|
|
|
<Button
|
|
|
|
|
className={`${baseClass}__undo`}
|
|
|
|
|
variant="unstyled"
|
|
|
|
|
onClick={onUndoActionClick(undoAction)}
|
|
|
|
|
>
|
|
|
|
|
Undo
|
|
|
|
|
</Button>
|
2021-04-12 13:32:25 +00:00
|
|
|
)}
|
2016-10-03 17:54:22 +00:00
|
|
|
</div>
|
2016-11-03 19:40:54 +00:00
|
|
|
<div className={`${baseClass}__action`}>
|
2017-01-05 18:08:19 +00:00
|
|
|
<Button
|
|
|
|
|
className={`${baseClass}__remove ${baseClass}__remove--${alertType}`}
|
|
|
|
|
variant="unstyled"
|
2016-12-05 17:55:30 +00:00
|
|
|
onClick={onRemoveFlash}
|
2016-10-21 23:13:41 +00:00
|
|
|
>
|
2020-12-15 02:24:16 +00:00
|
|
|
<KolideIcon name="x" />
|
2017-01-05 18:08:19 +00:00
|
|
|
</Button>
|
2016-10-03 17:54:22 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
FlashMessage.propTypes = {
|
2016-12-29 20:27:43 +00:00
|
|
|
fullWidth: PropTypes.bool,
|
2016-10-21 23:13:41 +00:00
|
|
|
notification: notificationInterface,
|
2016-12-05 17:55:30 +00:00
|
|
|
onRemoveFlash: PropTypes.func,
|
|
|
|
|
onUndoActionClick: PropTypes.func,
|
2016-10-03 17:54:22 +00:00
|
|
|
};
|
|
|
|
|
|
2016-11-03 19:40:54 +00:00
|
|
|
export default FlashMessage;
|