This commit is contained in:
MeysamMoghaddam
2025-10-12 23:21:30 +03:30
parent f69cdf4a05
commit 6585c8014a
2 changed files with 202 additions and 114 deletions

View File

@@ -1,9 +1,8 @@
using FluentValidation;
using FrontOffice.BFF.Package.Protobuf.Protos.Package;
using FrontOffice.BFF.User.Protobuf.Protos.User;
using FrontOffice.Main.Utilities;
using Mapster;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using MudBlazor;
using System.ComponentModel.DataAnnotations;
using Severity = MudBlazor.Severity;
@@ -22,6 +21,8 @@ public partial class Index
private bool _isPersonalSaving;
private bool _isSettingsSaving;
private string _copyMessage = string.Empty;
private readonly UserProfileValidator _personalValidator = new();
protected override async Task OnAfterRenderAsync(bool firstRender)
@@ -36,11 +37,20 @@ public partial class Index
private async Task LoadUserProfile()
{
_userProfile = await UserContract.GetUserAsync(request: new());
_updateUserRequest = _userProfile.Adapt<UpdateUserRequest>();
try
{
_userProfile = await UserContract.GetUserAsync(request: new());
_updateUserRequest = _userProfile.Adapt<UpdateUserRequest>();
}
catch (Exception ex)
{
// Handle the case when user is not authenticated or API fails
_userProfile = new GetUserResponse();
}
StateHasChanged();
}
private async Task LoadAccountSettings()
{
// TODO: Load settings from API
@@ -117,6 +127,48 @@ public partial class Index
Snackbar.Add("تغییرات تنظیمات لغو شد.", Severity.Info);
}
private async Task CopyReferralCode()
{
try
{
await JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", $"{Navigation.BaseUri}?ref={_userProfile.ReferralCode}");
_copyMessage = "کد دعوت کپی شد!";
Snackbar.Add("کد دعوت در کلیپ‌بورد کپی شد.", Severity.Success);
// Clear message after 3 seconds
await Task.Delay(3000);
_copyMessage = string.Empty;
await InvokeAsync(StateHasChanged);
}
catch (Exception ex)
{
Snackbar.Add("خطا در کپی کردن کد دعوت.", Severity.Error);
}
}
private async Task ShareReferralCode()
{
var shareText = $"کد دعوت من در فرصت: {_userProfile.ReferralCode}\nبرای عضویت از این لینک استفاده کنید: {Navigation.BaseUri}?ref={_userProfile.ReferralCode}";
try
{
// Try to use Web Share API if available
await JSRuntime.InvokeVoidAsync("navigator.share",
new
{
title = "کد دعوت فرصت",
text = shareText,
url = $"{Navigation.BaseUri}?ref={_userProfile.ReferralCode}"
});
}
catch
{
// Fallback: copy to clipboard
await JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", $"{Navigation.BaseUri}?ref={_userProfile.ReferralCode}");
Snackbar.Add("لینک دعوت در کلیپ‌بورد کپی شد.", Severity.Success);
}
}
public class UserProfile
{
[Required(ErrorMessage = "نام الزامی است")]