fixes to applying coupon

This commit is contained in:
Damodar Lohani
2025-01-20 07:13:17 +05:45
parent 654718d019
commit 67aeaedb9e
3 changed files with 27 additions and 13 deletions
@@ -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";
@@ -13,6 +15,7 @@
export let collaborators: string[];
export let couponId: string;
export let fixedCoupon = false;
export let isDowngrade = false;
export let billingBudget: number;
@@ -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"
@@ -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');
@@ -152,7 +142,7 @@
billingPlan,
paymentMethodId,
null,
couponData?.code,
couponId,
collaborators,
billingBudget,
taxId
@@ -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>