Skip to content

Commit

Permalink
🐛 Mobile | Restore opening user profile on QR code scan (#1109)
Browse files Browse the repository at this point in the history
* Return correct staff ID

* Return correct UserID and add error handling

* Update message

* Update message
  • Loading branch information
zacharykeeping authored Oct 23, 2024
1 parent f10b6bf commit 3ba0421
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,28 @@ public async Task<ClaimAchievementResult> Handle(PostAchievementCommand request,
// check for milestone achievements
if (requestedAchievement.Type == AchievementType.Scanned)
{
// TODO: Re-enable when fixed
// var scannedUser = await _context.Users
// .FirstOrDefaultAsync(u => u.AchievementId == requestedAchievement.Id, cancellationToken);
//
// if (scannedUser == null)
// {
// var staffMember = await _context.StaffMembers
// .Include(s => s.StaffAchievement)
// .Where(s => s.StaffAchievement != null)
// .FirstOrDefaultAsync(s => s.StaffAchievement!.Id == requestedAchievement.Id, cancellationToken);
//
// achievementModel.UserId = staffMember?.Id;
// }
// else
// {
// achievementModel.UserId = scannedUser.Id;
// }
var scannedUser = await _context.Users
.FirstOrDefaultAsync(u => u.AchievementId == requestedAchievement.Id, cancellationToken);

if (scannedUser == null)
{
var staffMember = await _context.StaffMembers
.Include(s => s.StaffAchievement)
.Where(s => s.StaffAchievement != null)
.FirstOrDefaultAsync(s => s.StaffAchievement!.Id == requestedAchievement.Id, cancellationToken);

if (staffMember != null)
{
var staffUser = await _context.Users
.FirstOrDefaultAsync(u => u.Email == staffMember.Email, cancellationToken);

achievementModel.UserId = staffUser?.Id;
}
}
else
{
achievementModel.UserId = scannedUser.Id;
}

if (!userAchievements.Any(ua => ua.Achievement.Name == MilestoneAchievements.MeetSSW))
{
Expand Down
44 changes: 26 additions & 18 deletions src/MobileUI/Features/Profile/ProfileViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,26 +103,34 @@ protected async Task LoadProfileSections()
if (!_loadingProfileSectionsSemaphore.Wait(0))
return;

IsLoading = true;
var profileTask = _userService.GetUserAsync(UserId);
var socialMediaTask = LoadSocialMedia();
try
{
IsLoading = true;
var profileTask = _userService.GetUserAsync(UserId);
var socialMediaTask = LoadSocialMedia();

await Task.WhenAll(profileTask, socialMediaTask);

var profile = profileTask.Result;

ProfilePic = profile.ProfilePic ?? "v2sophie";
Name = profile.FullName;
Rank = profile.Rank;
Points = profile.Points;
Balance = profile.Balance;
IsStaff = profile.IsStaff;
UserEmail = profile.Email;
Title = GetTitle();
await Task.WhenAll(profileTask, socialMediaTask);

var profile = profileTask.Result;

ProfilePic = profile.ProfilePic ?? "v2sophie";
Name = profile.FullName;
Rank = profile.Rank;
Points = profile.Points;
Balance = profile.Balance;
IsStaff = profile.IsStaff;
UserEmail = profile.Email;
Title = GetTitle();

await UpdateSkillsSectionIfRequired();
UpdateLastSeenSection(profile.Achievements);
UpdateRecentActivitySection(profile.Achievements, profile.Rewards);
await UpdateSkillsSectionIfRequired();
UpdateLastSeenSection(profile.Achievements);
UpdateRecentActivitySection(profile.Achievements, profile.Rewards);
}
catch (Exception)
{
await ClosePage();
await App.Current.MainPage.DisplayAlert("Oops...", "There was an error loading this profile", "OK");
}

_loadingProfileSectionsSemaphore.Release();
IsLoading = false;
Expand Down

0 comments on commit 3ba0421

Please sign in to comment.