Skip to content

Commit b1162e8

Browse files
authored
πŸ’„ Profile button on the header (#21)
### πŸ“ μž‘μ—… λ‚΄μš© - ν—€λ”μ˜ 'λ‘œκ·Έμ•„μ›ƒ' λ²„νŠΌμ„ ν”„λ‘œν•„ 아바타 λ²„νŠΌμœΌλ‘œ λŒ€μ²΄ν•˜μ˜€μŠ΅λ‹ˆλ‹€. - 이 κ³Όμ •μ—μ„œ `shadcn` UIλ₯Ό μΆ”κ°€ν•˜μ˜€μŠ΅λ‹ˆλ‹€. 이미 λ§Œλ“€μ–΄μ§„ μ»΄ν¬λ„ŒνŠΈλ₯Ό κ°€μ Έμ™€μ„œ μ“Έ 수 μžˆμŠ΅λ‹ˆλ‹€! - μžμ„Έν•œ λ‚΄μš©μ€ [shadcn/ui λ¬Έμ„œ](https://ui.shadcn.com/docs/components)λ₯Ό μ°Έμ‘°ν•˜μ„Έμš”. - 이외에도 `shadcn`μ—μ„œ μ»€μŠ€ν…€ ν›…, μ•„μ΄μ½˜ 등을 μ œκ³΅ν•˜λ‹ˆ [shadcn.io](https://www.shadcn.io)λ₯Ό ν™•μΈν•΄λ³΄μ‹œλ©΄ 쒋을 λ“―ν•©λ‹ˆλ‹€. - `./src` 경둜의 별칭을 `@`으둜 μ„€μ •ν•˜μ˜€μŠ΅λ‹ˆλ‹€. 이제 μ•„λž˜μ™€ 같이 경둜λ₯Ό μž‘μ„±ν•  수 μžˆμŠ΅λ‹ˆλ‹€. - 예: `../hooks/useAuth` β†’ `@/src/hooks/useAuth` - 기쑴의 μƒλŒ€ 경둜 방식도 μ—¬μ „νžˆ μ‚¬μš© κ°€λŠ₯ν•©λ‹ˆλ‹€. - `shadcn` UIλ₯Ό μ‚¬μš©ν•˜λ €λ©΄ `tw-animate-css` λΌμ΄λΈŒλŸ¬λ¦¬κ°€ ν•„μš”ν•œλ°, `knip`κ°€ 이 라이브러리λ₯Ό [μ‚¬μš©λ˜μ§€ μ•Šμ€ κ²ƒμœΌλ‘œ μΈμ‹ν•œλ‹€λŠ” 문제](https://knip.dev/guides/handling-issues#unused-dependencies)κ°€ μžˆμ—ˆμŠ΅λ‹ˆλ‹€. 이 문제λ₯Ό ν•΄κ²°ν•˜κΈ° μœ„ν•΄ `knip.json`을 μƒˆλ‘œ λ§Œλ“  λ‹€μŒ, `knip`κ°€ `tw-animate-css`λ₯Ό κ°•μ œλ‘œ λ¬΄μ‹œν•˜λ„λ‘ μ„€μ •ν–ˆμŠ΅λ‹ˆλ‹€. ### πŸ“Έ μŠ€ν¬λ¦°μƒ· (선택) - 둜그인 μƒνƒœ <img width="1806" height="1168" alt="둜그인 μƒνƒœμ˜ 헀더" src="https://github.com/user-attachments/assets/0abba663-0036-4145-b18a-89a7e4d3225f" /> - λ‘œκ·Έμ•„μ›ƒ μƒνƒœ <img width="1806" height="1168" alt="λ‘œκ·Έμ•„μ›ƒ μƒνƒœμ˜ 헀더" src="https://github.com/user-attachments/assets/ed036c06-d3c2-4d08-9257-ab09d37e0a10" /> ### πŸš€ 리뷰 μš”κ΅¬μ‚¬ν•­ (선택) μ—†μŒ
1 parent 0b27cf4 commit b1162e8

File tree

14 files changed

+1375
-18
lines changed

14 files changed

+1375
-18
lines changed

β€Žcomponents.jsonβ€Ž

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"$schema": "https://ui.shadcn.com/schema.json",
3+
"style": "new-york",
4+
"rsc": false,
5+
"tsx": true,
6+
"tailwind": {
7+
"config": "",
8+
"css": "src/App.css",
9+
"baseColor": "neutral",
10+
"cssVariables": true,
11+
"prefix": ""
12+
},
13+
"iconLibrary": "lucide",
14+
"aliases": {
15+
"components": "@/components",
16+
"utils": "@/lib/utils",
17+
"ui": "@/components/ui",
18+
"lib": "@/lib",
19+
"hooks": "@/hooks"
20+
},
21+
"registries": {}
22+
}

