import {useEffect, useState, type FormEvent} from 'react'; import {KeyRound, Loader2} from 'lucide-react'; import {AuthProvider, updateMe, useMe} from '@/api'; import {AppShell, PageContainer} from '@/components/layout/AppShell'; import {Button} from '@/components/ui/button'; import {Input} from '@/components/ui/input'; import {notify, notifyApiError} from '@/lib/notify'; import {toAuthUser, useAuthStore} from '@/stores/auth'; /** * 내 정보 — `PATCH /v1/auth/me` 한 곳이 받는 것만 그린다. * * ★ 상호 칸은 없다. 회사(테넌트)를 걷어내면서(2026-09-08) 계정에 상호가 없어졌다 — * 가게 이름은 사업장(place)이 갖는다. * ★ 구글 계정에는 바꿀 비밀번호가 없다(서버가 ACCOUNT_PROVIDER_CONFLICT 로 막는다) — * 입력칸 자체를 그리지 않는다. */ export function AccountPage() { const {data, isLoading, refetch} = useMe(); const setUser = useAuthStore((s) => s.setUser); const [name, setName] = useState(''); const [email, setEmail] = useState(''); const [contact, setContact] = useState(''); const [password, setPassword] = useState(''); const [isSaving, setIsSaving] = useState(false); // 서버 값이 도착하면 한 번 채운다. 타이핑 중에 덮어쓰지 않게 응답이 바뀔 때만 돈다. useEffect(() => { if (!data) return; setName(data.name ?? ''); setEmail(data.email ?? ''); setContact(data.contact_number ?? ''); }, [data]); const isGoogle = data?.provider === AuthProvider.GOOGLE; const handleSubmit = async (event: FormEvent) => { event.preventDefault(); setIsSaving(true); try { const res = await updateMe({ name, email, contact_number: contact, ...(password ? {password} : {}), }); if (!res.result?.success) { notifyApiError({data: res}, '저장하지 못했습니다.'); return; } // 사이드바가 이름을 들고 있다 — 저장하고 스토어를 안 갱신하면 새로고침 전까지 옛 이름이다. if (res.user_id && res.id) setUser(toAuthUser(res)); setPassword(''); notify.success('저장했습니다.'); await refetch(); } catch (error) { notifyApiError(error, '저장하지 못했습니다.'); } finally { setIsSaving(false); } }; return ( {isLoading ? (
) : (

{isGoogle ? (data?.email ?? '구글 계정') : (data?.id ?? '')}

{isGoogle ? '구글 계정으로 로그인합니다.' : '아이디는 바꿀 수 없습니다.'}

setName(e.target.value)} placeholder="홍길동" /> setEmail(e.target.value)} placeholder="owner@example.com" /> setContact(e.target.value)} placeholder="010-0000-0000" />
{!isGoogle && (
setPassword(e.target.value)} placeholder="비우면 지금 비밀번호를 그대로 씁니다" autoComplete="new-password" />
)} {isGoogle && (

구글 계정이라 비밀번호가 없습니다 — 비밀번호는 구글에서 관리합니다.

)}
)}
); } function Field({label, children}: {label: string; children: React.ReactNode}) { return ( ); } // 라우트 모듈은 default export 를 요구한다(routes.ts 가 이 파일을 가리킨다). export default AccountPage;