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

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

@@ -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 {