Skip to content

Commit da6629a

Browse files
authored
Merge pull request #2078 from appwrite/fix-undefined-name
fix: undefined errors around billing pages
2 parents 468473a + 1a296a2 commit da6629a

File tree

14 files changed

+101
-107
lines changed

14 files changed

+101
-107
lines changed

src/lib/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export enum Dependencies {
1818
INVOICES = 'dependency:invoices',
1919
ADDRESS = 'dependency:address',
2020
UPGRADE_PLAN = 'dependency:upgrade_plan',
21-
CREATE_ORGANIZATION = 'dependency:create_organization',
21+
ORGANIZATIONS = 'dependency:organizations',
2222
PAYMENT_METHODS = 'dependency:paymentMethods',
2323
ORGANIZATION = 'dependency:organization',
2424
MEMBERS = 'dependency:members',

src/lib/stores/billing.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ export function checkForEnterpriseTrial(org: Organization) {
287287
}
288288

289289
export function calculateEnterpriseTrial(org: Organization) {
290+
if (!org || !org.billingNextInvoiceDate) return 0;
290291
const endDate = new Date(org.billingNextInvoiceDate);
291292
const startDate = new Date(org.billingCurrentInvoiceDate);
292293
const today = new Date();

src/routes/(console)/account/payments/addressModal.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
if (organization) {
5757
org = await sdk.forConsole.billing.setBillingAddress(organization, response.$id);
5858
trackEvent(Submit.OrganizationBillingAddressUpdate);
59-
await invalidate(Dependencies.ORGANIZATION);
59+
await invalidate(Dependencies.ORGANIZATIONS);
6060
}
6161
await invalidate(Dependencies.ADDRESS);
6262

src/routes/(console)/create-organization/+page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { Organization } from '$lib/stores/organization';
66

77
export const load: PageLoad = async ({ url, parent, depends }) => {
88
const { organizations } = await parent();
9-
depends(Dependencies.CREATE_ORGANIZATION);
9+
depends(Dependencies.ORGANIZATIONS);
1010

1111
const [coupon, paymentMethods] = await Promise.all([
1212
getCoupon(url),

src/routes/(console)/onboarding/create-organization/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
5151
// fixes an edge case where
5252
// the org is not available for some reason!
53-
await invalidate(Dependencies.CREATE_ORGANIZATION);
53+
await invalidate(Dependencies.ORGANIZATIONS);
5454
}
5555
isLoading = false;
5656
}

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

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<script lang="ts">
22
import { Container } from '$lib/layout';
3-
import { organization } from '$lib/stores/organization';
43
import BudgetCap from './budgetCap.svelte';
54
import PlanSummary from './planSummary.svelte';
65
import BillingAddress from './billingAddress.svelte';
@@ -25,14 +24,15 @@
2524
import type { PageData } from './$types';
2625
2726
export let data: PageData;
27+
let organization = data.organization;
2828
2929
// why are these reactive?
3030
$: defaultPaymentMethod = data?.paymentMethods?.paymentMethods?.find(
31-
(method: PaymentMethodData) => method.$id === $organization?.paymentMethodId
31+
(method: PaymentMethodData) => method.$id === organization?.paymentMethodId
3232
);
3333
3434
$: backupPaymentMethod = data?.paymentMethods?.paymentMethods?.find(
35-
(method: PaymentMethodData) => method.$id === $organization?.backupPaymentMethodId
35+
(method: PaymentMethodData) => method.$id === organization?.backupPaymentMethodId
3636
);
3737
3838
onMount(async () => {
@@ -52,10 +52,10 @@
5252
);
5353
5454
await confirmPayment(
55-
$organization.$id,
55+
organization.$id,
5656
invoice.clientSecret,
57-
$organization.paymentMethodId,
58-
`${base}/organization-${$organization.$id}/billing?type=validate-invoice&invoice=${invoice.$id}`
57+
organization.paymentMethodId,
58+
`${base}/organization-${organization.$id}/billing?type=validate-invoice&invoice=${invoice.$id}`
5959
);
6060
}
6161
@@ -64,7 +64,7 @@
6464
page.url.searchParams.get('type') === 'validate-invoice'
6565
) {
6666
const invoiceId = page.url.searchParams.get('invoice');
67-
await sdk.forConsole.billing.updateInvoiceStatus($organization.$id, invoiceId);
67+
await sdk.forConsole.billing.updateInvoiceStatus(organization.$id, invoiceId);
6868
invalidate(Dependencies.INVOICES);
6969
invalidate(Dependencies.ORGANIZATION);
7070
}
@@ -84,7 +84,7 @@
8484
}
8585
if (page.url.searchParams.has('clientSecret')) {
8686
const clientSecret = page.url.searchParams.get('clientSecret');
87-
await confirmPayment($organization.$id, clientSecret, $organization.paymentMethodId);
87+
await confirmPayment(organization.$id, clientSecret, organization.paymentMethodId);
8888
}
8989
});
9090
</script>
@@ -93,7 +93,7 @@
9393
{#if $failedInvoice}
9494
{#if $failedInvoice?.lastError}
9595
<Alert.Inline status="error">
96-
The scheduled payment for {$organization.name} failed due to following error: {$failedInvoice.lastError}
96+
The scheduled payment for {organization.name} failed due to following error: {$failedInvoice.lastError}
9797
<svelte:fragment slot="actions">
9898
<Button
9999
text
@@ -106,7 +106,7 @@
106106
{:else}
107107
<Alert.Inline
108108
status="error"
109-
title={`The scheduled payment for ${$organization.name} failed`}>
109+
title={`The scheduled payment for ${organization.name} failed`}>
110110
To avoid service disruptions in organization's your projects, please verify your
111111
payment details and update them if necessary.
112112
</Alert.Inline>
@@ -115,29 +115,33 @@
115115
{#if defaultPaymentMethod?.failed && !backupPaymentMethod}
116116
<Alert.Inline
117117
status="error"
118-
title={`The default payment method for ${$organization.name} has expired`}>
118+
title={`The default payment method for ${organization.name} has expired`}>
119119
To avoid service disruptions in your organization's projects, please update your payment
120120
details.
121121
</Alert.Inline>
122122
{/if}
123-
{#if $organization?.billingPlanDowngrade}
123+
{#if organization?.billingPlanDowngrade}
124124
<Alert.Inline status="info">
125-
Your organization has changed to {tierToPlan($organization?.billingPlanDowngrade).name} plan.
126-
You will continue to have access to {tierToPlan($organization?.billingPlan).name} plan features
127-
until your billing period ends on {toLocaleDate($organization.billingNextInvoiceDate)}.
125+
Your organization has changed to {tierToPlan(organization?.billingPlanDowngrade).name} plan.
126+
You will continue to have access to {tierToPlan(organization?.billingPlan).name} plan features
127+
until your billing period ends on {toLocaleDate(organization.billingNextInvoiceDate)}.
128128
</Alert.Inline>
129129
{/if}
130130
<Typography.Title>Billing</Typography.Title>
131131
<PlanSummary
132132
availableCredit={data?.availableCredit}
133-
currentPlan={data?.aggregationBillingPlan}
133+
currentPlan={data?.currentPlan}
134134
currentAggregation={data?.billingAggregation}
135135
currentInvoice={data?.billingInvoice} />
136136
<PaymentHistory />
137-
<PaymentMethods methods={data?.paymentMethods} />
138-
<BillingAddress {data} />
137+
<PaymentMethods organization={data?.organization} methods={data?.paymentMethods} />
138+
<BillingAddress
139+
organization={data?.organization}
140+
billingAddress={data?.billingAddress}
141+
locale={data?.locale}
142+
countryList={data?.countryList} />
139143
<TaxId />
140-
<BudgetCap />
144+
<BudgetCap organization={data?.organization} currentPlan={data?.currentPlan} />
141145
<AvailableCredit areCreditsSupported={data.areCreditsSupported} />
142146
</Container>
143147

src/routes/(console)/organization-[organization]/billing/+page.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { PageLoad } from './$types';
77
import { isCloud } from '$lib/system';
88

99
export const load: PageLoad = async ({ parent, depends }) => {
10-
const { organization, scopes, currentPlan, countryList, locale, plansInfo } = await parent();
10+
const { organization, scopes, currentPlan, countryList, locale } = await parent();
1111

1212
if (!scopes.includes('billing.read')) {
1313
return redirect(301, `/console/organization-${organization.$id}`);
@@ -64,18 +64,13 @@ export const load: PageLoad = async ({ parent, depends }) => {
6464
areCreditsSupported ? sdk.forConsole.billing.getAvailableCredit(organization.$id) : null
6565
]);
6666

67-
const aggregationBillingPlan = plansInfo.get(
68-
billingAggregation?.plan ?? organization.billingPlan
69-
);
70-
7167
// make number
7268
const credits = availableCredit ? availableCredit.available : null;
7369

7470
return {
7571
paymentMethods,
7672
addressList,
7773
billingAddress,
78-
aggregationBillingPlan,
7974
availableCredit: credits,
8075
billingAggregation,
8176
billingInvoice,

src/routes/(console)/organization-[organization]/billing/billingAddress.svelte

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import type { Address } from '$lib/sdk/billing';
88
import { addressList } from '$lib/stores/billing';
99
import { addNotification } from '$lib/stores/notifications';
10-
import { organization } from '$lib/stores/organization';
10+
import { type Organization } from '$lib/stores/organization';
1111
import { sdk } from '$lib/stores/sdk';
1212
import RemoveAddress from './removeAddress.svelte';
1313
import { user } from '$lib/stores/user';
@@ -23,14 +23,11 @@
2323
IconTrash
2424
} from '@appwrite.io/pink-icons-svelte';
2525
import type { Models } from '@appwrite.io/console';
26-
import type { PageData } from './$types';
2726
28-
export let data: PageData;
29-
30-
const locale: Models.Locale = data.locale;
31-
const countryList: Models.CountryList = data.countryList;
32-
33-
let billingAddress: Address = data?.billingAddress;
27+
export let organization: Organization;
28+
export let locale: Models.Locale;
29+
export let countryList: Models.CountryList;
30+
export let billingAddress: Address;
3431
3532
let showCreate = false;
3633
let showEdit = false;
@@ -39,16 +36,16 @@
3936
4037
async function addAddress(addressId: string) {
4138
try {
42-
await sdk.forConsole.billing.setBillingAddress($organization.$id, addressId);
39+
await sdk.forConsole.billing.setBillingAddress(organization.$id, addressId);
4340
4441
addNotification({
4542
type: 'success',
46-
message: `A new billing address has been added to ${$organization.name}`
43+
message: `A new billing address has been added to ${organization.name}`
4744
});
4845
trackEvent(Submit.OrganizationBillingAddressUpdate);
4946
5047
invalidate(Dependencies.ADDRESS);
51-
invalidate(Dependencies.ORGANIZATION);
48+
invalidate(Dependencies.ORGANIZATIONS);
5249
} catch (error) {
5350
addNotification({
5451
type: 'error',
@@ -63,7 +60,7 @@
6360
<svelte:fragment slot="title">Billing address</svelte:fragment>
6461
View or update your billing address. This address will be included in your invoices from Appwrite.
6562
<svelte:fragment slot="aside">
66-
{#if $organization?.billingAddressId && billingAddress}
63+
{#if organization?.billingAddressId && billingAddress}
6764
<Card.Base variant="secondary" padding="s">
6865
<Layout.Stack direction="row" justifyContent="space-between">
6966
<div>
@@ -140,7 +137,7 @@
140137
</CardGrid>
141138

142139
{#if showCreate}
143-
<AddressModal bind:show={showCreate} organization={$organization?.$id} {countryList} {locale} />
140+
<AddressModal bind:show={showCreate} organization={organization?.$id} {countryList} {locale} />
144141
{/if}
145142
{#if showEdit}
146143
<EditAddressModal

src/routes/(console)/organization-[organization]/billing/budgetAlert.svelte

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@
77
import { Button, Form } from '$lib/elements/forms';
88
import { symmetricDifference } from '$lib/helpers/array';
99
import { addNotification } from '$lib/stores/notifications';
10-
import { currentPlan, organization } from '$lib/stores/organization';
10+
import { type Organization } from '$lib/stores/organization';
1111
import { sdk } from '$lib/stores/sdk';
12-
import { onMount } from 'svelte';
1312
import { Alert, Icon, Table } from '@appwrite.io/pink-svelte';
1413
import { IconTrash } from '@appwrite.io/pink-icons-svelte';
1514
import InputSelect from '$lib/elements/forms/inputSelect.svelte';
15+
import type { Plan } from '$lib/sdk/billing';
1616
17+
export let organization: Organization;
18+
export let currentPlan: Plan;
1719
export let alertsEnabled = false;
1820
1921
let search: string;
2022
let selectedAlert: number;
21-
let alerts: number[] = [];
23+
let alerts: number[] = organization?.budgetAlerts ?? [];
2224
2325
$: options = [
2426
{ value: 25, label: '25%', disabled: false },
@@ -33,10 +35,6 @@
3335
};
3436
});
3537
36-
onMount(() => {
37-
alerts = $organization?.budgetAlerts ?? [];
38-
});
39-
4038
function addAlert() {
4139
if (alerts.some((alert) => alert === selectedAlert)) {
4240
return;
@@ -50,8 +48,8 @@
5048
async function updateBudget() {
5149
try {
5250
await sdk.forConsole.billing.updateBudget(
53-
$organization.$id,
54-
$organization.billingBudget,
51+
organization.$id,
52+
organization.billingBudget,
5553
alerts
5654
);
5755
@@ -60,7 +58,7 @@
6058
addNotification({
6159
type: 'success',
6260
isHtml: true,
63-
message: `<span> ${alerts.length === 0 ? 'Budget alerts removed from' : alerts.length > 1 ? `Budget alerts added to` : 'A budget alert has been added to'} <b>${$organization.name}</b> </span>`
61+
message: `<span> ${alerts.length === 0 ? 'Budget alerts removed from' : alerts.length > 1 ? `Budget alerts added to` : 'A budget alert has been added to'} <b>${organization.name}</b> </span>`
6462
});
6563
trackEvent(Submit.BudgetAlertsUpdate, {
6664
alerts
@@ -75,26 +73,26 @@
7573
}
7674
7775
$: isButtonDisabled =
78-
symmetricDifference(alerts, $organization.budgetAlerts).length === 0 || !alertsEnabled;
76+
symmetricDifference(alerts, organization.budgetAlerts).length === 0 || !alertsEnabled;
7977
</script>
8078

8179
<CardGrid>
8280
<svelte:fragment slot="title">Billing alerts</svelte:fragment>
83-
{#if !$currentPlan.budgeting}
81+
{#if !currentPlan.budgeting}
8482
Get notified by email when your organization meets a percentage of your budget cap. <b
85-
>{tierToPlan($organization.billingPlan).name} organizations will receive one notification
83+
>{tierToPlan(organization.billingPlan).name} organizations will receive one notification
8684
at 75% resource usage.</b>
8785
{:else}
8886
Get notified by email when your organization meets or exceeds a percentage of your specified
8987
billing alert(s).
9088
{/if}
9189
<svelte:fragment slot="aside">
92-
{#if !$currentPlan.budgeting}
90+
{#if !currentPlan.budgeting}
9391
<Alert.Inline status="info" title="Billing alerts are a Pro plan feature">
9492
Upgrade to a Pro plan to manage when you receive billing alerts for your
9593
organization.
9694
</Alert.Inline>
97-
{:else if !$currentPlan.budgetCapEnabled}
95+
{:else if !currentPlan.budgetCapEnabled}
9896
<Alert.Inline status="info" title="Budget cap disabled">
9997
Budget caps are not supported on your current plan. For more information, please
10098
reach out to your customer success manager.
@@ -150,7 +148,7 @@
150148

151149
<svelte:fragment slot="actions">
152150
<Form onSubmit={updateBudget}>
153-
{#if $organization?.billingPlan === BillingPlan.FREE || $organization?.billingPlan === BillingPlan.GITHUB_EDUCATION}
151+
{#if organization?.billingPlan === BillingPlan.FREE || organization?.billingPlan === BillingPlan.GITHUB_EDUCATION}
154152
<Button
155153
secondary
156154
href={$upgradeURL}

0 commit comments

Comments
 (0)