Alert.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import React from 'react';
  2. import cx from 'classnames';
  3. import { useDispatch } from 'react-redux';
  4. import { dismissAlert } from 'redux/actions';
  5. import { Alert as AlertProps } from 'redux/interfaces';
  6. const Alert: React.FC<AlertProps> = ({
  7. id,
  8. type,
  9. title,
  10. message,
  11. response,
  12. }) => {
  13. const classNames = React.useMemo(
  14. () =>
  15. cx('notification', {
  16. 'is-danger': type === 'error',
  17. 'is-success': type === 'success',
  18. 'is-info': type === 'info',
  19. 'is-warning': type === 'warning',
  20. }),
  21. [type]
  22. );
  23. const dispatch = useDispatch();
  24. const dismiss = React.useCallback(() => {
  25. dispatch(dismissAlert(id));
  26. }, []);
  27. return (
  28. <div className={classNames}>
  29. <button className="delete" type="button" onClick={dismiss}>
  30. x
  31. </button>
  32. <div>
  33. <h6 className="title is-6">{title}</h6>
  34. <p className="subtitle is-6">{message}</p>
  35. {response && (
  36. <div className="is-flex">
  37. <div className="mr-3">{response.status}</div>
  38. <div>{response.body?.message || response.statusText}</div>
  39. </div>
  40. )}
  41. </div>
  42. </div>
  43. );
  44. };
  45. export default Alert;