β€Žknip.jsonβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "https://unpkg.com/knip@5/schema.json",
3+
"ignoreDependencies": ["tw-animate-css"]
4+
}

β€Žpackage.jsonβ€Ž

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@
1313
"check-all": "yarn check:types && yarn check:format && yarn check:unused"
1414
},
1515
"dependencies": {
16+
"@radix-ui/react-avatar": "^1.1.11",
17+
"@radix-ui/react-dropdown-menu": "^2.1.16",
1618
"@tailwindcss/vite": "^4.1.18",
1719
"axios": "^1.13.2",
20+
"clsx": "^2.1.1",
1821
"react": "^19.1.0",
1922
"react-dom": "^19.1.0",
2023
"react-router": "^7.11.0",
24+
"tailwind-merge": "^3.4.0",
2125
"zustand": "^5.0.9"
2226
},
2327
"devDependencies": {
@@ -27,6 +31,7 @@
2731
"@types/react-dom": "^19.1.2",
2832
"@vitejs/plugin-react-swc": "^3.9.0",
2933
"knip": "^5.59.1",
34+
"tw-animate-css": "^1.4.0",
3035
"typescript": "~5.8.3",
3136
"vite": "^6.3.5"
3237
}

β€Žsrc/App.cssβ€Ž

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
@import "tailwindcss";
77

