11"use client" ;
22
3+ import { useState } from "react" ;
4+
35import { tokenParse } from "@/utils/jwtUtils" ;
46
57import CloudSpinnerPage from "@/components/ui/CloudSpinnerPage" ;
@@ -14,16 +16,46 @@ import useAuthStore from "@/lib/zustand/useAuthStore";
1416
1517const MentorClient = ( ) => {
1618 const { isLoading, accessToken } = useAuthStore ( ) ;
17- const isMentor = tokenParse ( accessToken ) ?. role === UserRole . MENTOR ;
19+ const parsedToken = tokenParse ( accessToken ) ;
20+ const userRole = parsedToken ?. role ;
21+ const isMentor = userRole === UserRole . MENTOR || userRole === UserRole . ADMIN ;
22+ const isAdmin = userRole === UserRole . ADMIN ;
23+
24+ // 어드민 전용: 뷰 전환 상태 (true: 멘토 뷰, false: 멘티 뷰)
25+ const [ showMentorView , setShowMentorView ] = useState < boolean > ( true ) ;
26+
27+ if ( isLoading || ! accessToken ) return < CloudSpinnerPage /> ; // 로딩 중일 때 스피너 표시
28+
29+ // 어드민이 아닌 경우 기존 로직대로
30+ const shouldShowMentorView = isAdmin ? showMentorView : isMentor ;
1831
19- if ( isLoading ) return < CloudSpinnerPage /> ; // 로딩 중일 때 스피너 표시
2032 return (
2133 < >
22- { isMentor ? (
34+ { /* 어드민 전용 뷰 전환 버튼 */ }
35+ { isAdmin && (
36+ < div className = "mb-4 flex gap-2" >
37+ < button
38+ onClick = { ( ) => setShowMentorView ( true ) }
39+ className = { `flex-1 rounded-lg px-4 py-2.5 text-sm font-semibold transition-colors ${
40+ showMentorView ? "bg-primary text-white" : "border border-k-200 bg-white text-k-600 hover:bg-k-50"
41+ } `}
42+ >
43+ 멘토 페이지 보기
44+ </ button >
45+ < button
46+ onClick = { ( ) => setShowMentorView ( false ) }
47+ className = { `flex-1 rounded-lg px-4 py-2.5 text-sm font-semibold transition-colors ${
48+ ! showMentorView ? "bg-primary text-white" : "border border-k-200 bg-white text-k-600 hover:bg-k-50"
49+ } `}
50+ >
51+ 멘티 페이지 보기
52+ </ button >
53+ </ div >
54+ ) }
55+
56+ { shouldShowMentorView ? (
2357 // 멘토페이지
24- < >
25- < MentorPage />
26- </ >
58+ < MentorPage />
2759 ) : (
2860 // 멘티페이지
2961 < >
0 commit comments