| | 1 | | @namespace Syki.Front.Features.Academic.CreateCampus |
| | 2 | |
|
| | 3 | | <MudDialog Class="pb-2"> |
| | 4 | | <TitleContent> |
| | 5 | | <SykiDialogTitle Text="Novo Campus" /> |
| | 6 | | </TitleContent> |
| | 7 | | <DialogContent> |
| 0 | 8 | | <MudForm @ref="@_form"> |
| 0 | 9 | | <SykiTextField Label="Nome" AutoFocus="true" @bind-Value="@_name" /> |
| 0 | 10 | | <SykiTextField Label="Cidade" @bind-Value="@_city" /> |
| 0 | 11 | | </MudForm> |
| 0 | 12 | | </DialogContent> |
| 0 | 13 | | <DialogActions> |
| | 14 | | <DialogCancelButton OnClick="@Cancel" /> |
| | 15 | | <SykiProgressCircular Loading="@_loading" /> |
| | 16 | | <DialogSaveButton OnClick="@Submit" /> |
| | 17 | | </DialogActions> |
| | 18 | | </MudDialog> |
| | 19 | |
|
| | 20 | | @inject ISnackbar Snackbar |
| | 21 | | @inject CreateCampusClient Client |
| | 22 | |
|
| | 23 | | @code |
| | 24 | | { |
| | 25 | | [CascadingParameter] |
| 0 | 26 | | MudDialogInstance MudDialog { get; set; } |
| | 27 | |
|
| | 28 | | private MudForm _form; |
| | 29 | | private bool _loading; |
| | 30 | | private string _name; |
| | 31 | | private string _city; |
| | 32 | |
|
| | 33 | | private async Task Submit() |
| | 34 | | { |
| 0 | 35 | | if (_loading) return; |
| | 36 | |
|
| 0 | 37 | | await _form.Validate(); |
| 0 | 38 | | if (!_form.IsValid) return; |
| | 39 | |
|
| 0 | 40 | | _loading = true; |
| 0 | 41 | | var response = await Client.Create(_name, _city); |
| 0 | 42 | | if (response.IsSuccessStatusCode) |
| | 43 | | { |
| 0 | 44 | | MudDialog.Close(DialogResult.Ok(true)); |
| 0 | 45 | | Snackbar.Add("Campus cadastrado com sucesso!", Severity.Success); |
| | 46 | | } |
| | 47 | | else |
| | 48 | | { |
| 0 | 49 | | var error = await response.ToError(); |
| 0 | 50 | | Snackbar.Add(error.Message, Severity.Error); |
| | 51 | | } |
| 0 | 52 | | _loading = false; |
| 0 | 53 | | } |
| | 54 | |
|
| 0 | 55 | | private void Cancel() => MudDialog.Cancel(); |
| | 56 | | } |