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:
@@ -6,6 +6,8 @@ import '../../core/availability/mitra_availability_notifier.dart';
|
||||
import '../../core/chat/active_session_notifier.dart';
|
||||
import '../../core/notifications/notif_permission.dart';
|
||||
import '../../core/theme/halo_tokens.dart';
|
||||
import 'providers/bestie_history_provider.dart';
|
||||
import 'widgets/bestie_choice_sheet.dart';
|
||||
|
||||
/// Session-only dismiss flag for the "notif denied" banner. Resets on cold
|
||||
/// restart by design — `StateProvider` lives in memory only.
|
||||
@@ -58,16 +60,27 @@ class _HomeScreenState extends ConsumerState<HomeScreen> with WidgetsBindingObse
|
||||
}
|
||||
}
|
||||
|
||||
void _onStartChatPressed(BuildContext context) {
|
||||
Future<void> _onStartChatPressed(BuildContext context) async {
|
||||
// Phase 4 Stage 2 removes the home-screen topic sensitivity prompt; the
|
||||
// ESP picks collected during onboarding feed the same column server-side
|
||||
// (info-only — no longer drives matching). Mitras still flip
|
||||
// `topic_sensitivity` mid-session via the AppBar toggle.
|
||||
//
|
||||
// Phase 4 Stage 3: enter the new multi-screen payment shell. The entry
|
||||
// route picks discount-paywall vs. method-pick based on first-session
|
||||
// eligibility. The legacy `/payment` route is preserved for the
|
||||
// chat-history "Curhat lagi" path until Stage 5 migrates it.
|
||||
// Phase 4 Stage 8: returning users get the bestie-choice sheet first; new
|
||||
// users skip straight to the multi-screen payment shell. We fetch the
|
||||
// history-has-items flag on-tap so a stale cache from logout/login doesn't
|
||||
// mis-route. On error (e.g. offline), fall back to the new-user path.
|
||||
bool hasHistory;
|
||||
try {
|
||||
hasHistory = await ref.read(bestieHistoryHasItemsProvider.future);
|
||||
} catch (_) {
|
||||
hasHistory = false;
|
||||
}
|
||||
if (!context.mounted) return;
|
||||
if (hasHistory) {
|
||||
await BestieChoiceSheet.show(context);
|
||||
return;
|
||||
}
|
||||
context.push('/payment/entry');
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../../core/api/api_client_provider.dart';
|
||||
|
||||
class BestieHistoryItem {
|
||||
final String sessionId;
|
||||
final String? mitraId;
|
||||
final String mitraName;
|
||||
final DateTime? endedAt;
|
||||
final List<String> topics;
|
||||
final int sessionsCount;
|
||||
final bool mitraIsOnline;
|
||||
|
||||
const BestieHistoryItem({
|
||||
required this.sessionId,
|
||||
required this.mitraId,
|
||||
required this.mitraName,
|
||||
required this.endedAt,
|
||||
required this.topics,
|
||||
required this.sessionsCount,
|
||||
required this.mitraIsOnline,
|
||||
});
|
||||
|
||||
factory BestieHistoryItem.fromJson(Map<String, dynamic> json) {
|
||||
final endedAtRaw = json['ended_at'];
|
||||
return BestieHistoryItem(
|
||||
sessionId: json['id'] as String,
|
||||
mitraId: json['mitra_id'] as String?,
|
||||
mitraName: json['mitra_display_name'] as String? ?? 'Bestie',
|
||||
endedAt: endedAtRaw is String ? DateTime.tryParse(endedAtRaw)?.toLocal() : null,
|
||||
topics: (json['topics'] as List?)?.cast<String>() ?? const [],
|
||||
sessionsCount: (json['sessions_count'] as num?)?.toInt() ?? 1,
|
||||
mitraIsOnline: json['mitra_is_online'] as bool? ?? false,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final bestieHistoryProvider = FutureProvider<List<BestieHistoryItem>>((ref) async {
|
||||
final api = ref.read(apiClientProvider);
|
||||
final response = await api.get('/api/client/chat/history');
|
||||
final items = (response['data']['items'] as List<dynamic>? ?? [])
|
||||
.cast<Map<String, dynamic>>();
|
||||
return items.map(BestieHistoryItem.fromJson).toList();
|
||||
});
|
||||
|
||||
/// Cheap derived provider used by the home CTA to decide whether to show the
|
||||
/// bestie-choice sheet or skip straight into the new-payment flow.
|
||||
final bestieHistoryHasItemsProvider = FutureProvider<bool>((ref) async {
|
||||
final items = await ref.watch(bestieHistoryProvider.future);
|
||||
return items.isNotEmpty;
|
||||
});
|
||||
141
client_app/lib/features/home/widgets/bestie_choice_sheet.dart
Normal file
141
client_app/lib/features/home/widgets/bestie_choice_sheet.dart
Normal file
@@ -0,0 +1,141 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../../core/theme/halo_tokens.dart';
|
||||
import '../../../core/theme/widgets/widgets.dart';
|
||||
|
||||
/// Phase 4 Stage 8 — Bestie Choice Sheet.
|
||||
///
|
||||
/// Triggered from the home `Mulai Curhat` CTA when the user has at least one
|
||||
/// prior session. Two cards: continue with a known bestie (→ history list)
|
||||
/// vs. find a new bestie (→ soft-prompt + blast).
|
||||
class BestieChoiceSheet extends StatelessWidget {
|
||||
const BestieChoiceSheet({super.key});
|
||||
|
||||
static Future<void> show(BuildContext context) {
|
||||
return HaloBottomSheet.show<void>(
|
||||
context,
|
||||
child: const BestieChoiceSheet(),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const Text(
|
||||
'mau curhat sama siapa?',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontFamily: HaloTokens.fontDisplay,
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: HaloTokens.ink,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: HaloSpacing.s8),
|
||||
const Text(
|
||||
'pilih lanjut sama bestie yang udah kenal, atau coba bestie baru.',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontFamily: HaloTokens.fontBody,
|
||||
fontSize: 14,
|
||||
color: HaloTokens.inkSoft,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: HaloSpacing.s24),
|
||||
_ChoiceCard(
|
||||
title: 'bestie yang udah kenal',
|
||||
subtitle: 'lanjut cerita ke bestie yang pernah dengerin kamu.',
|
||||
icon: Icons.favorite_outline,
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
context.push('/chat/history');
|
||||
},
|
||||
),
|
||||
const SizedBox(height: HaloSpacing.s12),
|
||||
_ChoiceCard(
|
||||
title: 'bestie baru',
|
||||
subtitle: 'cari bestie baru yang siap dengerin sekarang.',
|
||||
icon: Icons.auto_awesome_outlined,
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
context.push('/payment/entry');
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ChoiceCard extends StatelessWidget {
|
||||
final String title;
|
||||
final String subtitle;
|
||||
final IconData icon;
|
||||
final VoidCallback onTap;
|
||||
|
||||
const _ChoiceCard({
|
||||
required this.title,
|
||||
required this.subtitle,
|
||||
required this.icon,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
color: HaloTokens.brandSofter,
|
||||
borderRadius: HaloRadius.lg,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: HaloRadius.lg,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(HaloSpacing.s16),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
decoration: const BoxDecoration(
|
||||
color: HaloTokens.brandSoft,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Icon(icon, color: HaloTokens.brandDark, size: 24),
|
||||
),
|
||||
const SizedBox(width: HaloSpacing.s12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontFamily: HaloTokens.fontDisplay,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: HaloTokens.ink,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
subtitle,
|
||||
style: const TextStyle(
|
||||
fontFamily: HaloTokens.fontBody,
|
||||
fontSize: 13,
|
||||
height: 18 / 13,
|
||||
color: HaloTokens.inkSoft,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Icon(Icons.chevron_right, color: HaloTokens.brandDark),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user