- Upgrade Fastify 4→5 with all plugins (@fastify/websocket 11, cors 11, sensible 6) - Migrate all SSE endpoints to WebSocket + FCM push (mitra chat requests, customer pairing status) - Add flutter_local_notifications for foreground push notifications with sound - Add splash screen to both apps (hide auth loading flash) - Introduce constants/enums across entire codebase (no raw string literals) - Move price tiers from hardcoded array to app_config DB (data-driven, includes 1-min test tier) - Add session ownership validation on all shared chat routes - Add ownership checks on endSession, respondToExtension, requestExtension - Fix session timer: auto-complete expired/stale sessions on server restart - Add 5-min grace period for abandoned closing sessions - Fix extension flow: proper session_resumed handling, clearExtensionRequest, closure grace timer cleanup - Fix chat screens: ConnectChat in initState, session status check on connect - Fix customer expired view: 5-min countdown, closure state priority over expired state - Fix mitra extension UI: loading spinner, disable buttons, handle EXTENSION_RESOLVED error - Fix GoRouter navigation consistency (no more Navigator.pushNamed) - Fix goodbye view keyboard overflow (SingleChildScrollView) - Add active session card on customer home screen with refresh on navigate back - Fix PricingBottomSheet extension mode (RequestExtension instead of new pairing) - Send session_resumed to both parties on extension accept Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
95 lines
3.1 KiB
Dart
95 lines
3.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import '../../../core/api/api_client.dart';
|
|
|
|
class ActiveSessionsScreen extends StatefulWidget {
|
|
const ActiveSessionsScreen({super.key});
|
|
|
|
@override
|
|
State<ActiveSessionsScreen> createState() => _ActiveSessionsScreenState();
|
|
}
|
|
|
|
class _ActiveSessionsScreenState extends State<ActiveSessionsScreen> {
|
|
List<Map<String, dynamic>> _sessions = [];
|
|
bool _loading = true;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_loadSessions();
|
|
}
|
|
|
|
Future<void> _loadSessions() async {
|
|
try {
|
|
final apiClient = context.read<ApiClient>();
|
|
final response = await apiClient.get('/api/mitra/chat-requests/sessions/active');
|
|
setState(() {
|
|
_sessions = List<Map<String, dynamic>>.from(response['data'] as List);
|
|
_loading = false;
|
|
});
|
|
} catch (_) {
|
|
setState(() => _loading = false);
|
|
}
|
|
}
|
|
|
|
Future<void> _endSession(String sessionId) async {
|
|
final confirmed = await showDialog<bool>(
|
|
context: context,
|
|
builder: (ctx) => AlertDialog(
|
|
title: const Text('Akhiri Sesi?'),
|
|
content: const Text('Apakah kamu yakin ingin mengakhiri sesi ini?'),
|
|
actions: [
|
|
TextButton(onPressed: () => Navigator.of(ctx).pop(false), child: const Text('Batal')),
|
|
TextButton(onPressed: () => Navigator.of(ctx).pop(true), child: const Text('Ya, Akhiri')),
|
|
],
|
|
),
|
|
);
|
|
|
|
if (confirmed == true) {
|
|
try {
|
|
final apiClient = context.read<ApiClient>();
|
|
await apiClient.post('/api/mitra/chat-requests/sessions/$sessionId/end');
|
|
_loadSessions();
|
|
} catch (_) {
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(content: Text('Gagal mengakhiri sesi.')),
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('Sesi Aktif')),
|
|
body: _loading
|
|
? const Center(child: CircularProgressIndicator())
|
|
: _sessions.isEmpty
|
|
? const Center(child: Text('Tidak ada sesi aktif.'))
|
|
: ListView.builder(
|
|
itemCount: _sessions.length,
|
|
itemBuilder: (context, index) {
|
|
final session = _sessions[index];
|
|
final customerName = session['customer_display_name'] as String? ?? 'Customer';
|
|
return ListTile(
|
|
leading: const Icon(Icons.chat),
|
|
title: Text(customerName),
|
|
subtitle: Text('Status: ${session['status']}'),
|
|
trailing: TextButton(
|
|
onPressed: () => _endSession(session['id'] as String),
|
|
child: const Text('Akhiri', style: TextStyle(color: Colors.red)),
|
|
),
|
|
onTap: () => context.push(
|
|
'/chat/session/${session['id']}',
|
|
extra: {'customerName': customerName},
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|