8+
@import "tw-animate-css";
9+
10+
@custom-variant dark (&:is(.dark *));
11+
812
@layer base {
913
html,
1014
body {
@@ -122,3 +126,220 @@
122126
-webkit-box-orient: vertical;
123127
}
124128
}
129+
130+
@theme inline {
131+
--radius-sm: calc(var(--radius) - 4px);
132+
133+
--radius-md: calc(var(--radius) - 2px);
134+
135+
--radius-lg: var(--radius);
136+
137+
--radius-xl: calc(var(--radius) + 4px);
138+
139+
--radius-2xl: calc(var(--radius) + 8px);
140+
141+
--radius-3xl: calc(var(--radius) + 12px);
142+
143+
--radius-4xl: calc(var(--radius) + 16px);
144+
145+
--color-background: var(--background);
146+
147+
--color-foreground: var(--foreground);
148+
149+
--color-card: var(--card);
150+
151+
--color-card-foreground: var(--card-foreground);
152+
153+
--color-popover: var(--popover);
154+
155+
--color-popover-foreground: var(--popover-foreground);
156+
157+
--color-primary: var(--primary);
158+
159+
--color-primary-foreground: var(--primary-foreground);
160+
161+
--color-secondary: var(--secondary);
162+
163+
--color-secondary-foreground: var(--secondary-foreground);
164+
165+
--color-muted: var(--muted);
166+
167+
--color-muted-foreground: var(--muted-foreground);
168+
169+
--color-accent: var(--accent);
170+
171+
--color-accent-foreground: var(--accent-foreground);
172+
173+
--color-destructive: var(--destructive);
174+
175+
--color-border: var(--border);
176+
177+
--color-input: var(--input);
178+
179+
--color-ring: var(--ring);
180+
181+
--color-chart-1: var(--chart-1);
182+
183+
--color-chart-2: var(--chart-2);
184+
185+
--color-chart-3: var(--chart-3);
186+
187+
--color-chart-4: var(--chart-4);
188+
189+
--color-chart-5: var(--chart-5);
190+
191+
--color-sidebar: var(--sidebar);
192+
193+
--color-sidebar-foreground: var(--sidebar-foreground);
194+
195+
--color-sidebar-primary: var(--sidebar-primary);
196+
197+
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
198+
199+
--color-sidebar-accent: var(--sidebar-accent);
200+
201+
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
202+
203+
--color-sidebar-border: var(--sidebar-border);
204+
205+
--color-sidebar-ring: var(--sidebar-ring);
206+
}
207+
208+
:root {
209+
--radius: 0.625rem;
210+
211+
--background: oklch(1 0 0);
212+
213+
--foreground: oklch(0.145 0 0);
214+
215+
--card: oklch(1 0 0);
216+
217+
--card-foreground: oklch(0.145 0 0);
218+
219+
--popover: oklch(1 0 0);
220+
221+
--popover-foreground: oklch(0.145 0 0);
222+
223+
--primary: oklch(0.205 0 0);
224+
225+
--primary-foreground: oklch(0.985 0 0);
226+
227+
--secondary: oklch(0.97 0 0);
228+
229+
--secondary-foreground: oklch(0.205 0 0);
230+
231+
--muted: oklch(0.97 0 0);
232+
233+
--muted-foreground: oklch(0.556 0 0);
234+
235+
--accent: oklch(0.97 0 0);
236+
237+
--accent-foreground: oklch(0.205 0 0);
238+
239+
--destructive: oklch(0.577 0.245 27.325);
240+
241+
--border: oklch(0.922 0 0);
242+
243+
--input: oklch(0.922 0 0);
244+
245+
--ring: oklch(0.708 0 0);
246+
247+
--chart-1: oklch(0.646 0.222 41.116);
248+
249+
--chart-2: oklch(0.6 0.118 184.704);
250+
251+
--chart-3: oklch(0.398 0.07 227.392);
252+
253+
--chart-4: oklch(0.828 0.189 84.429);
254+
255+
--chart-5: oklch(0.769 0.188 70.08);
256+
257+
--sidebar: oklch(0.985 0 0);
258+
259+
--sidebar-foreground: oklch(0.145 0 0);
260+
261+
--sidebar-primary: oklch(0.205 0 0);
262+
263+
--sidebar-primary-foreground: oklch(0.985 0 0);
264+
265+
--sidebar-accent: oklch(0.97 0 0);
266+
267+
--sidebar-accent-foreground: oklch(0.205 0 0);
268+
269+
--sidebar-border: oklch(0.922 0 0);
270+
271+
--sidebar-ring: oklch(0.708 0 0);
272+
}
273+
274+
.dark {
275+
--background: oklch(0.145 0 0);
276+
277+
--foreground: oklch(0.985 0 0);
278+
279+
--card: oklch(0.205 0 0);
280+
281+
--card-foreground: oklch(0.985 0 0);
282+
283+
--popover: oklch(0.205 0 0);
284+
285+
--popover-foreground: oklch(0.985 0 0);
286+
287+
--primary: oklch(0.922 0 0);
288+
289+
--primary-foreground: oklch(0.205 0 0);
290+
291+
--secondary: oklch(0.269 0 0);
292+
293+
--secondary-foreground: oklch(0.985 0 0);
294+
295+
--muted: oklch(0.269 0 0);
296+
297+
--muted-foreground: oklch(0.708 0 0);
298+
299+
--accent: oklch(0.269 0 0);
300+
301+
--accent-foreground: oklch(0.985 0 0);
302+
303+
--destructive: oklch(0.704 0.191 22.216);
304+
305+
--border: oklch(1 0 0 / 10%);
306+
307+
--input: oklch(1 0 0 / 15%);
308+
309+
--ring: oklch(0.556 0 0);
310+
311+
--chart-1: oklch(0.488 0.243 264.376);
312+
313+
--chart-2: oklch(0.696 0.17 162.48);
314+
315+
--chart-3: oklch(0.769 0.188 70.08);
316+
317+
--chart-4: oklch(0.627 0.265 303.9);
318+
319+
--chart-5: oklch(0.645 0.246 16.439);
320+
321+
--sidebar: oklch(0.205 0 0);
322+
323+
--sidebar-foreground: oklch(0.985 0 0);
324+
325+
--sidebar-primary: oklch(0.488 0.243 264.376);
326+
327+
--sidebar-primary-foreground: oklch(0.985 0 0);
328+
329+
--sidebar-accent: oklch(0.269 0 0);
330+
331+
--sidebar-accent-foreground: oklch(0.985 0 0);
332+
333+
--sidebar-border: oklch(1 0 0 / 10%);
334+
335+
--sidebar-ring: oklch(0.556 0 0);
336+
}
337+
338+
@layer base {
339+
* {
340+
@apply border-border outline-ring/50;
341+
}
342+
body {
343+
@apply bg-background text-foreground;
344+
}
345+
}

