feat: campaigns

This commit is contained in:
Arman committed 2024-07-30 12:31:21 +02:00
1 parent 7b784ee2d5
commit c07941e699
2 files changed
+14 -6

No files matched your search

+7 -3
View File
@@ -1,11 +1,14 @@
//campaign welcome and startup
import { BillingPlan } from '$lib/constants';
export type CampaignData = {
title: string;
description: string;
template: 'card' | 'review';
data?: Record<string, unknown>;
onlyNewOrgs?: boolean;
plan?: BillingPlan;
footer?: boolean;
};
@@ -22,7 +25,7 @@ campaigns
template: 'card',
title: 'Welcome to the Startups program!',
description:
"We're excited to have you on board. Add the coupon code to your Appwrite Pro account to join."
"We're excited to have you on board. Add the coupon code to your Appwrite Scale account to join."
})
.set('RenderATL2024', {
template: 'card',
@@ -52,10 +55,11 @@ campaigns
template: 'review',
title: 'Welcome to the Startups program',
description:
"We're excited to have you on board. Add your credit code to your Appwrite Pro account to join.",
"We're excited to have you on board. Add your credit code to your Appwrite Scale account to join.",
onlyNewOrgs: true,
plan: BillingPlan.SCALE,
data: {
cta: 'Get everything out of Cloud with Pro',
cta: 'Get everything out of Cloud with Scale',
claimed: 'Your credits will be valid for 12 months.',
unclaimed: 'Apply your code to join the Startups program.',
reviews: [
+7 -3
View File
@@ -70,6 +70,7 @@
let coupon: string;
let couponData = data?.couponData;
let campaign = campaigns.get(data?.couponData?.campaign ?? data?.campaign);
let billingPlan = BillingPlan.PRO;
onMount(async () => {
await loadPaymentMethods();
@@ -80,6 +81,9 @@
selectedOrgId = $page.url.searchParams.get('org');
canSelectOrg = false;
}
if (campaign?.plan) {
billingPlan = campaign.plan;
}
});
async function loadPaymentMethods() {
@@ -101,15 +105,15 @@
org = await sdk.forConsole.billing.createOrganization(
newOrgId,
name,
BillingPlan.PRO,
billingPlan,
paymentMethodId
);
}
// Upgrade existing org
else if (selectedOrg?.billingPlan !== BillingPlan.PRO) {
else if (selectedOrg?.billingPlan === BillingPlan.FREE) {
org = await sdk.forConsole.billing.updatePlan(
selectedOrg.$id,
BillingPlan.PRO,
billingPlan,
paymentMethodId,
null
);