Skip to content

Commit 3a91a8e

Browse files
committed
refactor: alert 기능 추가
1 parent cfef93e commit 3a91a8e

File tree

2 files changed

+49
-23
lines changed

2 files changed

+49
-23
lines changed

front/src/app/page.tsx

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,29 @@
1+
"use client"
12
import Link from "next/link"
3+
import { useRouter } from "next/navigation"
24
import { Button } from "@/components/ui/Button"
35
import { ArrowRight, Github, Sparkles, BarChart3, Users, Shield } from "lucide-react"
6+
import { useAuth } from "@/hooks/auth/useAuth"
47

58
export default function LandingPage() {
9+
const router = useRouter()
10+
const { isAuthed } = useAuth()
11+
12+
const handleStartAnalysis = () => {
13+
if (!isAuthed) {
14+
alert("로그인해주세요")
15+
return
16+
}
17+
router.push("/analysis")
18+
}
19+
20+
const handleGoCommunity = () => {
21+
if (!isAuthed) {
22+
alert("로그인해주세요")
23+
return
24+
}
25+
router.push("/community")
26+
}
627
return (
728
<div className="min-h-screen bg-background">
829
{/* Hero Section */}
@@ -28,18 +49,13 @@ export default function LandingPage() {
2849
</p>
2950

3051
<div className="flex flex-col items-center justify-center gap-4 sm:flex-row">
31-
<Button size="lg" className="group" asChild>
32-
{/* 로그인 확인하고 로그인 안 되어 있으면 회원가입 or 로그인으로, 로그인되어 있으면 /analysis로 이동동 */}
33-
<Link href="/signup">
34-
분석 시작하기
35-
<ArrowRight className="ml-2 h-4 w-4 transition-transform group-hover:translate-x-1" />
36-
</Link>
52+
<Button size="lg" className="group" onClick={handleStartAnalysis}>
53+
분석 시작하기
54+
<ArrowRight className="ml-2 h-4 w-4 transition-transform group-hover:translate-x-1" />
3755
</Button>
38-
<Button size="lg" variant="outline" asChild>
39-
<Link href="/community">
40-
<Users className="mr-2 h-4 w-4" />
41-
커뮤니티 보기
42-
</Link>
56+
<Button size="lg" variant="outline" onClick={handleGoCommunity}>
57+
<Users className="mr-2 h-4 w-4" />
58+
커뮤니티 보기
4359
</Button>
4460
</div>
4561
</div>

front/src/components/Header.tsx

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,23 @@
22

33
import Link from "next/link"
44
import { useState } from "react"
5+
import { useRouter } from "next/navigation"
56
import { Sparkles } from "lucide-react"
67
import { Button } from "@/components/ui/Button"
8+
import { useAuth } from "@/hooks/auth/useAuth"
79

810
export default function Header() {
911
const [isLoggedIn, setIsLoggedIn] = useState(false)
12+
const router = useRouter()
13+
const { isAuthed } = useAuth()
14+
15+
const guardNav = (path: string) => () => {
16+
if (!isAuthed) {
17+
alert("로그인해주세요")
18+
return
19+
}
20+
router.push(path)
21+
}
1022

1123
return (
1224
<nav className="border-b border-gray-200 bg-background/80 backdrop-blur-xl">
@@ -28,15 +40,15 @@ export default function Header() {
2840
<div className="flex items-center gap-6">
2941
{isLoggedIn ? (
3042
<>
31-
<Link href="/history" className="text-sm text-muted-foreground hover:text-foreground transition-colors">
43+
<button onClick={guardNav("/history")} className="text-sm text-muted-foreground hover:text-foreground transition-colors">
3244
히스토리
33-
</Link>
34-
<Link href="/community" className="text-sm text-muted-foreground hover:text-foreground transition-colors">
45+
</button>
46+
<button onClick={guardNav("/community")} className="text-sm text-muted-foreground hover:text-foreground transition-colors">
3547
커뮤니티
36-
</Link>
37-
<Link href="/settings" className="text-sm text-muted-foreground hover:text-foreground transition-colors">
48+
</button>
49+
<button onClick={guardNav("/settings")} className="text-sm text-muted-foreground hover:text-foreground transition-colors">
3850
마이페이지
39-
</Link>
51+
</button>
4052
{/* 로그아웃 구현 필요요 */}
4153
<Button
4254
variant="ghost"
@@ -49,20 +61,18 @@ export default function Header() {
4961
</>
5062
) : (
5163
<>
52-
<Link href="/community" className="text-sm text-muted-foreground hover:text-foreground transition-colors">
64+
<button onClick={guardNav("/community")} className="text-sm text-muted-foreground hover:text-foreground transition-colors">
5365
커뮤니티
54-
</Link>
66+
</button>
5567

5668
<div className="flex items-center gap-3">
5769
{/* 현재는 로그인 누르면 바로 로그인 상태로 변경 중 */}
5870
{/* 로그인 누르면 로그인 화면으로, 시작하기 누르면 회원가입으로 넘어가야 함함 */}
5971
<Button variant="ghost" size="sm" onClick={() => setIsLoggedIn(true)}>
6072
로그인
6173
</Button>
62-
<Button size="sm" className="bg-primary text-primary-foreground hover:bg-primary/90" asChild>
63-
<Link href="/signup">
64-
시작하기
65-
</Link>
74+
<Button size="sm" className="bg-primary text-primary-foreground hover:bg-primary/90" onClick={guardNav("/signup")}>
75+
시작하기
6676
</Button>
6777
</div>
6878
</>

0 commit comments

Comments
 (0)