Skip to content

Commit b7abc66

Browse files
Merge pull request #1973 from appwrite/fix-estimated-total
fix: update EstimatedTotalBox to display data from estimation
2 parents 7e04da2 + d70488d commit b7abc66

File tree

3 files changed

+49
-14
lines changed

3 files changed

+49
-14
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 type { Coupon } from '$lib/sdk/billing';
3+
import { formatCurrency } from '$lib/helpers/numbers';
4+
import { IconTag } from '@appwrite.io/pink-icons-svelte';
5+
import { Badge, Icon, Layout, Typography } from '@appwrite.io/pink-svelte';
6+
7+
export let label: string;
8+
export let value: number;
9+
export let couponData: Partial<Coupon> = {
10+
code: null,
11+
status: null,
12+
credits: null
13+
};
14+
15+
let adjustedValue = value;
16+
17+
$: if (label?.toLowerCase() === 'credits' && couponData?.status === 'active') {
18+
adjustedValue = value - (couponData?.credits || 0);
19+
} else {
20+
adjustedValue = value;
21+
}
22+
</script>
23+
24+
{#if adjustedValue > 0}
25+
<Layout.Stack direction="row" justifyContent="space-between">
26+
<Layout.Stack inline direction="row" gap="xxs" alignItems="center" alignContent="center">
27+
<Icon icon={IconTag} color="--fgcolor-success" size="s" />
28+
<Typography.Text>{label}</Typography.Text>
29+
</Layout.Stack>
30+
{#if value >= 100}
31+
<Badge variant="secondary" content="Credits applied" />
32+
{:else}
33+
<Typography.Text color="--fgcolor-success"
34+
>-{formatCurrency(adjustedValue)}</Typography.Text>
35+
{/if}
36+
</Layout.Stack>
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

src/routes/(console)/organization-[organization]/change-plan/+page.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,7 @@
302302
</Layout.Stack>
303303
</Fieldset>
304304

305-
<!-- Show email input if upgrading from free plan -->
306-
{#if selectedPlan !== BillingPlan.FREE && data.organization.billingPlan === BillingPlan.FREE}
305+
{#if isUpgrade}
307306
<Fieldset legend="Payment">
308307
<SelectPaymentMethod
309308
methods={data.paymentMethods}

0 commit comments

Comments
 (0)