2019-06-19 14:40:52 +00:00
|
|
|
import Button from "@material-ui/core/Button";
|
|
|
|
import IconButton from "@material-ui/core/IconButton";
|
2020-06-24 11:44:35 +00:00
|
|
|
import SnackbarContent from "@material-ui/core/SnackbarContent";
|
2019-11-25 16:23:52 +00:00
|
|
|
import Typography from "@material-ui/core/Typography";
|
2019-06-19 14:40:52 +00:00
|
|
|
import CloseIcon from "@material-ui/icons/Close";
|
2020-06-23 11:47:30 +00:00
|
|
|
import classNames from "classnames";
|
|
|
|
import React, { useState } from "react";
|
|
|
|
import { FormattedMessage } from "react-intl";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2020-06-30 19:32:20 +00:00
|
|
|
import { INotification } from "./";
|
2020-06-23 11:47:30 +00:00
|
|
|
import { useStyles } from "./styles";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2020-06-30 17:41:43 +00:00
|
|
|
export interface IMessageManagerProps extends INotification {
|
2020-07-02 12:44:03 +00:00
|
|
|
onMouseEnter?: () => void;
|
|
|
|
onMouseLeave?: () => void;
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
|
2020-06-30 17:41:43 +00:00
|
|
|
export const MessageManagerTemplate: React.FC<IMessageManagerProps> = props => {
|
2020-06-24 11:44:35 +00:00
|
|
|
const {
|
|
|
|
close,
|
2020-06-30 17:41:43 +00:00
|
|
|
onMouseEnter,
|
|
|
|
onMouseLeave,
|
2020-06-30 19:32:20 +00:00
|
|
|
message: { actionBtn, expandText, status = "info", title, text, onUndo },
|
|
|
|
timeout
|
2020-06-24 11:44:35 +00:00
|
|
|
} = props;
|
2020-06-23 11:47:30 +00:00
|
|
|
|
2020-06-23 16:02:59 +00:00
|
|
|
const [expand, setExpand] = useState(false);
|
2020-06-23 11:47:30 +00:00
|
|
|
|
|
|
|
const classes = useStyles({});
|
2020-07-02 13:39:11 +00:00
|
|
|
const id = props.id.toString();
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2020-06-23 11:47:30 +00:00
|
|
|
return (
|
2020-06-30 17:41:43 +00:00
|
|
|
<div
|
|
|
|
key={props.id}
|
|
|
|
className={classes.snackbarContainer}
|
2020-07-02 13:39:11 +00:00
|
|
|
onMouseEnter={onMouseEnter}
|
|
|
|
onMouseLeave={onMouseLeave}
|
2020-06-30 17:41:43 +00:00
|
|
|
>
|
2020-06-24 11:44:35 +00:00
|
|
|
<SnackbarContent
|
2020-07-02 13:39:11 +00:00
|
|
|
id={id}
|
|
|
|
key={id}
|
|
|
|
aria-describedby={`message-id-${id}`}
|
2020-06-23 11:47:30 +00:00
|
|
|
className={classNames(classes.snackbar, {
|
2020-06-24 14:17:56 +00:00
|
|
|
[classes.info]: status === "info",
|
2020-06-23 11:47:30 +00:00
|
|
|
[classes.error]: status === "error",
|
|
|
|
[classes.success]: status === "success",
|
|
|
|
[classes.warning]: status === "warning"
|
|
|
|
})}
|
|
|
|
message={
|
2020-07-02 13:39:11 +00:00
|
|
|
<span id={`message-id-${id}`} data-test="notification">
|
2020-06-23 11:47:30 +00:00
|
|
|
{title && (
|
|
|
|
<Typography variant="h5" style={{ fontWeight: "bold" }}>
|
|
|
|
{title}
|
|
|
|
</Typography>
|
|
|
|
)}
|
|
|
|
<Typography
|
|
|
|
className={status === "info" ? classes.textInfo : classes.text}
|
|
|
|
>
|
2019-08-27 13:29:00 +00:00
|
|
|
{text}
|
2020-06-23 11:47:30 +00:00
|
|
|
</Typography>
|
|
|
|
</span>
|
|
|
|
}
|
|
|
|
action={[
|
2020-06-23 16:02:59 +00:00
|
|
|
!!expandText ? (
|
|
|
|
<div
|
2020-06-24 11:44:35 +00:00
|
|
|
key="expanded"
|
2020-06-23 16:02:59 +00:00
|
|
|
className={classNames(classes.expandedContainer, {
|
|
|
|
[classes.expandedContainerInfo]: status === "info"
|
|
|
|
})}
|
2020-06-23 11:47:30 +00:00
|
|
|
>
|
2020-06-23 16:02:59 +00:00
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
classes.expandedContainerContent,
|
|
|
|
expand ? classes.expandedText : classes.hiddenText
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<p>{expandText}</p>
|
|
|
|
</div>
|
|
|
|
<button
|
|
|
|
className={classNames(classes.expandBtn, {
|
|
|
|
[classes.expandBtnInfo]: status === "info"
|
|
|
|
})}
|
|
|
|
onClick={() => {
|
|
|
|
setExpand(expand => !expand);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{!expand ? (
|
|
|
|
<FormattedMessage
|
|
|
|
defaultMessage="Expand"
|
|
|
|
description="snackbar expand"
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<FormattedMessage
|
|
|
|
defaultMessage="Collapse"
|
|
|
|
description="snackbar collapse"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</button>
|
|
|
|
</div>
|
2020-06-23 11:47:30 +00:00
|
|
|
) : (
|
|
|
|
undefined
|
|
|
|
),
|
2020-06-23 16:02:59 +00:00
|
|
|
<div key="actions" className={classes.actionContainer}>
|
|
|
|
{!!onUndo && (
|
|
|
|
<Button
|
|
|
|
key="undo"
|
|
|
|
color="default"
|
|
|
|
size="small"
|
2020-06-24 11:44:35 +00:00
|
|
|
onClick={close}
|
2020-07-02 12:55:39 +00:00
|
|
|
data-test="button-undo"
|
2020-06-23 16:02:59 +00:00
|
|
|
>
|
|
|
|
<FormattedMessage
|
|
|
|
defaultMessage="Undo"
|
|
|
|
description="snackbar button undo"
|
|
|
|
/>
|
|
|
|
</Button>
|
|
|
|
)}
|
|
|
|
{!!actionBtn && (
|
|
|
|
<Button
|
|
|
|
key="action"
|
|
|
|
color="default"
|
|
|
|
size="small"
|
|
|
|
onClick={actionBtn.action}
|
2020-07-02 12:55:39 +00:00
|
|
|
data-test="button-action"
|
2020-06-23 16:02:59 +00:00
|
|
|
>
|
|
|
|
{actionBtn.label}
|
|
|
|
</Button>
|
|
|
|
)}
|
|
|
|
</div>,
|
2020-06-23 11:47:30 +00:00
|
|
|
<IconButton
|
|
|
|
key="close"
|
|
|
|
aria-label="Close"
|
|
|
|
color="inherit"
|
2020-06-24 11:44:35 +00:00
|
|
|
onClick={close}
|
2020-06-23 16:02:59 +00:00
|
|
|
className={classNames(classes.closeBtn, {
|
|
|
|
[classes.closeBtnInfo]: status === "info"
|
|
|
|
})}
|
2020-06-23 11:47:30 +00:00
|
|
|
>
|
|
|
|
<CloseIcon />
|
|
|
|
</IconButton>,
|
|
|
|
<div className={classes.progressBarContainer} key="progressBar">
|
|
|
|
<div
|
|
|
|
className={classNames(classes.progressBar, {
|
|
|
|
[classes.progressBarSuccess]: status === "success",
|
|
|
|
[classes.progressBarWarning]: status === "warning",
|
|
|
|
[classes.progressBarError]: status === "error"
|
|
|
|
})}
|
2020-06-24 11:44:35 +00:00
|
|
|
style={{ ["--animationTime" as any]: `${timeout}ms` }}
|
2020-06-23 11:47:30 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
]}
|
|
|
|
/>
|
2020-06-24 11:44:35 +00:00
|
|
|
</div>
|
2020-06-23 11:47:30 +00:00
|
|
|
);
|
|
|
|
};
|