Skip to content

Commit 16b2278

Browse files
committed
fix: update EstimatedTotalBox to display data from estimation
1 parent 51d6ebe commit 16b2278

File tree

2 files changed

+48
-12
lines changed

2 files changed

+48
-12
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<script lang="ts">
2+
import { formatCurrency } from '$lib/helpers/numbers';
3+
import type { Coupon } from '$lib/sdk/billing';
4+
export let label: string;
5+
export let value: number;
6+
export let couponData: Partial<Coupon> = {
7+
code: null,
8+
status: null,
9+
credits: null
10+
};
11+
12+
let adjustedValue = value;
13+
14+
$: if (label?.toLowerCase() === 'credits' && couponData?.status === 'active') {
15+
adjustedValue = value - (couponData?.credits || 0);
16+
} else {
17+
adjustedValue = value;
18+
}
19+
</script>
20+
21+
{#if adjustedValue > 0}
22+
<span class="u-flex u-main-space-between">
23+
<div class="u-flex u-cross-center u-gap-4">
24+
<p class="text">
25+
<span class="icon-tag u-color-text-success" aria-hidden="true"></span>
26+
<span>
27+
{label}
28+
</span>
29+
</p>
30+
</div>
31+
{#if value >= 100}
32+
<p class="inline-tag">Credits applied</p>
33+
{:else}
34+
<span class="u-color-text-success">-{formatCurrency(adjustedValue)}</span>
35+
{/if}
36+
</span>
37+
{/if}

src/lib/components/billing/estimatedTotalBox.svelte

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import { CreditsApplied } from '.';
88
import { sdk } from '$lib/stores/sdk';
99
import { AppwriteException } from '@appwrite.io/console';
10+
import DiscountsApplied from './discountsApplied.svelte';
1011
1112
export let billingPlan: Tier;
1213
export let collaborators: string[];
@@ -35,7 +36,8 @@
3536
if (
3637
e.type === 'billing_coupon_not_found' ||
3738
e.type === 'billing_coupon_already_used' ||
38-
e.type === 'billing_credit_unsupported'
39+
e.type === 'billing_credit_unsupported' ||
40+
e.type === 'billing_coupon_not_eligible'
3941
) {
4042
couponData = {
4143
code: null,
@@ -65,7 +67,8 @@
6567
if (
6668
e.type === 'billing_coupon_not_found' ||
6769
e.type === 'billing_coupon_already_used' ||
68-
e.type === 'billing_credit_unsupported'
70+
e.type === 'billing_credit_unsupported' ||
71+
e.type === 'billing_coupon_not_eligible'
6972
) {
7073
couponData = {
7174
code: null,
@@ -80,13 +83,6 @@
8083
$: organizationId
8184
? getUpdatePlanEstimate(organizationId, billingPlan, collaborators, couponData?.code)
8285
: getEstimate(billingPlan, collaborators, couponData?.code);
83-
84-
$: estimatedTotal =
85-
couponData?.status === 'active'
86-
? estimation?.grossAmount - couponData.credits >= 0
87-
? estimation?.grossAmount - couponData.credits
88-
: 0
89-
: estimation?.grossAmount;
9086
</script>
9187

9288
{#if estimation}
@@ -102,6 +98,9 @@
10298
>{formatCurrency(item.value)}</Typography.Text>
10399
</Layout.Stack>
104100
{/each}
101+
{#each estimation.discounts ?? [] as item}
102+
<DiscountsApplied {couponData} {...item} />
103+
{/each}
105104

106105
{#if couponData?.status === 'active'}
107106
<CreditsApplied bind:couponData {fixedCoupon} />
@@ -110,15 +109,15 @@
110109
<Layout.Stack direction="row" justifyContent="space-between">
111110
<Typography.Text>Total due</Typography.Text>
112111
<Typography.Text>
113-
{formatCurrency(estimatedTotal)}
112+
{formatCurrency(estimation.grossAmount)}
114113
</Typography.Text>
115114
</Layout.Stack>
116115

117116
<Typography.Text>
118-
You'll pay <b>{formatCurrency(estimatedTotal)}</b>
117+
You'll pay <b>{formatCurrency(estimation.grossAmount)}</b>
119118
now.
120119
{#if couponData?.code}Once your credits run out,{:else}Then{/if} you'll be charged
121-
<b>{formatCurrency(estimation.grossAmount)}</b> every 30 days.
120+
<b>{formatCurrency(estimation.amount)}</b> every 30 days.
122121
</Typography.Text>
123122

124123
<InputChoice

0 commit comments

Comments
 (0)