Introduced a feature to display and apply recent receiver suggestions in the `CreateEnvelopeWizardPopup` component. Added a new section in step 2 to show recently used receivers, with loading and state management logic. Updated the `ReceiverService` to fetch suggestions from the backend API. Enhanced the UI with new styles for the suggestions section and improved localization support. Refactored state management to handle loading, resetting, and applying suggestions. Minor cleanup and adjustments to ensure proper state transitions.
48 lines
1.9 KiB
C#
48 lines
1.9 KiB
C#
using System.Net.Http.Json;
|
|
using System.Text.Json;
|
|
using EnvelopeGenerator.Application.Common.Dto.Receiver;
|
|
|
|
namespace EnvelopeGenerator.Server.Client.Services;
|
|
|
|
public class ReceiverService(IHttpClientFactory httpClientFactory)
|
|
{
|
|
private static readonly JsonSerializerOptions JsonOptions = new(JsonSerializerDefaults.Web);
|
|
|
|
/// <summary>
|
|
/// Fetches receiver email suggestions from sender-authorized API.
|
|
/// Calls GET /api/Receiver?EmailAddressSearch={term}&onlyEmailAddress=true.
|
|
/// </summary>
|
|
public async Task<IReadOnlyList<string>> SearchReceiverEmailsAsync(string searchTerm, CancellationToken cancel = default)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(searchTerm))
|
|
return [];
|
|
|
|
using var http = httpClientFactory.CreateClient("EnvelopeGenerator.Server");
|
|
var url = $"/api/Receiver?EmailAddressSearch={Uri.EscapeDataString(searchTerm)}&onlyEmailAddress=true";
|
|
var response = await http.GetAsync(url, cancel);
|
|
|
|
if (!response.IsSuccessStatusCode)
|
|
return [];
|
|
|
|
var emails = await response.Content.ReadFromJsonAsync<List<string>>(JsonOptions, cancel);
|
|
return emails ?? [];
|
|
}
|
|
|
|
/// <summary>
|
|
/// Fetches recent receiver suggestions for the authenticated sender.
|
|
/// Calls GET /api/EnvelopeReceiver/recent-suggestions?take={take}.
|
|
/// </summary>
|
|
public async Task<IReadOnlyList<RecentReceiverSuggestionDto>> GetRecentReceiverSuggestionsAsync(int take = 5, CancellationToken cancel = default)
|
|
{
|
|
using var http = httpClientFactory.CreateClient("EnvelopeGenerator.Server");
|
|
var url = $"/api/EnvelopeReceiver/recent-suggestions?take={take}";
|
|
var response = await http.GetAsync(url, cancel);
|
|
|
|
if (!response.IsSuccessStatusCode)
|
|
return [];
|
|
|
|
var suggestions = await response.Content.ReadFromJsonAsync<List<RecentReceiverSuggestionDto>>(JsonOptions, cancel);
|
|
return suggestions ?? [];
|
|
}
|
|
}
|