feat(admin): première connexion → panneau Paramètres, reste grisé jusqu'à Sauvegarder (#14)
- Au chargement admin: appel getSetupStatus(), si non terminé → onglet Paramètres par défaut - Onglet Gestion des utilisateurs grisé et inaccessible tant que setup non complété - Sauvegarder: updateBulk + completeSetup + déblocage des panneaux - Tester SMTP: saveBulkOnly puis test (sans completeSetup, panneaux restent verrouillés) Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
358eefdab3
commit
ca7ef862da
@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:p_tits_pas/services/configuration_service.dart';
|
||||
import 'package:p_tits_pas/widgets/admin/assistante_maternelle_management_widget.dart';
|
||||
import 'package:p_tits_pas/widgets/admin/gestionnaire_management_widget.dart';
|
||||
import 'package:p_tits_pas/widgets/admin/parent_managmant_widget.dart';
|
||||
@ -14,12 +15,34 @@ class AdminDashboardScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _AdminDashboardScreenState extends State<AdminDashboardScreen> {
|
||||
/// null = chargement du statut setup, true/false = connu
|
||||
bool? _setupCompleted;
|
||||
|
||||
/// 0 = Gestion des utilisateurs, 1 = Paramètres
|
||||
int mainTabIndex = 0;
|
||||
|
||||
/// Sous-onglet quand mainTabIndex == 0 : 0=Gestionnaires, 1=Parents, 2=AM, 3=Administrateurs
|
||||
int subIndex = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadSetupStatus();
|
||||
}
|
||||
|
||||
Future<void> _loadSetupStatus() async {
|
||||
try {
|
||||
final completed = await ConfigurationService.getSetupStatus();
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_setupCompleted = completed;
|
||||
if (!completed) mainTabIndex = 1;
|
||||
});
|
||||
} catch (_) {
|
||||
if (mounted) setState(() => _setupCompleted = true);
|
||||
}
|
||||
}
|
||||
|
||||
void onMainTabChange(int index) {
|
||||
setState(() {
|
||||
mainTabIndex = index;
|
||||
@ -34,6 +57,11 @@ class _AdminDashboardScreenState extends State<AdminDashboardScreen> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_setupCompleted == null) {
|
||||
return const Scaffold(
|
||||
body: Center(child: CircularProgressIndicator()),
|
||||
);
|
||||
}
|
||||
return Scaffold(
|
||||
appBar: PreferredSize(
|
||||
preferredSize: const Size.fromHeight(60.0),
|
||||
@ -46,6 +74,7 @@ class _AdminDashboardScreenState extends State<AdminDashboardScreen> {
|
||||
child: DashboardAppBarAdmin(
|
||||
selectedIndex: mainTabIndex,
|
||||
onTabChange: onMainTabChange,
|
||||
setupCompleted: _setupCompleted!,
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -67,7 +96,9 @@ class _AdminDashboardScreenState extends State<AdminDashboardScreen> {
|
||||
|
||||
Widget _getBody() {
|
||||
if (mainTabIndex == 1) {
|
||||
return const ParametresPanel();
|
||||
return ParametresPanel(
|
||||
onSetupCompleted: () => setState(() => _setupCompleted = true),
|
||||
);
|
||||
}
|
||||
switch (subIndex) {
|
||||
case 0:
|
||||
|
||||
@ -4,11 +4,14 @@ import 'package:flutter/material.dart';
|
||||
class DashboardAppBarAdmin extends StatelessWidget implements PreferredSizeWidget {
|
||||
final int selectedIndex;
|
||||
final ValueChanged<int> onTabChange;
|
||||
/// Si false, l'onglet "Gestion des utilisateurs" est grisé et inaccessible.
|
||||
final bool setupCompleted;
|
||||
|
||||
const DashboardAppBarAdmin({
|
||||
Key? key,
|
||||
required this.selectedIndex,
|
||||
required this.onTabChange,
|
||||
this.setupCompleted = true,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
@ -32,9 +35,9 @@ class DashboardAppBarAdmin extends StatelessWidget implements PreferredSizeWidge
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_buildNavItem(context, 'Gestion des utilisateurs', 0),
|
||||
_buildNavItem(context, 'Gestion des utilisateurs', 0, enabled: setupCompleted),
|
||||
const SizedBox(width: 24),
|
||||
_buildNavItem(context, 'Paramètres', 1),
|
||||
_buildNavItem(context, 'Paramètres', 1, enabled: true),
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -74,10 +77,12 @@ class DashboardAppBarAdmin extends StatelessWidget implements PreferredSizeWidge
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNavItem(BuildContext context, String title, int index) {
|
||||
Widget _buildNavItem(BuildContext context, String title, int index, {bool enabled = true}) {
|
||||
final bool isActive = index == selectedIndex;
|
||||
return InkWell(
|
||||
onTap: () => onTabChange(index),
|
||||
onTap: enabled ? () => onTabChange(index) : null,
|
||||
child: Opacity(
|
||||
opacity: enabled ? 1.0 : 0.5,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
@ -94,6 +99,7 @@ class DashboardAppBarAdmin extends StatelessWidget implements PreferredSizeWidge
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,10 @@ import 'package:p_tits_pas/services/configuration_service.dart';
|
||||
|
||||
/// Panneau Paramètres / Configuration (ticket #15) : 3 sections sur une page.
|
||||
class ParametresPanel extends StatefulWidget {
|
||||
const ParametresPanel({super.key});
|
||||
/// Appelé après une sauvegarde réussie (pour débloquer le reste du dashboard si config initiale).
|
||||
final VoidCallback? onSetupCompleted;
|
||||
|
||||
const ParametresPanel({super.key, this.onSetupCompleted});
|
||||
|
||||
@override
|
||||
State<ParametresPanel> createState() => _ParametresPanelState();
|
||||
@ -104,6 +107,12 @@ class _ParametresPanelState extends State<ParametresPanel> {
|
||||
return payload;
|
||||
}
|
||||
|
||||
/// Enregistre en base sans marquer la config initiale comme terminée (utilisé avant test SMTP).
|
||||
Future<void> _saveBulkOnly() async {
|
||||
await ConfigurationService.updateBulk(_buildPayload());
|
||||
}
|
||||
|
||||
/// Sauvegarde + marque la config initiale comme terminée + débloque les panneaux.
|
||||
Future<void> _save() async {
|
||||
setState(() {
|
||||
_message = null;
|
||||
@ -112,6 +121,9 @@ class _ParametresPanelState extends State<ParametresPanel> {
|
||||
try {
|
||||
await ConfigurationService.updateBulk(_buildPayload());
|
||||
if (!mounted) return;
|
||||
await ConfigurationService.completeSetup();
|
||||
if (!mounted) return;
|
||||
widget.onSetupCompleted?.call();
|
||||
setState(() {
|
||||
_isSaving = false;
|
||||
_message = 'Configuration enregistrée.';
|
||||
@ -160,7 +172,7 @@ class _ParametresPanelState extends State<ParametresPanel> {
|
||||
if (email == null || !mounted) return;
|
||||
setState(() => _message = null);
|
||||
try {
|
||||
await _save();
|
||||
await _saveBulkOnly();
|
||||
if (!mounted) return;
|
||||
final msg = await ConfigurationService.testSmtp(email);
|
||||
if (!mounted) return;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user