INTO-CPS-Association/DTaaS

View on GitHub
client/src/preview/route/digitaltwins/Snackbar.tsx

Summary

Maintainability
A
0 mins
Test Coverage
import * as React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import Snackbar from '@mui/material/Snackbar';
import Alert from '@mui/material/Alert';
import { RootState } from 'store/store';
import { hideSnackbar } from 'preview/store/snackbar.slice';

const CustomSnackbar: React.FC = () => {
  const dispatch = useDispatch();

  const { open, message, severity } = useSelector(
    (state: RootState) => state.snackbar,
  );

  const handleClose = () => {
    dispatch(hideSnackbar());
  };

  return (
    <Snackbar open={open} autoHideDuration={6000} onClose={handleClose}>
      <Alert onClose={handleClose} severity={severity}>
        {message}
      </Alert>
    </Snackbar>
  );
};

export default CustomSnackbar;