Skip to content

Fix: Show current plan in the select plan list #1702

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 47 additions & 2 deletions src/lib/components/billing/selectPlan.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,69 @@
import { BillingPlan } from '$lib/constants';
import { formatCurrency } from '$lib/helpers/numbers';
import { plansInfo } from '$lib/stores/billing';
import { organization } from '$lib/stores/organization';
import { currentPlan, organization } from '$lib/stores/organization';
import { LabelCard } from '..';

export let billingPlan: string;
export let anyOrgFree = false;
export let isNewOrg = false;
let classes: string = '';
export { classes as class };

let isCurrentPlanShown: boolean = false;

function currentPlanExists() {
let planFound = $plansInfo.values().find((plan) => plan.$id == $currentPlan?.$id);
if (planFound) {
return true;
}
return false;
}

$: isCurrentPlanShown = currentPlanExists();
</script>

{#if billingPlan}
<ul class="u-flex u-flex-vertical u-gap-16 u-margin-block-start-8 {classes}">
{#if !isCurrentPlanShown && $currentPlan}
<li>
<LabelCard
name="plan"
bind:group={billingPlan}
disabled={($currentPlan.$id === BillingPlan.FREE && anyOrgFree) ||
(!$currentPlan?.selfService && !isNewOrg)}
value={$currentPlan.$id}
tooltipShow={$currentPlan.$id === BillingPlan.FREE && anyOrgFree}
tooltipText={$currentPlan.$id === BillingPlan.FREE
? 'You are limited to 1 Free organization per account.'
: ''}
padding={1.5}>
<svelte:fragment slot="custom" let:disabled>
<div
class="u-flex u-flex-vertical u-gap-4 u-width-full-line"
class:u-opacity-50={disabled}>
<h4 class="body-text-2 u-bold">
{$currentPlan.name}
<span class="inline-tag">Current plan</span>
</h4>
<p class="u-color-text-offline u-small">
{$currentPlan.desc}
</p>
<p>
{formatCurrency($currentPlan?.price ?? 0)}
</p>
</div>
</svelte:fragment>
</LabelCard>
</li>
{/if}
{#each $plansInfo.values() as plan}
<li>
<LabelCard
name="plan"
bind:group={billingPlan}
disabled={(plan.$id === BillingPlan.FREE && anyOrgFree) || !plan.selfService}
disabled={(plan.$id === BillingPlan.FREE && anyOrgFree) ||
(!$currentPlan?.selfService && !isNewOrg)}
value={plan.$id}
tooltipShow={plan.$id === BillingPlan.FREE && anyOrgFree}
tooltipText={plan.$id === BillingPlan.FREE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@
await validate(organizationId, invites);
}
}
if ($currentPlan?.$id === BillingPlan.SCALE) {
billingPlan = BillingPlan.SCALE;
} else {
billingPlan = BillingPlan.PRO;
}

selfService = $currentPlan?.selfService ?? true;
});
Expand Down Expand Up @@ -274,8 +269,8 @@
}
}

$: isUpgrade = $plansInfo.get(billingPlan).order > $currentPlan.order;
$: isDowngrade = $plansInfo.get(billingPlan).order < $currentPlan.order;
$: isUpgrade = $plansInfo.get(billingPlan)?.order > $currentPlan.order;
$: isDowngrade = $plansInfo.get(billingPlan)?.order < $currentPlan.order;
$: if (billingPlan !== BillingPlan.FREE) {
loadPaymentMethods();
}
Expand Down