Skip to content

Commit

Permalink
Hide usage page when not available
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaHegde committed Jan 7, 2025
1 parent f27be46 commit fd68d34
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 5 additions & 2 deletions web-admin/src/routes/[organization]/-/settings/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,24 @@
export let data: PageData;
$: ({ subscription, neverSubscribed } = data);
$: ({ subscription, neverSubscribed, billingPortalUrl } = data);
$: organization = $page.params.organization;
$: basePage = `/${organization}/-/settings`;
$: onEnterprisePlan =
subscription?.plan && isEnterprisePlan(subscription?.plan);
$: hideBillingSettings = neverSubscribed;
$: hideUsageSettings = onEnterprisePlan || !billingPortalUrl;
$: console.log(subscription);
$: navItems = [
{ label: "General", route: "" },
...(hideBillingSettings
? []
: [
{ label: "Billing", route: "/billing" },
...(onEnterprisePlan ? [] : [{ label: "Usage", route: "/usage" }]),
...(hideUsageSettings ? [] : [{ label: "Usage", route: "/usage" }]),
]),
];
</script>
Expand Down
10 changes: 7 additions & 3 deletions web-admin/src/routes/[organization]/-/settings/usage/+page.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { isEnterprisePlan } from "@rilldata/web-admin/features/billing/plans/utils";
import { error } from "@sveltejs/kit";
import { error, redirect } from "@sveltejs/kit";
import type { PageLoad } from "./$types";

export const load: PageLoad = async ({ parent }) => {
const { subscription } = await parent();
export const load: PageLoad = async ({ params: { organization }, parent }) => {
const { subscription, billingPortalUrl } = await parent();

if (!billingPortalUrl) {
throw redirect(307, `/${organization}/-/settings`);
}

// Orgs on an Enterprise Plan should not see this page
if (subscription?.plan && isEnterprisePlan(subscription.plan)) {
Expand Down

0 comments on commit fd68d34

Please sign in to comment.