|
1 | 1 | import useToastStore from '@/stores/toastStore'; |
2 | | -import { useEffect } from 'react'; |
3 | | -import { twMerge } from 'tailwind-merge'; |
| 2 | +import ToastItem from './ToastItem'; |
4 | 3 |
|
5 | 4 | interface Toast {} |
6 | 5 | export default function Toast({}: Toast) { |
7 | | - const isActive = useToastStore((state) => state.isActive); |
8 | | - const toastObj = useToastStore((state) => state.toastObj); |
9 | | - const setToastUnActive = useToastStore((state) => state.setToastUnActive); |
| 6 | + const toastObjects = useToastStore((state) => state.toastObjects); |
10 | 7 |
|
11 | | - const TOAST_DESIGN = { |
12 | | - Warning: { style: 'bg-primary-4', imoji: '⚠️' }, |
13 | | - Success: { style: 'bg-[#38d9a9] text-[#FFFFFF]', imoji: '✅' }, |
14 | | - Error: { style: 'bg-[#FFDCD8] text-[#FF0000]', imoji: '🚨' }, |
15 | | - Info: { style: 'bg-[#FFFFFF]', imoji: 'ℹ️' }, |
16 | | - }; |
17 | | - |
18 | | - const animation = `toast-blink ${toastObj.time}s ease-in-out forwards`; |
19 | | - const toastStyle = twMerge( |
20 | | - 'fixed bottom-20 left-1/2 z-40 flex h-[40px] max-w-150 min-w-[335px] w-[85%] -translate-1/2 items-center justify-center rounded-2xl caption-sb', |
21 | | - TOAST_DESIGN[toastObj.toastType].style, |
22 | | - ); |
23 | | - |
24 | | - const activeTime = toastObj.time * 1000; |
25 | | - useEffect(() => { |
26 | | - const closeToast = setTimeout(() => { |
27 | | - setToastUnActive(); |
28 | | - }, activeTime); |
29 | | - |
30 | | - return () => clearTimeout(closeToast); |
31 | | - }); |
32 | | - |
33 | | - if (!isActive) return null; |
| 8 | + if (toastObjects.length <= 0) return; |
34 | 9 | return ( |
35 | | - <div className={toastStyle} style={{ animation: animation }} onClick={() => setToastUnActive()}> |
36 | | - {`${TOAST_DESIGN[toastObj.toastType].imoji} ${toastObj.content} ${TOAST_DESIGN[toastObj.toastType].imoji}`} |
37 | | - </div> |
| 10 | + <> |
| 11 | + {toastObjects.map((toastObj, index) => ( |
| 12 | + <ToastItem toastObj={toastObj} index={index} key={index} /> |
| 13 | + ))} |
| 14 | + </> |
38 | 15 | ); |
39 | 16 | } |
0 commit comments