From 5ab1354bccd3bffda3dacd12134c0dffe6b2cb99 Mon Sep 17 00:00:00 2001 From: kent Date: Tue, 30 Dec 2025 20:47:12 +0900 Subject: [PATCH] =?UTF-8?q?fix(WEB):=20=EA=B3=84=EC=A0=95=20=EA=B4=80?= =?UTF-8?q?=EB=A6=AC=20=ED=8E=98=EC=9D=B4=EC=A7=80=20API=20=EC=97=B0?= =?UTF-8?q?=EB=8F=99=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - AccountInfoManagement/actions.ts: 내 정보 관리 API 연동 - AccountManagement/actions.ts: 계정 관리 API 연동 개선 --- .../settings/AccountInfoManagement/actions.ts | 75 +++++++++++++++++++ .../settings/AccountManagement/actions.ts | 21 +++++- 2 files changed, 92 insertions(+), 4 deletions(-) diff --git a/src/components/settings/AccountInfoManagement/actions.ts b/src/components/settings/AccountInfoManagement/actions.ts index 4ae42797..ec414759 100644 --- a/src/components/settings/AccountInfoManagement/actions.ts +++ b/src/components/settings/AccountInfoManagement/actions.ts @@ -1,6 +1,81 @@ 'use server'; import { serverFetch } from '@/lib/api/fetch-wrapper'; +import type { AccountInfo, TermsAgreement, MarketingConsent } from './types'; + +// ===== 계정 정보 조회 ===== +export async function getAccountInfo(): Promise<{ + success: boolean; + data?: { + accountInfo: AccountInfo; + termsAgreements: TermsAgreement[]; + marketingConsent: MarketingConsent; + }; + error?: string; + __authError?: boolean; +}> { + try { + const { response, error } = await serverFetch( + `${process.env.NEXT_PUBLIC_API_URL}/api/v1/users/me`, + { + method: 'GET', + } + ); + + if (error) { + return { + success: false, + error: error.message, + __authError: error.code === 'UNAUTHORIZED', + }; + } + + if (!response) { + return { + success: false, + error: '계정 정보를 불러올 수 없습니다.', + }; + } + + const result = await response.json(); + + if (!response.ok || !result.success) { + return { + success: false, + error: result.message || '계정 정보 조회에 실패했습니다.', + }; + } + + const user = result.data; + + return { + success: true, + data: { + accountInfo: { + id: user.id?.toString() || '', + email: user.email || '', + profileImage: user.profile_image || undefined, + role: user.role?.name || user.role || '', + status: user.status || 'active', + isTenantMaster: user.is_tenant_master || false, + createdAt: user.created_at || '', + updatedAt: user.updated_at || '', + }, + termsAgreements: user.terms_agreements || [], + marketingConsent: user.marketing_consent || { + email: { agreed: false }, + sms: { agreed: false }, + }, + }, + }; + } catch (error) { + console.error('[AccountInfoActions] getAccountInfo error:', error); + return { + success: false, + error: '서버 오류가 발생했습니다.', + }; + } +} // ===== 계정 탈퇴 ===== export async function withdrawAccount(): Promise<{ diff --git a/src/components/settings/AccountManagement/actions.ts b/src/components/settings/AccountManagement/actions.ts index 9f01516f..ddb8cb26 100644 --- a/src/components/settings/AccountManagement/actions.ts +++ b/src/components/settings/AccountManagement/actions.ts @@ -26,11 +26,18 @@ interface PaginationMeta { total: number; } +interface PaginatedData { + current_page: number; + last_page: number; + per_page: number; + total: number; + data: BankAccountApiData[]; +} + interface ApiListResponse { success: boolean; message?: string; - data: BankAccountApiData[]; - meta?: PaginationMeta; + data: PaginatedData; } interface ApiSingleResponse { @@ -112,8 +119,14 @@ export async function getBankAccounts(params?: { return { success: false, error: result.message || '계좌 목록 조회에 실패했습니다.' }; } - const accounts = result.data.map(transformApiToFrontend); - return { success: true, data: accounts, meta: result.meta }; + const accounts = result.data.data.map(transformApiToFrontend); + const meta: PaginationMeta = { + current_page: result.data.current_page, + last_page: result.data.last_page, + per_page: result.data.per_page, + total: result.data.total, + }; + return { success: true, data: accounts, meta }; } catch (error) { console.error('[getBankAccounts] Error:', error); return { success: false, error: '서버 오류가 발생했습니다.' };