|
| 1 | +@page "/teams/{teamGuid:guid}/events/create" |
| 2 | + |
| 3 | +@rendermode InteractiveAuto |
| 4 | + |
| 5 | +@inherits CancellableComponent |
| 6 | + |
| 7 | +@using System.Text.Json |
| 8 | +@using BitzArt.Blazor.Cookies |
| 9 | + |
| 10 | +@inject NavigationManager NavigationManager |
| 11 | +@inject IToastService ToastService |
| 12 | +@inject EventService EventService |
| 13 | +@inject TeamService TeamService |
| 14 | + |
| 15 | +<PageTitle>Create Event</PageTitle> |
| 16 | + |
| 17 | +<div Class="body-small h-auto padding-large"> |
| 18 | + <h1 style="margin-bottom: 16px">Create Event</h1> |
| 19 | + |
| 20 | + <FluentDivider /> |
| 21 | + |
| 22 | + <FluentBreadcrumb Class="padding-small"> |
| 23 | + <FluentBreadcrumbItem Href="@($"/teams/{TeamGuid}")"> |
| 24 | + Team |
| 25 | + </FluentBreadcrumbItem> |
| 26 | + <FluentBreadcrumbItem> |
| 27 | + Cerate Event |
| 28 | + </FluentBreadcrumbItem> |
| 29 | + </FluentBreadcrumb> |
| 30 | + |
| 31 | + <FluentDivider /> |
| 32 | + |
| 33 | + <EditForm Model="@Input" OnValidSubmit="CreateEventAsync" FormName="CreateEventForm" Style="margin-top: 16px"> |
| 34 | + <CustomValidation @ref="ValidationComponent" /> |
| 35 | + |
| 36 | + <FluentStack Orientation="Orientation.Vertical"> |
| 37 | + <FluentCombobox TOption="EventTypeResponse" Items="EventTypes" Label="Event Type" Multiple="false" OptionText="x => x.Name" |
| 38 | + OptionValue="x => x.Id.Value.ToString()" SelectedOptionChanged="@(e => Input.EventTypeId = e.Id)" Required="true" /> |
| 39 | + |
| 40 | + <FluentTextField @bind-value="Input.Description" Immediate="true" Required="true" Placeholder="description" Label="Event Description" Class="w-100" /> |
| 41 | + <FluentValidationMessage For="() => Input.Description" Class="text-danger" /> |
| 42 | + |
| 43 | + <div> |
| 44 | + <FluentDatePicker Value="Input.FromUtc.Date" ValueChanged="@(e => Input.FromUtc = e!.Value.AddTicks(Input.FromUtc.TimeOfDay.Ticks))" Label="From" Required="true" /> |
| 45 | + <FluentTimePicker Value="Input.FromUtc" ValueChanged="@(e => Input.FromUtc = Input.FromUtc.Date.AddTicks(e!.Value.TimeOfDay.Ticks))" Required="true" /> |
| 46 | + </div> |
| 47 | + <FluentValidationMessage For="() => Input.FromUtc" Class="text-danger" /> |
| 48 | + |
| 49 | + <FluentTabs Class="w-100" @bind-ActiveTabId="eventDurationMethod"> |
| 50 | + <FluentTab Label="@($"Event Duration ({(int)(Input.ToUtc - Input.FromUtc).TotalMinutes} minutes)")" Id="tab-timespan" DeferredLoading="true"> |
| 51 | + <FluentSlider Orientation="Orientation.Horizontal" Min="60" Max="180" Step="15" TValue="double" Style="margin-top: 16px; margin-bottom: 32px" |
| 52 | + Value="@((int)(Input.ToUtc - Input.FromUtc).TotalMinutes)" ValueChanged="@(e => Input.ToUtc = Input.FromUtc.AddMinutes(e))"> |
| 53 | + |
| 54 | + <FluentSliderLabel Position="60">1 h</FluentSliderLabel> |
| 55 | + <FluentSliderLabel Position="90">1.5 h</FluentSliderLabel> |
| 56 | + <FluentSliderLabel Position="120">2 h</FluentSliderLabel> |
| 57 | + <FluentSliderLabel Position="150">2.5 h</FluentSliderLabel> |
| 58 | + <FluentSliderLabel Position="180">3 h</FluentSliderLabel> |
| 59 | + </FluentSlider> |
| 60 | + </FluentTab> |
| 61 | + <FluentTab Label="@($"To ({Input.ToUtc.ToLocalTime()})")" Id="tab-datetime" DeferredLoading="true"> |
| 62 | + <div> |
| 63 | + <FluentDatePicker Value="Input.ToUtc.Date" ValueChanged="@(e => Input.ToUtc = e!.Value.AddTicks(Input.ToUtc.TimeOfDay.Ticks))" /> |
| 64 | + <FluentTimePicker Value="Input.ToUtc" ValueChanged="@(e => Input.ToUtc = Input.ToUtc.Date.AddTicks(e!.Value.TimeOfDay.Ticks))" /> |
| 65 | + </div> |
| 66 | + <FluentValidationMessage For="() => Input.ToUtc" Class="text-danger" /> |
| 67 | + </FluentTab> |
| 68 | + </FluentTabs> |
| 69 | + |
| 70 | + |
| 71 | + <FluentSlider Orientation="Orientation.Horizontal" Label="@($"Meet Time: {(Input.FromUtc - Input.MeetTime).TimeOfDay.ToString("hh\\:mm\\:ss")} ({Input.MeetTime.TotalMinutes} minutes before the event)")" |
| 72 | + Min="0" Max="180" Step="5" TValue="double" Style="margin-bottom: 32px" |
| 73 | + Value="@(Input.MeetTime.TotalMinutes)" ValueChanged="@(e => Input.MeetTime = TimeSpan.FromMinutes(e))"> |
| 74 | + |
| 75 | + <FluentSliderLabel Position="0">0 m</FluentSliderLabel> |
| 76 | + <FluentSliderLabel Position="15">15 m</FluentSliderLabel> |
| 77 | + <FluentSliderLabel Position="30">30 m</FluentSliderLabel> |
| 78 | + <FluentSliderLabel Position="60">1 h</FluentSliderLabel> |
| 79 | + <FluentSliderLabel Position="120">2 h</FluentSliderLabel> |
| 80 | + <FluentSliderLabel Position="180">3 h</FluentSliderLabel> |
| 81 | + </FluentSlider> |
| 82 | + <FluentValidationMessage For="() => Input.MeetTime" Class="text-danger" /> |
| 83 | + |
| 84 | + <FluentSlider Orientation="Orientation.Horizontal" Label="@($"Reply Close Time: {(Input.FromUtc - Input.MeetTime - Input.ReplyClosingTimeBeforeMeetTime).TimeOfDay.ToString("hh\\:mm\\:ss")} ({Input.ReplyClosingTimeBeforeMeetTime.TotalMinutes} minutes before meet time)")" |
| 85 | + Min="0" Max="180" Step="5" TValue="double" Style="margin-bottom: 32px" |
| 86 | + Value="@(Input.ReplyClosingTimeBeforeMeetTime.TotalMinutes)" |
| 87 | + ValueChanged="@(e => Input.ReplyClosingTimeBeforeMeetTime = TimeSpan.FromMinutes(e))"> |
| 88 | + |
| 89 | + <FluentSliderLabel Position="0">0 m</FluentSliderLabel> |
| 90 | + <FluentSliderLabel Position="15">15 m</FluentSliderLabel> |
| 91 | + <FluentSliderLabel Position="30">30 m</FluentSliderLabel> |
| 92 | + <FluentSliderLabel Position="60">1 h</FluentSliderLabel> |
| 93 | + <FluentSliderLabel Position="120">2 h</FluentSliderLabel> |
| 94 | + <FluentSliderLabel Position="180">3 h</FluentSliderLabel> |
| 95 | + </FluentSlider> |
| 96 | + <FluentValidationMessage For="() => Input.ReplyClosingTimeBeforeMeetTime" Class="text-danger" /> |
| 97 | + |
| 98 | + <FluentButton Type="ButtonType.Submit" Appearance="Appearance.Accent" Style="margin-top: 8px">Create</FluentButton> |
| 99 | + </FluentStack> |
| 100 | + </EditForm> |
| 101 | +</div> |
| 102 | + |
| 103 | +@code |
| 104 | +{ |
| 105 | + private string eventDurationMethod = "tab-timespan"; |
| 106 | + |
| 107 | + [Parameter] |
| 108 | + public Guid TeamGuid { get; init; } = default!; |
| 109 | + |
| 110 | + [SupplyParameterFromForm] |
| 111 | + private CreateEventRequest Input { get; set; } = new() |
| 112 | + { |
| 113 | + Description = "", |
| 114 | + EventTypeId = null!, |
| 115 | + FromUtc = DateTime.Now, |
| 116 | + ToUtc = DateTime.Now.AddHours(1), |
| 117 | + MeetTime = TimeSpan.FromMinutes(15), |
| 118 | + ReplyClosingTimeBeforeMeetTime = TimeSpan.FromMinutes(15), |
| 119 | + }; |
| 120 | + |
| 121 | + private List<EventTypeResponse>? EventTypes = null; |
| 122 | + |
| 123 | + private CustomValidation ValidationComponent { get; set; } = null!; |
| 124 | + |
| 125 | + protected override async Task OnInitializedAsync() |
| 126 | + { |
| 127 | + var teamId = TeamId.FromGuid(TeamGuid); |
| 128 | + var teamResult = await TeamService.GetEventTypesAsync(teamId, false, CTS.Token); |
| 129 | + if (teamResult.IsSuccess) |
| 130 | + { |
| 131 | + EventTypes = teamResult.Value; |
| 132 | + } |
| 133 | + } |
| 134 | + |
| 135 | + public async Task CreateEventAsync() |
| 136 | + { |
| 137 | + var teamId = TeamId.FromGuid(TeamGuid); |
| 138 | + |
| 139 | + var result = await EventService.CreateEventAsync(teamId, Input, CTS.Token); |
| 140 | + if (result.IsFailure) |
| 141 | + { |
| 142 | + if (result.Error is ApiValidationError error) |
| 143 | + { |
| 144 | + ValidationComponent.DisplayErrors(error.Errors); |
| 145 | + } |
| 146 | + |
| 147 | + ToastService.ShowError(result.Error.Message); |
| 148 | + return; |
| 149 | + } |
| 150 | + |
| 151 | + ToastService.ShowSuccess("Event has been successfully created."); |
| 152 | + NavigationManager.NavigateTo($"/teams/{teamId.Value}/events/{result.Value.Value}"); |
| 153 | + } |
| 154 | +} |
0 commit comments