added password reset - resend invite link #10
@@ -102,6 +102,15 @@ class StaffCubit extends Cubit<StaffState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> 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<void> assignMemberToStore(String staffId, String storeId) async {
|
||||
try {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -60,6 +60,17 @@ class StaffRepository {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> 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
|
||||
|
||||
@@ -174,7 +174,46 @@ class _StaffScreenState extends State<StaffScreen> {
|
||||
),
|
||||
],
|
||||
),
|
||||
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<StaffCubit>().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<StaffCubit>().resetPasswordOrResendInviteLink(
|
||||
member.email!,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
|
||||
onTap: () =>
|
||||
canManageStaff ? _openStaffForm(context, member: member) : null,
|
||||
),
|
||||
@@ -395,6 +434,32 @@ class _StaffScreenState extends State<StaffScreen> {
|
||||
),
|
||||
),
|
||||
),
|
||||
/* 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<StaffCubit>()
|
||||
.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<StaffCubit>()
|
||||
.resetPasswordOrResendInviteLink(member.email!);
|
||||
},
|
||||
), */
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user