Skip to content

Commit

Permalink
fixes to applying coupon
Browse files Browse the repository at this point in the history
  • Loading branch information
lohanidamodar committed Jan 20, 2025
1 parent 654718d commit 67aeaed
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
16 changes: 15 additions & 1 deletion src/lib/components/billing/estimatedTotal.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<script lang="ts">
import { FormList, InputChoice, InputNumber } from "$lib/elements/forms";
import { toLocaleDate } from "$lib/helpers/date";
// import { FormList, InputChoice } from "$lib/elements/forms";
import { formatCurrency } from "$lib/helpers/numbers";
import type { Estimation } from "$lib/sdk/billing";
import { organization } from "$lib/stores/organization";
import { sdk } from "$lib/stores/sdk";
import DiscountsApplied from "./discountsApplied.svelte";
Expand All @@ -13,6 +15,7 @@
export let collaborators: string[];
export let couponId: string;
export let fixedCoupon = false;
export let isDowngrade = false;
export let billingBudget: number;
Expand Down Expand Up @@ -41,7 +44,18 @@
</script>

{#if estimation}
{#if isDowngrade}
<section
class="card u-flex u-flex-vertical u-gap-8"
style:--p-card-padding="1.5rem"
style:--p-card-border-radius="var(--border-radius-small)">
<slot />
<p class="text u-margin-block-start-16">
Your change will take effect once your current billing cycle ends on <span class="u-bold">{toLocaleDate($organization.billingNextInvoiceDate)}</span>.
</p>
</section>

{:else if estimation}

<section
class="card u-flex u-flex-vertical u-gap-8"
Expand Down
14 changes: 2 additions & 12 deletions src/routes/(console)/create-organization/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,7 @@
onMount(async () => {
if ($page.url.searchParams.has('coupon')) {
const coupon = $page.url.searchParams.get('coupon');
try {
const response = await sdk.forConsole.billing.getCoupon(coupon);
couponData = response;
} catch (e) {
couponData = {
code: null,
status: null,
credits: null
};
}
couponId = $page.url.searchParams.get('coupon');
}
if ($page.url.searchParams.has('name')) {
name = $page.url.searchParams.get('name');
Expand Down Expand Up @@ -152,7 +142,7 @@
billingPlan,
paymentMethodId,
null,
couponData?.code,
couponId,
collaborators,
billingBudget,
taxId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,22 @@
<svelte:fragment slot="aside">
{#if billingPlan !== BillingPlan.FREE && $organization.billingPlan !== billingPlan && $organization.billingPlan !== BillingPlan.CUSTOM && isUpgrade}
<EstimatedTotal
{isDowngrade}
{billingBudget}
organizationId={$organization.$id}
{billingPlan}
{collaborators}
{couponId} />
{:else if $organization.billingPlan !== BillingPlan.CUSTOM}
{#if isDowngrade}
<EstimatedTotal
{isDowngrade}
{billingBudget}
organizationId={$organization.$id}
{billingPlan}
{collaborators}
{couponId} />
{/if}
<PlanComparisonBox downgrade={isDowngrade} />
{/if}
</svelte:fragment>
Expand Down

0 comments on commit 67aeaed

Please sign in to comment.