mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-22 04:49:36 +02:00
52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
import { useEffect, useState } from 'react';
|
|
import { connect } from 'react-redux';
|
|
import { clearNotification } from '../../../store/actions';
|
|
|
|
import classes from './Notification.module.css';
|
|
|
|
interface ComponentProps {
|
|
title: string;
|
|
message: string;
|
|
id: number;
|
|
url: string | null;
|
|
clearNotification: (id: number) => void;
|
|
}
|
|
|
|
const Notification = (props: ComponentProps): JSX.Element => {
|
|
const [isOpen, setIsOpen] = useState(true);
|
|
const elementClasses = [
|
|
classes.Notification,
|
|
isOpen ? classes.NotificationOpen : classes.NotificationClose,
|
|
].join(' ');
|
|
|
|
useEffect(() => {
|
|
const closeNotification = setTimeout(() => {
|
|
setIsOpen(false);
|
|
}, 3500);
|
|
|
|
const clearNotification = setTimeout(() => {
|
|
props.clearNotification(props.id);
|
|
}, 3600);
|
|
|
|
return () => {
|
|
window.clearTimeout(closeNotification);
|
|
window.clearTimeout(clearNotification);
|
|
};
|
|
}, []);
|
|
|
|
const clickHandler = () => {
|
|
if (props.url) {
|
|
window.open(props.url, '_blank');
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div className={elementClasses} onClick={clickHandler}>
|
|
<h4>{props.title}</h4>
|
|
<p>{props.message}</p>
|
|
<div className={classes.Pog}></div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default connect(null, { clearNotification })(Notification);
|