β€Žsrc/components/Header.tsxβ€Ž

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1+
import ProfileButton from '@/components/ProfileButton';
2+
import useAuth from '@/hooks/useAuth';
13
import { Link, NavLink } from 'react-router';
2-
import useAuth from '../hooks/useAuth';
4+
5+
const userExample = {
6+
id: 1,
7+
email: 'user@example.com',
8+
name: 'λ°•μ€€μ˜',
9+
profileImage: 'https://github.com/shadcn.png',
10+
createdAt: '2023-01-01T00:00:00.000Z',
11+
updatedAt: '2023-01-01T00:00:00.000Z',
12+
};
313

414
export default function Header() {
515
const { isLoggedIn, handleLogout } = useAuth();
@@ -16,7 +26,7 @@ export default function Header() {
1626
λͺ¨μ΄μƒ€
1727
</Link>
1828
<div className="items-center space-x-2">
19-
{isLoggedIn === false ? (
29+
{!isLoggedIn ? (
2030
<>
2131
<NavLink
2232
to="/login"
@@ -32,15 +42,7 @@ export default function Header() {
3242
</NavLink>
3343
</>
3444
) : (
35-
<>
36-
<button
37-
onClick={handleLogout}
38-
className="font-bold h-[42px] items-center px-4 py-2 rounded-md hover:bg-gray-200 transition-all text-gray-500"
39-
>
40-
λ‘œκ·Έμ•„μ›ƒ
41-
</button>
42-
{/* TODO: Add an avatar UI */}
43-
</>
45+
<ProfileButton user={userExample} handleLogout={handleLogout} />
4446
)}
4547
</div>
4648
</div>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
2+
import {
3+
DropdownMenu,
4+
DropdownMenuContent,
5+
DropdownMenuGroup,
6+
DropdownMenuItem,
7+
DropdownMenuLabel,
8+
DropdownMenuSeparator,
9+
DropdownMenuTrigger,
10+
} from '@/components/ui/dropdown-menu';
11+
import type { User } from '@/types/auth';
12+
13+
interface ProfileButtonProps {
14+
user: User;
15+
handleLogout: () => void;
16+
}
17+
18+
export default function ProfileButton({
19+
user,
20+
handleLogout,
21+
}: ProfileButtonProps) {
22+
const goToProfileEdit = () => {
23+
// TODO: Implement navigation to profile edit page
24+
console.info('Navigating to profile edit page...');
25+
};
26+
27+
return (
28+
<DropdownMenu>
29+
<DropdownMenuTrigger asChild>
30+
<button>
31+
<Avatar className="border-2">
32+
<AvatarImage src={user.profileImage} />
33+
<AvatarFallback>CN</AvatarFallback>
34+
</Avatar>
35+
</button>
36+
</DropdownMenuTrigger>
37+
<DropdownMenuContent className="w-40" align="end">
38+
<DropdownMenuLabel>
39+
<span className="font-bold">{user.name}</span> λ‹˜
40+
</DropdownMenuLabel>
41+
<DropdownMenuSeparator />
42+
<DropdownMenuGroup>
43+
<DropdownMenuItem onClick={goToProfileEdit}>
44+
ν”„λ‘œν•„ μˆ˜μ •
45+
</DropdownMenuItem>
46+
<DropdownMenuItem onClick={handleLogout}>λ‘œκ·Έμ•„μ›ƒ</DropdownMenuItem>
47+
</DropdownMenuGroup>
48+
</DropdownMenuContent>
49+
</DropdownMenu>
50+
);
51+
}

0 commit comments

Comments
Β (0)