-
Notifications
You must be signed in to change notification settings - Fork 210
Remove: BillingPlan hardcoded constant #2737
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: billing-sdk-refactor
Are you sure you want to change the base?
Changes from all commits
5b0fd91
69baca8
05cfdd2
4c47118
0804f64
5b652af
aa06130
54b00a6
cf68297
f9e2510
ea6084f
d5e5b93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,26 +2,19 @@ | |
| import { base } from '$app/paths'; | ||
| import { page } from '$app/state'; | ||
| import { Click, trackEvent } from '$lib/actions/analytics'; | ||
| import { BillingPlan } from '$lib/constants'; | ||
| import { Button } from '$lib/elements/forms'; | ||
| import { HeaderAlert } from '$lib/layout'; | ||
| import { | ||
| hideBillingHeaderRoutes, | ||
| readOnly, | ||
| billingIdToPlan, | ||
| upgradeURL | ||
| } from '$lib/stores/billing'; | ||
| import { hideBillingHeaderRoutes, readOnly, upgradeURL } from '$lib/stores/billing'; | ||
| import { organization } from '$lib/stores/organization'; | ||
| </script> | ||
|
|
||
| {#if $organization?.$id && $organization?.billingPlan === BillingPlan.FREE && $readOnly && !hideBillingHeaderRoutes.includes(page.url.pathname)} | ||
| {#if $organization?.$id && !$organization?.billingPlanDetails.usage && $readOnly && !hideBillingHeaderRoutes.includes(page.url.pathname)} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make sure properly with test that negation in conditions are all tested correctly. these are all very complex conditions |
||
| <HeaderAlert | ||
| type="error" | ||
| title={`${$organization.name} usage has reached the ${billingIdToPlan($organization.billingPlan).name} plan limit`}> | ||
| title={`${$organization.name} usage has reached the ${$organization.billingPlanDetails.name} plan limit`}> | ||
| <svelte:fragment> | ||
| Usage for the <b>{$organization.name}</b> organization has reached the limits of the {billingIdToPlan( | ||
| $organization.billingPlan | ||
| ).name} | ||
| Usage for the <b>{$organization.name}</b> organization has reached the limits of the {$organization | ||
| .billingPlanDetails.name} | ||
| plan. Consider upgrading to increase your resource usage. | ||
| </svelte:fragment> | ||
| <svelte:fragment slot="buttons"> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,41 +1,60 @@ | ||
| <script lang="ts"> | ||
| import { BillingPlan } from '$lib/constants'; | ||
| import { LabelCard } from '..'; | ||
| import { page } from '$app/state'; | ||
| import { formatCurrency } from '$lib/helpers/numbers'; | ||
| import { currentPlan, organization } from '$lib/stores/organization'; | ||
| import { BillingPlanGroup, type Models } from '@appwrite.io/console'; | ||
| import { Badge, Layout, Tooltip, Typography } from '@appwrite.io/pink-svelte'; | ||
| import { LabelCard } from '..'; | ||
| import { page } from '$app/state'; | ||
| import type { Models } from '@appwrite.io/console'; | ||
| import { billingIdToPlan } from '$lib/stores/billing'; | ||
| export let billingPlan: string; | ||
| export let isNewOrg = false; | ||
| export let selfService = true; | ||
| export let anyOrgFree = false; | ||
| let { | ||
| isNewOrg = false, | ||
| selfService = true, | ||
| anyOrgFree = false, | ||
| selectedBillingPlan = $bindable() | ||
| }: { | ||
| isNewOrg?: boolean; | ||
| selfService?: boolean; | ||
| anyOrgFree?: boolean; | ||
| selectedBillingPlan: Models.BillingPlan; | ||
| } = $props(); | ||
| $: plans = Object.values(page.data.plans.plans) as Models.BillingPlan[]; | ||
| $: currentPlanInList = plans.some((plan) => plan.$id === $currentPlan?.$id); | ||
| let selectedPlan = $state(selectedBillingPlan.$id); | ||
| const plans = $derived(Object.values(page.data.plans.plans) as Models.BillingPlan[]); | ||
| const currentPlanInList = $derived(plans.some((plan) => plan.$id === $currentPlan?.$id)); | ||
| // experiment to remove scale plan temporarily | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. after latest changes this should be hidden from BE |
||
| $: plansWithoutScale = plans.filter((plan) => plan.$id != BillingPlan.SCALE); | ||
| const plansWithoutScale = $derived( | ||
| plans.filter((plan) => plan.group != BillingPlanGroup.Scale) | ||
| ); | ||
| function shouldShowTooltip(plan: Models.BillingPlan) { | ||
| if (plan.$id !== BillingPlan.FREE) return true; | ||
| if (plan.group !== BillingPlanGroup.Starter) return true; | ||
| else return !anyOrgFree; | ||
| } | ||
| function shouldDisable(plan: Models.BillingPlan) { | ||
| return plan.group === BillingPlanGroup.Starter && anyOrgFree; | ||
| } | ||
| $effect(() => { | ||
| selectedBillingPlan = billingIdToPlan(selectedPlan); | ||
| }); | ||
| </script> | ||
|
|
||
| <Layout.Stack> | ||
| {#each plansWithoutScale as plan} | ||
| <Tooltip disabled={shouldShowTooltip(plan)} maxWidth="fit-content"> | ||
| <LabelCard | ||
| name="plan" | ||
| bind:group={billingPlan} | ||
| disabled={!selfService || (plan.$id === BillingPlan.FREE && anyOrgFree)} | ||
| tooltipShow={plan.$id === BillingPlan.FREE && anyOrgFree} | ||
| bind:group={selectedPlan} | ||
| disabled={!selfService || shouldDisable(plan)} | ||
| tooltipShow={shouldDisable(plan)} | ||
| value={plan.$id} | ||
| title={plan.name}> | ||
| <svelte:fragment slot="action"> | ||
| {#if $organization?.billingPlan === plan.$id && !isNewOrg} | ||
| {#if $organization?.billingPlanId === plan.$id && !isNewOrg} | ||
| <Badge variant="secondary" size="xs" content="Current plan" /> | ||
| {/if} | ||
| </svelte:fragment> | ||
|
|
@@ -57,11 +76,11 @@ | |
| {#if $currentPlan && !currentPlanInList} | ||
| <LabelCard | ||
| name="plan" | ||
| bind:group={billingPlan} | ||
| bind:group={selectedPlan} | ||
| value={$currentPlan.$id} | ||
| title={$currentPlan.name}> | ||
| <svelte:fragment slot="action"> | ||
| {#if $organization?.billingPlan === $currentPlan.$id && !isNewOrg} | ||
| {#if $organization?.billingPlanId === $currentPlan.$id && !isNewOrg} | ||
| <Badge variant="secondary" size="xs" content="Current plan" /> | ||
| {/if} | ||
| </svelte:fragment> | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why two components selectPlan and planSelection? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix comment.