add dashboard to phone app

This commit is contained in:
root
2026-05-25 05:10:43 -04:00
parent d04c8ce437
commit 277db06d26
67 changed files with 7872 additions and 570 deletions
@@ -1,9 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:intl/intl.dart';
import '../providers/dashboard_providers.dart';
import '../../../widgets/status_badge.dart';
import '../../../widgets/error_view.dart';
import '../../../widgets/reservation_card.dart';
import 'customer_form_screen.dart';
class CustomerDetailScreen extends ConsumerWidget {
final String id;
@@ -13,6 +16,9 @@ class CustomerDetailScreen extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final async = ref.watch(customerDetailProvider(id));
final reservationsAsync = ref.watch(
reservationsProvider({'customerId': id, 'page': 1, 'pageSize': 10}),
);
return async.when(
loading: () =>
@@ -27,7 +33,62 @@ class CustomerDetailScreen extends ConsumerWidget {
data: (customer) {
final fmt = DateFormat('MMM d, yyyy');
return Scaffold(
appBar: AppBar(title: Text(customer.fullName)),
appBar: AppBar(
title: Text(customer.fullName),
actions: [
IconButton(
icon: const Icon(Icons.edit_outlined),
onPressed: () async {
final result = await Navigator.of(context).push<bool>(
MaterialPageRoute(
builder: (_) =>
CustomerFormScreen(customer: customer)),
);
if (result == true) {
ref.invalidate(customerDetailProvider(id));
}
},
),
PopupMenuButton<String>(
onSelected: (v) async {
if (v == 'flag') {
await _showFlagDialog(context, ref, customer.isFlagged);
} else if (v == 'approve') {
await _showApproveLicenseDialog(context, ref);
}
},
itemBuilder: (_) => [
PopupMenuItem(
value: 'flag',
child: Row(
children: [
Icon(
customer.isFlagged ? Icons.flag_outlined : Icons.flag,
size: 18,
color: const Color(0xFFE02424),
),
const SizedBox(width: 8),
Text(
customer.isFlagged ? 'Remove Flag' : 'Flag Customer',
style: const TextStyle(color: Color(0xFFE02424)),
),
],
),
),
const PopupMenuItem(
value: 'approve',
child: Row(
children: [
Icon(Icons.badge_outlined, size: 18),
SizedBox(width: 8),
Text('Review License'),
],
),
),
],
),
],
),
body: ListView(
padding: const EdgeInsets.all(16),
children: [
@@ -128,12 +189,213 @@ class CustomerDetailScreen extends ConsumerWidget {
),
),
),
const SizedBox(height: 16),
if (customer.licenseStatus == 'PENDING')
_ActionButton(
label: 'Approve License',
color: const Color(0xFF0E9F6E),
icon: Icons.check_circle_outline,
onTap: () => _showApproveLicenseDialog(context, ref),
),
if (customer.licenseStatus == 'PENDING')
_ActionButton(
label: 'Reject License',
color: const Color(0xFFE02424),
icon: Icons.cancel_outlined,
onTap: () => _showRejectLicenseDialog(context, ref),
),
if (!customer.isFlagged)
_ActionButton(
label: 'Flag Customer',
color: const Color(0xFFE02424),
icon: Icons.flag_outlined,
onTap: () => _showFlagDialog(context, ref, false),
)
else
_ActionButton(
label: 'Remove Flag',
color: const Color(0xFF6B7280),
icon: Icons.flag_outlined,
onTap: () => _showFlagDialog(context, ref, true),
),
const SizedBox(height: 8),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text(
'Reservations',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
color: Color(0xFF111928),
),
),
TextButton(
onPressed: () =>
context.push('/dashboard/reservations'),
child: const Text('View all'),
),
],
),
const SizedBox(height: 8),
reservationsAsync.when(
loading: () =>
const Center(child: CircularProgressIndicator()),
error: (_, _) => const SizedBox.shrink(),
data: (res) => res.data.isEmpty
? const Padding(
padding: EdgeInsets.symmetric(vertical: 16),
child: Center(
child: Text(
'No reservations yet',
style: TextStyle(color: Color(0xFF9CA3AF)),
),
),
)
: Column(
children: res.data
.map(
(r) => Padding(
padding: const EdgeInsets.only(bottom: 10),
child: ReservationCard(
reservation: r,
onTap: () => context.push(
'/dashboard/reservations/${r.id}',
),
),
),
)
.toList(),
),
),
],
),
);
},
);
}
Future<void> _showFlagDialog(
BuildContext context, WidgetRef ref, bool isFlagged) async {
if (isFlagged) {
final confirmed = await showDialog<bool>(
context: context,
builder: (_) => AlertDialog(
title: const Text('Remove Flag'),
content: const Text('Remove the flag from this customer?'),
actions: [
TextButton(
onPressed: () => Navigator.pop(context, false),
child: const Text('Cancel')),
ElevatedButton(
onPressed: () => Navigator.pop(context, true),
child: const Text('Remove Flag')),
],
),
);
if (confirmed == true && context.mounted) {
await ref.read(customerServiceProvider).unflagCustomer(id);
ref.invalidate(customerDetailProvider(id));
}
} else {
final ctrl = TextEditingController();
final confirmed = await showDialog<bool>(
context: context,
builder: (_) => AlertDialog(
title: const Text('Flag Customer'),
content: TextField(
controller: ctrl,
decoration: const InputDecoration(labelText: 'Reason'),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context, false),
child: const Text('Cancel')),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFFE02424)),
onPressed: () => Navigator.pop(context, true),
child: const Text('Flag'),
),
],
),
);
if (confirmed == true && ctrl.text.isNotEmpty && context.mounted) {
await ref
.read(customerServiceProvider)
.flagCustomer(id, ctrl.text.trim());
ref.invalidate(customerDetailProvider(id));
}
}
}
Future<void> _showApproveLicenseDialog(
BuildContext context, WidgetRef ref) async {
final noteCtrl = TextEditingController();
final confirmed = await showDialog<bool>(
context: context,
builder: (_) => AlertDialog(
title: const Text('Approve License'),
content: TextField(
controller: noteCtrl,
decoration: const InputDecoration(labelText: 'Note (optional)'),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context, false),
child: const Text('Cancel')),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF0E9F6E)),
onPressed: () => Navigator.pop(context, true),
child: const Text('Approve'),
),
],
),
);
if (confirmed == true && context.mounted) {
await ref.read(customerServiceProvider).approveLicense(
id,
'APPROVED',
note: noteCtrl.text.isNotEmpty ? noteCtrl.text : null,
);
ref.invalidate(customerDetailProvider(id));
}
}
Future<void> _showRejectLicenseDialog(
BuildContext context, WidgetRef ref) async {
final noteCtrl = TextEditingController();
final confirmed = await showDialog<bool>(
context: context,
builder: (_) => AlertDialog(
title: const Text('Reject License'),
content: TextField(
controller: noteCtrl,
decoration: const InputDecoration(labelText: 'Reason'),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context, false),
child: const Text('Cancel')),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFFE02424)),
onPressed: () => Navigator.pop(context, true),
child: const Text('Reject'),
),
],
),
);
if (confirmed == true && context.mounted) {
await ref.read(customerServiceProvider).approveLicense(
id,
'REJECTED',
note: noteCtrl.text.isNotEmpty ? noteCtrl.text : null,
);
ref.invalidate(customerDetailProvider(id));
}
}
}
class _InfoRow extends StatelessWidget {
@@ -151,11 +413,40 @@ class _InfoRow extends StatelessWidget {
Icon(icon, size: 18, color: const Color(0xFF6B7280)),
const SizedBox(width: 10),
Expanded(
child: Text(value,
style: const TextStyle(fontSize: 14)),
child: Text(value, style: const TextStyle(fontSize: 14)),
),
],
),
);
}
}
class _ActionButton extends StatelessWidget {
final String label;
final Color color;
final IconData icon;
final VoidCallback onTap;
const _ActionButton({
required this.label,
required this.color,
required this.icon,
required this.onTap,
});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(bottom: 10),
child: ElevatedButton.icon(
style: ElevatedButton.styleFrom(
backgroundColor: color,
minimumSize: const Size.fromHeight(48),
),
icon: Icon(icon),
label: Text(label),
onPressed: onTap,
),
);
}
}