Phase 3.5: Mitra Chat Request History (backend route + mitra app screens)
Replaces the home-screen pending-requests banner with a "Riwayat
Permintaan" CTA that opens a list of the mitra's last 20 chat requests
(any status). Pending rows pin to the top; non-pending rows open a
read-only detail screen with a "Lihat percakapan" CTA on accepted rows.
Backend:
- New service `getRecentRequestsForMitra(mitraId, { limit })` capped at
20, pending pinned via `(response IS NULL AND status='pending_acceptance')
DESC`. Customer call_name returned verbatim, with `'Anonim'` only as
null-safety fallback (no anonymity-flag masking — see project memory).
- New route `GET /api/mitra/chat-requests/recent`. Strictly per-mitra
scoped via the existing `resolveMitra` preHandler.
Mitra app:
- New `RequestResponse` enum in core/constants.dart.
- New Riverpod notifier `requestHistoryProvider` (AsyncValue<List<...>>,
keepAlive) — pull-to-refresh + screen-mount fetch only, no WS.
- Two new screens (history list + detail) and two new GoRoutes.
- Home screen: `_PendingRequestsBanner` removed → `_RequestHistoryButton`
Card with red count badge. Live count comes from the existing
chatRequestProvider so nothing changes about the WS-driven badge math.
Plan + acceptance criteria in requirement/phase3.5-plan.md. flutter
analyze clean (zero new issues). Backend smoke-tested against real DB.
Real-device E2E pending.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -57,7 +57,6 @@ class HomeScreen extends ConsumerWidget {
|
||||
const SizedBox(height: 32),
|
||||
const _StatusToggle(),
|
||||
const SizedBox(height: 16),
|
||||
const _PendingRequestsBanner(),
|
||||
const _ActiveSessionsButton(),
|
||||
],
|
||||
),
|
||||
@@ -125,51 +124,6 @@ class _StatusToggle extends ConsumerWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _PendingRequestsBanner extends ConsumerWidget {
|
||||
const _PendingRequestsBanner();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final requestState = ref.watch(chatRequestProvider);
|
||||
final count = ref.read(chatRequestProvider.notifier).activeRequestCount;
|
||||
|
||||
if (count == 0) return const SizedBox.shrink();
|
||||
|
||||
final isShowingOverlay = requestState is ChatRequestIncomingData ||
|
||||
requestState is ChatRequestStaleData;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 16),
|
||||
child: Card(
|
||||
color: Colors.blue.shade50,
|
||||
child: ListTile(
|
||||
leading: Badge(
|
||||
label: Text('$count'),
|
||||
child: const Icon(Icons.notifications_active, color: Colors.blue),
|
||||
),
|
||||
title: Text(
|
||||
'$count permintaan chat menunggu',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
subtitle: isShowingOverlay
|
||||
? null
|
||||
: const Text('Ketuk untuk melihat'),
|
||||
onTap: isShowingOverlay
|
||||
? null
|
||||
: () {
|
||||
// Re-advance queue to show the next request overlay
|
||||
final notifier = ref.read(chatRequestProvider.notifier);
|
||||
if (requestState is ChatRequestListeningData) {
|
||||
// Requests are queued but none is displayed — trigger next
|
||||
notifier.ignore();
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ActiveSessionsButton extends ConsumerWidget {
|
||||
const _ActiveSessionsButton();
|
||||
|
||||
@@ -192,6 +146,7 @@ class _ActiveSessionsButton extends ConsumerWidget {
|
||||
onTap: () => context.push('/sessions'),
|
||||
),
|
||||
),
|
||||
const _RequestHistoryButton(),
|
||||
Card(
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.history),
|
||||
@@ -204,3 +159,56 @@ class _ActiveSessionsButton extends ConsumerWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _RequestHistoryButton extends ConsumerWidget {
|
||||
const _RequestHistoryButton();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
// Watch state to rebuild when requests arrive/clear; count comes from
|
||||
// the notifier which tracks both displayed + queued requests.
|
||||
ref.watch(chatRequestProvider);
|
||||
final count = ref.read(chatRequestProvider.notifier).activeRequestCount;
|
||||
|
||||
final hasPending = count > 0;
|
||||
final trailing = hasPending
|
||||
? Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.red,
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
),
|
||||
child: Text(
|
||||
'$count',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
const Icon(Icons.chevron_right),
|
||||
],
|
||||
)
|
||||
: const Icon(Icons.chevron_right);
|
||||
|
||||
return Card(
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.notifications_outlined),
|
||||
title: const Text('Riwayat Permintaan'),
|
||||
subtitle: Text(
|
||||
hasPending
|
||||
? '$count permintaan baru'
|
||||
: 'Lihat permintaan chat sebelumnya',
|
||||
),
|
||||
trailing: trailing,
|
||||
onTap: () => context.push('/chat/requests/history'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user