| | 1 | | @namespace Syki.Front.Features.Academic.CreateTeacher |
| | 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 | | Novo Professor |
| | 8 | | </MudText> |
| | 9 | | </TitleContent> |
| | 10 | | <DialogContent> |
| 0 | 11 | | <MudForm @ref="@_form" Class="pt-1"> |
| 0 | 12 | | <MudTextField |
| 0 | 13 | | OnlyValidateIfDirty="true" |
| 0 | 14 | | Immediate="true" |
| 0 | 15 | | Margin="Margin.Dense" |
| 0 | 16 | | Variant="Variant.Outlined" |
| | 17 | | Class="pb-2" |
| | 18 | | AutoFocus="true" |
| | 19 | | @bind-Value="@_name" |
| | 20 | | T="String" |
| | 21 | | Label="Nome" |
| | 22 | | Required="true" |
| | 23 | | RequiredError="Informe!" |
| | 24 | | /> |
| | 25 | | <MudTextField |
| | 26 | | OnlyValidateIfDirty="true" |
| | 27 | | Immediate="true" |
| | 28 | | Margin="Margin.Dense" |
| | 29 | | Variant="Variant.Outlined" |
| | 30 | | Class="mb-2" |
| | 31 | | @bind-Value="@_email" |
| | 32 | | T="String" |
| | 33 | | Label="Email" |
| | 34 | | Required="true" |
| | 35 | | RequiredError="Informe!" |
| | 36 | | /> |
| | 37 | | </MudForm> |
| | 38 | | </DialogContent> |
| | 39 | | <DialogActions> |
| | 40 | | <DialogCancelButton OnClick="@Cancel" /> |
| | 41 | | <SykiProgressCircular Loading="@_loading" /> |
| | 42 | | <DialogSaveButton OnClick="@Submit" /> |
| | 43 | | </DialogActions> |
| | 44 | | </MudDialog> |
| | 45 | |
|
| | 46 | | @inject ISnackbar Snackbar |
| | 47 | | @inject CreateTeacherClient Client |
| | 48 | |
|
| | 49 | | @code |
| | 50 | | { |
| | 51 | | [CascadingParameter] |
| 0 | 52 | | MudDialogInstance MudDialog { get; set; } |
| | 53 | |
|
| | 54 | | private MudForm _form; |
| | 55 | | private bool _loading; |
| | 56 | | private string _name; |
| | 57 | | private string _email; |
| | 58 | |
|
| | 59 | | async Task Submit() |
| | 60 | | { |
| 0 | 61 | | if (_loading) return; |
| | 62 | |
|
| 0 | 63 | | await _form.Validate(); |
| 0 | 64 | | if (!_form.IsValid) return; |
| | 65 | |
|
| 0 | 66 | | _loading = true; |
| 0 | 67 | | var response = await Client.Create(_name, _email); |
| 0 | 68 | | if (response.IsSuccess()) |
| | 69 | | { |
| 0 | 70 | | MudDialog.Close(DialogResult.Ok(true)); |
| 0 | 71 | | Snackbar.Add("Professor cadastrado com sucesso!", Severity.Success); |
| | 72 | | } |
| | 73 | | else |
| | 74 | | { |
| 0 | 75 | | Snackbar.Add(response.GetError().Message, Severity.Error); |
| | 76 | | } |
| 0 | 77 | | _loading = false; |
| 0 | 78 | | } |
| | 79 | |
|
| 0 | 80 | | void Cancel() => MudDialog.Cancel(); |
| | 81 | | } |