| | 1 | | @namespace Syki.Front.Features.Academic.CreateNotification |
| | 2 | |
|
| | 3 | | <MudDialog Class="pb-2"> |
| | 4 | | <TitleContent> |
| | 5 | | <MudText Typo="Typo.h6"> |
| | 6 | | <MudIcon Icon="@Icons.Material.Filled.Add" Class="mr-1 mb-n1" /> |
| | 7 | | Nova Notificação |
| | 8 | | </MudText> |
| | 9 | | </TitleContent> |
| | 10 | | <DialogContent> |
| 0 | 11 | | <MudForm @ref="@_form" Class="pt-1"> |
| 0 | 12 | | <SykiTextField Label="Título" AutoFocus="true" @bind-Value="@_title" /> |
| 0 | 13 | | <SykiTextField Label="Descrição" @bind-Value="@_description" /> |
| 0 | 14 | | <MudSelect |
| 0 | 15 | | Dense="true" |
| 0 | 16 | | Margin="Margin.Dense" |
| | 17 | | Variant="Variant.Outlined" |
| | 18 | | Class="mb-4" |
| | 19 | | @bind-Value="@_targetUsers" |
| | 20 | | Label="Usuários" |
| | 21 | | Required="true" |
| | 22 | | RequiredError="Informe!" |
| | 23 | | AdornmentColor="Color.Primary" |
| | 24 | | > |
| 0 | 25 | | @foreach (UsersGroup? item in Enum.GetValues<UsersGroup>()) |
| | 26 | | { |
| | 27 | | <MudSelectItem Value="@item">@item.GetDescription()</MudSelectItem> |
| | 28 | | } |
| | 29 | | </MudSelect> |
| | 30 | | <MudStack Row="true" AlignItems="AlignItems.Center" Spacing="1" Class="pl-0"> |
| | 31 | | <MudCheckBox @bind-Value="@_timeless" Label="Notificar novos usuários?" Color="Color.Primary" /> |
| | 32 | | <MudTooltip Text="Se marcado, usuários criados após a notificação também irão recebê-la." Arrow="true" P |
| | 33 | | <MudIconButton Icon="@Icons.Material.Filled.Info" Size="Size.Small" /> |
| | 34 | | </MudTooltip> |
| | 35 | | </MudStack> |
| | 36 | | </MudForm> |
| | 37 | | </DialogContent> |
| | 38 | | <DialogActions> |
| | 39 | | <DialogCancelButton OnClick="@Cancel" /> |
| | 40 | | <SykiProgressCircular Loading="@_loading" /> |
| | 41 | | <DialogSaveButton OnClick="@Submit" /> |
| | 42 | | </DialogActions> |
| | 43 | | </MudDialog> |
| | 44 | |
|
| | 45 | | @inject ISnackbar Snackbar |
| | 46 | | @inject CreateNotificationClient Client |
| | 47 | |
|
| | 48 | | @code |
| | 49 | | { |
| | 50 | | [CascadingParameter] |
| 0 | 51 | | MudDialogInstance MudDialog { get; set; } |
| | 52 | |
|
| | 53 | | private MudForm _form; |
| | 54 | | private bool _loading; |
| | 55 | |
|
| | 56 | | private string _title; |
| | 57 | | private string _description; |
| | 58 | | private UsersGroup? _targetUsers; |
| | 59 | | private bool _timeless; |
| | 60 | |
|
| | 61 | | private async Task Submit() |
| | 62 | | { |
| 0 | 63 | | if (_loading) return; |
| | 64 | |
|
| 0 | 65 | | await _form.Validate(); |
| 0 | 66 | | if (!_form.IsValid) return; |
| | 67 | |
|
| 0 | 68 | | _loading = true; |
| 0 | 69 | | var response = await Client.Create(_title, _description, _targetUsers!.Value, _timeless); |
| 0 | 70 | | if (response.IsSuccessStatusCode) |
| | 71 | | { |
| 0 | 72 | | MudDialog.Close(DialogResult.Ok(true)); |
| 0 | 73 | | Snackbar.Add("Notificação cadastrada com sucesso!", Severity.Success); |
| | 74 | | } |
| | 75 | | else |
| | 76 | | { |
| 0 | 77 | | var error = await response.ToError(); |
| 0 | 78 | | Snackbar.Add(error.Message, Severity.Error); |
| | 79 | | } |
| 0 | 80 | | _loading = false; |
| 0 | 81 | | } |
| | 82 | |
|
| 0 | 83 | | private void Cancel() => MudDialog.Cancel(); |
| | 84 | | } |