AppNotificationItem.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import React, { Component } from 'react';
  2. import { AppNotification } from 'app/types';
  3. interface Props {
  4. appNotification: AppNotification;
  5. onClearNotification: (id) => void;
  6. }
  7. export default class AppNotificationItem extends Component<Props> {
  8. shouldComponentUpdate(nextProps) {
  9. return this.props.appNotification.id !== nextProps.appNotification.id;
  10. }
  11. componentDidMount() {
  12. const { appNotification, onClearNotification } = this.props;
  13. setTimeout(() => {
  14. onClearNotification(appNotification.id);
  15. }, appNotification.timeout);
  16. }
  17. render() {
  18. const { appNotification, onClearNotification } = this.props;
  19. return (
  20. <div className={`alert-${appNotification.severity} alert`}>
  21. <div className="alert-icon">
  22. <i className={appNotification.icon} />
  23. </div>
  24. <div className="alert-body">
  25. <div className="alert-title">{appNotification.title}</div>
  26. <div className="alert-text">{appNotification.text}</div>
  27. </div>
  28. <button type="button" className="alert-close" onClick={() => onClearNotification(appNotification.id)}>
  29. <i className="fa fa fa-remove" />
  30. </button>
  31. </div>
  32. );
  33. }
  34. }