fix(WEB): 대시보드 모달 데이터 연동 오류 수정
- transformers.ts: footer_summary destructuring 누락 수정 - cardManagementConfigTransformers.ts: items, by_user, monthly_trend 방어적 코드 추가 - undefined 배열 접근 시 빈 배열 기본값 적용 - 카드 사용 상세(cm1), 가지급금 상세(cm2) 모달 에러 해결
This commit is contained in:
@@ -63,7 +63,7 @@ function formatPercentage(value: number, showSign = true): string {
|
||||
export function transformCm1ModalConfig(
|
||||
data: CardDashboardDetailApiResponse
|
||||
): DetailModalConfig {
|
||||
const { summary, monthly_trend, by_user, items } = data;
|
||||
const { summary, monthly_trend = [], by_user = [], items = [] } = data;
|
||||
|
||||
// 전월 대비 증감률 계산
|
||||
const changeRate = calculateChangeRate(
|
||||
@@ -72,13 +72,14 @@ export function transformCm1ModalConfig(
|
||||
);
|
||||
|
||||
// 미정리 건수 계산 (usage_type이 '미설정'인 항목)
|
||||
const unprocessedCount = items.filter(
|
||||
const unprocessedCount = (items || []).filter(
|
||||
(item) => item.usage_type === '미설정' || !item.usage_type
|
||||
).length;
|
||||
|
||||
// 사용자별 비율 계산
|
||||
const totalAmount = by_user.reduce((sum, user) => sum + user.amount, 0);
|
||||
const pieChartData = by_user.map((user) => ({
|
||||
const safeByUser = by_user || [];
|
||||
const totalAmount = safeByUser.reduce((sum, user) => sum + user.amount, 0);
|
||||
const pieChartData = safeByUser.map((user) => ({
|
||||
name: user.user_name,
|
||||
value: user.amount,
|
||||
percentage: totalAmount > 0 ? Math.round((user.amount / totalAmount) * 100) : 0,
|
||||
@@ -88,14 +89,14 @@ export function transformCm1ModalConfig(
|
||||
// 사용자 필터 옵션 동적 생성
|
||||
const userFilterOptions = [
|
||||
{ value: 'all', label: '전체' },
|
||||
...by_user.map((user) => ({
|
||||
...safeByUser.map((user) => ({
|
||||
value: user.user_name,
|
||||
label: user.user_name,
|
||||
})),
|
||||
];
|
||||
|
||||
// 테이블 데이터 매핑
|
||||
const tableData = items.map((item) => ({
|
||||
const tableData = (items || []).map((item) => ({
|
||||
cardName: item.card_name,
|
||||
user: item.user_name,
|
||||
date: item.transaction_date,
|
||||
@@ -118,7 +119,7 @@ export function transformCm1ModalConfig(
|
||||
],
|
||||
barChart: {
|
||||
title: '월별 카드 사용 추이',
|
||||
data: monthly_trend.map((trend) => ({
|
||||
data: (monthly_trend || []).map((trend) => ({
|
||||
name: trend.label,
|
||||
value: trend.amount,
|
||||
})),
|
||||
@@ -189,10 +190,10 @@ export function transformCm1ModalConfig(
|
||||
export function transformCm2ModalConfig(
|
||||
data: LoanDashboardApiResponse
|
||||
): DetailModalConfig {
|
||||
const { summary, items } = data;
|
||||
const { summary, items = [] } = data;
|
||||
|
||||
// 테이블 데이터 매핑
|
||||
const tableData = items.map((item) => ({
|
||||
const tableData = (items || []).map((item) => ({
|
||||
date: item.loan_date,
|
||||
target: item.user_name,
|
||||
category: '-', // API에서 별도 필드 없음
|
||||
@@ -202,7 +203,7 @@ export function transformCm2ModalConfig(
|
||||
}));
|
||||
|
||||
// 대상 필터 옵션 동적 생성
|
||||
const uniqueTargets = [...new Set(items.map((item) => item.user_name))];
|
||||
const uniqueTargets = [...new Set((items || []).map((item) => item.user_name))];
|
||||
const targetFilterOptions = [
|
||||
{ value: 'all', label: '전체' },
|
||||
...uniqueTargets.map((target) => ({
|
||||
|
||||
Reference in New Issue
Block a user