diff --git a/src/lib/elements/forms/inputSelect.svelte b/src/lib/elements/forms/inputSelect.svelte index c6a5fa2bb..9de5dd726 100644 --- a/src/lib/elements/forms/inputSelect.svelte +++ b/src/lib/elements/forms/inputSelect.svelte @@ -6,14 +6,14 @@ export let label: string | undefined = undefined; export let optionalText: string | undefined = undefined; export let showLabel = true; - export let value: string | number | boolean; + export let value: string | number | boolean | null; export let placeholder = ''; export let required = false; export let hideRequired = false; export let disabled = false; export let wrapperTag: FormItemTag = 'li'; export let options: { - value: string | boolean | number; + value: string | boolean | number | null; label: string; }[]; export let isMultiple = false; diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index a298eace4..bca6cbb0a 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -64,6 +64,7 @@ export type Coupon = { expiration: string; status: string; // 'active' | 'disabled' | 'expired' validity: number; + campaign?: string; }; export type Credit = { diff --git a/src/routes/console/apply-credit/+page.svelte b/src/routes/console/apply-credit/+page.svelte new file mode 100644 index 000000000..253cea0c1 --- /dev/null +++ b/src/routes/console/apply-credit/+page.svelte @@ -0,0 +1,187 @@ + + + + Apply credits - Appwrite + + + + Apply credits + + {#if $organizationList?.total} + + + + {/if} + {#if selectedOrg?.billingPlan !== BillingPlan.PRO || !selectedOrg?.paymentMethodId} +
+ + + + +
+ {/if} + +
+ +
+ +
+
+ + + + + +
diff --git a/src/routes/console/apply-credit/+page.ts b/src/routes/console/apply-credit/+page.ts new file mode 100644 index 000000000..0c0762b5e --- /dev/null +++ b/src/routes/console/apply-credit/+page.ts @@ -0,0 +1,23 @@ +import { base } from '$app/paths'; +import type { Coupon } from '$lib/sdk/billing.js'; +import { sdk } from '$lib/stores/sdk.js'; +import { redirect } from '@sveltejs/kit'; + +export const load = async ({ url }) => { + let couponData: Coupon; + if (url.searchParams.has('code')) { + const code = url.searchParams.get('code'); + try { + couponData = await sdk.forConsole.billing.getCoupon(code); + } catch (e) { + redirect(303, `${base}/console`); + } + } + if (!couponData?.campaign) { + redirect(303, `${base}/console`); + } + + return { + couponData + }; +}; diff --git a/src/routes/console/organization-[organization]/change-plan/+page.svelte b/src/routes/console/organization-[organization]/change-plan/+page.svelte index f35988bd7..f278cfac3 100644 --- a/src/routes/console/organization-[organization]/change-plan/+page.svelte +++ b/src/routes/console/organization-[organization]/change-plan/+page.svelte @@ -73,8 +73,8 @@ let feedbackMessage: string; onMount(async () => { - if ($page.url.searchParams.has('coupon')) { - const coupon = $page.url.searchParams.get('coupon'); + if ($page.url.searchParams.has('code')) { + const coupon = $page.url.searchParams.get('code'); try { const response = await sdk.forConsole.billing.getCoupon(coupon); couponData = response; @@ -360,9 +360,6 @@ {/if} -
- -
{#if billingPlan !== BillingPlan.STARTER && $organization.billingPlan !== BillingPlan.PRO}