Skip to content

Commit f3545e4

Browse files
committed
refactor: App.tsx에서 NotificationList 컴포넌트로 알림 표시 로직 분리
1 parent f36deee commit f3545e4

File tree

2 files changed

+54
-41
lines changed

2 files changed

+54
-41
lines changed

src/basic/App.tsx

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import {
1313
calculateItemTotal,
1414
getCartItemCount,
1515
} from "./utils/cartUtils";
16+
import { NotificationList } from "./NotificationList";
1617

17-
interface Notification {
18+
export interface Notification {
1819
id: string;
1920
message: string;
2021
type: "error" | "success" | "warning";
@@ -61,46 +62,10 @@ const App = () => {
6162

6263
return (
6364
<div className="min-h-screen bg-gray-50">
64-
{notifications.length > 0 && (
65-
<div className="fixed top-20 right-4 z-50 space-y-2 max-w-sm">
66-
{notifications.map((notif) => (
67-
<div
68-
key={notif.id}
69-
className={`p-4 rounded-md shadow-md text-white flex justify-between items-center ${
70-
notif.type === "error"
71-
? "bg-red-600"
72-
: notif.type === "warning"
73-
? "bg-yellow-600"
74-
: "bg-green-600"
75-
}`}
76-
>
77-
<span className="mr-2">{notif.message}</span>
78-
<button
79-
onClick={() =>
80-
setNotifications((prev) =>
81-
prev.filter((n) => n.id !== notif.id)
82-
)
83-
}
84-
className="text-white hover:text-gray-200"
85-
>
86-
<svg
87-
className="w-4 h-4"
88-
fill="none"
89-
stroke="currentColor"
90-
viewBox="0 0 24 24"
91-
>
92-
<path
93-
strokeLinecap="round"
94-
strokeLinejoin="round"
95-
strokeWidth={2}
96-
d="M6 18L18 6M6 6l12 12"
97-
/>
98-
</svg>
99-
</button>
100-
</div>
101-
))}
102-
</div>
103-
)}
65+
<NotificationList
66+
notifications={notifications}
67+
setNotifications={setNotifications}
68+
/>
10469
<Header
10570
isAdmin={isAdmin}
10671
setIsAdmin={setIsAdmin}

src/basic/NotificationList.tsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { Notification } from "./App";
2+
3+
export const NotificationList = ({
4+
notifications,
5+
setNotifications,
6+
}: {
7+
notifications: Notification[];
8+
setNotifications: React.Dispatch<React.SetStateAction<Notification[]>>;
9+
}) => {
10+
return (
11+
<div className="fixed top-20 right-4 z-50 space-y-2 max-w-sm">
12+
{notifications.map((notif) => (
13+
<div
14+
key={notif.id}
15+
className={`p-4 rounded-md shadow-md text-white flex justify-between items-center ${
16+
notif.type === "error"
17+
? "bg-red-600"
18+
: notif.type === "warning"
19+
? "bg-yellow-600"
20+
: "bg-green-600"
21+
}`}
22+
>
23+
<span className="mr-2">{notif.message}</span>
24+
<button
25+
onClick={() =>
26+
setNotifications((prev) => prev.filter((n) => n.id !== notif.id))
27+
}
28+
className="text-white hover:text-gray-200"
29+
>
30+
<svg
31+
className="w-4 h-4"
32+
fill="none"
33+
stroke="currentColor"
34+
viewBox="0 0 24 24"
35+
>
36+
<path
37+
strokeLinecap="round"
38+
strokeLinejoin="round"
39+
strokeWidth={2}
40+
d="M6 18L18 6M6 6l12 12"
41+
/>
42+
</svg>
43+
</button>
44+
</div>
45+
))}
46+
</div>
47+
);
48+
};

0 commit comments

Comments
 (0)