Implementert admin-funksjoner: Dashboard, Ansattliste, Avvikshåndtering og Profil-oppdatering

This commit is contained in:
steinhelge
2025-11-24 21:17:29 +01:00
parent feda00ac83
commit 237d56066b
7 changed files with 578 additions and 45 deletions
+76 -45
View File
@@ -1,74 +1,94 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../providers/auth_provider.dart';
import '../../models/user_model.dart';
import '../admin/admin_dashboard_screen.dart';
class ProfileScreen extends ConsumerWidget {
const ProfileScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final userData = ref.watch(userDataProvider);
final signOut = ref.read(signOutProvider);
final userDataAsync = ref.watch(userDataProvider);
final authService = ref.read(authServiceProvider);
return Scaffold(
appBar: AppBar(
title: const Text('Profil'),
actions: [
IconButton(
icon: const Icon(Icons.logout),
onPressed: () async {
await authService.signOut();
},
),
],
),
body: userData.when(
body: userDataAsync.when(
data: (user) {
if (user == null) {
return const Center(child: Text('Ingen brukerdata'));
}
if (user == null) return const Center(child: Text('Ingen brukerdata'));
final isAdmin = user.role == UserRole.admin || user.role == UserRole.systemAdmin;
return ListView(
padding: const EdgeInsets.all(16.0),
children: [
Card(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
CircleAvatar(
radius: 40,
child: Text(
user.displayName.isNotEmpty
? user.displayName[0].toUpperCase()
: '?',
style: const TextStyle(fontSize: 32),
),
),
const SizedBox(height: 16),
Text(
user.displayName,
style: Theme.of(context).textTheme.titleLarge,
),
Text(
user.email,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Colors.grey,
),
),
const SizedBox(height: 8),
Chip(
label: Text(
user.role.name == 'employee'
? 'Ansatt'
: user.role.name == 'admin'
? 'Administrator'
: 'Systemadministrator',
),
),
],
),
),
const CircleAvatar(
radius: 50,
child: Icon(Icons.person, size: 50),
),
const SizedBox(height: 16),
Text(
user.displayName,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.headlineSmall,
),
Text(
user.email,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Colors.grey,
),
),
const SizedBox(height: 32),
if (isAdmin) ...[
Card(
color: Theme.of(context).colorScheme.primaryContainer,
child: ListTile(
leading: const Icon(Icons.admin_panel_settings),
title: const Text('Admin Dashboard'),
subtitle: const Text('Administrer ansatte og avvik'),
trailing: const Icon(Icons.chevron_right),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const AdminDashboardScreen(),
),
);
},
),
),
const SizedBox(height: 16),
],
const Divider(),
ListTile(
leading: const Icon(Icons.business),
title: const Text('Organisasjon'),
subtitle: Text(user.organizationId),
),
ListTile(
leading: const Icon(Icons.badge),
title: const Text('Rolle'),
subtitle: Text(_getRoleDisplayName(user.role)),
),
ListTile(
leading: const Icon(Icons.rule),
title: const Text('Tariffprofil'),
subtitle: Text(user.tariffProfileId),
),
const Divider(),
@@ -76,7 +96,7 @@ class ProfileScreen extends ConsumerWidget {
leading: const Icon(Icons.logout),
title: const Text('Logg ut'),
onTap: () async {
await signOut();
await authService.signOut();
},
),
],
@@ -87,4 +107,15 @@ class ProfileScreen extends ConsumerWidget {
),
);
}
String _getRoleDisplayName(UserRole role) {
switch (role) {
case UserRole.employee:
return 'Ansatt';
case UserRole.admin:
return 'Admin';
case UserRole.systemAdmin:
return 'System Admin';
}
}
}