Skip to content

Commit 6fa9e30

Browse files
committed
address some comments.
1 parent 331f794 commit 6fa9e30

3 files changed

Lines changed: 51 additions & 51 deletions

File tree

src/lib/components/billing/planSelection.svelte

Lines changed: 47 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,27 @@
2424
tierOptions?: { value: string; label: string; badge?: string }[];
2525
};
2626
27-
// filter, group, and sort plans
2827
$: groupedPlans = (() => {
2928
const plans = Object.values(page.data.plans.plans) as Plan[];
29+
const groups = filterAndGroupPlans(plans);
30+
return buildPlanGroups(groups);
31+
})();
32+
33+
$: currentPlanInList = Object.values(page.data.plans.plans).some(
34+
(plan: Plan) => plan.$id === $currentPlan?.$id
35+
);
36+
37+
$: {
38+
for (const group of groupedPlans) {
39+
if (group.isGrouped) {
40+
selectedTiers[group.key] = getDefaultTierForGroup(group);
41+
}
42+
}
43+
}
44+
45+
function filterAndGroupPlans(plans: Plan[]): Map<string, Plan[]> {
3046
const groups = new Map<string, Plan[]>();
3147
32-
// Filter and group in one pass
3348
for (const plan of plans) {
3449
if (plan.$id === BillingPlan.SCALE) continue;
3550
@@ -42,58 +57,48 @@
4257
}
4358
}
4459
45-
// convert to array and process groups
60+
return groups;
61+
}
62+
63+
function buildPlanGroups(groups: Map<string, Plan[]>): PlanGroup[] {
4664
return Array.from(groups.entries())
4765
.map(([key, groupPlans]) => {
4866
const isGrouped = groupPlans.length > 1;
4967
const group: PlanGroup = { key, plans: groupPlans, isGrouped };
5068
51-
// pre-compute tier options for grouped plans
5269
if (isGrouped) {
53-
group.tierOptions = groupPlans.map((plan) => ({
54-
value: plan.$id,
55-
label: getTierLabel(plan),
56-
badge: $organization?.billingPlan === plan.$id ? 'Current' : undefined
57-
}));
70+
group.tierOptions = buildTierOptions(groupPlans);
5871
}
5972
6073
return group;
6174
})
6275
.sort((a, b) => (a.plans[0]?.order ?? 0) - (b.plans[0]?.order ?? 0));
63-
})();
76+
}
6477
65-
$: currentPlanInList = Object.values(page.data.plans.plans).some(
66-
(plan: Plan) => plan.$id === $currentPlan?.$id
67-
);
78+
function buildTierOptions(plans: Plan[]): { value: string; label: string; badge?: string }[] {
79+
return plans.map((plan) => ({
80+
value: plan.$id,
81+
label: getPlanLabel(plan),
82+
badge: $organization?.billingPlan === plan.$id ? 'Current' : undefined
83+
}));
84+
}
6885
69-
$: {
70-
for (const group of groupedPlans) {
71-
if (group.isGrouped) {
72-
// check if billingPlan is in this group
73-
const selectedGroupPlan = group.plans.find((p) => p.$id === billingPlan);
74-
if (selectedGroupPlan) {
75-
selectedTiers[group.key] = selectedGroupPlan.$id;
76-
} else {
77-
// If billingPlan not in group, check organization's current plan
78-
const orgCurrentPlan = group.plans.find(
79-
(p) => p.$id === $organization?.billingPlan
80-
);
81-
if (orgCurrentPlan) {
82-
selectedTiers[group.key] = orgCurrentPlan.$id;
83-
} else if (!selectedTiers[group.key]) {
84-
// default to first plan in group
85-
selectedTiers[group.key] = group.plans[0].$id;
86-
}
87-
}
88-
}
86+
function getDefaultTierForGroup(group: PlanGroup): string {
87+
// billingPlan if in group, else org's current plan, else first plan
88+
const selectedGroupPlan = group.plans.find((p) => p.$id === billingPlan);
89+
if (selectedGroupPlan) {
90+
return selectedGroupPlan.$id;
8991
}
90-
}
9192
92-
function handleTierChange(group: PlanGroup) {
93-
billingPlan = selectedTiers[group.key] as BillingPlan;
93+
const orgCurrentPlan = group.plans.find((p) => p.$id === $organization?.billingPlan);
94+
if (orgCurrentPlan) {
95+
return orgCurrentPlan.$id;
96+
}
97+
98+
return selectedTiers[group.key] || group.plans[0].$id;
9499
}
95100
96-
function message(plan: Plan): string {
101+
function getPlanLabel(plan: Plan): string {
97102
const price = formatCurrency(plan?.price ?? 0);
98103
if (resolvedProfile.id === ProfileMode.STUDIO) {
99104
if (plan.limits?.dailyCredits) {
@@ -105,16 +110,8 @@
105110
return `${price} per month`;
106111
}
107112
108-
function getTierLabel(plan: Plan): string {
109-
const price = formatCurrency(plan?.price ?? 0);
110-
if (resolvedProfile.id === ProfileMode.STUDIO) {
111-
if (plan.limits?.dailyCredits) {
112-
return `${plan.limits.dailyCredits.toLocaleString()} daily credits for ${price} per month`;
113-
} else if (plan.limits?.credits) {
114-
return `${plan.limits.credits.toLocaleString()} credits per month for ${price}`;
115-
}
116-
}
117-
return `${price} per month`;
113+
function handleTierChange(group: PlanGroup) {
114+
billingPlan = selectedTiers[group.key] as BillingPlan;
118115
}
119116
</script>
120117

@@ -145,9 +142,9 @@
145142
{@const isZeroPrice = (basePlan.price ?? 0) <= 0}
146143
{@const price = formatCurrency(basePlan.price ?? 0)}
147144
{#if resolvedProfile.id === ProfileMode.STUDIO}
148-
{message(basePlan)}
145+
{getPlanLabel(basePlan)}
149146
{:else}
150-
{isZeroPrice ? price : message(basePlan)}
147+
{isZeroPrice ? price : getPlanLabel(basePlan)}
151148
{/if}
152149
</Typography.Text>
153150
{/if}
@@ -183,7 +180,7 @@
183180
<Typography.Text>
184181
{@const isZeroPrice = ($currentPlan?.price ?? 0) <= 0}
185182
{@const price = formatCurrency($currentPlan?.price ?? 0)}
186-
{isZeroPrice ? price : message($currentPlan)}
183+
{isZeroPrice ? price : getPlanLabel($currentPlan)}
187184
</Typography.Text>
188185
</LabelCard>
189186
{/if}

src/lib/components/support.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
cta: 'Discord',
5656
showSupport: false,
5757
label: 'Community support',
58-
link: `${resolvedProfile.website}/discord`,
58+
link: `${resolvedProfile.discord}`,
5959
description: 'Get support from our community through Discord'
6060
},
6161
...(!resolvedProfile.showGithubIssueSupport

src/lib/profiles/index.svelte.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export type Profile = {
4444
sites: boolean;
4545
settings: boolean;
4646
};
47+
discord: string;
4748
website: string;
4849
showOrgInBreadcrumbs: boolean;
4950
minimalOrgHeader: boolean;
@@ -86,6 +87,7 @@ export const base: Profile = {
8687
sites: true,
8788
settings: true
8889
},
90+
discord: 'https://appwrite.io/discord',
8991
website: 'https://appwrite.io',
9092
showOrgInBreadcrumbs: true,
9193
minimalOrgHeader: false,
@@ -131,6 +133,7 @@ export const studio: Profile = {
131133
settings: true
132134
},
133135
website: 'https://imagine.dev',
136+
discord: 'https://imagine.dev/discord',
134137
showOrgInBreadcrumbs: false,
135138
minimalOrgHeader: true,
136139
getProjectRoute({ region, project }) {

0 commit comments

Comments
 (0)