diff --git a/lib/ui/views/support_view.dart b/lib/ui/views/support_view.dart index f583f35..4d8c59c 100644 --- a/lib/ui/views/support_view.dart +++ b/lib/ui/views/support_view.dart @@ -1,5 +1,6 @@ import 'package:prosapp_web_app/models/setting.dart'; import 'package:prosapp_web_app/providers/settings_provider.dart'; +import 'package:prosapp_web_app/services/api_service.dart'; import 'package:prosapp_web_app/ui/cards/white_card.dart'; import 'package:flutter/material.dart'; import 'package:prosapp_web_app/ui/labels/custom_labels.dart'; @@ -34,9 +35,81 @@ class SupportView extends StatelessWidget { await _launchURL(url); } - Future _goSugerencias() async { - const url = 'https://admin.prosapp.co/sugerencias'; - await _launchURL(url); + Future _goSugerencias(BuildContext context) async { + final controller = TextEditingController(); + final api = ApiService.instance; + bool sending = false; + + await showDialog( + context: context, + builder: (ctx) => StatefulBuilder( + builder: (ctx, setState) => AlertDialog( + title: const Text('Enviar sugerencia'), + content: Column( + mainAxisSize: MainAxisSize.min, + children: [ + const Text( + 'Cuéntanos cómo podemos mejorar ProsApp', + style: TextStyle(fontSize: 14), + ), + const SizedBox(height: 16), + TextField( + controller: controller, + maxLines: 4, + decoration: const InputDecoration( + hintText: 'Escribe tu sugerencia aquí...', + border: OutlineInputBorder(), + ), + ), + ], + ), + actions: [ + TextButton( + onPressed: sending ? null : () => Navigator.pop(ctx), + child: const Text('Cancelar'), + ), + FilledButton( + onPressed: sending + ? null + : () async { + final msg = controller.text.trim(); + if (msg.isEmpty) return; + setState(() => sending = true); + try { + await api.post('/suggestions', {'message': msg}); + if (ctx.mounted) { + Navigator.pop(ctx); + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text('¡Gracias por tu sugerencia!'), + backgroundColor: Colors.green, + ), + ); + } + } catch (_) { + setState(() => sending = false); + if (ctx.mounted) { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text('Error al enviar. Intenta de nuevo.'), + backgroundColor: Colors.red, + ), + ); + } + } + }, + child: sending + ? const SizedBox( + width: 16, + height: 16, + child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white), + ) + : const Text('Enviar'), + ), + ], + ), + ), + ); } Future _goPoliticas(String urlText) async { @@ -137,7 +210,7 @@ class SupportView extends StatelessWidget { context, icon: Icons.feedback, text: 'Sugerencias', - onPressed: _goSugerencias, + onPressed: () => _goSugerencias(context), ), _buildGridButton( context,