'use client'; import '../styles/profile.scss'; import { useEffect, useState } from 'react'; import Link from 'next/link'; import { GoogleOAuthProvider, GoogleLogin, useGoogleOneTapLogin } from '@react-oauth/google'; import useAuth from '@/hooks/useAuth'; import { useConfigContext } from '@/contexts/configProvider'; import { fetchApi } from '@/lib/utils/client'; import { DropdownData } from '@/types/response/mypage/dropdown'; import { LoginResponse } from '@/types/response/auth'; import { Avatar, AvatarImage, AvatarFallback } from '@/components/ui/avatar'; import SignalSteamIcon from '@/public/icons/user/signal-steam.svg'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { Package, UserRoundCog, LogOut } from 'lucide-react'; export default function Profile() { const config = useConfigContext(); const clientId = config?.external?.googleClientId ?? ''; return ( ); } function ProfileInner() { const { member, login, logout } = useAuth(); const [open, setOpen] = useState(false); const [data, setData] = useState(null); // 구글 로그인 핸들러 const handleGoogleLogin = async (credentialResponse: { credential?: string }) => { try { const res = await fetchApi('/api/auth/google-login', { method: 'POST', body: { credential: credentialResponse.credential } }); login(true); } catch { // silent } }; // Google One Tap — 비로그인 상태에서만 활성화 useGoogleOneTapLogin({ onSuccess: handleGoogleLogin, onError: () => {}, disabled: !!member }); // 드롭다운 열 때 잔액 조회 const loadData = async () => { const res = await fetchApi('/api/mypage/dropdown'); if (res.data) { setData(res.data); } }; useEffect(() => { if (!open) { return; } loadData(); }, [open]); // 충전 완료 시 팝업에서 postMessage 수신 → 잔액 갱신 useEffect(() => { const handleMessage = (e: MessageEvent) => { if (e.data?.type === 'CHARGE_COMPLETE') { loadData(); } }; window.addEventListener('message', handleMessage); return () => window.removeEventListener('message', handleMessage); }, []); // ── 비로그인 ────────────────────────────────── if (!member) { return ( 로그인 {}} size="large" shape="rectangular" logo_alignment="center" /> ); } // ── 로그인 ──────────────────────────────────── const displayName = member.name || member.sid; const initial = (member.name || member.sid || '?').charAt(0).toUpperCase(); return ( {initial} {/* 프로필 헤더 */} {initial} {displayName} {data && ( <> P {data.spendableBalance.toLocaleString()} {data.isCreator && data.withdrawableBalance !== null && ( M {data.withdrawableBalance.toLocaleString()} )} > )} {member.isCreator && ( 채널 관리 )} 내 정보 보관함 로그아웃 ); }