Add receiver removal functionality to SenderEditor
Enhanced the `SenderEditorPage.razor` by injecting the `EnvelopeReceiverService` to manage envelope receivers. Updated the UI to include a remove button for each receiver, invoking the new `RemoveReceiverAsync` method. This method handles the deletion of receivers from both the UI and the server. Modified `ReceiverDraft` and `SignatureFieldDraft` models to include `ReceiverId` and `ReceiverDraftId` for better tracking. Updated logic for identifying receivers without signature fields and creating receiver commands to use these new identifiers. Added `DeleteAsync` method in `EnvelopeReceiverService.cs` to send DELETE requests for removing receivers. Updated `envelope-viewer.css` to style the new remove button with distinct appearance and hover effects.
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
using EnvelopeGenerator.Application.EnvelopeReceivers.Commands.CreateEnvelopeReceiver;
|
||||
using EnvelopeGenerator.Server.Client.Models;
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
|
||||
namespace EnvelopeGenerator.Server.Client.Services;
|
||||
|
||||
@@ -93,4 +94,31 @@ public class EnvelopeReceiverService(IHttpClientFactory httpClientFactory)
|
||||
var payload = await response.Content.ReadFromJsonAsync<ReceiverEnvelopeUrlEnabledResponse>(_jsonOptions, cancel);
|
||||
return payload?.Enabled == true;
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(int envelopeId, int receiverId, CancellationToken cancel = default)
|
||||
{
|
||||
if (envelopeId <= 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(envelopeId));
|
||||
if (receiverId <= 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(receiverId));
|
||||
|
||||
using var http = httpClientFactory.CreateClient("EnvelopeGenerator.Server");
|
||||
var url = QueryHelpers.AddQueryString("/api/EnvelopeReceiver", new Dictionary<string, string?>
|
||||
{
|
||||
["EnvelopeId"] = envelopeId.ToString(),
|
||||
["ReceiverId"] = receiverId.ToString()
|
||||
});
|
||||
|
||||
var response = await http.DeleteAsync(url, cancel);
|
||||
if (response.IsSuccessStatusCode)
|
||||
return;
|
||||
|
||||
var body = await response.Content.ReadAsStringAsync(cancel);
|
||||
var statusCode = (int)response.StatusCode;
|
||||
var reasonPhrase = response.ReasonPhrase ?? "Unknown error";
|
||||
throw new HttpRequestException(
|
||||
$"Failed to remove receiver. Status: {statusCode} ({reasonPhrase}){(string.IsNullOrWhiteSpace(body) ? string.Empty : $" - {body}")}",
|
||||
null,
|
||||
response.StatusCode);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user