feat: implement user reporting in chat and dynamic environment-aware testimonial links
This commit is contained in:
@@ -2,8 +2,10 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:real_estate_mobile/config/app_config.dart';
|
||||
import 'package:real_estate_mobile/core/constants/app_colors.dart';
|
||||
import 'package:real_estate_mobile/features/profile/presentation/providers/profile_provider.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class TestimonialsTab extends ConsumerStatefulWidget {
|
||||
const TestimonialsTab({super.key});
|
||||
@@ -26,6 +28,22 @@ class _TestimonialsTabState extends ConsumerState<TestimonialsTab> {
|
||||
_loadTestimonials();
|
||||
}
|
||||
|
||||
/// Derive the web app URL from the current API base URL.
|
||||
/// api: https://beta.re-quest.com/api/v1 → web: https://beta.re-quest.com
|
||||
/// api: https://prod.api.re-quest.com/api/v1 → web: https://prod.re-quest.com
|
||||
String _getWebBaseUrl() {
|
||||
final apiUrl = AppConfig.apiBaseUrl; // e.g. https://beta.re-quest.com/api/v1
|
||||
try {
|
||||
final uri = Uri.parse(apiUrl);
|
||||
final host = uri.host; // e.g. beta.re-quest.com or prod.api.re-quest.com
|
||||
// Remove "api." prefix if present (prod uses subdomain-based API)
|
||||
final webHost = host.replaceFirst('api.', '');
|
||||
return '${uri.scheme}://$webHost';
|
||||
} catch (_) {
|
||||
return 'https://re-quest.com';
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadTestimonials() async {
|
||||
if (_isLoadingTestimonials) return;
|
||||
setState(() => _isLoadingTestimonials = true);
|
||||
@@ -46,8 +64,11 @@ class _TestimonialsTabState extends ConsumerState<TestimonialsTab> {
|
||||
try {
|
||||
final repo = ref.read(profileRepositoryProvider);
|
||||
final token = await repo.generateTestimonialLink();
|
||||
// Derive the web app URL from the API base URL so the link works
|
||||
// correctly across all environments (dev, beta, prod).
|
||||
final webBaseUrl = _getWebBaseUrl();
|
||||
setState(() {
|
||||
_testimonialLink = 'https://re-quest.co/testimonials/$token';
|
||||
_testimonialLink = '$webBaseUrl/testimonials/$token';
|
||||
_isGeneratingLink = false;
|
||||
});
|
||||
} catch (e) {
|
||||
@@ -139,16 +160,25 @@ class _TestimonialsTabState extends ConsumerState<TestimonialsTab> {
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
child: Text(
|
||||
_testimonialLink!,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Fractul',
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w300,
|
||||
color: Colors.black,
|
||||
child: GestureDetector(
|
||||
onTap: () async {
|
||||
final uri = Uri.parse(_testimonialLink!);
|
||||
if (await canLaunchUrl(uri)) {
|
||||
await launchUrl(uri, mode: LaunchMode.externalApplication);
|
||||
}
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
child: Text(
|
||||
_testimonialLink!,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Fractul',
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w300,
|
||||
color: AppColors.accentOrange,
|
||||
decoration: TextDecoration.underline,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user