All files / src/components/ToastClient index.tsx

100% Statements 16/16
100% Branches 8/8
100% Functions 1/1
100% Lines 16/16

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 281x 1x     1x             1x 5x 5x 5x 5x 5x   5x 3x 2x 5x   5x 5x   1x  
import { toast, Toaster } from 'sonner';
import { useEffect } from 'react';
 
// Types
import { ToastStatus } from '@shared/types';
 
interface ToastClientProps {
  message?: string;
  type?: ToastStatus;
}
 
const ToastClient = ({
  message = '',
  type = ToastStatus.Info,
}: ToastClientProps) => {
  useEffect(() => {
    if (!message?.trim()) return;
 
    if (type === ToastStatus.Success) toast.success(message);
    else if (type === ToastStatus.Error) toast.error(message);
    else toast(message);
  }, [message, type]);
 
  return <Toaster position="top-center" className="z-10 mt-20" />;
};
 
export default ToastClient;