Skip to content

Commit

Permalink
Gateway page (#918)
Browse files Browse the repository at this point in the history
* Gateway page to HBP GitHub repo

* Gateway page to HBP GitHub repo - skip next time functionality

* Gateway page - text adj.

* review - simplification, fixes

---------

Co-authored-by: Robert Haken <haken@havit.cz>
  • Loading branch information
Harvey1214 and hakenr authored Oct 31, 2024
1 parent 27a3d80 commit aa4c10f
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 2 deletions.
24 changes: 24 additions & 0 deletions Havit.Blazor.Documentation/Pages/Premium/GatewayToPremium.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@page "/premium/access-content"

<HeadContent>
@GenerateHeadContent()
</HeadContent>

<h1>HAVIT Blazor Premium</h1>

<p class="lead">You are accessing content for Premium subscribers.</p>

<div class="hstack align-items-start gap-3">
<div>
<HxButton Text="Continue"
Size="ButtonSize.Large"
Color="ThemeColor.Primary"
OnClick="ContinueToPremiumContent" />
<HxCheckbox @bind-Value="_skipGatewayPage" Text="Skip this page next time" CssClass="mt-1" TextCssClass="small" />
</div>
<HxButton Text="How to get Premium"
Size="ButtonSize.Large"
Color="ThemeColor.Secondary"
Outline="true"
OnClick="LearnMoreAboutPremium" />
</div>
53 changes: 53 additions & 0 deletions Havit.Blazor.Documentation/Pages/Premium/GatewayToPremium.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Microsoft.JSInterop;

namespace Havit.Blazor.Documentation.Pages.Premium;

public partial class GatewayToPremium : IAsyncDisposable
{
[SupplyParameterFromQuery] public string Url { get; set; }

[Inject] private NavigationManager NavigationManager { get; set; }
[Inject] private IJSRuntime JSRuntime { get; set; }

private IJSObjectReference _jsModule;
private bool _skipGatewayPage = false;

private void LearnMoreAboutPremium()
{
NavigationManager.NavigateTo("/premium");
}

private async Task ContinueToPremiumContent()
{
if (_skipGatewayPage)
{
await EnsureJsModuleAsync();
await _jsModule.InvokeVoidAsync("setSkipGatewayPage", true);
}
NavigationManager.NavigateTo(Url);
}

private async Task EnsureJsModuleAsync()
{
_jsModule ??= await JSRuntime.ImportModuleAsync($"./Pages/Premium/{nameof(GatewayToPremium)}.razor.js");
}

private MarkupString GenerateHeadContent()
{
return (MarkupString)$$"""
<script>
if (document.cookie.split(';').some((item) => item.trim() === 'SkipGatewayPage=true')) {
window.location.href = '{{Url}}'
}
</script>
""";
}

public async ValueTask DisposeAsync()
{
if (_jsModule != null)
{
await _jsModule.DisposeAsync();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function setSkipGatewayPage(skipGatewayPage) {
const date = new Date();
date.setTime(date.getTime() + (60 * 24 * 60 * 60 * 1000)); // 60 days
document.cookie = "SkipGatewayPage=" + skipGatewayPage + "; expires = " + date.toGMTString() + "; path = /";
}
2 changes: 1 addition & 1 deletion Havit.Blazor.Documentation/Pages/Premium/GetPremium.razor
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<p class="fw-medium">Contact sales</p>
<div class="d-flex flex-column gap-2 opacity-75 mb-5 mt-2 small">
<strong>Tailor-made support for your team</strong>
<PlanItem Text="Regular team consulations (mentorship)" />
<PlanItem Text="Regular team consultations (mentorship)" />
<PlanItem Text="Custom components development" />
<PlanItem Text="Enterprise support" />
<PlanItem Text="Custom themes implementation" />
Expand Down
2 changes: 1 addition & 1 deletion Havit.Blazor.sln
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# 17
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Havit.Blazor.Components.Web", "Havit.Blazor.Components.Web\Havit.Blazor.Components.Web.csproj", "{DF1C423F-ACA1-446E-A9F1-099DFDF70D44}"
Expand Down

0 comments on commit aa4c10f

Please sign in to comment.