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: '서버 오류가 발생했습니다.' };