Skip to content

Commit f08bad0

Browse files
authored
Merge pull request #2060 from appwrite/fix-payments-state
2 parents ea2e749 + af6d3f9 commit f08bad0

File tree

9 files changed

+46
-19
lines changed

9 files changed

+46
-19
lines changed

e2e/journeys/upgrade-free-tier.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ test('upgrade - free tier', async ({ page }) => {
1111
await page.waitForURL(/\/organization-[^/]+\/change-plan/);
1212
await page.locator('input[value="tier-1"]').click();
1313
await page.getByRole('button', { name: 'add' }).first().click();
14+
1415
await enterCreditCard(page);
16+
17+
// wait for a second after adding a card to update the UI.
18+
await page.waitForSelector('button#method[role="combobox"]');
19+
1520
// skip members
1621
await page.getByRole('button', { name: 'change plan' }).click();
1722
await page.waitForURL(/\/console\/project-(?:[a-z0-9]+-)?([^/]+)\/get-started/);

src/lib/components/billing/paymentModal.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
try {
2222
const card = await submitStripeCard(name, page?.params?.organization ?? null);
2323
modal.closeModal();
24-
invalidate(Dependencies.PAYMENT_METHODS);
24+
await invalidate(Dependencies.PAYMENT_METHODS);
2525
dispatch('submit', card);
2626
addNotification({
2727
type: 'success',

src/lib/components/billing/selectPaymentMethod.svelte

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,19 @@
2020
2121
async function cardSaved(event: CustomEvent<PaymentMethodData>) {
2222
value = event.detail.$id;
23-
invalidate(Dependencies.UPGRADE_PLAN);
24-
invalidate(Dependencies.CREATE_ORGANIZATION);
23+
24+
if (value) {
25+
methods = {
26+
...methods,
27+
total: methods.total + 1,
28+
paymentMethods: [...methods.paymentMethods, event.detail]
29+
};
30+
}
31+
32+
await Promise.all([
33+
invalidate(Dependencies.UPGRADE_PLAN),
34+
invalidate(Dependencies.ORGANIZATION)
35+
]);
2536
}
2637
2738
onMount(() => {

src/lib/components/breadcrumbs.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@
101101
102102
async function createProjectsBottomSheet(organization: Organization): Promise<SheetMenu> {
103103
isLoadingProjects = true;
104-
loadedProjects = await projects;
104+
// null on non-org/project path like `onboarding`.
105+
loadedProjects = (await projects) ?? loadedProjects;
105106
isLoadingProjects = false;
106107
107108
const createProjectItem = {

src/routes/(console)/+layout.svelte

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,19 @@
316316
317317
$: checkForUsageLimits($organization);
318318
319-
$: projects = sdk.forConsole.projects.list([
320-
Query.equal(
321-
'teamId',
322-
// id from page params ?? id from store ?? id from preferences
323-
page.params.organization ?? currentOrganizationId ?? data.currentOrgId
324-
),
325-
Query.limit(5),
326-
Query.orderDesc('$updatedAt')
327-
]);
319+
$: isOnOnboarding = page.route?.id?.includes('/(console)/onboarding');
320+
321+
$: projects = isOnOnboarding
322+
? null
323+
: sdk.forConsole.projects.list([
324+
Query.equal(
325+
'teamId',
326+
// id from page params ?? id from store ?? id from preferences
327+
page.params.organization ?? currentOrganizationId ?? data.currentOrgId
328+
),
329+
Query.limit(5),
330+
Query.orderDesc('$updatedAt')
331+
]);
328332
329333
$: if ($requestedMigration) {
330334
openMigrationWizard();

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import type { Coupon } from '$lib/sdk/billing';
55
import type { Organization } from '$lib/stores/organization';
66

77
export const load: PageLoad = async ({ url, parent, depends }) => {
8-
depends(Dependencies.CREATE_ORGANIZATION);
98
const { organizations } = await parent();
9+
depends(Dependencies.CREATE_ORGANIZATION);
10+
1011
const [coupon, paymentMethods] = await Promise.all([
1112
getCoupon(url),
1213
sdk.forConsole.billing.listPaymentMethods()

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
import { isCloud } from '$lib/system';
33
import { sdk } from '$lib/stores/sdk';
44
import { ID } from '@appwrite.io/console';
5-
import { BillingPlan } from '$lib/constants';
5+
import { BillingPlan, Dependencies } from '$lib/constants';
66
import { tierToPlan } from '$lib/stores/billing';
77
import { addNotification } from '$lib/stores/notifications';
88
import { loadAvailableRegions } from '$routes/(console)/regions';
99
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
1010
import { Button, Card, Layout, Input, Typography, Spinner } from '@appwrite.io/pink-svelte';
1111
import { Form } from '$lib/elements/forms/index.js';
12-
import { goto } from '$app/navigation';
12+
import { goto, invalidate } from '$app/navigation';
1313
import { base } from '$app/paths';
1414
1515
let isLoading = false;
@@ -47,6 +47,10 @@
4747
if (organization) {
4848
loadAvailableRegions(organization?.$id).then();
4949
await goto(`${base}/organization-${organization.$id}`);
50+
51+
// fixes an edge case where
52+
// the org is not available for some reason!
53+
await invalidate(Dependencies.CREATE_ORGANIZATION);
5054
}
5155
isLoading = false;
5256
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,12 @@
334334
</Layout.Stack>
335335
</Layout.Stack>
336336
</Fieldset>
337-
{:then paymentMethods}
337+
{:then}
338338
<Fieldset legend="Payment">
339339
<SelectPaymentMethod
340-
methods={paymentMethods}
340+
bind:taxId
341341
bind:value={paymentMethodId}
342-
bind:taxId>
342+
bind:methods={paymentMethods}>
343343
<svelte:fragment slot="actions">
344344
{#if !selectedCoupon?.code}
345345
{#if paymentMethodId}

src/routes/+layout.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const ssr = false;
1616

1717
export const load: LayoutLoad = async ({ depends, url, route }) => {
1818
depends(Dependencies.ACCOUNT);
19+
depends(Dependencies.CREATE_ORGANIZATION);
1920

2021
const [account, error] = (await sdk.forConsole.account
2122
.get()

0 commit comments

Comments
 (0)