Phase 4 Stage 8: returning-user shell + Tanya Admin sheet
Bestie Choice Sheet on home Mulai Curhat CTA. When the user has at least one prior session (bestieHistoryHasItemsProvider hits the chat- sessions history endpoint), the CTA opens a HaloBottomSheet with two cards: 'bestie yang udah kenal' -> /chat/history, 'bestie baru' -> /payment/entry. Empty history -> direct to /payment/entry. Bestie history list visual upgrade: HaloOrb (mitraId seed) + name + last-session date + topic pills + sessions count + ONLINE pill. Backend getCustomerHistory now returns topics, mitra_is_online, sessions_count in a single payload (no per-row presence round-trip). BestieOfflinePopup with two variants (returning | new_) replacing the legacy BestieUnavailableDialog. tanya admin ghost CTA on both variants opens the new TanyaAdminSheet. Stage 5's targeted-wait declined stub + Stage 7's chat-screen 409 stub + searching-screen call site all migrated to the real component. TanyaAdminSheet: HaloBottomSheet with WA + Telegram buttons, deeplinks fetched via supportHandlesProvider (CC-config-driven). url_launcher added to client_app; ios LSApplicationQueriesSchemes covers https/http/whatsapp/tg. Stage 2's OTP-blocked popup hubungi admin SnackBar stub also migrated to TanyaAdminSheet. Dev-only POST /internal/_test/seed-history-session lets Maestro 08 flow seed a history row before exercising the choice sheet. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -4,50 +4,56 @@ import 'package:go_router/go_router.dart';
|
||||
import '../../../core/availability/mitra_availability_notifier.dart';
|
||||
import '../../../core/constants.dart';
|
||||
import '../../../core/pairing/pairing_notifier.dart';
|
||||
import '../../../core/theme/halo_tokens.dart';
|
||||
import '../../../core/theme/widgets/widgets.dart';
|
||||
import '../../support/widgets/tanya_admin_sheet.dart';
|
||||
|
||||
/// Shown when a "Curhat lagi" attempt against a specific bestie can't proceed
|
||||
/// — either a 409 `targeted_mitra_offline` response on the targeted POST, or
|
||||
/// one of the intermediate WS events (`returning_chat_timeout`,
|
||||
/// `returning_chat_rejected`).
|
||||
/// Phase 4 Stage 8 — `BestieOfflinePopup`.
|
||||
///
|
||||
/// CTAs:
|
||||
/// - "Chat dengan bestie lain" — only rendered when
|
||||
/// [mitraAvailabilityProvider] reports `available == true` at the time of
|
||||
/// build. Tapping calls [Pairing.fallbackToBlast] (reuses the same payment
|
||||
/// session — no double-charge) and closes the dialog. The caller is expected
|
||||
/// to be the searching screen, which will transition into PairingSearchingData
|
||||
/// and stay put.
|
||||
/// - "Kembali" — pops dialog and routes home. Backend has already audit-logged
|
||||
/// the targeted failure; payment session stays `confirmed` until the sweeper
|
||||
/// expires it.
|
||||
class BestieUnavailableDialog extends ConsumerWidget {
|
||||
final String paymentSessionId;
|
||||
final String mitraName;
|
||||
final TopicSensitivity topicSensitivity;
|
||||
/// Two variants:
|
||||
/// - [BestieOfflineVariant.returning] — the customer tried to chat with a
|
||||
/// specific mitra (history "Curhat lagi"); the targeted attempt failed
|
||||
/// (409 `targeted_mitra_offline`, or WS `returning_chat_timeout` /
|
||||
/// `returning_chat_rejected`). Payment session is still `confirmed`, so we
|
||||
/// surface a `Chat dengan bestie lain` primary CTA when other besties are
|
||||
/// reachable (calls [Pairing.fallbackToBlast]).
|
||||
/// - [BestieOfflineVariant.new_] — the customer triggered a general blast
|
||||
/// that bottomed out (no online besties). No fallback button; just a
|
||||
/// ghost `tanya admin` and a `kembali ke home` exit.
|
||||
///
|
||||
/// Both variants expose `tanya admin` via a ghost CTA that opens the
|
||||
/// [TanyaAdminSheet].
|
||||
enum BestieOfflineVariant { returning, new_ }
|
||||
|
||||
const BestieUnavailableDialog({
|
||||
class BestieOfflinePopup extends ConsumerWidget {
|
||||
final BestieOfflineVariant variant;
|
||||
final String mitraName;
|
||||
final String? paymentSessionId;
|
||||
final TopicSensitivity? topicSensitivity;
|
||||
|
||||
const BestieOfflinePopup({
|
||||
super.key,
|
||||
required this.paymentSessionId,
|
||||
required this.variant,
|
||||
required this.mitraName,
|
||||
required this.topicSensitivity,
|
||||
this.paymentSessionId,
|
||||
this.topicSensitivity,
|
||||
});
|
||||
|
||||
/// Convenience: show this dialog and return when it closes. Per project
|
||||
/// memory ("Riverpod ref.listen in build is unsafe"), callers should
|
||||
/// invoke this from `ref.listenManual` callbacks in `initState`, not from
|
||||
/// `build`.
|
||||
static Future<void> show(
|
||||
BuildContext context, {
|
||||
required String paymentSessionId,
|
||||
required BestieOfflineVariant variant,
|
||||
required String mitraName,
|
||||
required TopicSensitivity topicSensitivity,
|
||||
String? paymentSessionId,
|
||||
TopicSensitivity? topicSensitivity,
|
||||
}) {
|
||||
return showDialog<void>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (_) => BestieUnavailableDialog(
|
||||
paymentSessionId: paymentSessionId,
|
||||
barrierColor: const Color(0x66000000),
|
||||
builder: (_) => BestieOfflinePopup(
|
||||
variant: variant,
|
||||
mitraName: mitraName,
|
||||
paymentSessionId: paymentSessionId,
|
||||
topicSensitivity: topicSensitivity,
|
||||
),
|
||||
);
|
||||
@@ -55,44 +61,122 @@ class BestieUnavailableDialog extends ConsumerWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
// Snapshot at dialog-open time — we don't keep listening, we just check
|
||||
// whether other bestie are around right now.
|
||||
final availabilityAsync = ref.watch(mitraAvailabilityProvider);
|
||||
final hasOtherAvailable = availabilityAsync.valueOrNull ?? false;
|
||||
|
||||
return AlertDialog(
|
||||
title: const Text('Bestie sedang tidak online'),
|
||||
content: Text(
|
||||
'$mitraName sedang tidak bisa menerima chat saat ini. '
|
||||
'Kamu bisa coba chat dengan bestie lain atau kembali ke beranda.',
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
// Reset pairing state and route home. Payment session stays
|
||||
// confirmed until sweeper expires it — no extra API call needed.
|
||||
ref.read(pairingProvider.notifier).reset();
|
||||
Navigator.of(context).pop();
|
||||
context.go('/home');
|
||||
},
|
||||
child: const Text('Kembali'),
|
||||
final isReturning = variant == BestieOfflineVariant.returning;
|
||||
final title = isReturning ? '$mitraName lagi nggak online' : 'semua bestie lagi istirahat';
|
||||
final body = isReturning
|
||||
? 'bestie kamu belum bisa nerima chat sekarang. coba bestie lain atau balik ke beranda dulu ya.'
|
||||
: 'lagi nggak ada bestie yang siap dengerin. coba lagi bentar, atau hubungin admin biar dibantu.';
|
||||
|
||||
final canFallbackToBlast = isReturning &&
|
||||
hasOtherAvailable &&
|
||||
paymentSessionId != null &&
|
||||
topicSensitivity != null;
|
||||
|
||||
return Dialog(
|
||||
backgroundColor: HaloTokens.surface,
|
||||
elevation: 0,
|
||||
shape: const RoundedRectangleBorder(borderRadius: HaloRadius.xl),
|
||||
insetPadding: const EdgeInsets.symmetric(horizontal: HaloSpacing.s24),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(HaloSpacing.s24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Center(
|
||||
child: Container(
|
||||
width: 64,
|
||||
height: 64,
|
||||
decoration: const BoxDecoration(
|
||||
color: HaloTokens.brandSofter,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: const Icon(
|
||||
Icons.cloud_off_outlined,
|
||||
color: HaloTokens.brandDark,
|
||||
size: 28,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: HaloSpacing.s16),
|
||||
Text(
|
||||
title,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
fontFamily: HaloTokens.fontDisplay,
|
||||
fontSize: 22,
|
||||
height: 28 / 22,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: HaloTokens.ink,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: HaloSpacing.s12),
|
||||
Text(
|
||||
body,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
fontFamily: HaloTokens.fontBody,
|
||||
fontSize: 15,
|
||||
height: 22 / 15,
|
||||
color: HaloTokens.inkSoft,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: HaloSpacing.s24),
|
||||
if (canFallbackToBlast)
|
||||
HaloButton(
|
||||
label: 'chat dengan bestie lain',
|
||||
fullWidth: true,
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
// ignore: discarded_futures
|
||||
ref.read(pairingProvider.notifier).fallbackToBlast(
|
||||
paymentSessionId: paymentSessionId!,
|
||||
topicSensitivity: topicSensitivity!,
|
||||
);
|
||||
},
|
||||
)
|
||||
else
|
||||
HaloButton(
|
||||
label: 'kembali ke home',
|
||||
fullWidth: true,
|
||||
onPressed: () {
|
||||
ref.read(pairingProvider.notifier).reset();
|
||||
Navigator.of(context).pop();
|
||||
context.go('/home');
|
||||
},
|
||||
),
|
||||
const SizedBox(height: HaloSpacing.s8),
|
||||
HaloButton(
|
||||
label: 'tanya admin',
|
||||
variant: HaloButtonVariant.ghost,
|
||||
fullWidth: true,
|
||||
onPressed: () {
|
||||
// Keep the popup open underneath; the sheet sits on top and
|
||||
// closes back to it.
|
||||
// ignore: discarded_futures
|
||||
TanyaAdminSheet.show(context);
|
||||
},
|
||||
),
|
||||
if (canFallbackToBlast) ...[
|
||||
const SizedBox(height: HaloSpacing.s4),
|
||||
HaloButton(
|
||||
label: 'kembali ke home',
|
||||
variant: HaloButtonVariant.ghost,
|
||||
fullWidth: true,
|
||||
onPressed: () {
|
||||
ref.read(pairingProvider.notifier).reset();
|
||||
Navigator.of(context).pop();
|
||||
context.go('/home');
|
||||
},
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
if (hasOtherAvailable)
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
// Close the dialog first, then kick off the fallback. The
|
||||
// searching screen will pick up the new PairingSearchingData
|
||||
// state and render normally (no targeted overlay).
|
||||
Navigator.of(context).pop();
|
||||
// ignore: discarded_futures
|
||||
ref.read(pairingProvider.notifier).fallbackToBlast(
|
||||
paymentSessionId: paymentSessionId,
|
||||
topicSensitivity: topicSensitivity,
|
||||
);
|
||||
},
|
||||
child: const Text('Chat dengan bestie lain'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user