diff --git a/lib/features/master_data/staff/blocs/staff_cubit.dart b/lib/features/master_data/staff/blocs/staff_cubit.dart index 548addb..8cd77f5 100644 --- a/lib/features/master_data/staff/blocs/staff_cubit.dart +++ b/lib/features/master_data/staff/blocs/staff_cubit.dart @@ -102,6 +102,15 @@ class StaffCubit extends Cubit { } } + Future resetPasswordOrResendInviteLink(String email) async { + try { + await _repository.resetPasswordOrResendInviteLink(email); + emit(state.copyWith(status: StaffStatus.emailSent, error: null)); + } catch (e) { + emit(state.copyWith(status: StaffStatus.error, error: e.toString())); + } + } + // Associa un dipendente a un negozio Future assignMemberToStore(String staffId, String storeId) async { try { diff --git a/lib/features/master_data/staff/blocs/staff_state.dart b/lib/features/master_data/staff/blocs/staff_state.dart index 5ef9055..2a3b7d4 100644 --- a/lib/features/master_data/staff/blocs/staff_state.dart +++ b/lib/features/master_data/staff/blocs/staff_state.dart @@ -1,6 +1,6 @@ part of 'staff_cubit.dart'; -enum StaffStatus { initial, loading, success, error } +enum StaffStatus { initial, loading, success, emailSent, error } class StaffState extends Equatable { final StaffStatus status; diff --git a/lib/features/master_data/staff/data/staff_repository.dart b/lib/features/master_data/staff/data/staff_repository.dart index ec35c7c..c6a3553 100644 --- a/lib/features/master_data/staff/data/staff_repository.dart +++ b/lib/features/master_data/staff/data/staff_repository.dart @@ -60,6 +60,17 @@ class StaffRepository { } } + Future resetPasswordOrResendInviteLink(String email) async { + try { + await _supabase.auth.resetPasswordForEmail( + email, + redirectTo: 'https://flux-web-invite.marco-6ba.workers.dev/', + ); + } catch (e) { + throw Exception("Errore nell'invio del link: $e"); + } + } + // --- LOGICA DI GIUNZIONE (Staff <-> Store) --- // Recupera i membri assegnati a uno specifico negozio diff --git a/lib/features/master_data/staff/ui/staff_screen.dart b/lib/features/master_data/staff/ui/staff_screen.dart index 5d1c774..1213672 100644 --- a/lib/features/master_data/staff/ui/staff_screen.dart +++ b/lib/features/master_data/staff/ui/staff_screen.dart @@ -174,7 +174,46 @@ class _StaffScreenState extends State { ), ], ), - trailing: canManageStaff ? const Icon(Icons.edit_note) : null, + trailing: Row( + mainAxisSize: MainAxisSize.min, + children: [ + if (member.jobTitle != null && member.jobTitle!.isNotEmpty) ...[ + Text('Qualifica: ${member.jobTitle!}'), + const SizedBox(width: 8), + ], + + if (canManageStaff) ...[ + const SizedBox(width: 8), + + if (!member.hasJoined) + ElevatedButton.icon( + icon: const Icon(Icons.send), + label: const Text("Re-invia Invito (In Attesa)"), + style: ElevatedButton.styleFrom( + backgroundColor: Colors.orange, + ), + onPressed: () { + // Chiama la funzione di reset password mascherata da invito + context.read().resetPasswordOrResendInviteLink( + member.email!, + ); + }, + ) + else + OutlinedButton.icon( + icon: const Icon(Icons.lock_reset), + label: const Text("Invia Reset Password"), + onPressed: () { + // Chiama LA STESSA IDENTICA FUNZIONE! + context.read().resetPasswordOrResendInviteLink( + member.email!, + ); + }, + ), + ], + ], + ), + onTap: () => canManageStaff ? _openStaffForm(context, member: member) : null, ), @@ -395,6 +434,32 @@ class _StaffScreenState extends State { ), ), ), + /* const SizedBox(height: 16), + if (!member!.hasJoined) + ElevatedButton.icon( + icon: const Icon(Icons.send), + label: const Text("Re-invia Invito (In Attesa)"), + style: ElevatedButton.styleFrom( + backgroundColor: Colors.orange, + ), + onPressed: () { + // Chiama la funzione di reset password mascherata da invito + context + .read() + .resetPasswordOrResendInviteLink(member.email!); + }, + ) + else + OutlinedButton.icon( + icon: const Icon(Icons.lock_reset), + label: const Text("Invia Reset Password"), + onPressed: () { + // Chiama LA STESSA IDENTICA FUNZIONE! + context + .read() + .resetPasswordOrResendInviteLink(member.email!); + }, + ), */ ], ), ),