mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
feat: add campaign constant, fix edge cases
This commit is contained in:
1 parent
5902d29f72
commit
af5d97aaba
7 files changed
+67
-34
No files matched your search
@@ -6,6 +6,7 @@
|
||||
import LoginLight from '$lib/images/login/login-light-mode.png';
|
||||
import type { Coupon } from '$lib/sdk/billing';
|
||||
import { app } from '$lib/stores/app';
|
||||
import { campaigns } from '$lib/stores/campaigns';
|
||||
import { user } from '$lib/stores/user';
|
||||
|
||||
export const imgLight = LoginLight;
|
||||
@@ -14,6 +15,7 @@
|
||||
export let coupon: Coupon = null;
|
||||
|
||||
$: variation = coupon?.code ? 'card' : 'default';
|
||||
$: campaign = campaigns.get(coupon.campaign);
|
||||
</script>
|
||||
|
||||
<main class="grid-1-1 is-full-page" id="main">
|
||||
@@ -60,11 +62,10 @@
|
||||
|
||||
<div class="u-text-center">
|
||||
<Heading size="3" tag="h3" class="u-margin-block-start-56" trimmed={false}>
|
||||
You've received ${coupon.credits} in credits
|
||||
{campaign.title.replace('VALUE', coupon.credits)}
|
||||
</Heading>
|
||||
<p class="body-text-1 u-margin-block-start-8">
|
||||
Get ${coupon.credits} in credits when you upgrade or create an organization with
|
||||
a Pro plan.
|
||||
{campaign.description.replace('VALUE', coupon.credits)}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
//campaign welcome and startup
|
||||
|
||||
export const campaigns = new Map();
|
||||
|
||||
campaigns
|
||||
.set('welcome', {
|
||||
title: "You've received $VALUE in credits",
|
||||
description:
|
||||
'Get $VALUE in credits when you upgrade or create an organization with a Pro plan.'
|
||||
})
|
||||
.set('startup', {
|
||||
title: "You've received $VALUE in credits",
|
||||
description:
|
||||
'Get $VALUE in credits when you upgrade or create an organization with a Pro plan.'
|
||||
});
|
||||
@@ -39,13 +39,14 @@
|
||||
let collaborators: string[];
|
||||
let taxId: string;
|
||||
let billingBudget: number;
|
||||
let newOrgId = ID.unique();
|
||||
let options = [
|
||||
...($organizationList?.teams?.map((team) => ({
|
||||
value: team.$id,
|
||||
label: team.name
|
||||
})) ?? []),
|
||||
{
|
||||
value: null,
|
||||
value: newOrgId,
|
||||
label: 'Create new organization'
|
||||
}
|
||||
];
|
||||
@@ -54,9 +55,7 @@
|
||||
onMount(async () => {
|
||||
await loadPaymentMethods();
|
||||
if (!$organizationList?.total) {
|
||||
selectedOrgId = null;
|
||||
} else {
|
||||
selectedOrgId = $organizationList?.teams[0]?.$id;
|
||||
selectedOrgId = newOrgId;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -75,7 +74,7 @@
|
||||
// Create new org
|
||||
if (!selectedOrgId) {
|
||||
org = await sdk.forConsole.billing.createOrganization(
|
||||
ID.unique(),
|
||||
newOrgId,
|
||||
name,
|
||||
BillingPlan.PRO,
|
||||
paymentMethodId
|
||||
@@ -166,14 +165,14 @@
|
||||
label="Select organization"
|
||||
{options}
|
||||
required
|
||||
placeholder="Create new organization"
|
||||
placeholder="Select organization"
|
||||
id="organization" />
|
||||
</FormList>
|
||||
{/if}
|
||||
{#if selectedOrg?.billingPlan !== BillingPlan.PRO || !selectedOrg?.paymentMethodId}
|
||||
{#if selectedOrgId && (selectedOrg?.billingPlan !== BillingPlan.PRO || !selectedOrg?.paymentMethodId)}
|
||||
<Form bind:this={formComponent} onSubmit={handleSubmit} bind:isSubmitting>
|
||||
<FormList>
|
||||
{#if !selectedOrgId}
|
||||
{#if selectedOrgId === newOrgId}
|
||||
<InputText
|
||||
label="Name"
|
||||
id="name"
|
||||
@@ -194,11 +193,19 @@
|
||||
</Form>
|
||||
{/if}
|
||||
<svelte:fragment slot="aside">
|
||||
<div class="card card-bg">
|
||||
<img
|
||||
src={`/images/campaigns/${data.couponData.campaign}/${$app.themeInUse}.png`}
|
||||
class="u-block u-image-object-fit-cover"
|
||||
alt="promo" />
|
||||
<div class="card card-container u-position-relative">
|
||||
<div class="card-bg"></div>
|
||||
<div
|
||||
class="u-flex u-flex-vertical u-gap-24 u-cross-center u-position-relative"
|
||||
style:z-index={10}>
|
||||
<img
|
||||
src={`/images/campaigns/${data.couponData.campaign}/${$app.themeInUse}.png`}
|
||||
class="u-block u-image-object-fit-cover"
|
||||
alt="promo" />
|
||||
<p class="body-text-1">
|
||||
{data.campaign.title.replace('VALUE', data.couponData.credits)}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{#if selectedOrg?.billingPlan === BillingPlan.PRO}
|
||||
<section class="card u-margin-block-start-32">
|
||||
@@ -207,7 +214,7 @@
|
||||
>{toLocaleDate(selectedOrg.billingNextInvoiceDate)}.</b>
|
||||
</p>
|
||||
</section>
|
||||
{:else if selectedOrg?.$id}
|
||||
{:else if selectedOrgId}
|
||||
<EstimatedTotalBox
|
||||
billingPlan={BillingPlan.PRO}
|
||||
{collaborators}
|
||||
@@ -229,12 +236,15 @@
|
||||
</WizardSecondaryContainer>
|
||||
|
||||
<style lang="scss">
|
||||
.card-bg {
|
||||
position: relative;
|
||||
.card-container {
|
||||
overflow: hidden;
|
||||
& > img {
|
||||
z-index: 10;
|
||||
}
|
||||
}
|
||||
.card-bg {
|
||||
position: absolute;
|
||||
overflow: hidden;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
inset: 0;
|
||||
}
|
||||
.card-bg::before {
|
||||
position: absolute;
|
||||
@@ -245,8 +255,7 @@
|
||||
inline-size: 30%;
|
||||
block-size: 30%;
|
||||
background: radial-gradient(49.55% 43.54% at 47% 50.69%, #e7f8f7 0%, #85dbd8 100%);
|
||||
filter: blur(50px);
|
||||
z-index: 1;
|
||||
filter: blur(70px);
|
||||
}
|
||||
.card-bg::after {
|
||||
position: absolute;
|
||||
@@ -257,6 +266,6 @@
|
||||
inline-size: 30%;
|
||||
block-size: 30%;
|
||||
background: radial-gradient(50% 46.73% at 50% 53.27%, #fe9567 28.17%, #fd366e 59.38%);
|
||||
filter: blur(50px);
|
||||
filter: blur(70px);
|
||||
}
|
||||
</style>
|
||||
@@ -1,5 +1,6 @@
|
||||
import { base } from '$app/paths';
|
||||
import type { Coupon } from '$lib/sdk/billing.js';
|
||||
import { campaigns } from '$lib/stores/campaigns.js';
|
||||
import { sdk } from '$lib/stores/sdk.js';
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
|
||||
@@ -13,11 +14,12 @@ export const load = async ({ url }) => {
|
||||
redirect(303, `${base}/console`);
|
||||
}
|
||||
}
|
||||
if (!couponData?.campaign) {
|
||||
if (!couponData?.campaign || !campaigns.has(couponData.campaign)) {
|
||||
redirect(303, `${base}/console`);
|
||||
}
|
||||
|
||||
return {
|
||||
couponData
|
||||
couponData,
|
||||
campaign: campaigns.get(couponData.campaign)
|
||||
};
|
||||
};
|
||||
@@ -42,8 +42,8 @@
|
||||
}
|
||||
|
||||
await invalidate(Dependencies.ACCOUNT);
|
||||
trackEvent(Submit.AccountCreate, { campaign_name: data?.couponData?.code });
|
||||
if (data?.couponData?.code) {
|
||||
trackEvent(Submit.AccountCreate, { campaign_name: data?.couponData?.code });
|
||||
await goto(`${base}/console/apply-credit?code=${data?.couponData?.code}`);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { base } from '$app/paths';
|
||||
import { campaigns } from '$lib/stores/campaigns';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
|
||||
@@ -7,9 +8,11 @@ export const load = async ({ url }) => {
|
||||
const code = url.searchParams.get('code');
|
||||
try {
|
||||
const couponData = await sdk.forConsole.billing.getCoupon(code);
|
||||
return {
|
||||
couponData
|
||||
};
|
||||
if (couponData?.campaign && campaigns.has(couponData.campaign)) {
|
||||
return {
|
||||
couponData
|
||||
};
|
||||
} else redirect(303, `${base}/login`);
|
||||
} catch (e) {
|
||||
redirect(303, `${base}/login`);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { base } from '$app/paths';
|
||||
import { campaigns } from '$lib/stores/campaigns.js';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
|
||||
@@ -7,9 +8,11 @@ export const load = async ({ url }) => {
|
||||
const code = url.searchParams.get('code');
|
||||
try {
|
||||
const couponData = await sdk.forConsole.billing.getCoupon(code);
|
||||
return {
|
||||
couponData
|
||||
};
|
||||
if (couponData?.campaign && campaigns.has(couponData.campaign)) {
|
||||
return {
|
||||
couponData
|
||||
};
|
||||
} else redirect(303, `${base}/register`);
|
||||
} catch (e) {
|
||||
redirect(303, `${base}/register`);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user