review improvements

This commit is contained in:
Damodar Lohani committed 2025-01-29 03:26:09 +00:00
1 parent c52db33abd
commit 47d0b32ea8
4 files changed
+43 -26

No files matched your search

@@ -3,9 +3,11 @@
import { formatCurrency } from '$lib/helpers/numbers';
import type { Coupon, Estimation } from '$lib/sdk/billing';
import { sdk } from '$lib/stores/sdk';
import { AppwriteException } from '@appwrite.io/console';
import Alert from '../alert.svelte';
import Card from '../card.svelte';
import DiscountsApplied from './discountsApplied.svelte';
import { addNotification } from '$lib/stores/notifications';
export let organizationId: string | undefined = undefined;
export let billingPlan: string;
@@ -22,15 +24,30 @@
async function getEstimate(billingPlan: string, collaborators: string[], couponId: string) {
try {
error = '';
estimation = await sdk.forConsole.billing.estimationCreateOrganization(
billingPlan,
couponId === '' ? null : couponId,
collaborators ?? []
);
error = estimation.error ?? '';
} catch (e) {
error = e.message;
if (e instanceof AppwriteException) {
if (
e.type === 'coupon_not_found' ||
e.type === 'coupon_already_used' ||
e.type === 'billing_credits_unsupported'
) {
couponData = {
code: null,
status: null,
credits: null
};
}
}
addNotification({
type: 'error',
isHtml: false,
message: e.message
});
}
}
@@ -41,16 +58,18 @@
couponId: string | undefined
) {
try {
error = '';
estimation = await sdk.forConsole.billing.estimationUpdatePlan(
organizationId,
billingPlan,
couponId && couponId.length > 0 ? couponId : null,
collaborators ?? []
);
error = estimation.error ?? '';
} catch (e) {
error = e.message;
addNotification({
type: 'error',
isHtml: false,
message: e.message
});
}
}
@@ -70,10 +89,10 @@
{#if estimation}
{#each estimation.items ?? [] as item}
{#if item.value > 0}
<span class="u-flex u-main-space-between">
<p class="text">{item.label}</p>
<p class="text">{formatCurrency(item.value)}</p>
</span>
<span class="u-flex u-main-space-between">
<p class="text">{item.label}</p>
<p class="text">{formatCurrency(item.value)}</p>
</span>
{/if}
{/each}
{#each estimation.discounts ?? [] as item}
+1 -1
View File
@@ -14,7 +14,7 @@
</script>
<Modal
title="Exit Process"
title="Exit process"
bind:show
onSubmit={handleSubmit}
icon="exclamation"
@@ -326,7 +326,7 @@
{#if selectedOrgId === newOrgId}
Create Organization
{:else}
Apply Credits
Apply credits
{/if}
</Button>
</WizardSecondaryFooter>
@@ -3,13 +3,7 @@
import { base } from '$app/paths';
import { page } from '$app/stores';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import {
PlanComparisonBox,
SelectPaymentMethod,
SelectPlan
} from '$lib/components/billing';
import { PlanComparisonBox, SelectPaymentMethod, SelectPlan } from '$lib/components/billing';
import EstimatedTotal from '$lib/components/billing/estimatedTotal.svelte';
import ValidateCreditModal from '$lib/components/billing/validateCreditModal.svelte';
import Default from '$lib/components/roles/default.svelte';
@@ -227,23 +221,27 @@
id="members" />
<SelectPaymentMethod bind:methods bind:value={paymentMethodId} bind:taxId
></SelectPaymentMethod>
<InputText
bind:value={couponId}
label="Coupon"
placeholder="Enter coupon code"
id="couponId" />
</FormList>
{#if !couponData?.code}
<Button
text
noMargin
class="u-margin-block-start-16"
on:click={() => (showCreditModal = true)}>
<span class="icon-plus"></span> <span class="text">Add credits</span>
</Button>
{/if}
{/if}
</Form>
<svelte:fragment slot="aside">
{#if billingPlan !== BillingPlan.FREE}
<EstimatedTotal
bind:error={error}
bind:error
{billingBudget}
{billingPlan}
{collaborators}
{couponId}
/>
{couponData} />
{:else}
<PlanComparisonBox />
{/if}