71 lines
1.9 KiB
Plaintext
71 lines
1.9 KiB
Plaintext
@page "/checkout"
|
|
@attribute [Authorize]
|
|
@inject OrderState OrderState
|
|
@inject OrdersClient OrdersClient
|
|
@inject NavigationManager NavigationManager
|
|
@inject IJSRuntime JSRuntime
|
|
|
|
<div class="main">
|
|
<EditForm Model="OrderState.Order.DeliveryAddress" OnValidSubmit="PlaceOrder">
|
|
<div class="checkout-cols">
|
|
<div class="checkout-order-details">
|
|
<h4>Bestellung überprüfen</h4>
|
|
<OrderReview Order="OrderState.Order" />
|
|
</div>
|
|
|
|
<div class="checkout-delivery-address">
|
|
<h4>Lieferaddresse...</h4>
|
|
<AddressEditor Address="OrderState.Order.DeliveryAddress" />
|
|
</div>
|
|
</div>
|
|
|
|
<button type="submit" class="checkout-button btn btn-warning" disabled="@isSubmitting">
|
|
Bestellen
|
|
</button>
|
|
|
|
<DataAnnotationsValidator />
|
|
</EditForm>
|
|
</div>
|
|
|
|
@code {
|
|
bool isSubmitting;
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
// In the background, ask if they want to be notified about order updates
|
|
_ = RequestNotificationSubscriptionAsync();
|
|
}
|
|
|
|
async Task RequestNotificationSubscriptionAsync()
|
|
{
|
|
var subscription = await JSRuntime.InvokeAsync<NotificationSubscription>("blazorPushNotifications.requestSubscription");
|
|
if (subscription != null)
|
|
{
|
|
try
|
|
{
|
|
await OrdersClient.SubscribeToNotifications(subscription);
|
|
}
|
|
catch (AccessTokenNotAvailableException ex)
|
|
{
|
|
ex.Redirect();
|
|
}
|
|
}
|
|
}
|
|
|
|
async Task PlaceOrder()
|
|
{
|
|
isSubmitting = true;
|
|
|
|
try
|
|
{
|
|
var newOrderId = await OrdersClient.PlaceOrder(OrderState.Order);
|
|
OrderState.ResetOrder();
|
|
NavigationManager.NavigateTo($"myorders/{newOrderId}");
|
|
}
|
|
catch (AccessTokenNotAvailableException ex)
|
|
{
|
|
ex.Redirect();
|
|
}
|
|
}
|
|
}
|