|
7 | 7 | import { CreditsApplied } from '.';
|
8 | 8 | import { sdk } from '$lib/stores/sdk';
|
9 | 9 | import { AppwriteException } from '@appwrite.io/console';
|
| 10 | + import DiscountsApplied from './discountsApplied.svelte'; |
10 | 11 |
|
11 | 12 | export let billingPlan: Tier;
|
12 | 13 | export let collaborators: string[];
|
|
35 | 36 | if (
|
36 | 37 | e.type === 'billing_coupon_not_found' ||
|
37 | 38 | 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' |
39 | 41 | ) {
|
40 | 42 | couponData = {
|
41 | 43 | code: null,
|
|
65 | 67 | if (
|
66 | 68 | e.type === 'billing_coupon_not_found' ||
|
67 | 69 | 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' |
69 | 72 | ) {
|
70 | 73 | couponData = {
|
71 | 74 | code: null,
|
|
80 | 83 | $: organizationId
|
81 | 84 | ? getUpdatePlanEstimate(organizationId, billingPlan, collaborators, couponData?.code)
|
82 | 85 | : 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; |
90 | 86 | </script>
|
91 | 87 |
|
92 | 88 | {#if estimation}
|
|
102 | 98 | >{formatCurrency(item.value)}</Typography.Text>
|
103 | 99 | </Layout.Stack>
|
104 | 100 | {/each}
|
| 101 | + {#each estimation.discounts ?? [] as item} |
| 102 | + <DiscountsApplied {couponData} {...item} /> |
| 103 | + {/each} |
105 | 104 |
|
106 | 105 | {#if couponData?.status === 'active'}
|
107 | 106 | <CreditsApplied bind:couponData {fixedCoupon} />
|
|
110 | 109 | <Layout.Stack direction="row" justifyContent="space-between">
|
111 | 110 | <Typography.Text>Total due</Typography.Text>
|
112 | 111 | <Typography.Text>
|
113 |
| - {formatCurrency(estimatedTotal)} |
| 112 | + {formatCurrency(estimation.grossAmount)} |
114 | 113 | </Typography.Text>
|
115 | 114 | </Layout.Stack>
|
116 | 115 |
|
117 | 116 | <Typography.Text>
|
118 |
| - You'll pay <b>{formatCurrency(estimatedTotal)}</b> |
| 117 | + You'll pay <b>{formatCurrency(estimation.grossAmount)}</b> |
119 | 118 | now.
|
120 | 119 | {#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. |
122 | 121 | </Typography.Text>
|
123 | 122 |
|
124 | 123 | <InputChoice
|
|
0 commit comments