diff --git a/src/FrontOffice.Main/FrontOffice.Main.csproj b/src/FrontOffice.Main/FrontOffice.Main.csproj index 114386a..096fae9 100644 --- a/src/FrontOffice.Main/FrontOffice.Main.csproj +++ b/src/FrontOffice.Main/FrontOffice.Main.csproj @@ -9,8 +9,8 @@ - - + + diff --git a/src/FrontOffice.Main/Pages/Profile/Index.razor b/src/FrontOffice.Main/Pages/Profile/Index.razor index c3e9f6e..c661f56 100644 --- a/src/FrontOffice.Main/Pages/Profile/Index.razor +++ b/src/FrontOffice.Main/Pages/Profile/Index.razor @@ -70,18 +70,14 @@ + Variant="Variant.Outlined" /> + Variant="Variant.Outlined" /> @@ -91,6 +87,15 @@ Variant="Variant.Outlined" InputType="InputType.Text" /> + + + + @@ -103,61 +108,66 @@ - @* -
- تنظیمات حساب + +
- - - - اعلان‌ها - - - - - - + + + + اعلان‌ها + + + + + + + @* + + + حریم خصوصی + + + + + - - - حریم خصوصی - - - - - + + + زبان و تم + + + + فارسی + English + + + + + روشن + تیره + خودکار + + + + *@ - - - زبان و تم - - - - فارسی - English - - - - - روشن - تیره - خودکار - - - - - - - - لغو - - - ذخیره تنظیمات - - - -
-
*@ + + + ذخیره تنظیمات + + + +
+
@* diff --git a/src/FrontOffice.Main/Pages/Profile/Index.razor.cs b/src/FrontOffice.Main/Pages/Profile/Index.razor.cs index 05668c3..f3fc1aa 100644 --- a/src/FrontOffice.Main/Pages/Profile/Index.razor.cs +++ b/src/FrontOffice.Main/Pages/Profile/Index.razor.cs @@ -1,5 +1,6 @@ using FluentValidation; using FrontOffice.BFF.User.Protobuf.Protos.User; +using FrontOffice.Main.Utilities; using Mapster; using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; @@ -24,14 +25,13 @@ public partial class Index private string _copyMessage = string.Empty; private readonly UserProfileValidator _personalValidator = new(); - + private DateTime? _date; protected override async Task OnAfterRenderAsync(bool firstRender) { await base.OnAfterRenderAsync(firstRender); - if(firstRender) + if (firstRender) { await LoadUserProfile(); - await LoadAccountSettings(); } } @@ -41,6 +41,8 @@ public partial class Index { _userProfile = await UserContract.GetUserAsync(request: new()); _updateUserRequest = _userProfile.Adapt(); + if (_userProfile.BirthDate != null) + _date = _userProfile.BirthDate.ToDateTime(); } catch (Exception ex) { @@ -51,21 +53,6 @@ public partial class Index } - 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" - //}; - } - private async Task SavePersonalInfo() { if (_personalForm is null) return; @@ -77,6 +64,9 @@ public partial class Index try { + if (_date != null) + _updateUserRequest.BirthDate = _date.Value.DateTimeToTimestamp(); + await UserContract.UpdateUserAsync(request: _updateUserRequest); await LoadUserProfile(); Snackbar.Add("اطلاعات شخصی با موفقیت ذخیره شد.", Severity.Success); @@ -105,8 +95,8 @@ public partial class Index try { - // TODO: Save settings to API - await Task.Delay(1000); // Simulate API call + + await SavePersonalInfo(); Snackbar.Add("تنظیمات با موفقیت ذخیره شد.", Severity.Success); } @@ -121,12 +111,6 @@ public partial class Index } } - private void CancelSettingsChanges() - { - // TODO: Reset settings to original values - Snackbar.Add("تغییرات تنظیمات لغو شد.", Severity.Info); - } - private async Task CopyReferralCode() { try diff --git a/src/FrontOffice.Main/Utilities/Extensions.cs b/src/FrontOffice.Main/Utilities/Extensions.cs index be9cd0e..4120abf 100644 --- a/src/FrontOffice.Main/Utilities/Extensions.cs +++ b/src/FrontOffice.Main/Utilities/Extensions.cs @@ -1,4 +1,5 @@ using System.ComponentModel.DataAnnotations; +using System.Globalization; using System.Net; using System.Reflection; using System.Text.RegularExpressions; @@ -9,6 +10,38 @@ namespace FrontOffice.Main.Utilities; public static class Extensions { + public static CultureInfo GetPersianCulture() + { + var culture = new CultureInfo("fa-IR"); + DateTimeFormatInfo formatInfo = culture.DateTimeFormat; + formatInfo.AbbreviatedDayNames = new[] { "ی", "د", "س", "چ", "پ", "ج", "ش" }; + formatInfo.DayNames = new[] { "یکشنبه", "دوشنبه", "سه شنبه", "چهار شنبه", "پنجشنبه", "جمعه", "شنبه" }; + var monthNames = new[] + { + "فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", + "اسفند", + "", + }; + formatInfo.AbbreviatedMonthNames = + formatInfo.MonthNames = + formatInfo.MonthGenitiveNames = formatInfo.AbbreviatedMonthGenitiveNames = monthNames; + formatInfo.AMDesignator = "ق.ظ"; + formatInfo.PMDesignator = "ب.ظ"; + formatInfo.ShortDatePattern = "yyyy/MM/dd"; + formatInfo.LongDatePattern = "dddd, dd MMMM,yyyy"; + formatInfo.FirstDayOfWeek = DayOfWeek.Saturday; + Calendar cal = new PersianCalendar(); + FieldInfo fieldInfo = culture.GetType().GetField("calendar", BindingFlags.NonPublic | BindingFlags.Instance); + if (fieldInfo != null) + fieldInfo.SetValue(culture, cal); + FieldInfo info = formatInfo.GetType().GetField("calendar", BindingFlags.NonPublic | BindingFlags.Instance); + if (info != null) + info.SetValue(formatInfo, cal); + culture.NumberFormat.NumberDecimalSeparator = "/"; + culture.NumberFormat.DigitSubstitution = DigitShapes.NativeNational; + culture.NumberFormat.NumberNegativePattern = 0; + return culture; + } public static string ExtractUserFriendlyMessage(this string errorMessage) { // کلیدواژه‌ای که بعد از آن بخش مورد نظر شروع می‌شود