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:
2026-05-10 17:33:01 +08:00
parent 14b5cc966b
commit d454fd39db
9 changed files with 480 additions and 42 deletions

View 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,
),
],
),
);
}
}