-
Notifications
You must be signed in to change notification settings - Fork 170
Expand file tree
/
Copy pathPlan.svelte
More file actions
63 lines (58 loc) · 2.7 KB
/
Plan.svelte
File metadata and controls
63 lines (58 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<script lang="ts">
import { createAdminServiceGetBillingSubscription } from "@rilldata/web-admin/client";
import CancelledTeamPlan from "@rilldata/web-admin/features/billing/plans/CancelledTeamPlan.svelte";
import EnterprisePlan from "@rilldata/web-admin/features/billing/plans/EnterprisePlan.svelte";
import FreePlan from "@rilldata/web-admin/features/billing/plans/FreePlan.svelte";
import ProPlan from "@rilldata/web-admin/features/billing/plans/ProPlan.svelte";
import POCPlan from "@rilldata/web-admin/features/billing/plans/POCPlan.svelte";
import TeamPlan from "@rilldata/web-admin/features/billing/plans/TeamPlan.svelte";
import TrialPlan from "@rilldata/web-admin/features/billing/plans/TrialPlan.svelte";
import {
isFreePlan,
isProPlan,
isManagedPlan,
isTeamPlan,
} from "@rilldata/web-admin/features/billing/plans/utils";
import { useCategorisedOrganizationBillingIssues } from "@rilldata/web-admin/features/billing/selectors";
export let organization: string;
export let showUpgradeDialog: boolean;
$: subscriptionQuery = createAdminServiceGetBillingSubscription(organization);
$: subscription = $subscriptionQuery?.data?.subscription;
$: hasPayment = !!$subscriptionQuery?.data?.organization?.paymentCustomerId;
$: plan = subscription?.plan;
$: categorisedIssues = useCategorisedOrganizationBillingIssues(organization);
// fresh orgs will have a never subscribed issue associated with it
$: neverSubbed = !!$categorisedIssues.data?.neverSubscribed;
// trial plan will have a trial issue associated with it
$: isTrial = !!$categorisedIssues.data?.trial;
// ended subscription will have a cancelled issue associated with it
$: subHasEnded = !!$categorisedIssues.data?.cancelled;
$: subIsFreePlan = plan && isFreePlan(plan.name);
$: subIsProPlan = plan && isProPlan(plan.name);
$: subIsTeamPlan = plan && isTeamPlan(plan.name);
$: subIsManagedPlan = plan && isManagedPlan(plan.name);
$: subIsEnterprisePlan =
plan &&
!isTrial &&
!subIsFreePlan &&
!subIsProPlan &&
!subIsTeamPlan &&
!subIsManagedPlan;
</script>
{#if neverSubbed}
<!-- TODO: once mocks are in. Right now we just disable the routes. -->
{:else if isTrial}
<TrialPlan {organization} {subscription} {showUpgradeDialog} {plan} />
{:else if subHasEnded}
<CancelledTeamPlan {organization} {showUpgradeDialog} {plan} />
{:else if subIsFreePlan}
<FreePlan {organization} {plan} />
{:else if subIsProPlan}
<ProPlan {organization} {subscription} {plan} />
{:else if subIsTeamPlan}
<TeamPlan {organization} {subscription} {plan} />
{:else if subIsManagedPlan}
<POCPlan {organization} {hasPayment} {plan} />
{:else if subIsEnterprisePlan}
<EnterprisePlan {organization} {plan} />
{/if}