- Upgrade Fastify 4→5 with all plugins (@fastify/websocket 11, cors 11, sensible 6) - Migrate all SSE endpoints to WebSocket + FCM push (mitra chat requests, customer pairing status) - Add flutter_local_notifications for foreground push notifications with sound - Add splash screen to both apps (hide auth loading flash) - Introduce constants/enums across entire codebase (no raw string literals) - Move price tiers from hardcoded array to app_config DB (data-driven, includes 1-min test tier) - Add session ownership validation on all shared chat routes - Add ownership checks on endSession, respondToExtension, requestExtension - Fix session timer: auto-complete expired/stale sessions on server restart - Add 5-min grace period for abandoned closing sessions - Fix extension flow: proper session_resumed handling, clearExtensionRequest, closure grace timer cleanup - Fix chat screens: ConnectChat in initState, session status check on connect - Fix customer expired view: 5-min countdown, closure state priority over expired state - Fix mitra extension UI: loading spinner, disable buttons, handle EXTENSION_RESOLVED error - Fix GoRouter navigation consistency (no more Navigator.pushNamed) - Fix goodbye view keyboard overflow (SingleChildScrollView) - Add active session card on customer home screen with refresh on navigate back - Fix PricingBottomSheet extension mode (RequestExtension instead of new pairing) - Send session_resumed to both parties on extension accept Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
166 lines
5.9 KiB
Dart
166 lines
5.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import '../../../core/api/api_client.dart';
|
|
import '../../../core/chat/chat_opening_bloc.dart';
|
|
import '../../../core/chat/session_closure_bloc.dart';
|
|
import '../../../core/pairing/pairing_bloc.dart';
|
|
|
|
class PricingBottomSheet extends StatelessWidget {
|
|
/// If set, the bottom sheet is in "extension" mode — selecting a tier extends the session.
|
|
final String? extensionSessionId;
|
|
|
|
const PricingBottomSheet({super.key, this.extensionSessionId});
|
|
|
|
/// Show for new pairing (from home screen)
|
|
static Future<void> show(BuildContext context) {
|
|
return showModalBottomSheet(
|
|
context: context,
|
|
isScrollControlled: true,
|
|
builder: (_) => BlocProvider(
|
|
create: (ctx) => ChatOpeningBloc(apiClient: ctx.read<ApiClient>())..add(LoadPricing()),
|
|
child: MultiBlocProvider(
|
|
providers: [
|
|
BlocProvider.value(value: context.read<PairingBloc>()),
|
|
],
|
|
child: const PricingBottomSheet(),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// Show for session extension (from chat screen)
|
|
static Future<void> showForExtension(BuildContext context, {required String sessionId}) {
|
|
return showModalBottomSheet(
|
|
context: context,
|
|
isScrollControlled: true,
|
|
builder: (_) => BlocProvider(
|
|
create: (ctx) => ChatOpeningBloc(apiClient: ctx.read<ApiClient>())..add(LoadPricing()),
|
|
child: MultiBlocProvider(
|
|
providers: [
|
|
BlocProvider.value(value: context.read<SessionClosureBloc>()),
|
|
],
|
|
child: PricingBottomSheet(extensionSessionId: sessionId),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
String _formatPrice(int price) {
|
|
final str = price.toString();
|
|
final buffer = StringBuffer();
|
|
for (var i = 0; i < str.length; i++) {
|
|
if (i > 0 && (str.length - i) % 3 == 0) buffer.write('.');
|
|
buffer.write(str[i]);
|
|
}
|
|
return 'Rp $buffer';
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final isExtension = extensionSessionId != null;
|
|
|
|
return BlocBuilder<ChatOpeningBloc, ChatOpeningState>(
|
|
builder: (context, state) {
|
|
if (state is PricingLoading || state is PricingInitial) {
|
|
return const SizedBox(
|
|
height: 200,
|
|
child: Center(child: CircularProgressIndicator()),
|
|
);
|
|
}
|
|
|
|
if (state is PricingError) {
|
|
return SizedBox(
|
|
height: 200,
|
|
child: Center(child: Text(state.message)),
|
|
);
|
|
}
|
|
|
|
if (state is PricingLoaded) {
|
|
return DraggableScrollableSheet(
|
|
initialChildSize: 0.6,
|
|
minChildSize: 0.4,
|
|
maxChildSize: 0.8,
|
|
expand: false,
|
|
builder: (_, scrollController) {
|
|
return Padding(
|
|
padding: const EdgeInsets.all(24),
|
|
child: ListView(
|
|
controller: scrollController,
|
|
children: [
|
|
Text(
|
|
isExtension ? 'Perpanjang Durasi' : 'Pilih Durasi Curhat',
|
|
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
const SizedBox(height: 16),
|
|
if (!isExtension && state.freeTrialEligible) ...[
|
|
Card(
|
|
color: Colors.green.shade50,
|
|
child: ListTile(
|
|
leading: const Icon(Icons.card_giftcard, color: Colors.green),
|
|
title: Text('Free Trial (${state.freeTrialDurationMinutes} Menit)'),
|
|
subtitle: const Text('Gratis untuk pertama kali!'),
|
|
trailing: const Icon(Icons.arrow_forward_ios, size: 16),
|
|
onTap: () {
|
|
Navigator.of(context).pop();
|
|
_startPairing(context, isFreeTrial: true);
|
|
},
|
|
),
|
|
),
|
|
const Divider(height: 24),
|
|
],
|
|
...state.tiers.map((tier) => Card(
|
|
child: ListTile(
|
|
title: Text(tier.label),
|
|
trailing: Text(
|
|
_formatPrice(tier.price),
|
|
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
|
|
),
|
|
onTap: () {
|
|
Navigator.of(context).pop();
|
|
if (isExtension) {
|
|
_requestExtension(
|
|
context,
|
|
sessionId: extensionSessionId!,
|
|
durationMinutes: tier.durationMinutes,
|
|
price: tier.price,
|
|
);
|
|
} else {
|
|
_startPairing(
|
|
context,
|
|
durationMinutes: tier.durationMinutes,
|
|
price: tier.price,
|
|
);
|
|
}
|
|
},
|
|
),
|
|
)),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
return const SizedBox.shrink();
|
|
},
|
|
);
|
|
}
|
|
|
|
void _startPairing(BuildContext context, {bool isFreeTrial = false, int? durationMinutes, int? price}) {
|
|
context.read<PairingBloc>().add(RequestPairingWithTier(
|
|
durationMinutes: durationMinutes,
|
|
price: price,
|
|
isFreeTrial: isFreeTrial,
|
|
));
|
|
}
|
|
|
|
void _requestExtension(BuildContext context, {required String sessionId, required int durationMinutes, required int price}) {
|
|
context.read<SessionClosureBloc>().add(RequestExtension(
|
|
sessionId: sessionId,
|
|
durationMinutes: durationMinutes,
|
|
price: price,
|
|
));
|
|
}
|
|
}
|