| | 1 | | @namespace Syki.Front.Features.Academic.CreateEnrollmentPeriod |
| | 2 | |
|
| | 3 | | <MudDialog Class="pb-2" Style="min-height: 450px"> |
| | 4 | | <TitleContent> |
| | 5 | | <MudText Typo="Typo.h6"> |
| | 6 | | <MudIcon Icon="@Icons.Material.Filled.Add" Class="mr-1 mb-n1" /> |
| | 7 | | Novo Período de Matrícula |
| | 8 | | </MudText> |
| | 9 | | </TitleContent> |
| | 10 | | <DialogContent> |
| 0 | 11 | | <MudForm @ref="@_form" Class="py-1"> |
| 0 | 12 | | <MudGrid Spacing="2"> |
| 0 | 13 | | <MudItem xs="12"> |
| 0 | 14 | | <MudSelect |
| 0 | 15 | | Dense="true" |
| 0 | 16 | | AutoFocus="true" |
| | 17 | | Margin="Margin.Dense" |
| | 18 | | Variant="Variant.Outlined" |
| | 19 | | Class="mb-4" |
| | 20 | | @bind-Value="@_id" |
| | 21 | | Label="Período Acadêmico" |
| | 22 | | Required="true" |
| | 23 | | RequiredError="Informe!" |
| | 24 | | AdornmentColor="Color.Primary" |
| | 25 | | > |
| 0 | 26 | | @foreach (string? item in _periods.ConvertAll(p => p.Id)) |
| | 27 | | { |
| | 28 | | <MudSelectItem Value="@item">@item</MudSelectItem> |
| | 29 | | } |
| | 30 | | </MudSelect> |
| | 31 | | </MudItem> |
| | 32 | | <MudItem xs="12"> |
| | 33 | | <SykiDatePicker Label="Início" @bind-Date="@_start" Editable="false" /> |
| | 34 | | </MudItem> |
| | 35 | | <MudItem xs="12"> |
| | 36 | | <SykiDatePicker Label="Fim" @bind-Date="@_end" Editable="false" /> |
| | 37 | | </MudItem> |
| | 38 | | </MudGrid> |
| | 39 | | </MudForm> |
| | 40 | | </DialogContent> |
| | 41 | | <DialogActions> |
| | 42 | | <DialogCancelButton OnClick="@Cancel" /> |
| | 43 | | <SykiProgressCircular Loading="@_loading" /> |
| | 44 | | <DialogSaveButton OnClick="@Submit" /> |
| | 45 | | </DialogActions> |
| | 46 | | </MudDialog> |
| | 47 | |
|
| | 48 | | @inject ISnackbar Snackbar |
| | 49 | | @inject GetAcademicPeriodsClient GetClient |
| | 50 | | @inject CreateEnrollmentPeriodClient CreateClient |
| | 51 | |
|
| | 52 | | @code |
| | 53 | | { |
| | 54 | | [CascadingParameter] |
| 0 | 55 | | MudDialogInstance MudDialog { get; set; } |
| | 56 | |
|
| | 57 | | private MudForm _form; |
| | 58 | | private bool _loading; |
| | 59 | |
|
| | 60 | | private string _id; |
| | 61 | | private DateTime? _start; |
| | 62 | | private DateTime? _end; |
| | 63 | |
|
| 0 | 64 | | List<AcademicPeriodOut> _periods = []; |
| | 65 | |
|
| | 66 | | protected override async Task OnInitializedAsync() |
| | 67 | | { |
| 0 | 68 | | _periods = await GetClient.Get(); |
| 0 | 69 | | } |
| | 70 | |
|
| | 71 | | async Task Submit() |
| | 72 | | { |
| 0 | 73 | | if (_loading) return; |
| | 74 | |
|
| 0 | 75 | | await _form.Validate(); |
| 0 | 76 | | if (!_form.IsValid) return; |
| | 77 | |
|
| 0 | 78 | | var start = DateOnly.FromDateTime(_start!.Value); |
| 0 | 79 | | var end = DateOnly.FromDateTime(_end!.Value); |
| | 80 | |
|
| 0 | 81 | | _loading = true; |
| 0 | 82 | | var response = await CreateClient.Create(_id, start, end); |
| 0 | 83 | | if (response.IsSuccess()) |
| | 84 | | { |
| 0 | 85 | | MudDialog.Close(DialogResult.Ok(true)); |
| 0 | 86 | | Snackbar.Add("Período cadastrado com sucesso!", Severity.Success); |
| | 87 | | } |
| | 88 | | else |
| | 89 | | { |
| 0 | 90 | | Snackbar.Add(response.GetError().Message, Severity.Error); |
| | 91 | | } |
| 0 | 92 | | _loading = false; |
| 0 | 93 | | } |
| | 94 | |
|
| 0 | 95 | | void Cancel() => MudDialog.Cancel(); |
| | 96 | | } |