feat: add club membership contract dialog and city autocomplete
This commit is contained in:
@@ -3,6 +3,7 @@ using FrontOffice.BFF.UserAddress.Protobuf.Validator;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using MudBlazor;
|
||||
using Severity = MudBlazor.Severity;
|
||||
using CityProto = FrontOffice.BFF.City.Protobuf;
|
||||
|
||||
namespace FrontOffice.Main.Pages.Profile.Components;
|
||||
|
||||
@@ -10,19 +11,48 @@ public partial class AddAddressDialog : ComponentBase
|
||||
{
|
||||
[CascadingParameter] private IDialogReference MudDialog { get; set; } = default!;
|
||||
[Inject] private UserAddressContract.UserAddressContractClient UserAddressContract { get; set; } = default!;
|
||||
[Inject] private CityProto.CityContract.CityContractClient CityContract { get; set; } = default!;
|
||||
|
||||
private MudForm? _form;
|
||||
private readonly CreateNewUserAddressRequestValidator _validator = new();
|
||||
private bool _isSaving;
|
||||
private CreateNewUserAddressRequest _request = new();
|
||||
private CityProto.GetAllCitiesByFilterResponseModel? _selectedCity;
|
||||
|
||||
private async Task<IEnumerable<CityProto.GetAllCitiesByFilterResponseModel>> SearchCities(string value, CancellationToken ct)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value) || value.Length < 2)
|
||||
return Enumerable.Empty<CityProto.GetAllCitiesByFilterResponseModel>();
|
||||
|
||||
try
|
||||
{
|
||||
var response = await CityContract.GetAllCitiesByFilterAsync(new CityProto.GetAllCitiesByFilterRequest
|
||||
{
|
||||
PaginationState = new CityProto.PaginationState { PageNumber = 1, PageSize = 20 },
|
||||
Filter = new CityProto.GetAllCitiesByFilterFilter { Native = value }
|
||||
}, cancellationToken: ct);
|
||||
|
||||
return response?.Models?.ToList() ?? new List<CityProto.GetAllCitiesByFilterResponseModel>();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Enumerable.Empty<CityProto.GetAllCitiesByFilterResponseModel>();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SaveAddress()
|
||||
{
|
||||
if (_form == null) return;
|
||||
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid) return;
|
||||
if (!_form.IsValid || _selectedCity == null)
|
||||
{
|
||||
if (_selectedCity == null)
|
||||
Snackbar.Add("لطفاً شهر را انتخاب کنید.", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
_request.CityId = _selectedCity.Id;
|
||||
_isSaving = true;
|
||||
try
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user