-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSidebar.tsx
More file actions
181 lines (161 loc) · 5.84 KB
/
Sidebar.tsx
File metadata and controls
181 lines (161 loc) · 5.84 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
'use client';
import { Check, LogOut, Menu, Pencil, User, X } from 'lucide-react';
import Image from 'next/image';
import { useRouter } from 'next/navigation';
import { useState } from 'react';
// import DisquietBadge from '@/components/DisquietBadge';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Separator } from '@/components/ui/separator';
import {
Sheet,
SheetContent,
SheetFooter,
SheetHeader,
SheetTitle,
SheetTrigger,
} from '@/components/ui/sheet';
import useVersionDialog from '@/hooks/useVersionDialog';
import useAuthStore from '@/stores/useAuthStore';
export default function Sidebar() {
// 목업 인증 상태
const { user, isAuthenticated, logout, changeNickname } = useAuthStore();
const [isOpenSidebar, setIsOpenSidebar] = useState(false);
const [isEditing, setIsEditing] = useState(false);
const [newNickname, setNewNickname] = useState(user?.nickname || '');
const { version } = useVersionDialog();
const router = useRouter();
const handleEditStart = () => {
setIsEditing(true);
setNewNickname(user?.nickname || '');
};
// 닉네임 수정 취소
const handleEditCancel = () => {
setIsEditing(false);
setNewNickname(user?.nickname || '');
};
const handleEditSave = async () => {
const result = await changeNickname(newNickname);
if (result) setIsEditing(false);
};
const handleOpenGithub = () => {
window.open('https://github.com/GulSam00/sing-code', '_blank');
};
const handleOpenTerm = () => {
window.open(
'https://coding-sham.notion.site/Singcode-215286f3bd70802c8191d2a0344ecc1c',
'_blank',
);
};
const handleLogin = () => {
router.push('/login');
setIsOpenSidebar(false);
};
const handleLogout = async () => {
const result = await logout();
if (result) {
window.location.reload();
}
};
const handleWithdrawal = () => {
router.push('/withdrawal');
setIsOpenSidebar(false);
};
return (
<Sheet open={isOpenSidebar} onOpenChange={setIsOpenSidebar}>
<SheetTrigger asChild>
<Button className="flex items-center justify-center">
<Menu className="h-6 w-6" />
</Button>
</SheetTrigger>
<SheetContent className="fixed right-1/2 w-full max-w-md translate-x-1/2 p-4 sm:max-w-md">
<SheetHeader>
<SheetTitle>메뉴</SheetTitle>
</SheetHeader>
<div className="space-y-6">
<div className="flex flex-col items-center space-y-2">
<div className="bg-primary text-primary-foreground flex h-24 w-24 items-center justify-center rounded-full text-xl font-bold">
{user?.nickname.slice(0, 4)}
</div>
<div className="w-full text-center">
<div className="relative flex w-full items-center justify-center gap-2 font-medium">
{isEditing ? (
// 수정 모드
<>
<Input
value={newNickname}
onChange={e => setNewNickname(e.target.value)}
className="h-8 w-32 text-center"
maxLength={10}
/>
<div className="absolute right-0 flex items-center gap-1">
<Button size="icon" onClick={handleEditSave}>
<Check className="h-4 w-4" />
</Button>
<Button size="icon" variant="outline" onClick={handleEditCancel}>
<X className="h-4 w-4" />
</Button>
</div>
</>
) : (
// 표시 모드
<>
<span>{user ? user.nickname : '손님'}</span>
{user && (
<div className="absolute right-0">
<Button variant="ghost" size="sm" className="" onClick={handleEditStart}>
<Pencil className="h-4 w-4" />
</Button>
</div>
)}
</>
)}
</div>
</div>
</div>
<Separator />
<div className="space-y-2"></div>
</div>
<SheetFooter>
{/* <DisquietBadge /> */}
{isAuthenticated ? (
<>
<Button
variant="outline"
className="dark:hover:bg-primary dark:hover:text-primary-foreground w-full"
onClick={handleLogout}
>
<LogOut className="mr-2 h-4 w-4" />
로그아웃
</Button>
<Button variant="destructive" className="mt-2 w-full" onClick={handleWithdrawal}>
회원 탈퇴
</Button>
</>
) : (
<Button variant="outline" className="w-full" onClick={handleLogin}>
<User className="mr-2 h-4 w-4" />
로그인
</Button>
)}
<div className="text-muted-foreground flex flex-col items-center gap-2 border-t pt-2">
<div className="flex w-full flex-col items-center gap-2">
<span className="text-xs">© 2025 singcode - Released under the MIT License.</span>
<Button variant="ghost" size="icon" className="h-8 w-8" onClick={handleOpenGithub}>
<Image src="/github_mark.svg" alt="github" width={32} height={32} />
</Button>
<div>버전 {version}</div>
<Button
variant="link"
className="text-muted-foreground h-auto p-0 text-xs"
onClick={handleOpenTerm}
>
이용약관
</Button>
</div>
</div>
</SheetFooter>
</SheetContent>
</Sheet>
);
}