- 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>
93 lines
3.5 KiB
Dart
93 lines
3.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import '../../../core/api/api_client.dart';
|
|
import '../../../core/constants.dart';
|
|
|
|
class ChatTranscriptScreen extends StatefulWidget {
|
|
final String sessionId;
|
|
|
|
const ChatTranscriptScreen({super.key, required this.sessionId});
|
|
|
|
@override
|
|
State<ChatTranscriptScreen> createState() => _ChatTranscriptScreenState();
|
|
}
|
|
|
|
class _ChatTranscriptScreenState extends State<ChatTranscriptScreen> {
|
|
List<Map<String, dynamic>> _messages = [];
|
|
List<Map<String, dynamic>> _closures = [];
|
|
bool _loading = true;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_loadTranscript();
|
|
}
|
|
|
|
Future<void> _loadTranscript() async {
|
|
try {
|
|
final api = context.read<ApiClient>();
|
|
final response = await api.get('/api/shared/chat/${widget.sessionId}/transcript');
|
|
final data = response['data'] as Map<String, dynamic>;
|
|
setState(() {
|
|
_messages = (data['messages'] as List<dynamic>).cast<Map<String, dynamic>>();
|
|
_closures = (data['closures'] as List<dynamic>).cast<Map<String, dynamic>>();
|
|
_loading = false;
|
|
});
|
|
} catch (_) {
|
|
setState(() => _loading = false);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('Transkrip Chat')),
|
|
body: _loading
|
|
? const Center(child: CircularProgressIndicator())
|
|
: ListView(
|
|
padding: const EdgeInsets.all(16),
|
|
children: [
|
|
..._messages.map((m) {
|
|
final isMe = m['sender_type'] == UserType.customer;
|
|
final time = DateTime.parse(m['created_at'] as String).toLocal();
|
|
return Align(
|
|
alignment: isMe ? Alignment.centerRight : Alignment.centerLeft,
|
|
child: Container(
|
|
margin: const EdgeInsets.symmetric(vertical: 4),
|
|
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
|
constraints: BoxConstraints(maxWidth: MediaQuery.of(context).size.width * 0.75),
|
|
decoration: BoxDecoration(
|
|
color: isMe ? Colors.blue.shade100 : Colors.grey.shade200,
|
|
borderRadius: BorderRadius.circular(16),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
Text(m['content'] as String, style: const TextStyle(fontSize: 15)),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
'${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}',
|
|
style: const TextStyle(fontSize: 10, color: Colors.grey),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}),
|
|
if (_closures.isNotEmpty) ...[
|
|
const Divider(height: 32),
|
|
const Text('Pesan Penutup', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16)),
|
|
const SizedBox(height: 8),
|
|
..._closures.map((c) => Card(
|
|
child: ListTile(
|
|
title: Text(c['user_type'] == UserType.customer ? 'Kamu' : 'Bestie'),
|
|
subtitle: Text(c['message'] as String),
|
|
),
|
|
)),
|
|
],
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|