From 6585c8014a3744eee5f9a9ee24fd701e97e60439 Mon Sep 17 00:00:00 2001 From: MeysamMoghaddam <65253484+MeysamMoghaddam@users.noreply.github.com> Date: Sun, 12 Oct 2025 23:21:30 +0330 Subject: [PATCH] u --- .../Pages/Profile/Index.razor | 256 ++++++++++-------- .../Pages/Profile/Index.razor.cs | 60 +++- 2 files changed, 202 insertions(+), 114 deletions(-) diff --git a/src/FrontOffice.Main/Pages/Profile/Index.razor b/src/FrontOffice.Main/Pages/Profile/Index.razor index 0742979..c3e9f6e 100644 --- a/src/FrontOffice.Main/Pages/Profile/Index.razor +++ b/src/FrontOffice.Main/Pages/Profile/Index.razor @@ -8,123 +8,159 @@ - - - - -
- @_userProfile.FirstName @_userProfile.LastName - @_userProfile.Mobile + + + + + +
+ @($"{_userProfile.FirstName} {_userProfile.LastName}") + @(_userProfile.Mobile) عضو از @(_userProfile.MobileVerifiedAt?.ToDateTime().MiladiToJalali())
- - - - - - - - -
- - - - - + + + + + کد دعوت شما + + + اشتراک‌گذاری + + + + این کد را با دوستان خود به اشتراک بگذارید تا از خریدهای آنها پاداش دریافت کنید. + - - - + + + - - - - + @if (!string.IsNullOrWhiteSpace(_copyMessage)) + { + @(_copyMessage) + } + + + + - - - ذخیره تغییرات - - - -
-
+ + + + + + +
+ + + + + - - @* -
- تنظیمات حساب + + + - - - - اعلان‌ها - - - - - - + + + + - - - حریم خصوصی - - - - - - - - - زبان و تم - - - - فارسی - English - - - - - روشن - تیره - خودکار - - - - - - - - لغو - - - ذخیره تنظیمات - - + + + ذخیره تغییرات + -
-
*@ +
+
+
- - @* + + @* +
+ تنظیمات حساب + + + + + اعلان‌ها + + + + + + + + + + حریم خصوصی + + + + + + + + + زبان و تم + + + + فارسی + English + + + + + روشن + تیره + خودکار + + + + + + + + لغو + + + ذخیره تنظیمات + + + +
+
*@ + + + @*
آمار حساب کاربری @@ -183,8 +219,8 @@
*@ -
-
-
- - \ No newline at end of file +
+
+
+ + \ No newline at end of file diff --git a/src/FrontOffice.Main/Pages/Profile/Index.razor.cs b/src/FrontOffice.Main/Pages/Profile/Index.razor.cs index d6bdd70..05668c3 100644 --- a/src/FrontOffice.Main/Pages/Profile/Index.razor.cs +++ b/src/FrontOffice.Main/Pages/Profile/Index.razor.cs @@ -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(); + try + { + _userProfile = await UserContract.GetUserAsync(request: new()); + _updateUserRequest = _userProfile.Adapt(); + } + 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 = "نام الزامی است")]