대시보드 결재 상세 진입 지원

This commit is contained in:
JiWoong Sul
2025-10-23 20:19:59 +09:00
parent 7e933a2dda
commit 9d6cbb1ab2
14 changed files with 543 additions and 76 deletions

View File

@@ -1,3 +1,5 @@
import 'package:flutter/foundation.dart';
import '../../../../core/common/utils/json_utils.dart';
import '../../domain/entities/dashboard_kpi.dart';
import '../../domain/entities/dashboard_pending_approval.dart';
@@ -20,17 +22,18 @@ class DashboardSummaryDto {
factory DashboardSummaryDto.fromJson(Map<String, dynamic> json) {
final generatedAt = _parseDate(json['generated_at']);
final kpiList = JsonUtils.extractList(json, keys: const ['kpis'])
.map(DashboardKpiDto.fromJson)
.toList(growable: false);
final transactionList =
JsonUtils.extractList(json, keys: const ['recent_transactions'])
.map(DashboardTransactionDto.fromJson)
.toList(growable: false);
final approvalList =
JsonUtils.extractList(json, keys: const ['pending_approvals'])
.map(DashboardApprovalDto.fromJson)
.toList(growable: false);
final kpiList = JsonUtils.extractList(
json,
keys: const ['kpis'],
).map(DashboardKpiDto.fromJson).toList(growable: false);
final transactionList = JsonUtils.extractList(
json,
keys: const ['recent_transactions'],
).map(DashboardTransactionDto.fromJson).toList(growable: false);
final approvalList = JsonUtils.extractList(
json,
keys: const ['pending_approvals'],
).map(DashboardApprovalDto.fromJson).toList(growable: false);
return DashboardSummaryDto(
generatedAt: generatedAt,
@@ -133,19 +136,42 @@ class DashboardTransactionDto {
class DashboardApprovalDto {
const DashboardApprovalDto({
this.approvalId,
required this.approvalNo,
required this.title,
required this.stepSummary,
this.requestedAt,
});
final int? approvalId;
final String approvalNo;
final String title;
final String stepSummary;
final String? requestedAt;
factory DashboardApprovalDto.fromJson(Map<String, dynamic> json) {
num? rawId = _readNum(json, 'approval_id');
if (rawId == null) {
final approvalMap = json['approval'];
if (approvalMap is Map<String, dynamic>) {
rawId = _readNum(approvalMap, 'id');
if (rawId == null && approvalMap.containsKey('id')) {
final fallbackValue = approvalMap['id'];
debugPrint(
'[DashboardSummaryDto] approval.id 파싱 실패: runtimeType=${fallbackValue.runtimeType}, value=$fallbackValue',
);
}
}
}
final approvalIdValue = rawId?.toInt();
if (approvalIdValue == null && json.containsKey('approval_id')) {
final rawValue = json['approval_id'];
debugPrint(
'[DashboardSummaryDto] approval_id 파싱 실패: runtimeType=${rawValue.runtimeType}, value=$rawValue',
);
}
return DashboardApprovalDto(
approvalId: approvalIdValue,
approvalNo: _readString(json, 'approval_no') ?? '',
title: _readString(json, 'title') ?? '',
stepSummary: _readString(json, 'step_summary') ?? '',
@@ -155,6 +181,7 @@ class DashboardApprovalDto {
DashboardPendingApproval toEntity() {
return DashboardPendingApproval(
approvalId: approvalId,
approvalNo: approvalNo,
title: title,
stepSummary: stepSummary,
@@ -190,7 +217,11 @@ num? _readNum(Map<String, dynamic>? source, String key) {
return value;
}
if (value is String) {
return num.tryParse(value);
final trimmed = value.trim();
if (trimmed.isEmpty) {
return null;
}
return num.tryParse(trimmed);
}
return null;
}

View File

@@ -1,4 +1,7 @@
import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import '../../../../core/network/api_client.dart';
import '../../../../core/network/api_routes.dart';
@@ -20,6 +23,17 @@ class DashboardRepositoryRemote implements DashboardRepository {
_summaryPath,
options: Options(responseType: ResponseType.json),
);
if (kDebugMode) {
try {
debugPrint(
'[DashboardRepositoryRemote] dashboard/summary 응답: ${jsonEncode(response.data)}',
);
} catch (error) {
debugPrint(
'[DashboardRepositoryRemote] dashboard/summary 응답 직렬화 실패: $error',
);
}
}
return DashboardSummaryDto.fromJson(_api.unwrapAsMap(response)).toEntity();
}
}

View File

@@ -1,12 +1,16 @@
/// 결재 대기 요약 정보.
class DashboardPendingApproval {
const DashboardPendingApproval({
this.approvalId,
required this.approvalNo,
required this.title,
required this.stepSummary,
this.requestedAt,
});
/// 결재 고유 식별자(ID). 상세 조회가 필요할 때 사용된다.
final int? approvalId;
/// 결재 문서 번호
final String approvalNo;

View File

@@ -2,11 +2,17 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:intl/intl.dart' as intl;
import 'package:lucide_icons_flutter/lucide_icons.dart' as lucide;
import 'package:shadcn_ui/shadcn_ui.dart';
import 'package:superport_v2/core/network/failure.dart';
import 'package:superport_v2/features/approvals/domain/entities/approval.dart';
import 'package:superport_v2/features/approvals/domain/repositories/approval_repository.dart';
import 'package:superport_v2/widgets/app_layout.dart';
import 'package:superport_v2/widgets/components/empty_state.dart';
import 'package:superport_v2/widgets/components/feedback.dart';
import 'package:superport_v2/widgets/components/superport_dialog.dart';
import '../../domain/entities/dashboard_kpi.dart';
import '../../domain/entities/dashboard_pending_approval.dart';
@@ -25,7 +31,7 @@ class DashboardPage extends StatefulWidget {
class _DashboardPageState extends State<DashboardPage> {
late final DashboardController _controller;
Timer? _autoRefreshTimer;
final DateFormat _timestampFormat = DateFormat('yyyy-MM-dd HH:mm');
final intl.DateFormat _timestampFormat = intl.DateFormat('yyyy-MM-dd HH:mm');
static const _kpiPresets = [
_KpiPreset(
@@ -203,7 +209,9 @@ class _DashboardPageState extends State<DashboardPage> {
return Flex(
direction: showSidePanel ? Axis.horizontal : Axis.vertical,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: showSidePanel ? MainAxisSize.max : MainAxisSize.min,
mainAxisSize: showSidePanel
? MainAxisSize.max
: MainAxisSize.min,
children: [
Flexible(
flex: 3,
@@ -287,14 +295,14 @@ class _DeltaTrendRow extends StatelessWidget {
final percentText = delta > 0
? '+$trimmedPercent%'
: delta < 0
? '-$trimmedPercent%'
: '0%';
? '-$trimmedPercent%'
: '0%';
final icon = delta > 0
? lucide.LucideIcons.arrowUpRight
: delta < 0
? lucide.LucideIcons.arrowDownRight
: lucide.LucideIcons.minus;
? lucide.LucideIcons.arrowDownRight
: lucide.LucideIcons.minus;
final Color color;
if (delta > 0) {
@@ -310,10 +318,7 @@ class _DeltaTrendRow extends StatelessWidget {
children: [
Icon(icon, size: 16, color: color),
const SizedBox(width: 4),
Text(
percentText,
style: theme.textTheme.small.copyWith(color: color),
),
Text(percentText, style: theme.textTheme.small.copyWith(color: color)),
const SizedBox(width: 8),
Flexible(
child: Text(
@@ -427,8 +432,8 @@ class _PendingApprovalCard extends StatelessWidget {
),
trailing: ShadButton.ghost(
size: ShadButtonSize.sm,
onPressed: () => _handleViewDetail(context, approval),
child: const Text('상세'),
onPressed: () {},
),
),
const Divider(),
@@ -437,6 +442,320 @@ class _PendingApprovalCard extends StatelessWidget {
),
);
}
void _handleViewDetail(
BuildContext context,
DashboardPendingApproval approval,
) async {
final approvalId = approval.approvalId;
debugPrint(
'[DashboardPage] 상세 버튼 클릭: approvalId=$approvalId, approvalNo=${approval.approvalNo}',
); // 클릭 시 결재 식별자를 로그로 남겨 추적한다.
if (approvalId == null) {
debugPrint(
'[DashboardPage] 결재 상세 조회 불가 - pending_approvals 응답에 approval_id가 없습니다.',
);
SuperportToast.error(context, '결재 상세를 조회할 수 없습니다. (식별자 없음)');
return;
}
final repository = GetIt.I<ApprovalRepository>();
final detailFuture = repository
.fetchDetail(approvalId, includeSteps: true, includeHistories: true)
.catchError((error) {
final failure = Failure.from(error);
debugPrint(
'[DashboardPage] 대시보드 결재 상세 조회 실패: ${failure.describe()}',
); // 콘솔에 에러를 표시해 즉시 추적한다.
if (context.mounted) {
SuperportToast.error(context, failure.describe());
}
throw error;
})
.then((detail) {
debugPrint(
'[DashboardPage] 결재 상세 조회 성공: id=${detail.id}, approvalNo=${detail.approvalNo}',
);
return detail;
});
if (!context.mounted) {
return;
}
await SuperportDialog.show<void>(
context: context,
dialog: SuperportDialog(
title: '결재 상세',
description: '결재번호 ${approval.approvalNo}',
constraints: const BoxConstraints(maxWidth: 760),
actions: [
ShadButton(
onPressed: () =>
Navigator.of(context, rootNavigator: true).maybePop(),
child: const Text('닫기'),
),
],
child: SizedBox(
width: double.infinity,
height: 480,
child: FutureBuilder<Approval>(
future: detailFuture,
builder: (dialogContext, snapshot) {
if (snapshot.connectionState != ConnectionState.done) {
return const Center(child: CircularProgressIndicator());
}
if (snapshot.hasError) {
final failure = Failure.from(snapshot.error!);
return Center(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Text(
failure.describe(),
style: ShadTheme.of(dialogContext).textTheme.muted,
textAlign: TextAlign.center,
),
),
);
}
final detail = snapshot.data!;
return _DashboardApprovalDetailContent(approval: detail);
},
),
),
),
);
}
}
class _DashboardApprovalDetailContent extends StatelessWidget {
const _DashboardApprovalDetailContent({required this.approval});
final Approval approval;
@override
Widget build(BuildContext context) {
final theme = ShadTheme.of(context);
final dateFormat = intl.DateFormat('yyyy-MM-dd HH:mm');
final overviewRows = [
('결재번호', approval.approvalNo),
('트랜잭션번호', approval.transactionNo),
('현재 상태', approval.status.name),
(
'현재 단계',
approval.currentStep == null
? '-'
: 'Step ${approval.currentStep!.stepOrder} · '
'${approval.currentStep!.approver.name}',
),
('상신자', approval.requester.name),
('상신일시', dateFormat.format(approval.requestedAt.toLocal())),
(
'최종결정일시',
approval.decidedAt == null
? '-'
: dateFormat.format(approval.decidedAt!.toLocal()),
),
];
final note = approval.note?.trim();
return SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('개요', style: theme.textTheme.h4),
const SizedBox(height: 12),
Wrap(
spacing: 16,
runSpacing: 12,
children: [
for (final row in overviewRows)
_DetailField(label: row.$1, value: row.$2),
],
),
if (note != null && note.isNotEmpty) ...[
const SizedBox(height: 16),
_DetailField(label: '비고', value: note, fullWidth: true),
],
const SizedBox(height: 24),
Text('단계', style: theme.textTheme.h4),
const SizedBox(height: 12),
_ApprovalStepList(steps: approval.steps, dateFormat: dateFormat),
const SizedBox(height: 24),
Text('이력', style: theme.textTheme.h4),
const SizedBox(height: 12),
_ApprovalHistoryList(
histories: approval.histories,
dateFormat: dateFormat,
),
],
),
);
}
}
class _DetailField extends StatelessWidget {
const _DetailField({
required this.label,
required this.value,
this.fullWidth = false,
});
final String label;
final String value;
final bool fullWidth;
@override
Widget build(BuildContext context) {
final theme = ShadTheme.of(context);
return SizedBox(
width: fullWidth ? double.infinity : 240,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(label, style: theme.textTheme.muted),
const SizedBox(height: 4),
Text(value, style: theme.textTheme.p),
],
),
);
}
}
class _ApprovalStepList extends StatelessWidget {
const _ApprovalStepList({required this.steps, required this.dateFormat});
final List<ApprovalStep> steps;
final intl.DateFormat dateFormat;
@override
Widget build(BuildContext context) {
final theme = ShadTheme.of(context);
if (steps.isEmpty) {
return Text('등록된 결재 단계가 없습니다.', style: theme.textTheme.muted);
}
return ShadCard(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
for (var index = 0; index < steps.length; index++) ...[
_ApprovalStepTile(step: steps[index], dateFormat: dateFormat),
if (index < steps.length - 1) const Divider(),
],
],
),
);
}
}
class _ApprovalStepTile extends StatelessWidget {
const _ApprovalStepTile({required this.step, required this.dateFormat});
final ApprovalStep step;
final intl.DateFormat dateFormat;
@override
Widget build(BuildContext context) {
final theme = ShadTheme.of(context);
final decidedAt = step.decidedAt;
final note = step.note?.trim();
return Padding(
padding: const EdgeInsets.symmetric(vertical: 6),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Step ${step.stepOrder} · ${step.approver.name}',
style: theme.textTheme.small,
),
const SizedBox(height: 4),
Text('상태: ${step.status.name}', style: theme.textTheme.p),
const SizedBox(height: 2),
Text(
'배정: ${dateFormat.format(step.assignedAt.toLocal())}',
style: theme.textTheme.small,
),
Text(
'결정: ${decidedAt == null ? '-' : dateFormat.format(decidedAt.toLocal())}',
style: theme.textTheme.small,
),
if (note != null && note.isNotEmpty) ...[
const SizedBox(height: 4),
Text('비고: $note', style: theme.textTheme.small),
],
],
),
);
}
}
class _ApprovalHistoryList extends StatelessWidget {
const _ApprovalHistoryList({
required this.histories,
required this.dateFormat,
});
final List<ApprovalHistory> histories;
final intl.DateFormat dateFormat;
@override
Widget build(BuildContext context) {
final theme = ShadTheme.of(context);
if (histories.isEmpty) {
return Text('등록된 결재 이력이 없습니다.', style: theme.textTheme.muted);
}
return ShadCard(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
for (var index = 0; index < histories.length; index++) ...[
_ApprovalHistoryTile(
history: histories[index],
dateFormat: dateFormat,
),
if (index < histories.length - 1) const Divider(),
],
],
),
);
}
}
class _ApprovalHistoryTile extends StatelessWidget {
const _ApprovalHistoryTile({required this.history, required this.dateFormat});
final ApprovalHistory history;
final intl.DateFormat dateFormat;
@override
Widget build(BuildContext context) {
final theme = ShadTheme.of(context);
final note = history.note?.trim();
final fromStatus = history.fromStatus?.name ?? '-';
final toStatus = history.toStatus.name;
return Padding(
padding: const EdgeInsets.symmetric(vertical: 6),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'${history.approver.name} · ${history.action.name}',
style: theme.textTheme.small,
),
const SizedBox(height: 4),
Text('상태: $fromStatus$toStatus', style: theme.textTheme.p),
const SizedBox(height: 2),
Text(
'처리일시: ${dateFormat.format(history.actionAt.toLocal())}',
style: theme.textTheme.small,
),
if (note != null && note.isNotEmpty) ...[
const SizedBox(height: 4),
Text('비고: $note', style: theme.textTheme.small),
],
],
),
);
}
}
class _KpiPreset {