store current user id

This commit is contained in:
2025-11-03 20:59:51 +07:00
parent 2a6ec8f6b8
commit 9df4b79a66
6 changed files with 123 additions and 10 deletions

View File

@@ -88,14 +88,14 @@ class _ProductDetailPageState extends ConsumerState<ProductDetailPage> {
super.dispose();
}
/// Auto-select warehouse user based on stored email from login
/// Auto-select warehouse user based on stored user ID from login
Future<void> _autoSelectWarehouseUser() async {
try {
// Get stored email from secure storage
// Get stored current user ID from secure storage
final secureStorage = SecureStorage();
final storedEmail = await secureStorage.getEmail();
if (storedEmail == null || storedEmail.isEmpty) {
final currentUserId = await secureStorage.getCurrentUserId();
print('user $currentUserId');
if (currentUserId == null) {
return;
}
@@ -104,9 +104,9 @@ class _ProductDetailPageState extends ConsumerState<ProductDetailPage> {
.where((user) => user.isWareHouseUser)
.toList();
// Find user with matching email
// Find user with matching ID
final matchingUsers = warehouseUsers
.where((user) => user.email.toLowerCase() == storedEmail.toLowerCase())
.where((user) => user.id == currentUserId)
.toList();
final matchingUser = matchingUsers.isNotEmpty ? matchingUsers.first : null;
@@ -656,7 +656,9 @@ class _ProductDetailPageState extends ConsumerState<ProductDetailPage> {
_buildUserDropdown(
label: 'Nhân viên *',
value: _selectedEmployee,
users: ref.watch(usersListProvider),
users: ref.watch(usersListProvider)
.where((user) => user.roleId == 2)
.toList(),
onChanged: (user) {
setState(() {
_selectedEmployee = user;