Phase 3.3: topic sensitivity + Phase 3.4: auth foundation
Phase 3.3 — Session Topic Sensitivity (complete): - Backend: topic_sensitivity column + session_sensitivity_log, sensitivity service (flip with one-way-latch + audit), PATCH /api/shared/chat/sessions/:id/topic, topic carried in pairing + extension WS payloads, CC filter + sensitive stats + per-mitra sensitive columns on activity page - client_app: TopicSelectionBottomSheet before pricing, topic flows through pairing request, silent WS handler for session_topic_updated - mitra_app: SensitivityBadge + SensitivityTheme + sensitivityConfigProvider, overlay badge + yellow accent, chat screen app-bar toggle with configurable confirmation + latch, extension card shows current flag, history + transcript yellow theme - control_center: Sensitivitas Topik settings section, topic filter + column with inline audit log, sensitive stats dashboard card, mitra activity sensitive columns with QC flag Phase 3.4 — Self-Managed Auth (foundation only): - Migration: auth_sessions + otp_requests tables, social identity columns on customers, password_hash + lockout on control_center_users, OTP + CC lockout app_config keys - New services: password (bcrypt + complexity), token (JWT HS256 + refresh rotation, session_id claim pre-wires future Valkey revocation), social-identity (Google + Apple JWKS), OTP (Fazpass stub — real API TBD) - Constants: AuthProvider + OtpChannel - Middleware, auth route rewrites, WS auth update, Firebase → FCM isolation still pending (next chunk); Fazpass docs + Apple Developer setup still required before E2E testing Docs: - requirement/phase3.3.md, phase3.3-plan.md, phase3.3-testing.md - requirement/phase3.4.md, phase3.4-plan.md Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -32,4 +32,9 @@ class ApiClient {
|
||||
final response = await _dio.post(path, data: data);
|
||||
return response.data as Map<String, dynamic>;
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> patch(String path, {Map<String, dynamic>? data}) async {
|
||||
final response = await _dio.patch(path, data: data);
|
||||
return response.data as Map<String, dynamic>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,11 +35,13 @@ class ChatRequestIncomingData extends ChatRequestData {
|
||||
final String sessionId;
|
||||
final int? durationMinutes;
|
||||
final bool? isFreeTrial;
|
||||
final TopicSensitivity topicSensitivity;
|
||||
final DateTime? createdAt;
|
||||
const ChatRequestIncomingData(
|
||||
this.sessionId, {
|
||||
this.durationMinutes,
|
||||
this.isFreeTrial,
|
||||
this.topicSensitivity = TopicSensitivity.regular,
|
||||
this.createdAt,
|
||||
});
|
||||
}
|
||||
@@ -99,6 +101,7 @@ class ChatRequest extends _$ChatRequest {
|
||||
'session_id': sessionId,
|
||||
'duration_minutes': r['duration_minutes'],
|
||||
'is_free_trial': r['is_free_trial'],
|
||||
'topic_sensitivity': r['topic_sensitivity'],
|
||||
'created_at': r['created_at'],
|
||||
};
|
||||
|
||||
@@ -111,6 +114,7 @@ class ChatRequest extends _$ChatRequest {
|
||||
sessionId,
|
||||
durationMinutes: r['duration_minutes'] as int?,
|
||||
isFreeTrial: r['is_free_trial'] as bool?,
|
||||
topicSensitivity: TopicSensitivity.fromString(r['topic_sensitivity'] as String?),
|
||||
createdAt: r['created_at'] != null
|
||||
? DateTime.tryParse(r['created_at'] as String)
|
||||
: null,
|
||||
@@ -200,6 +204,7 @@ class ChatRequest extends _$ChatRequest {
|
||||
sessionId,
|
||||
durationMinutes: data['duration_minutes'] as int?,
|
||||
isFreeTrial: data['is_free_trial'] as bool?,
|
||||
topicSensitivity: TopicSensitivity.fromString(data['topic_sensitivity'] as String?),
|
||||
createdAt: data['created_at'] != null
|
||||
? DateTime.tryParse(data['created_at'] as String)
|
||||
: null,
|
||||
@@ -279,6 +284,7 @@ class ChatRequest extends _$ChatRequest {
|
||||
sessionId,
|
||||
durationMinutes: next['duration_minutes'] as int?,
|
||||
isFreeTrial: next['is_free_trial'] as bool?,
|
||||
topicSensitivity: TopicSensitivity.fromString(next['topic_sensitivity'] as String?),
|
||||
createdAt: next['created_at'] != null
|
||||
? DateTime.tryParse(next['created_at'] as String)
|
||||
: null,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:web_socket_channel/web_socket_channel.dart';
|
||||
@@ -29,6 +30,7 @@ class MitraChatConnectedData extends MitraChatData {
|
||||
final bool sessionExpired;
|
||||
final bool sessionClosing;
|
||||
final Map<String, dynamic>? extensionRequest;
|
||||
final TopicSensitivity topicSensitivity;
|
||||
|
||||
const MitraChatConnectedData({
|
||||
required this.messages,
|
||||
@@ -37,6 +39,7 @@ class MitraChatConnectedData extends MitraChatData {
|
||||
this.sessionExpired = false,
|
||||
this.sessionClosing = false,
|
||||
this.extensionRequest,
|
||||
this.topicSensitivity = TopicSensitivity.regular,
|
||||
});
|
||||
|
||||
MitraChatConnectedData copyWith({
|
||||
@@ -47,6 +50,7 @@ class MitraChatConnectedData extends MitraChatData {
|
||||
bool? sessionClosing,
|
||||
Map<String, dynamic>? extensionRequest,
|
||||
bool clearExtensionRequest = false,
|
||||
TopicSensitivity? topicSensitivity,
|
||||
}) {
|
||||
return MitraChatConnectedData(
|
||||
messages: messages ?? this.messages,
|
||||
@@ -55,6 +59,7 @@ class MitraChatConnectedData extends MitraChatData {
|
||||
sessionExpired: sessionExpired ?? this.sessionExpired,
|
||||
sessionClosing: sessionClosing ?? this.sessionClosing,
|
||||
extensionRequest: clearExtensionRequest ? null : (extensionRequest ?? this.extensionRequest),
|
||||
topicSensitivity: topicSensitivity ?? this.topicSensitivity,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -119,6 +124,7 @@ class MitraChat extends _$MitraChat {
|
||||
}
|
||||
|
||||
final isClosing = sessionStatus == SessionStatus.closing;
|
||||
final sessionTopic = TopicSensitivity.fromString(sessionData?['topic_sensitivity'] as String?);
|
||||
|
||||
final response = await _apiClient.get('/api/shared/chat/$sessionId/messages');
|
||||
final messagesData = response['data'] as List<dynamic>;
|
||||
@@ -153,7 +159,7 @@ class MitraChat extends _$MitraChat {
|
||||
'session_id': sessionId,
|
||||
}));
|
||||
|
||||
state = MitraChatConnectedData(messages: messages, sessionClosing: isClosing);
|
||||
state = MitraChatConnectedData(messages: messages, sessionClosing: isClosing, topicSensitivity: sessionTopic);
|
||||
} catch (e) {
|
||||
state = const MitraChatErrorData('Gagal terhubung ke chat.');
|
||||
}
|
||||
@@ -288,6 +294,31 @@ class MitraChat extends _$MitraChat {
|
||||
case WsMessage.sessionCompleted:
|
||||
_cleanup();
|
||||
break;
|
||||
|
||||
case WsMessage.sessionTopicUpdated:
|
||||
final newValue = TopicSensitivity.fromString(data['topic_sensitivity'] as String?);
|
||||
state = current.copyWith(topicSensitivity: newValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// Flip the session's topic sensitivity. Returns error code on failure, null on success.
|
||||
Future<String?> flipTopic(String sessionId, TopicSensitivity toValue) async {
|
||||
try {
|
||||
final response = await _apiClient.patch(
|
||||
'/api/shared/chat/sessions/$sessionId/topic',
|
||||
data: {'topic_sensitivity': toValue.value},
|
||||
);
|
||||
final updated = TopicSensitivity.fromString(response['data']?['topic_sensitivity'] as String?);
|
||||
final current = state;
|
||||
if (current is MitraChatConnectedData) {
|
||||
state = current.copyWith(topicSensitivity: updated);
|
||||
}
|
||||
return null;
|
||||
} on DioException catch (e) {
|
||||
return e.response?.data?['error']?['code'] as String? ?? 'FLIP_FAILED';
|
||||
} catch (_) {
|
||||
return 'FLIP_FAILED';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
31
mitra_app/lib/core/chat/sensitivity_config_provider.dart
Normal file
31
mitra_app/lib/core/chat/sensitivity_config_provider.dart
Normal file
@@ -0,0 +1,31 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../api/api_client_provider.dart';
|
||||
|
||||
class SensitivityConfig {
|
||||
final bool flipConfirmationEnabled;
|
||||
final bool oneWayLatch;
|
||||
const SensitivityConfig({
|
||||
required this.flipConfirmationEnabled,
|
||||
required this.oneWayLatch,
|
||||
});
|
||||
|
||||
static const defaults = SensitivityConfig(
|
||||
flipConfirmationEnabled: true,
|
||||
oneWayLatch: false,
|
||||
);
|
||||
}
|
||||
|
||||
/// Fetches the sensitivity config once and caches it for the app lifetime.
|
||||
/// Falls back to defaults if the request fails.
|
||||
final sensitivityConfigProvider = FutureProvider<SensitivityConfig>((ref) async {
|
||||
try {
|
||||
final response = await ref.read(apiClientProvider).get('/api/shared/sensitivity');
|
||||
final data = response['data'] as Map<String, dynamic>;
|
||||
return SensitivityConfig(
|
||||
flipConfirmationEnabled: data['flip_confirmation_enabled'] as bool? ?? true,
|
||||
oneWayLatch: data['one_way_latch'] as bool? ?? false,
|
||||
);
|
||||
} catch (_) {
|
||||
return SensitivityConfig.defaults;
|
||||
}
|
||||
});
|
||||
@@ -1,7 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../chat_request_notifier.dart';
|
||||
import '../../constants.dart';
|
||||
import '../../../router.dart';
|
||||
import 'sensitivity_badge.dart';
|
||||
import 'sensitivity_theme.dart';
|
||||
|
||||
class ChatRequestOverlay extends ConsumerStatefulWidget {
|
||||
final Widget child;
|
||||
@@ -132,12 +135,17 @@ class _ChatRequestOverlayState extends ConsumerState<ChatRequestOverlay>
|
||||
: data.durationMinutes != null
|
||||
? '${data.durationMinutes} Menit'
|
||||
: '';
|
||||
final isSensitive = data.topicSensitivity == TopicSensitivity.sensitive;
|
||||
final theme = SensitivityTheme.of(data.topicSensitivity);
|
||||
|
||||
return Container(
|
||||
decoration: const BoxDecoration(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
||||
boxShadow: [BoxShadow(color: Colors.black26, blurRadius: 10, offset: Offset(0, -2))],
|
||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(20)),
|
||||
border: isSensitive
|
||||
? Border(top: BorderSide(color: theme.badgeBg, width: 4))
|
||||
: null,
|
||||
boxShadow: const [BoxShadow(color: Colors.black26, blurRadius: 10, offset: Offset(0, -2))],
|
||||
),
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
@@ -168,6 +176,10 @@ class _ChatRequestOverlayState extends ConsumerState<ChatRequestOverlay>
|
||||
'Durasi: $durationText',
|
||||
style: const TextStyle(fontSize: 14, color: Colors.grey),
|
||||
),
|
||||
if (isSensitive) ...[
|
||||
const SizedBox(height: 8),
|
||||
SensitivityBadge(sensitivity: data.topicSensitivity, fontSize: 12),
|
||||
],
|
||||
const SizedBox(height: 8),
|
||||
const Text(
|
||||
'Seorang customer ingin curhat denganmu.',
|
||||
|
||||
46
mitra_app/lib/core/chat/widgets/sensitivity_badge.dart
Normal file
46
mitra_app/lib/core/chat/widgets/sensitivity_badge.dart
Normal file
@@ -0,0 +1,46 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../constants.dart';
|
||||
import 'sensitivity_theme.dart';
|
||||
|
||||
/// Small pill-style badge used across the mitra app to indicate a sensitive session.
|
||||
/// Renders nothing for regular sessions.
|
||||
class SensitivityBadge extends StatelessWidget {
|
||||
final TopicSensitivity sensitivity;
|
||||
final double fontSize;
|
||||
final EdgeInsets padding;
|
||||
|
||||
const SensitivityBadge({
|
||||
super.key,
|
||||
required this.sensitivity,
|
||||
this.fontSize = 11,
|
||||
this.padding = const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (sensitivity != TopicSensitivity.sensitive) return const SizedBox.shrink();
|
||||
const theme = SensitivityTheme.sensitive;
|
||||
return Container(
|
||||
padding: padding,
|
||||
decoration: BoxDecoration(
|
||||
color: theme.badgeBg,
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.warning_amber_rounded, size: fontSize + 2, color: theme.badgeFg),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'Topik sensitif',
|
||||
style: TextStyle(
|
||||
color: theme.badgeFg,
|
||||
fontSize: fontSize,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
38
mitra_app/lib/core/chat/widgets/sensitivity_theme.dart
Normal file
38
mitra_app/lib/core/chat/widgets/sensitivity_theme.dart
Normal file
@@ -0,0 +1,38 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../constants.dart';
|
||||
|
||||
/// Color tokens used by the mitra chat UI to differentiate regular vs sensitive sessions.
|
||||
class SensitivityTheme {
|
||||
final Color bgTint;
|
||||
final Color accent;
|
||||
final Color banner;
|
||||
final Color badgeBg;
|
||||
final Color badgeFg;
|
||||
|
||||
const SensitivityTheme({
|
||||
required this.bgTint,
|
||||
required this.accent,
|
||||
required this.banner,
|
||||
required this.badgeBg,
|
||||
required this.badgeFg,
|
||||
});
|
||||
|
||||
static const regular = SensitivityTheme(
|
||||
bgTint: Color(0xFFF5D0D6),
|
||||
accent: Color(0xFFBE7C8A),
|
||||
banner: Color(0xFFC4868F),
|
||||
badgeBg: Color(0xFFBE7C8A),
|
||||
badgeFg: Colors.white,
|
||||
);
|
||||
|
||||
static const sensitive = SensitivityTheme(
|
||||
bgTint: Color(0xFFFFE8A3),
|
||||
accent: Color(0xFFB88900),
|
||||
banner: Color(0xFFE0A500),
|
||||
badgeBg: Color(0xFFF7B500),
|
||||
badgeFg: Color(0xFF3D2A00),
|
||||
);
|
||||
|
||||
static SensitivityTheme of(TopicSensitivity s) =>
|
||||
s == TopicSensitivity.sensitive ? sensitive : regular;
|
||||
}
|
||||
@@ -42,6 +42,18 @@ class ExtensionStatus {
|
||||
ExtensionStatus._();
|
||||
}
|
||||
|
||||
/// Session topic sensitivity
|
||||
enum TopicSensitivity {
|
||||
regular('regular'),
|
||||
sensitive('sensitive');
|
||||
|
||||
final String value;
|
||||
const TopicSensitivity(this.value);
|
||||
|
||||
static TopicSensitivity fromString(String? v) =>
|
||||
values.firstWhere((e) => e.value == v, orElse: () => TopicSensitivity.regular);
|
||||
}
|
||||
|
||||
/// WebSocket message types
|
||||
class WsMessage {
|
||||
// Auth
|
||||
@@ -72,6 +84,9 @@ class WsMessage {
|
||||
static const extensionRequest = 'extension_request';
|
||||
static const extensionResponse = 'extension_response';
|
||||
|
||||
// Topic sensitivity
|
||||
static const sessionTopicUpdated = 'session_topic_updated';
|
||||
|
||||
// Delivery
|
||||
static const delivered = 'delivered';
|
||||
static const read = 'read';
|
||||
|
||||
@@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../../core/api/api_client_provider.dart';
|
||||
import '../../../core/chat/widgets/sensitivity_badge.dart';
|
||||
import '../../../core/constants.dart';
|
||||
|
||||
class MitraChatHistoryScreen extends ConsumerStatefulWidget {
|
||||
const MitraChatHistoryScreen({super.key});
|
||||
@@ -53,9 +55,19 @@ class _MitraChatHistoryScreenState extends ConsumerState<MitraChatHistoryScreen>
|
||||
final duration = s['duration_minutes'] as int?;
|
||||
final closureMsg = s['mitra_closure_message'] as String?;
|
||||
|
||||
final topic = TopicSensitivity.fromString(s['topic_sensitivity'] as String?);
|
||||
|
||||
return ListTile(
|
||||
leading: const CircleAvatar(child: Icon(Icons.person)),
|
||||
title: Text(customerName),
|
||||
title: Row(
|
||||
children: [
|
||||
Flexible(child: Text(customerName, overflow: TextOverflow.ellipsis)),
|
||||
if (topic == TopicSensitivity.sensitive) ...[
|
||||
const SizedBox(width: 8),
|
||||
SensitivityBadge(sensitivity: topic, fontSize: 10),
|
||||
],
|
||||
],
|
||||
),
|
||||
subtitle: Text([
|
||||
if (endedAt != null) '${endedAt.day}/${endedAt.month}/${endedAt.year}',
|
||||
if (duration != null) '$duration menit',
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../../core/api/api_client_provider.dart';
|
||||
import '../../../core/chat/widgets/sensitivity_badge.dart';
|
||||
import '../../../core/chat/widgets/sensitivity_theme.dart';
|
||||
import '../../../core/constants.dart';
|
||||
|
||||
class MitraChatTranscriptScreen extends ConsumerStatefulWidget {
|
||||
@@ -15,6 +17,7 @@ class MitraChatTranscriptScreen extends ConsumerStatefulWidget {
|
||||
class _MitraChatTranscriptScreenState extends ConsumerState<MitraChatTranscriptScreen> {
|
||||
List<Map<String, dynamic>> _messages = [];
|
||||
List<Map<String, dynamic>> _closures = [];
|
||||
TopicSensitivity _topicSensitivity = TopicSensitivity.regular;
|
||||
bool _loading = true;
|
||||
|
||||
@override
|
||||
@@ -26,11 +29,16 @@ class _MitraChatTranscriptScreenState extends ConsumerState<MitraChatTranscriptS
|
||||
Future<void> _loadTranscript() async {
|
||||
try {
|
||||
final api = ref.read(apiClientProvider);
|
||||
final response = await api.get('/api/shared/chat/${widget.sessionId}/transcript');
|
||||
final data = response['data'] as Map<String, dynamic>;
|
||||
final results = await Future.wait([
|
||||
api.get('/api/shared/chat/${widget.sessionId}/transcript'),
|
||||
api.get('/api/shared/chat/${widget.sessionId}/info'),
|
||||
]);
|
||||
final data = results[0]['data'] as Map<String, dynamic>;
|
||||
final info = results[1]['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>>();
|
||||
_topicSensitivity = TopicSensitivity.fromString(info?['topic_sensitivity'] as String?);
|
||||
_loading = false;
|
||||
});
|
||||
} catch (_) {
|
||||
@@ -40,8 +48,21 @@ class _MitraChatTranscriptScreenState extends ConsumerState<MitraChatTranscriptS
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isSensitive = _topicSensitivity == TopicSensitivity.sensitive;
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Transkrip Chat')),
|
||||
backgroundColor: isSensitive ? SensitivityTheme.sensitive.bgTint : null,
|
||||
appBar: AppBar(
|
||||
title: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text('Transkrip Chat'),
|
||||
if (isSensitive) ...[
|
||||
const SizedBox(width: 8),
|
||||
SensitivityBadge(sensitivity: _topicSensitivity, fontSize: 11),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
body: _loading
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: ListView(
|
||||
|
||||
@@ -4,11 +4,13 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../../core/chat/mitra_chat_notifier.dart';
|
||||
import '../../../core/chat/extension_notifier.dart';
|
||||
import '../../../core/chat/sensitivity_config_provider.dart';
|
||||
import '../../../core/chat/widgets/sensitivity_badge.dart';
|
||||
import '../../../core/chat/widgets/sensitivity_theme.dart';
|
||||
import '../../../core/constants.dart';
|
||||
|
||||
// Chat theme colors
|
||||
const _kUserBubbleColor = Color(0xFFD4929A);
|
||||
const _kBgTint = Color(0xFFF5D0D6);
|
||||
const _kBannerColor = Color(0xFFC4868F);
|
||||
const _kAccentPink = Color(0xFFBE7C8A);
|
||||
|
||||
@@ -99,6 +101,10 @@ class _MitraChatScreenState extends ConsumerState<MitraChatScreen> {
|
||||
}
|
||||
});
|
||||
|
||||
final currentSensitivity = chatState is MitraChatConnectedData
|
||||
? chatState.topicSensitivity
|
||||
: TopicSensitivity.regular;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.white,
|
||||
@@ -111,6 +117,7 @@ class _MitraChatScreenState extends ConsumerState<MitraChatScreen> {
|
||||
),
|
||||
title: Text(widget.customerName),
|
||||
actions: [
|
||||
if (chatState is MitraChatConnectedData) _buildTopicToggle(chatState),
|
||||
if (chatState is MitraChatConnectedData && chatState.remainingSeconds != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 16),
|
||||
@@ -126,10 +133,120 @@ class _MitraChatScreenState extends ConsumerState<MitraChatScreen> {
|
||||
),
|
||||
],
|
||||
),
|
||||
body: _buildBody(chatState, extState),
|
||||
body: Column(
|
||||
children: [
|
||||
if (currentSensitivity == TopicSensitivity.sensitive)
|
||||
_buildSensitivityHeader(),
|
||||
Expanded(child: _buildBody(chatState, extState)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSensitivityHeader() {
|
||||
const theme = SensitivityTheme.sensitive;
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 12),
|
||||
color: theme.badgeBg,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.warning_amber_rounded, size: 16, color: theme.badgeFg),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
'Topik sensitif',
|
||||
style: TextStyle(
|
||||
color: theme.badgeFg,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTopicToggle(MitraChatConnectedData state) {
|
||||
final configAsync = ref.watch(sensitivityConfigProvider);
|
||||
final config = configAsync.value ?? SensitivityConfig.defaults;
|
||||
final isSensitive = state.topicSensitivity == TopicSensitivity.sensitive;
|
||||
final locked = config.oneWayLatch && isSensitive;
|
||||
|
||||
return Tooltip(
|
||||
message: locked
|
||||
? 'Sesi sudah terkunci sebagai topik sensitif'
|
||||
: isSensitive
|
||||
? 'Tandai sebagai topik umum'
|
||||
: 'Tandai sebagai topik sensitif',
|
||||
child: IconButton(
|
||||
icon: Icon(
|
||||
isSensitive ? Icons.flag : Icons.outlined_flag,
|
||||
color: isSensitive ? SensitivityTheme.sensitive.badgeBg : Colors.grey.shade600,
|
||||
),
|
||||
onPressed: locked ? null : () => _onTopicTogglePressed(state, config),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onTopicTogglePressed(
|
||||
MitraChatConnectedData state,
|
||||
SensitivityConfig config,
|
||||
) async {
|
||||
final toValue = state.topicSensitivity == TopicSensitivity.sensitive
|
||||
? TopicSensitivity.regular
|
||||
: TopicSensitivity.sensitive;
|
||||
|
||||
if (config.flipConfirmationEnabled) {
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: Text(
|
||||
toValue == TopicSensitivity.sensitive
|
||||
? 'Tandai sesi ini sebagai sensitif?'
|
||||
: 'Tandai sesi ini sebagai topik umum?',
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(ctx).pop(false),
|
||||
child: const Text('Batal'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.of(ctx).pop(true),
|
||||
child: const Text('Tandai'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (confirmed != true || !mounted) return;
|
||||
}
|
||||
|
||||
final err = await ref
|
||||
.read(mitraChatProvider.notifier)
|
||||
.flipTopic(widget.sessionId, toValue);
|
||||
|
||||
if (!mounted) return;
|
||||
if (err != null) {
|
||||
final msg = err == 'SENSITIVITY_LATCHED'
|
||||
? 'Sesi sudah ditandai sensitif dan tidak bisa dikembalikan.'
|
||||
: err == 'SESSION_NOT_ACTIVE'
|
||||
? 'Sesi sudah berakhir.'
|
||||
: 'Gagal mengubah topik. Coba lagi.';
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(msg)));
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
toValue == TopicSensitivity.sensitive
|
||||
? 'Sesi ditandai sensitif'
|
||||
: 'Sesi ditandai topik umum',
|
||||
),
|
||||
duration: const Duration(seconds: 2),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildBody(MitraChatData chatState, ExtensionData extState) {
|
||||
if (chatState is MitraChatConnectingData) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
@@ -154,12 +271,14 @@ class _MitraChatScreenState extends ConsumerState<MitraChatScreen> {
|
||||
return _buildGoodbyeView(extState);
|
||||
}
|
||||
|
||||
final bgTint = SensitivityTheme.of(state.topicSensitivity).bgTint;
|
||||
|
||||
return Stack(
|
||||
children: [
|
||||
// Background pattern
|
||||
Positioned.fill(
|
||||
child: Container(
|
||||
color: _kBgTint,
|
||||
color: bgTint,
|
||||
child: Image.asset(
|
||||
'assets/images/chat_pattern.png',
|
||||
repeat: ImageRepeat.repeat,
|
||||
@@ -328,8 +447,12 @@ class _MitraChatScreenState extends ConsumerState<MitraChatScreen> {
|
||||
final duration = request['duration_minutes'] as int?;
|
||||
final extensionId = request['extension_id'] as String?;
|
||||
final isResponding = extState is ExtensionRespondingData;
|
||||
final topic = TopicSensitivity.fromString(request['topic_sensitivity'] as String?);
|
||||
final isSensitive = topic == TopicSensitivity.sensitive;
|
||||
|
||||
return Center(
|
||||
return Container(
|
||||
color: isSensitive ? SensitivityTheme.sensitive.bgTint : null,
|
||||
child: Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: Column(
|
||||
@@ -338,6 +461,10 @@ class _MitraChatScreenState extends ConsumerState<MitraChatScreen> {
|
||||
const Icon(Icons.timer, size: 64, color: Colors.orange),
|
||||
const SizedBox(height: 16),
|
||||
const Text('Permintaan Perpanjangan', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
|
||||
if (isSensitive) ...[
|
||||
const SizedBox(height: 8),
|
||||
SensitivityBadge(sensitivity: topic),
|
||||
],
|
||||
const SizedBox(height: 8),
|
||||
Text('Customer ingin perpanjang $duration menit', textAlign: TextAlign.center),
|
||||
const SizedBox(height: 24),
|
||||
@@ -371,6 +498,7 @@ class _MitraChatScreenState extends ConsumerState<MitraChatScreen> {
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user