Add device detection and PDF generation features; refactor AuthDialog and update print utilities
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
<PageTitle>ثبتنام سریع</PageTitle>
|
||||
|
||||
<section class="py-12 wizard-section">
|
||||
<MudContainer MaxWidth="MaxWidth.Large">
|
||||
<MudContainer MaxWidth="MaxWidth.Large" Class="px-1">
|
||||
<MudGrid Spacing="4" Justify="Justify.Center">
|
||||
<MudItem xs="12" md="5" Class="d-none d-sm-block">
|
||||
<MudStack Spacing="2" Class="mb-6">
|
||||
@@ -68,7 +68,7 @@
|
||||
<MudProgressLinear Color="Color.Primary" Indeterminate="true" />
|
||||
}
|
||||
|
||||
<MudStepper @bind-ActiveIndex="_activeStep" Elevation="0" DisableClick="true" Class="mb-4 " id="registration-stepper">
|
||||
<MudStepper @bind-ActiveIndex="_activeStep" @ref="_mudStepper" Elevation="0" DisableClick="true" Class="mb-4 " id="registration-stepper">
|
||||
<ChildContent>
|
||||
<MudStep Label="تأیید موبایل" Icon="@Icons.Material.Filled.Smartphone">
|
||||
@* Inline AuthDialog with captcha enabled *@
|
||||
@@ -110,10 +110,9 @@
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Primary"
|
||||
StartIcon="@Icons.Material.Filled.Download" Disabled="_isSubmitting"
|
||||
OnClick="DownloadContract">
|
||||
دانلود قرارداد نمونه
|
||||
دانلود/پرینت قرارداد نمونه
|
||||
</MudButton>
|
||||
<MudText Typo="Typo.caption" Class="mud-text-secondary">فرمت: فایل متنی
|
||||
</MudText>
|
||||
<MudText Typo="Typo.caption" Class="mud-text-secondary">فرمت: PDF از طریق Print</MudText>
|
||||
</MudStack>
|
||||
|
||||
<MudCheckBox @bind-Checked="_model.AcceptTerms" Color="Color.Success"
|
||||
@@ -124,13 +123,23 @@
|
||||
</ChildContent>
|
||||
<ActionContent Context="stepper">
|
||||
<MudStack Row="true" Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center">
|
||||
@if (_isAuthenticated && _activeStep == 1)
|
||||
{
|
||||
<MudButton Variant="Variant.Text" Color="Color.Secondary"
|
||||
|
||||
OnClick="@AuthService.LogoutAsync">خروج از حساب</MudButton>
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
<MudButton Variant="Variant.Text" Color="Color.Secondary"
|
||||
Disabled="_activeStep == 0 || _isSubmitting"
|
||||
OnClick="@(async () => { await GoBack(stepper); })">مرحله قبل</MudButton>
|
||||
<MudSpacer />
|
||||
Disabled="_activeStep == 0 || _isSubmitting"
|
||||
OnClick="@(async () => { await GoBack(); })">مرحله قبل</MudButton>
|
||||
}
|
||||
<MudSpacer/>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary"
|
||||
Disabled="_isSubmitting"
|
||||
OnClick="@(async () => { await GoNextAsync(stepper); })">
|
||||
Disabled="_isSubmitting"
|
||||
OnClick="@(async () => { await GoNextAsync(); })">
|
||||
@_nextButtonText
|
||||
</MudButton>
|
||||
</MudStack>
|
||||
|
||||
@@ -4,6 +4,7 @@ using FrontOffice.Main.Shared;
|
||||
using FrontOffice.Main.Utilities;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.JSInterop;
|
||||
using MudBlazor;
|
||||
|
||||
namespace FrontOffice.Main.Pages;
|
||||
@@ -19,7 +20,12 @@ public partial class RegisterWizard
|
||||
private bool _isSubmitting;
|
||||
private bool _completed;
|
||||
private AuthDialog _authDialog;
|
||||
private MudStepper _mudStepper;
|
||||
private UpdateUserRequest _updateUserRequest = new();
|
||||
private bool _isAuthenticated;
|
||||
|
||||
[Inject] private AuthService AuthService { get; set; } = default!;
|
||||
[Inject] private IJSRuntime Js { get; set; } = default!;
|
||||
|
||||
private string _nextButtonText => _activeStep switch
|
||||
{
|
||||
@@ -28,21 +34,56 @@ public partial class RegisterWizard
|
||||
_ => _isSubmitting ? "در حال ارسال..." : "ثبت نهایی"
|
||||
};
|
||||
|
||||
protected override void OnInitialized()
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
base.OnInitialized();
|
||||
_isAuthenticated = await AuthService.IsAuthenticatedAsync();
|
||||
if (_isAuthenticated && _activeStep == 0)
|
||||
{
|
||||
await _mudStepper.NextStepAsync();
|
||||
_activeStep = 1;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
else if (_isAuthenticated && _activeStep == 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
var existUser = await UserContract.GetUserAsync(new Empty());
|
||||
if (existUser != null && !string.IsNullOrEmpty(existUser.FirstName) && string.IsNullOrWhiteSpace(_model.FirstName))
|
||||
{
|
||||
_model.FirstName = existUser.FirstName;
|
||||
}
|
||||
|
||||
if (existUser != null && !string.IsNullOrEmpty(existUser.LastName) && string.IsNullOrWhiteSpace(_model.LastName))
|
||||
{
|
||||
_model.LastName = existUser.LastName;
|
||||
}
|
||||
|
||||
if (existUser != null && !string.IsNullOrEmpty(existUser.NationalCode) && string.IsNullOrWhiteSpace(_model.NationalCode))
|
||||
{
|
||||
_model.NationalCode = existUser.NationalCode;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
}
|
||||
|
||||
private async Task GoBack(MudStepper mudStepper)
|
||||
private async Task GoBack()
|
||||
{
|
||||
if (_activeStep == 0 || _isSubmitting)
|
||||
if (_activeStep == 0 || _isSubmitting || (_isAuthenticated && _activeStep == 1))
|
||||
return;
|
||||
|
||||
_activeStep--;
|
||||
await mudStepper.PreviousStepAsync();
|
||||
await _mudStepper.PreviousStepAsync();
|
||||
}
|
||||
|
||||
private async Task GoNextAsync(MudStepper mudStepper)
|
||||
private async Task GoNextAsync()
|
||||
{
|
||||
if (_isSubmitting)
|
||||
return;
|
||||
@@ -61,7 +102,6 @@ public partial class RegisterWizard
|
||||
if (!verifyOtp)
|
||||
return;
|
||||
|
||||
|
||||
_activeStep = 1;
|
||||
}
|
||||
|
||||
@@ -76,6 +116,7 @@ public partial class RegisterWizard
|
||||
return;
|
||||
|
||||
_activeStep = 2;
|
||||
await _mudStepper.NextStepAsync();
|
||||
break;
|
||||
case 2:
|
||||
if (!await ValidateStepAsync(_stepThreeForm))
|
||||
@@ -83,8 +124,6 @@ public partial class RegisterWizard
|
||||
await SubmitAsync();
|
||||
break;
|
||||
}
|
||||
|
||||
await mudStepper.NextStepAsync();
|
||||
}
|
||||
|
||||
private async Task<bool> ValidateStepAsync(MudForm? form)
|
||||
@@ -111,16 +150,29 @@ public partial class RegisterWizard
|
||||
}
|
||||
}
|
||||
|
||||
private void DownloadContract()
|
||||
private async void DownloadContract()
|
||||
{
|
||||
Navigation.NavigateTo("docs/sample-contract.txt", true);
|
||||
// Example dynamic HTML (could be constructed based on user data)
|
||||
var html = $"<h1 style='text-align:center'>قرارداد اولیه کاربر</h1><p>نام: {_model.FirstName ?? "-"} {_model.LastName ?? "-"}</p><p>کد ملی: {_model.NationalCode ?? "-"}</p><p>این یک نسخه نمونه است.</p>";
|
||||
|
||||
// Option A: trigger browser print dialog for PDF (client-side)
|
||||
try
|
||||
{
|
||||
await Js.InvokeVoidAsync("printUtils.printHtml", html, new { title = "قرارداد نمونه" });
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Fallback to server-side generation endpoint if JS fails
|
||||
var encoded = Uri.EscapeDataString(html);
|
||||
Navigation.NavigateTo($"contract/generate?html={encoded}&fileName=sample-contract", true);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPhoneVerified()
|
||||
{
|
||||
// Move to next step after phone verification success
|
||||
// _activeStep = 1;
|
||||
// StateHasChanged();
|
||||
//StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task<bool> SavePersonalInfo()
|
||||
@@ -145,7 +197,7 @@ public partial class RegisterWizard
|
||||
Console.WriteLine(_updateUserRequest.FirstName);
|
||||
Console.WriteLine(_updateUserRequest.LastName);
|
||||
Console.WriteLine(_updateUserRequest.NationalCode);
|
||||
|
||||
|
||||
await UserContract.UpdateUserAsync(request: _updateUserRequest);
|
||||
Snackbar.Add("اطلاعات شخصی با موفقیت ذخیره شد.", Severity.Success);
|
||||
return true;
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
<!-- Load MudBlazor JS before Blazor to avoid early JS interop calls failing; add cache-busting -->
|
||||
<script src="_content/MudBlazor/MudBlazor.min.js" asp-append-version="true"></script>
|
||||
<script src="_framework/blazor.server.js"></script>
|
||||
<script src="/js/print-utils.js" asp-append-version="true"></script>
|
||||
<script>
|
||||
// elementId: id نوار (مثلاً "top")
|
||||
// containerSelector: کانتینری که اسکرول میخوره؛ برای MudLayout معمولا ".mud-main-content"
|
||||
|
||||
Reference in New Issue
Block a user