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

@@ -8,16 +8,52 @@
<!-- Profile Header -->
<MudItem xs="12">
<MudPaper Elevation="4" Class="mud-elevation-4 pa-6 rounded-2xl mud-theme-surface">
<MudStack Spacing="4">
<MudStack Row="true" Spacing="3" AlignItems="AlignItems.Center">
<MudAvatar Size="Size.Large" Color="Color.Primary">
<MudIcon Icon="@Icons.Material.Filled.Person" Size="Size.Large" />
</MudAvatar>
<div>
<MudText Typo="Typo.h5" Class="mud-typography-subtitle1">@_userProfile.FirstName @_userProfile.LastName</MudText>
<MudText Typo="Typo.body2" Class="mud-text-secondary">@_userProfile.Mobile</MudText>
<MudText Typo="Typo.h5" Class="mud-typography-subtitle1">@($"{_userProfile.FirstName} {_userProfile.LastName}")</MudText>
<MudText Typo="Typo.body2" Class="mud-text-secondary">@(_userProfile.Mobile)</MudText>
<MudText Typo="Typo.caption" Class="mud-text-secondary">عضو از @(_userProfile.MobileVerifiedAt?.ToDateTime().MiladiToJalali())</MudText>
</div>
</MudStack>
<!-- Referral Code Section -->
<MudDivider />
<MudStack Spacing="3">
<MudStack Row="true" AlignItems="AlignItems.Center">
<MudText Typo="Typo.subtitle1" Class="mud-typography-subtitle1">کد دعوت شما</MudText>
<MudSpacer />
<MudButton Variant="Variant.Filled"
Color="Color.Primary"
StartIcon="@Icons.Material.Filled.Share"
OnClick="ShareReferralCode">
اشتراک‌گذاری
</MudButton>
</MudStack>
<MudText Typo="Typo.body2" Class="mud-text-secondary">
این کد را با دوستان خود به اشتراک بگذارید تا از خریدهای آنها پاداش دریافت کنید.
</MudText>
<MudStack Row="true" Spacing="2" AlignItems="AlignItems.Center">
<MudTextField @bind-Value="_userProfile.ReferralCode"
Label="کد دعوت"
Variant="Variant.Outlined"
ReadOnly="true"
Class="flex-grow-1"
Adornment="Adornment.End"
AdornmentIcon="@Icons.Material.Filled.ContentCopy"
OnAdornmentClick="CopyReferralCode" />
</MudStack>
@if (!string.IsNullOrWhiteSpace(_copyMessage))
{
<MudText Typo="Typo.caption" Color="Color.Success">@(_copyMessage)</MudText>
}
</MudStack>
</MudStack>
</MudPaper>
</MudItem>

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)
@@ -35,12 +36,21 @@ public partial class Index
}
private async Task LoadUserProfile()
{
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 = "نام الزامی است")]