All files / src/app/public-shell PublicShellToastContainer.tsx

97.18% Statements 69/71
50% Branches 2/4
100% Functions 1/1
97.18% Lines 69/71

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 721x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 8x 8x 1x     1x 1x 1x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 1x 1x  
/**
 * @file PublicShellToastContainer.tsx
 * @description
 * Toast notification container for public shell.
 * Displays Snackbar with Alert based on toast state.
 *
 * @enterprise
 * - Fixed position at bottom-right (standard notification placement)
 * - Auto-hide after 2.5 seconds
 * - Supports success, info, warning, error severity levels
 * - Filled variant Alert for better visibility
 *
 * @example
 * ```tsx
 * <PublicShellToastContainer
 *   toast={toast}
 *   onClose={() => hideToast()}
 * />
 * ```
 */
import * as React from 'react';
import { Snackbar, Alert } from '@mui/material';
import type { SnackbarCloseReason } from '@mui/material/Snackbar';
import type { Toast } from './hooks';
 
interface PublicShellToastContainerProps {
  /** Toast state object or null if not visible */
  toast: Toast | null;
  /** Callback when toast should close */
  onClose: () => void;
}
 
/**
 * PublicShellToastContainer component
 * @param toast - Toast state
 * @param onClose - Close callback
 * @returns Snackbar with Alert notification
 */
const PublicShellToastContainer: React.FC<PublicShellToastContainerProps> = ({ toast, onClose }) => {
  const handleClose = React.useCallback(
    (_event: React.SyntheticEvent | Event, reason?: SnackbarCloseReason) => {
      if (reason === 'clickaway') {
        return;
      }
 
      onClose();
    },
    [onClose],
  );
 
  return (
    <Snackbar
      open={!!toast?.open}
      onClose={handleClose}
      autoHideDuration={2500}
      anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}
    >
      <Alert
        severity={toast?.severity || 'success'}
        elevation={1}
        variant="filled"
        onClose={handleClose}
        closeText="Close notification"
      >
        {toast?.msg}
      </Alert>
    </Snackbar>
  );
};
 
export default PublicShellToastContainer;