update
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using MudBlazor;
|
||||
|
||||
namespace FrontOffice.Main.Pages;
|
||||
|
||||
public partial class RegisterWizard
|
||||
{
|
||||
private readonly RegistrationModel _model = new();
|
||||
private MudForm? _stepOneForm;
|
||||
private MudForm? _stepTwoForm;
|
||||
private MudForm? _stepThreeForm;
|
||||
private int _activeStep;
|
||||
private bool _isSubmitting;
|
||||
private bool _completed;
|
||||
private string _captchaCode = string.Empty;
|
||||
|
||||
private string _nextButtonText => _activeStep switch
|
||||
{
|
||||
0 => "ادامه",
|
||||
1 => "ادامه",
|
||||
_ => _isSubmitting ? "در حال ارسال..." : "ثبت نهایی"
|
||||
};
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
base.OnInitialized();
|
||||
GenerateCaptcha();
|
||||
}
|
||||
|
||||
private void GenerateCaptcha()
|
||||
{
|
||||
var random = Guid.NewGuid().ToString("N")[..6].ToUpperInvariant();
|
||||
_captchaCode = random;
|
||||
_model.CaptchaInput = string.Empty;
|
||||
}
|
||||
|
||||
private void GoBack()
|
||||
{
|
||||
if (_activeStep == 0 || _isSubmitting)
|
||||
return;
|
||||
|
||||
_activeStep--;
|
||||
}
|
||||
|
||||
private async Task GoNextAsync()
|
||||
{
|
||||
if (_isSubmitting)
|
||||
return;
|
||||
|
||||
switch (_activeStep)
|
||||
{
|
||||
case 0:
|
||||
if (!await ValidateStepAsync(_stepOneForm))
|
||||
return;
|
||||
if (!string.Equals(_model.CaptchaInput?.Trim(), _captchaCode, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Snackbar.Add("کد کپچا صحیح نیست.", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
_activeStep = 1;
|
||||
break;
|
||||
case 1:
|
||||
if (!await ValidateStepAsync(_stepTwoForm))
|
||||
return;
|
||||
_activeStep = 2;
|
||||
break;
|
||||
case 2:
|
||||
if (!await ValidateStepAsync(_stepThreeForm))
|
||||
return;
|
||||
await SubmitAsync();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<bool> ValidateStepAsync(MudForm? form)
|
||||
{
|
||||
if (form is null)
|
||||
return true;
|
||||
|
||||
await form.Validate();
|
||||
return form.IsValid;
|
||||
}
|
||||
|
||||
private async Task SubmitAsync()
|
||||
{
|
||||
_isSubmitting = true;
|
||||
try
|
||||
{
|
||||
await Task.Delay(800);
|
||||
_completed = true;
|
||||
Snackbar.Add("ثبتنام اولیه با موفقیت انجام شد.", Severity.Success);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isSubmitting = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void DownloadContract()
|
||||
{
|
||||
Navigation.NavigateTo("docs/sample-contract.txt", true);
|
||||
}
|
||||
|
||||
private sealed class RegistrationModel
|
||||
{
|
||||
[Required(ErrorMessage = "شماره موبایل الزامی است.")]
|
||||
[RegularExpression(@"^09\d{9}$", ErrorMessage = "شماره موبایل معتبر نیست.")]
|
||||
public string? MobileNumber { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "کد کپچا را وارد کنید.")]
|
||||
public string? CaptchaInput { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "نام الزامی است.")]
|
||||
[StringLength(50, ErrorMessage = "حداکثر ۵۰ کاراکتر")]
|
||||
public string? FirstName { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "نام خانوادگی الزامی است.")]
|
||||
[StringLength(70, ErrorMessage = "حداکثر ۷۰ کاراکتر")]
|
||||
public string? LastName { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "کد ملی الزامی است.")]
|
||||
[RegularExpression(@"^\d{10}$", ErrorMessage = "کدملی باید ۱۰ رقم باشد.")]
|
||||
public string? NationalCode { get; set; }
|
||||
|
||||
[Range(typeof(bool), "true", "true", ErrorMessage = "برای ادامه باید قوانین را تایید کنید.")]
|
||||
public bool AcceptTerms { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user