| | 1 | | @namespace Syki.Front.Features.Academic.CreateWebhookSubscription |
| | 2 | |
|
| | 3 | | <MudDrawer @bind-Open="@_open" Width="@_width" Anchor="Anchor.Right" Elevation="1" Variant="@DrawerVariant.Temporary"> |
| | 4 | | <MudDrawerHeader Class="justify-space-between"> |
| | 5 | | <MudStack Row="true" Justify="Justify.FlexStart" AlignItems="AlignItems.Center" Spacing="3"> |
| | 6 | | <MudIcon Icon="@Icons.Material.Filled.Add" /> |
| | 7 | | <MudText Typo="Typo.h5"><b>Novo Webhook</b></MudText> |
| | 8 | | </MudStack> |
| | 9 | | <MudIconButton Icon="@Icons.Material.Filled.Close" OnClick="@Close" /> |
| | 10 | | </MudDrawerHeader> |
| | 11 | |
|
| | 12 | | <style> |
| | 13 | | .mud-treeview-item-arrow { |
| | 14 | | width: 0; |
| | 15 | | } |
| | 16 | | </style> |
| | 17 | | <MudGrid Spacing="1" Class="px-6"> |
| 0 | 18 | | <MudForm @ref="@_form" Style="width: 100%"> |
| 0 | 19 | | <MudItem xs="12"> |
| 0 | 20 | | <SykiTitleText Icon="@Icons.Material.Filled.Adjust" Text="Endpoint" /> |
| 0 | 21 | | <SykiTextField Label="Nome" AutoFocus="true" @bind-Value="@_name" Class="py-2" /> |
| 0 | 22 | | <SykiTextField Label="Url" @bind-Value="@_url" /> |
| 0 | 23 | | </MudItem> |
| | 24 | |
|
| | 25 | | <MudItem xs="12" Class="mt-4"> |
| | 26 | | <SykiTitleText Icon="@Icons.Material.Filled.NotificationAdd" Text="Notificações" /> |
| | 27 | | <MudTreeView T="WebhookEventType" SelectionMode="SelectionMode.MultiSelection" TriState="false" Selected |
| 0 | 28 | | @foreach (WebhookEventType eventType in Enum.GetValues<WebhookEventType>()) |
| | 29 | | { |
| | 30 | | <MudTreeViewItem Value="@eventType" Text="@eventType.GetDescription()" /> |
| | 31 | | } |
| | 32 | | </MudTreeView> |
| | 33 | | </MudItem> |
| | 34 | |
|
| | 35 | | <MudItem xs="12" Class="mt-4"> |
| | 36 | | <SykiTitleText Icon="@Icons.Material.Filled.LockPerson" Text="Autenticação" /> |
| | 37 | | <SykiTextField Label="ApiKey" @bind-Value="@_apiKey" Class="pt-2" /> |
| | 38 | | </MudItem> |
| | 39 | | </MudForm> |
| | 40 | | </MudGrid> |
| | 41 | |
|
| | 42 | | <MudStack Row="true" Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center" Spacing="3" Class="px-2 pt-6"> |
| | 43 | | <DialogCancelButton OnClick="@Close" /> |
| | 44 | | <DialogSaveButton OnClick="@Submit" /> |
| | 45 | | </MudStack> |
| | 46 | | </MudDrawer> |
| | 47 | |
|
| | 48 | | @inject ISnackbar Snackbar |
| | 49 | | @inject NavigationManager Nav |
| | 50 | | @inject IBrowserViewportService BrowserViewportService |
| | 51 | | @inject CreateWebhookSubscriptionClient CreateWebhookSubscriptionClient |
| | 52 | |
|
| | 53 | | @code |
| | 54 | | { |
| | 55 | | [Parameter] |
| 0 | 56 | | public EventCallback AfterSubmit { get; set; } |
| | 57 | |
|
| | 58 | | private bool _open; |
| 0 | 59 | | private string _width = "500px"; |
| | 60 | | private Breakpoint _breakpoint; |
| | 61 | |
|
| | 62 | | private MudForm _form; |
| | 63 | | private bool _loading; |
| | 64 | |
|
| | 65 | | private string? _name; |
| | 66 | | private string? _url; |
| 0 | 67 | | private List<WebhookEventType> _events = []; |
| | 68 | | private WebhookAuthenticationType _authenticationType; |
| | 69 | | private string? _apiKey; |
| | 70 | |
|
| | 71 | | protected override async Task OnInitializedAsync() |
| | 72 | | { |
| 0 | 73 | | _breakpoint = await BrowserViewportService.GetCurrentBreakpointAsync(); |
| 0 | 74 | | _width = _breakpoint == Breakpoint.Xs ? "100%" : "500px"; |
| 0 | 75 | | } |
| | 76 | |
|
| | 77 | | private void OnEventsChanged(IEnumerable<WebhookEventType> values) |
| | 78 | | { |
| 0 | 79 | | _events = values.ToList(); |
| 0 | 80 | | } |
| | 81 | |
|
| | 82 | | public async Task Open() |
| | 83 | | { |
| 0 | 84 | | _open = true; |
| 0 | 85 | | _name = null; |
| 0 | 86 | | _url = null; |
| 0 | 87 | | _events = []; |
| 0 | 88 | | _authenticationType = WebhookAuthenticationType.ApiKey; |
| 0 | 89 | | _apiKey = null; |
| | 90 | |
|
| 0 | 91 | | await _form?.ResetAsync(); |
| | 92 | |
|
| 0 | 93 | | _loading = false; |
| | 94 | |
|
| 0 | 95 | | StateHasChanged(); |
| 0 | 96 | | } |
| | 97 | |
|
| | 98 | | private void Close() |
| | 99 | | { |
| 0 | 100 | | _open = false; |
| 0 | 101 | | } |
| | 102 | |
|
| | 103 | | private async Task Submit() |
| | 104 | | { |
| 0 | 105 | | if (_loading) return; |
| | 106 | |
|
| 0 | 107 | | await _form.Validate(); |
| 0 | 108 | | if (!_form.IsValid) return; |
| | 109 | |
|
| 0 | 110 | | _loading = true; |
| 0 | 111 | | var response = await CreateWebhookSubscriptionClient.Create(_name!, _url!, _events, _authenticationType, _apiKey |
| 0 | 112 | | if (response.IsSuccess) |
| | 113 | | { |
| 0 | 114 | | Snackbar.Add("Webhook criado com sucesso!", Severity.Success); |
| 0 | 115 | | await AfterSubmit.InvokeAsync(); |
| 0 | 116 | | _open = false; |
| | 117 | | } |
| | 118 | | else |
| | 119 | | { |
| 0 | 120 | | Snackbar.Add(response.Error.Message, Severity.Error); |
| | 121 | | } |
| 0 | 122 | | _loading = false; |
| 0 | 123 | | } |
| | 124 | | } |