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: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/assistante_maternelle_management_widget.dart';
|
||||||
import 'package:p_tits_pas/widgets/admin/gestionnaire_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';
|
import 'package:p_tits_pas/widgets/admin/parent_managmant_widget.dart';
|
||||||
@ -14,12 +15,34 @@ class AdminDashboardScreen extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _AdminDashboardScreenState extends State<AdminDashboardScreen> {
|
class _AdminDashboardScreenState extends State<AdminDashboardScreen> {
|
||||||
|
/// null = chargement du statut setup, true/false = connu
|
||||||
|
bool? _setupCompleted;
|
||||||
|
|
||||||
/// 0 = Gestion des utilisateurs, 1 = Paramètres
|
/// 0 = Gestion des utilisateurs, 1 = Paramètres
|
||||||
int mainTabIndex = 0;
|
int mainTabIndex = 0;
|
||||||
|
|
||||||
/// Sous-onglet quand mainTabIndex == 0 : 0=Gestionnaires, 1=Parents, 2=AM, 3=Administrateurs
|
/// Sous-onglet quand mainTabIndex == 0 : 0=Gestionnaires, 1=Parents, 2=AM, 3=Administrateurs
|
||||||
int subIndex = 0;
|
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) {
|
void onMainTabChange(int index) {
|
||||||
setState(() {
|
setState(() {
|
||||||
mainTabIndex = index;
|
mainTabIndex = index;
|
||||||
@ -34,6 +57,11 @@ class _AdminDashboardScreenState extends State<AdminDashboardScreen> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
if (_setupCompleted == null) {
|
||||||
|
return const Scaffold(
|
||||||
|
body: Center(child: CircularProgressIndicator()),
|
||||||
|
);
|
||||||
|
}
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: PreferredSize(
|
appBar: PreferredSize(
|
||||||
preferredSize: const Size.fromHeight(60.0),
|
preferredSize: const Size.fromHeight(60.0),
|
||||||
@ -46,6 +74,7 @@ class _AdminDashboardScreenState extends State<AdminDashboardScreen> {
|
|||||||
child: DashboardAppBarAdmin(
|
child: DashboardAppBarAdmin(
|
||||||
selectedIndex: mainTabIndex,
|
selectedIndex: mainTabIndex,
|
||||||
onTabChange: onMainTabChange,
|
onTabChange: onMainTabChange,
|
||||||
|
setupCompleted: _setupCompleted!,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -67,7 +96,9 @@ class _AdminDashboardScreenState extends State<AdminDashboardScreen> {
|
|||||||
|
|
||||||
Widget _getBody() {
|
Widget _getBody() {
|
||||||
if (mainTabIndex == 1) {
|
if (mainTabIndex == 1) {
|
||||||
return const ParametresPanel();
|
return ParametresPanel(
|
||||||
|
onSetupCompleted: () => setState(() => _setupCompleted = true),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
switch (subIndex) {
|
switch (subIndex) {
|
||||||
case 0:
|
case 0:
|
||||||
|
|||||||
@ -4,11 +4,14 @@ import 'package:flutter/material.dart';
|
|||||||
class DashboardAppBarAdmin extends StatelessWidget implements PreferredSizeWidget {
|
class DashboardAppBarAdmin extends StatelessWidget implements PreferredSizeWidget {
|
||||||
final int selectedIndex;
|
final int selectedIndex;
|
||||||
final ValueChanged<int> onTabChange;
|
final ValueChanged<int> onTabChange;
|
||||||
|
/// Si false, l'onglet "Gestion des utilisateurs" est grisé et inaccessible.
|
||||||
|
final bool setupCompleted;
|
||||||
|
|
||||||
const DashboardAppBarAdmin({
|
const DashboardAppBarAdmin({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.selectedIndex,
|
required this.selectedIndex,
|
||||||
required this.onTabChange,
|
required this.onTabChange,
|
||||||
|
this.setupCompleted = true,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -32,9 +35,9 @@ class DashboardAppBarAdmin extends StatelessWidget implements PreferredSizeWidge
|
|||||||
child: Row(
|
child: Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
_buildNavItem(context, 'Gestion des utilisateurs', 0),
|
_buildNavItem(context, 'Gestion des utilisateurs', 0, enabled: setupCompleted),
|
||||||
const SizedBox(width: 24),
|
const SizedBox(width: 24),
|
||||||
_buildNavItem(context, 'Paramètres', 1),
|
_buildNavItem(context, 'Paramètres', 1, enabled: true),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -74,23 +77,26 @@ 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;
|
final bool isActive = index == selectedIndex;
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: () => onTabChange(index),
|
onTap: enabled ? () => onTabChange(index) : null,
|
||||||
child: Container(
|
child: Opacity(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
opacity: enabled ? 1.0 : 0.5,
|
||||||
decoration: BoxDecoration(
|
child: Container(
|
||||||
color: isActive ? const Color(0xFF9CC5C0) : Colors.transparent,
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||||
borderRadius: BorderRadius.circular(20),
|
decoration: BoxDecoration(
|
||||||
border: isActive ? null : Border.all(color: Colors.black26),
|
color: isActive ? const Color(0xFF9CC5C0) : Colors.transparent,
|
||||||
),
|
borderRadius: BorderRadius.circular(20),
|
||||||
child: Text(
|
border: isActive ? null : Border.all(color: Colors.black26),
|
||||||
title,
|
),
|
||||||
style: TextStyle(
|
child: Text(
|
||||||
color: isActive ? Colors.white : Colors.black,
|
title,
|
||||||
fontWeight: isActive ? FontWeight.w600 : FontWeight.normal,
|
style: TextStyle(
|
||||||
fontSize: 14,
|
color: isActive ? Colors.white : Colors.black,
|
||||||
|
fontWeight: isActive ? FontWeight.w600 : FontWeight.normal,
|
||||||
|
fontSize: 14,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -3,7 +3,10 @@ import 'package:p_tits_pas/services/configuration_service.dart';
|
|||||||
|
|
||||||
/// Panneau Paramètres / Configuration (ticket #15) : 3 sections sur une page.
|
/// Panneau Paramètres / Configuration (ticket #15) : 3 sections sur une page.
|
||||||
class ParametresPanel extends StatefulWidget {
|
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
|
@override
|
||||||
State<ParametresPanel> createState() => _ParametresPanelState();
|
State<ParametresPanel> createState() => _ParametresPanelState();
|
||||||
@ -104,6 +107,12 @@ class _ParametresPanelState extends State<ParametresPanel> {
|
|||||||
return payload;
|
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 {
|
Future<void> _save() async {
|
||||||
setState(() {
|
setState(() {
|
||||||
_message = null;
|
_message = null;
|
||||||
@ -112,6 +121,9 @@ class _ParametresPanelState extends State<ParametresPanel> {
|
|||||||
try {
|
try {
|
||||||
await ConfigurationService.updateBulk(_buildPayload());
|
await ConfigurationService.updateBulk(_buildPayload());
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
|
await ConfigurationService.completeSetup();
|
||||||
|
if (!mounted) return;
|
||||||
|
widget.onSetupCompleted?.call();
|
||||||
setState(() {
|
setState(() {
|
||||||
_isSaving = false;
|
_isSaving = false;
|
||||||
_message = 'Configuration enregistrée.';
|
_message = 'Configuration enregistrée.';
|
||||||
@ -160,7 +172,7 @@ class _ParametresPanelState extends State<ParametresPanel> {
|
|||||||
if (email == null || !mounted) return;
|
if (email == null || !mounted) return;
|
||||||
setState(() => _message = null);
|
setState(() => _message = null);
|
||||||
try {
|
try {
|
||||||
await _save();
|
await _saveBulkOnly();
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
final msg = await ConfigurationService.testSmtp(email);
|
final msg = await ConfigurationService.testSmtp(email);
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user