u
This commit is contained in:
@@ -28,13 +28,11 @@
|
|||||||
<!-- Personal Information Tab -->
|
<!-- Personal Information Tab -->
|
||||||
<MudTabPanel Text="اطلاعات شخصی" Icon="@Icons.Material.Filled.Person">
|
<MudTabPanel Text="اطلاعات شخصی" Icon="@Icons.Material.Filled.Person">
|
||||||
<div class="pa-4">
|
<div class="pa-4">
|
||||||
<MudText Typo="Typo.h6" Class="mb-4 mud-typography-subtitle1">اطلاعات شخصی</MudText>
|
|
||||||
|
|
||||||
<MudForm @ref="_personalForm" Model="_userProfile" Validation="@((Func<object, IEnumerable<FluentValidation.Results.ValidationFailure>>)((model) => _personalValidator.Validate((UserProfile)model).Errors))">
|
<MudForm @ref="_personalForm" Model="_userProfile" Validation="@((Func<object, IEnumerable<FluentValidation.Results.ValidationFailure>>)((model) => _personalValidator.Validate((UserProfile)model).Errors))">
|
||||||
<MudGrid Spacing="3">
|
<MudGrid Spacing="3">
|
||||||
<MudItem xs="12" md="6">
|
<MudItem xs="12" md="6">
|
||||||
<MudTextField @bind-Value="_userProfile.FirstName"
|
<MudTextField @bind-Value="_updateUserRequest.FirstName"
|
||||||
For="@(() => _userProfile.FirstName)"
|
For="@(() => _updateUserRequest.FirstName)"
|
||||||
Label="نام"
|
Label="نام"
|
||||||
Variant="Variant.Outlined"
|
Variant="Variant.Outlined"
|
||||||
Required="true"
|
Required="true"
|
||||||
@@ -42,8 +40,8 @@
|
|||||||
</MudItem>
|
</MudItem>
|
||||||
|
|
||||||
<MudItem xs="12" md="6">
|
<MudItem xs="12" md="6">
|
||||||
<MudTextField @bind-Value="_userProfile.LastName"
|
<MudTextField @bind-Value="_updateUserRequest.LastName"
|
||||||
For="@(() => _userProfile.LastName)"
|
For="@(() => _updateUserRequest.LastName)"
|
||||||
Label="نام خانوادگی"
|
Label="نام خانوادگی"
|
||||||
Variant="Variant.Outlined"
|
Variant="Variant.Outlined"
|
||||||
Required="true"
|
Required="true"
|
||||||
@@ -51,28 +49,15 @@
|
|||||||
</MudItem>
|
</MudItem>
|
||||||
|
|
||||||
<MudItem xs="12" md="6">
|
<MudItem xs="12" md="6">
|
||||||
<MudTextField @bind-Value="_userProfile.Mobile"
|
<MudTextField @bind-Value="_updateUserRequest.NationalCode"
|
||||||
For="@(() => _userProfile.Mobile)"
|
For="@(() => _updateUserRequest.NationalCode)"
|
||||||
Label="شماره موبایل"
|
|
||||||
Variant="Variant.Outlined"
|
|
||||||
InputType="InputType.Text"
|
|
||||||
Required="true"
|
|
||||||
RequiredError="وارد کردن شماره موبایل الزامی است." />
|
|
||||||
</MudItem>
|
|
||||||
|
|
||||||
<MudItem xs="12" md="6">
|
|
||||||
<MudTextField @bind-Value="_userProfile.NationalCode"
|
|
||||||
For="@(() => _userProfile.NationalCode)"
|
|
||||||
Label="کد ملی"
|
Label="کد ملی"
|
||||||
Variant="Variant.Outlined"
|
Variant="Variant.Outlined"
|
||||||
InputType="InputType.Text" />
|
InputType="InputType.Text" />
|
||||||
</MudItem>
|
</MudItem>
|
||||||
</MudGrid>
|
</MudGrid>
|
||||||
|
|
||||||
<MudStack Row="true" Spacing="2" Justify="Justify.FlexEnd" Class="mt-4">
|
<MudStack Row="true" Spacing="2" Justify="Justify.FlexEnd" Class="mt-4">
|
||||||
<MudButton Variant="Variant.Outlined" Color="Color.Secondary" OnClick="CancelPersonalChanges">
|
|
||||||
لغو
|
|
||||||
</MudButton>
|
|
||||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="SavePersonalInfo" Disabled="_isPersonalSaving">
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="SavePersonalInfo" Disabled="_isPersonalSaving">
|
||||||
ذخیره تغییرات
|
ذخیره تغییرات
|
||||||
</MudButton>
|
</MudButton>
|
||||||
@@ -82,7 +67,7 @@
|
|||||||
</MudTabPanel>
|
</MudTabPanel>
|
||||||
|
|
||||||
<!-- Account Settings Tab -->
|
<!-- Account Settings Tab -->
|
||||||
<MudTabPanel Text="تنظیمات حساب" Icon="@Icons.Material.Filled.Settings">
|
@* <MudTabPanel Text="تنظیمات حساب" Icon="@Icons.Material.Filled.Settings">
|
||||||
<div class="pa-4">
|
<div class="pa-4">
|
||||||
<MudText Typo="Typo.h6" Class="mb-4 mud-typography-subtitle1">تنظیمات حساب</MudText>
|
<MudText Typo="Typo.h6" Class="mb-4 mud-typography-subtitle1">تنظیمات حساب</MudText>
|
||||||
|
|
||||||
@@ -136,7 +121,7 @@
|
|||||||
</MudStack>
|
</MudStack>
|
||||||
</MudStack>
|
</MudStack>
|
||||||
</div>
|
</div>
|
||||||
</MudTabPanel>
|
</MudTabPanel> *@
|
||||||
|
|
||||||
<!-- Statistics Tab -->
|
<!-- Statistics Tab -->
|
||||||
@* <MudTabPanel Text="آمار و اطلاعات" Icon="@Icons.Material.Filled.BarChart">
|
@* <MudTabPanel Text="آمار و اطلاعات" Icon="@Icons.Material.Filled.BarChart">
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using FluentValidation;
|
|||||||
using FrontOffice.BFF.Package.Protobuf.Protos.Package;
|
using FrontOffice.BFF.Package.Protobuf.Protos.Package;
|
||||||
using FrontOffice.BFF.User.Protobuf.Protos.User;
|
using FrontOffice.BFF.User.Protobuf.Protos.User;
|
||||||
using FrontOffice.Main.Utilities;
|
using FrontOffice.Main.Utilities;
|
||||||
|
using Mapster;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
using MudBlazor;
|
using MudBlazor;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
@@ -14,18 +15,14 @@ public partial class Index
|
|||||||
[Inject] private UserContract.UserContractClient UserContract { get; set; } = default!;
|
[Inject] private UserContract.UserContractClient UserContract { get; set; } = default!;
|
||||||
|
|
||||||
private GetUserResponse _userProfile = new();
|
private GetUserResponse _userProfile = new();
|
||||||
private PasswordChangeModel _passwordModel = new();
|
private UpdateUserRequest _updateUserRequest = new();
|
||||||
private AccountSettings _settings = new();
|
|
||||||
|
|
||||||
private MudForm? _personalForm;
|
private MudForm? _personalForm;
|
||||||
private MudForm? _passwordForm;
|
|
||||||
|
|
||||||
private bool _isPersonalSaving;
|
private bool _isPersonalSaving;
|
||||||
private bool _isPasswordChanging;
|
|
||||||
private bool _isSettingsSaving;
|
private bool _isSettingsSaving;
|
||||||
|
|
||||||
private readonly UserProfileValidator _personalValidator = new();
|
private readonly UserProfileValidator _personalValidator = new();
|
||||||
private readonly PasswordChangeValidator _passwordValidator = new();
|
|
||||||
|
|
||||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||||
{
|
{
|
||||||
@@ -40,22 +37,23 @@ public partial class Index
|
|||||||
private async Task LoadUserProfile()
|
private async Task LoadUserProfile()
|
||||||
{
|
{
|
||||||
_userProfile = await UserContract.GetUserAsync(request: new());
|
_userProfile = await UserContract.GetUserAsync(request: new());
|
||||||
|
_updateUserRequest = _userProfile.Adapt<UpdateUserRequest>();
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task LoadAccountSettings()
|
private async Task LoadAccountSettings()
|
||||||
{
|
{
|
||||||
// TODO: Load settings from API
|
// TODO: Load settings from API
|
||||||
_settings = new AccountSettings
|
//_settings = new AccountSettings
|
||||||
{
|
//{
|
||||||
EmailNotifications = true,
|
// EmailNotifications = true,
|
||||||
SmsNotifications = true,
|
// SmsNotifications = true,
|
||||||
PushNotifications = false,
|
// PushNotifications = false,
|
||||||
ProfileVisibility = true,
|
// ProfileVisibility = true,
|
||||||
ShowOnlineStatus = true,
|
// ShowOnlineStatus = true,
|
||||||
Language = "fa",
|
// Language = "fa",
|
||||||
Theme = "light"
|
// Theme = "light"
|
||||||
};
|
//};
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task SavePersonalInfo()
|
private async Task SavePersonalInfo()
|
||||||
@@ -69,9 +67,8 @@ public partial class Index
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// TODO: Save to API
|
await UserContract.UpdateUserAsync(request: _updateUserRequest);
|
||||||
await Task.Delay(1000); // Simulate API call
|
await LoadUserProfile();
|
||||||
|
|
||||||
Snackbar.Add("اطلاعات شخصی با موفقیت ذخیره شد.", Severity.Success);
|
Snackbar.Add("اطلاعات شخصی با موفقیت ذخیره شد.", Severity.Success);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -91,45 +88,6 @@ public partial class Index
|
|||||||
Snackbar.Add("تغییرات لغو شد.", Severity.Info);
|
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()
|
private async Task SaveSettings()
|
||||||
{
|
{
|
||||||
@@ -184,21 +142,6 @@ public partial class Index
|
|||||||
public int TotalReferrals { get; set; }
|
public int TotalReferrals { get; set; }
|
||||||
public string? Level { 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 class AccountSettings
|
||||||
{
|
{
|
||||||
public bool EmailNotifications { get; set; }
|
public bool EmailNotifications { get; set; }
|
||||||
@@ -220,14 +163,4 @@ public partial class Index
|
|||||||
RuleFor(x => x.PhoneNumber).NotEmpty().WithMessage("شماره موبایل الزامی است");
|
RuleFor(x => x.PhoneNumber).NotEmpty().WithMessage("شماره موبایل الزامی است");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PasswordChangeValidator : AbstractValidator<PasswordChangeModel>
|
|
||||||
{
|
|
||||||
public PasswordChangeValidator()
|
|
||||||
{
|
|
||||||
RuleFor(x => x.CurrentPassword).NotEmpty().WithMessage("رمز عبور فعلی الزامی است");
|
|
||||||
RuleFor(x => x.NewPassword).NotEmpty().MinimumLength(8).WithMessage("رمز عبور جدید باید حداقل ۸ کاراکتر باشد");
|
|
||||||
RuleFor(x => x.ConfirmPassword).NotEmpty().WithMessage("تکرار رمز عبور الزامی است");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user