From f69cdf4a05496e3a3b5b4bfe9111d7980ad72cae Mon Sep 17 00:00:00 2001 From: MeysamMoghaddam <65253484+MeysamMoghaddam@users.noreply.github.com> Date: Sun, 12 Oct 2025 23:00:59 +0330 Subject: [PATCH] u --- .../Pages/Profile/Index.razor | 33 ++----- .../Pages/Profile/Index.razor.cs | 97 +++---------------- 2 files changed, 24 insertions(+), 106 deletions(-) diff --git a/src/FrontOffice.Main/Pages/Profile/Index.razor b/src/FrontOffice.Main/Pages/Profile/Index.razor index f212eab..0742979 100644 --- a/src/FrontOffice.Main/Pages/Profile/Index.razor +++ b/src/FrontOffice.Main/Pages/Profile/Index.razor @@ -28,13 +28,11 @@
- اطلاعات شخصی - - - - - - - - - - - لغو - + ذخیره تغییرات @@ -82,7 +67,7 @@ - + @*
تنظیمات حساب @@ -136,7 +121,7 @@
-
+
*@ @* diff --git a/src/FrontOffice.Main/Pages/Profile/Index.razor.cs b/src/FrontOffice.Main/Pages/Profile/Index.razor.cs index 8e5e9f4..d6bdd70 100644 --- a/src/FrontOffice.Main/Pages/Profile/Index.razor.cs +++ b/src/FrontOffice.Main/Pages/Profile/Index.razor.cs @@ -2,6 +2,7 @@ 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 MudBlazor; using System.ComponentModel.DataAnnotations; @@ -14,18 +15,14 @@ public partial class Index [Inject] private UserContract.UserContractClient UserContract { get; set; } = default!; private GetUserResponse _userProfile = new(); - private PasswordChangeModel _passwordModel = new(); - private AccountSettings _settings = new(); + private UpdateUserRequest _updateUserRequest = new(); private MudForm? _personalForm; - private MudForm? _passwordForm; private bool _isPersonalSaving; - private bool _isPasswordChanging; private bool _isSettingsSaving; private readonly UserProfileValidator _personalValidator = new(); - private readonly PasswordChangeValidator _passwordValidator = new(); protected override async Task OnAfterRenderAsync(bool firstRender) { @@ -40,22 +37,23 @@ public partial class Index private async Task LoadUserProfile() { _userProfile = await UserContract.GetUserAsync(request: new()); + _updateUserRequest = _userProfile.Adapt(); StateHasChanged(); } private async Task LoadAccountSettings() { // TODO: Load settings from API - _settings = new AccountSettings - { - EmailNotifications = true, - SmsNotifications = true, - PushNotifications = false, - ProfileVisibility = true, - ShowOnlineStatus = true, - Language = "fa", - Theme = "light" - }; + //_settings = new AccountSettings + //{ + // EmailNotifications = true, + // SmsNotifications = true, + // PushNotifications = false, + // ProfileVisibility = true, + // ShowOnlineStatus = true, + // Language = "fa", + // Theme = "light" + //}; } private async Task SavePersonalInfo() @@ -69,9 +67,8 @@ public partial class Index try { - // TODO: Save to API - await Task.Delay(1000); // Simulate API call - + await UserContract.UpdateUserAsync(request: _updateUserRequest); + await LoadUserProfile(); Snackbar.Add("اطلاعات شخصی با موفقیت ذخیره شد.", Severity.Success); } catch (Exception ex) @@ -91,45 +88,6 @@ public partial class Index Snackbar.Add("تغییرات لغو شد.", Severity.Info); } - private async Task ChangePassword() - { - if (_passwordForm is null) return; - - await _passwordForm.Validate(); - if (!_passwordForm.IsValid) return; - - if (_passwordModel.NewPassword != _passwordModel.ConfirmPassword) - { - Snackbar.Add("رمز عبور جدید و تکرار آن مطابقت ندارند.", Severity.Warning); - return; - } - - _isPasswordChanging = true; - - try - { - // TODO: Change password via API - await Task.Delay(1000); // Simulate API call - - Snackbar.Add("رمز عبور با موفقیت تغییر یافت.", Severity.Success); - _passwordModel = new PasswordChangeModel(); - } - catch (Exception ex) - { - Snackbar.Add($"خطا در تغییر رمز عبور: {ex.Message}", Severity.Error); - } - finally - { - _isPasswordChanging = false; - await InvokeAsync(StateHasChanged); - } - } - - private void CancelPasswordChange() - { - _passwordModel = new PasswordChangeModel(); - Snackbar.Add("تغییر رمز عبور لغو شد.", Severity.Info); - } private async Task SaveSettings() { @@ -184,21 +142,6 @@ public partial class Index public int TotalReferrals { get; set; } public string? Level { get; set; } } - - public class PasswordChangeModel - { - [Required(ErrorMessage = "رمز عبور فعلی الزامی است")] - public string? CurrentPassword { get; set; } - - [Required(ErrorMessage = "رمز عبور جدید الزامی است")] - [MinLength(8, ErrorMessage = "رمز عبور باید حداقل ۸ کاراکتر باشد")] - public string? NewPassword { get; set; } - - [Required(ErrorMessage = "تکرار رمز عبور الزامی است")] - [Compare(nameof(NewPassword), ErrorMessage = "رمز عبور و تکرار آن مطابقت ندارند")] - public string? ConfirmPassword { get; set; } - } - public class AccountSettings { public bool EmailNotifications { get; set; } @@ -220,14 +163,4 @@ public partial class Index RuleFor(x => x.PhoneNumber).NotEmpty().WithMessage("شماره موبایل الزامی است"); } } - - public class PasswordChangeValidator : AbstractValidator - { - public PasswordChangeValidator() - { - RuleFor(x => x.CurrentPassword).NotEmpty().WithMessage("رمز عبور فعلی الزامی است"); - RuleFor(x => x.NewPassword).NotEmpty().MinimumLength(8).WithMessage("رمز عبور جدید باید حداقل ۸ کاراکتر باشد"); - RuleFor(x => x.ConfirmPassword).NotEmpty().WithMessage("تکرار رمز عبور الزامی است"); - } - } } \ No newline at end of file