Phase 4 Stage 7: end-of-session 2-step confirm + thank-you screen
Customer-driven session end flow: - AppBar 'akhiri' action on chat_screen (visible when connected and not already closing). - Tap fires confirm_end_step1 HaloPopup. lanjut akhiri -> step2; gak jadi balik -> dismiss, stay in chat. - confirm_end_step2 HaloPopup. tulis pesan penutup -> closing_message_sheet HaloBottomSheet (textarea + kirim & akhiri / lewat — langsung akhiri). lewati saja closes immediately. - Both close paths POST /api/client/session/:sessionId/end via session_closure_notifier.closeSession() and route to /chat/thank-you. - 409 from the close endpoint surfaces a ClosureRejectedByMitraData state and a stub HaloPopup with TODO(stage8) for the BestieOfflinePopup returning variant. Removed the legacy _showSessionExpiredDialog modal — Stage 6's ChatExpiredBanner is the replacement notification. Inline _buildGoodbyeView retained with a TODO for the mitra-side early end flow (still reaches it). endSessionTwoStepConfirmProvider hardcoded to true with a TODO — the Stage 1.5 app_config row exists but no client-readable config endpoint exists yet. Flip the provider to a FutureProvider once the read endpoint ships. Maestro 07_end_session_2step.yaml chains after the chat-happy flow and asserts the Indonesian copy at each step. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
138
client_app/lib/features/chat/widgets/closing_message_sheet.dart
Normal file
138
client_app/lib/features/chat/widgets/closing_message_sheet.dart
Normal file
@@ -0,0 +1,138 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../../core/chat/session_closure_notifier.dart';
|
||||
import '../../../core/theme/halo_tokens.dart';
|
||||
import '../../../core/theme/widgets/halo_bottom_sheet.dart';
|
||||
import '../../../core/theme/widgets/halo_button.dart';
|
||||
|
||||
/// Stage 7 — replaces the legacy goodbye-composer screen with a bottom sheet.
|
||||
/// The sheet is launched after the two-step confirm; it submits the goodbye
|
||||
/// message AND closes the session. Both CTAs end the session — the difference
|
||||
/// is whether a closing message is sent first.
|
||||
class ClosingMessageSheet {
|
||||
const ClosingMessageSheet._();
|
||||
|
||||
static Future<void> show(
|
||||
BuildContext context, {
|
||||
required String sessionId,
|
||||
required VoidCallback onCompleted,
|
||||
}) {
|
||||
return HaloBottomSheet.show<void>(
|
||||
context,
|
||||
isScrollControlled: true,
|
||||
child: _ClosingMessageBody(
|
||||
sessionId: sessionId,
|
||||
onCompleted: onCompleted,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ClosingMessageBody extends ConsumerStatefulWidget {
|
||||
final String sessionId;
|
||||
final VoidCallback onCompleted;
|
||||
|
||||
const _ClosingMessageBody({
|
||||
required this.sessionId,
|
||||
required this.onCompleted,
|
||||
});
|
||||
|
||||
@override
|
||||
ConsumerState<_ClosingMessageBody> createState() =>
|
||||
_ClosingMessageBodyState();
|
||||
}
|
||||
|
||||
class _ClosingMessageBodyState extends ConsumerState<_ClosingMessageBody> {
|
||||
final _controller = TextEditingController();
|
||||
bool _busy = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _sendAndEnd() async {
|
||||
final text = _controller.text.trim();
|
||||
if (text.isEmpty || _busy) return;
|
||||
setState(() => _busy = true);
|
||||
final notifier = ref.read(sessionClosureProvider.notifier);
|
||||
await notifier.submitGoodbye(widget.sessionId, text);
|
||||
await notifier.closeSession(widget.sessionId);
|
||||
if (!mounted) return;
|
||||
Navigator.of(context).pop();
|
||||
widget.onCompleted();
|
||||
}
|
||||
|
||||
Future<void> _skipAndEnd() async {
|
||||
if (_busy) return;
|
||||
setState(() => _busy = true);
|
||||
await ref.read(sessionClosureProvider.notifier).closeSession(widget.sessionId);
|
||||
if (!mounted) return;
|
||||
Navigator.of(context).pop();
|
||||
widget.onCompleted();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final viewInsets = MediaQuery.of(context).viewInsets.bottom;
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(bottom: viewInsets),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const Text(
|
||||
'pesan penutup',
|
||||
style: TextStyle(
|
||||
fontFamily: HaloTokens.fontDisplay,
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: HaloTokens.ink,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: HaloSpacing.s8),
|
||||
const Text(
|
||||
'tulis sesuatu buat bestie sebelum sesi ditutup',
|
||||
style: TextStyle(
|
||||
fontFamily: HaloTokens.fontBody,
|
||||
fontSize: 14,
|
||||
color: HaloTokens.inkSoft,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: HaloSpacing.s16),
|
||||
TextField(
|
||||
controller: _controller,
|
||||
maxLines: 4,
|
||||
minLines: 3,
|
||||
enabled: !_busy,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'makasih ya bestie...',
|
||||
filled: true,
|
||||
fillColor: HaloTokens.brandSofter,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: HaloRadius.lg,
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: HaloSpacing.s16),
|
||||
HaloButton(
|
||||
label: 'kirim & akhiri sesi',
|
||||
fullWidth: true,
|
||||
onPressed: _busy ? null : _sendAndEnd,
|
||||
),
|
||||
const SizedBox(height: HaloSpacing.s8),
|
||||
HaloButton(
|
||||
label: 'lewat — langsung akhiri',
|
||||
variant: HaloButtonVariant.ghost,
|
||||
fullWidth: true,
|
||||
onPressed: _busy ? null : _skipAndEnd,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
26
client_app/lib/features/chat/widgets/confirm_end_step1.dart
Normal file
26
client_app/lib/features/chat/widgets/confirm_end_step1.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../core/theme/widgets/halo_popup.dart';
|
||||
|
||||
/// Stage 7 — first of two confirm popups before ending the session. Surface
|
||||
/// the soft "balik" exit prominently because the most common path here is the
|
||||
/// user mis-tapping "akhiri sesi" while still wanting to continue.
|
||||
class ConfirmEndStep1 {
|
||||
const ConfirmEndStep1._();
|
||||
|
||||
static Future<void> show(
|
||||
BuildContext context, {
|
||||
required VoidCallback onConfirm,
|
||||
}) {
|
||||
return HaloPopup.show<void>(
|
||||
context,
|
||||
title: 'yakin mau akhiri sesi?',
|
||||
body: 'sesi akan ditutup dan kamu balik ke home',
|
||||
icon: const Text('🤔', style: TextStyle(fontSize: 40)),
|
||||
primary: HaloPopupAction(label: 'lanjut akhiri', onPressed: onConfirm),
|
||||
secondary: HaloPopupAction(
|
||||
label: 'gak jadi, balik',
|
||||
onPressed: () {},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
27
client_app/lib/features/chat/widgets/confirm_end_step2.dart
Normal file
27
client_app/lib/features/chat/widgets/confirm_end_step2.dart
Normal file
@@ -0,0 +1,27 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../core/theme/widgets/halo_popup.dart';
|
||||
|
||||
/// Stage 7 — second confirm popup. Customer has already chosen to end; this
|
||||
/// step nudges (not forces) them to leave a closing message, with `lewati saja`
|
||||
/// as the bypass into the close-session API directly.
|
||||
class ConfirmEndStep2 {
|
||||
const ConfirmEndStep2._();
|
||||
|
||||
static Future<void> show(
|
||||
BuildContext context, {
|
||||
required VoidCallback onWriteMessage,
|
||||
required VoidCallback onSkip,
|
||||
}) {
|
||||
return HaloPopup.show<void>(
|
||||
context,
|
||||
title: 'mau tinggalin pesan penutup?',
|
||||
body: 'kamu bisa tulis pesan terakhir buat bestie sebelum sesi ditutup',
|
||||
icon: const Text('💌', style: TextStyle(fontSize: 40)),
|
||||
primary: HaloPopupAction(
|
||||
label: 'tulis pesan penutup',
|
||||
onPressed: onWriteMessage,
|
||||
),
|
||||
secondary: HaloPopupAction(label: 'lewati saja', onPressed: onSkip),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user