fix check with cloud

This commit is contained in:
Damodar Lohani committed 2024-09-03 09:17:18 +05:45
1 parent 414bc60bc8
commit c97e372386
5 files changed
+28 -48

No files matched your search

+2 -2
View File
@@ -1,5 +1,5 @@
import type { Client, Models } from '@appwrite.io/console';
import type { CreateOrgAuth, Organization, OrganizationList } from '../stores/organization';
import type { OrganizationError, Organization, OrganizationList } from '../stores/organization';
import type { PaymentMethod } from '@stripe/stripe-js';
import type { Tier } from '$lib/stores/billing';
@@ -332,7 +332,7 @@ export class Billing {
invites: Array<string> = [],
budget: number = undefined,
taxId: string = null
): Promise<Organization | CreateOrgAuth> {
): Promise<Organization | OrganizationError> {
const path = `/organizations`;
const params = {
organizationId,
+1 -1
View File
@@ -3,7 +3,7 @@ import { derived, writable } from 'svelte/store';
import type { Models } from '@appwrite.io/console';
import type { Tier } from './billing';
export type CreateOrgAuth = {
export type OrganizationError = {
status: number;
message: string;
teamId: string;
+2 -1
View File
@@ -6,6 +6,7 @@ import { redirect } from '@sveltejs/kit';
import { Dependencies } from '$lib/constants';
import type { LayoutLoad } from './$types';
import { redirectTo } from './store';
import { isCloud } from '$lib/system';
export const ssr = false;
@@ -22,7 +23,7 @@ export const load: LayoutLoad = async ({ depends, url }) => {
return {
account,
organizations: await sdk.forConsole.billing.listOrganization()
organizations: isCloud ? await sdk.forConsole.billing.listOrganization() : await sdk.forConsole.teams.list()
};
} catch (error) {
const acceptedRoutes = [
@@ -3,19 +3,24 @@ import { sdk } from '$lib/stores/sdk';
import { getLimit, getPage, pageToOffset } from '$lib/helpers/load';
import { CARD_LIMIT } from '$lib/constants';
import type { PageLoad } from './$types';
import { isCloud } from '$lib/system';
export const load: PageLoad = async ({ url, route }) => {
const page = getPage(url);
const limit = getLimit(url, route, CARD_LIMIT);
const offset = pageToOffset(page, limit);
const queries = [
Query.offset(offset),
Query.limit(limit),
Query.orderDesc('')
];
const organizations = isCloud ? await sdk.forConsole.billing.listOrganization(queries) : sdk.forConsole.teams.list(queries);
return {
offset,
limit,
organizations: await sdk.forConsole.billing.listOrganization([
Query.offset(offset),
Query.limit(limit),
Query.orderDesc('')
])
organizations
};
};
@@ -24,7 +24,7 @@
import { addNotification } from '$lib/stores/notifications';
import {
organizationList,
type CreateOrgAuth,
type OrganizationError,
type Organization
} from '$lib/stores/organization';
import { sdk } from '$lib/stores/sdk';
@@ -88,10 +88,10 @@
if (anyOrgFree) {
billingPlan = BillingPlan.PRO;
}
if($page.url.searchParams.has('type')) {
if ($page.url.searchParams.has('type')) {
const type = $page.url.searchParams.get('type');
if(type === 'confirmed') {
const organizationId= $page.url.searchParams.get('id');
if (type === 'confirmed') {
const organizationId = $page.url.searchParams.get('id');
const invites = $page.url.searchParams.getAll('invites');
await validate(organizationId, invites);
}
@@ -103,7 +103,7 @@
paymentMethodId = methods.paymentMethods.find((method) => !!method?.last4)?.$id ?? null;
}
function isOrganization(org: Organization | CreateOrgAuth): org is Organization {
function isOrganization(org: Organization | OrganizationError): org is Organization {
return (org as Organization).$id !== undefined;
}
@@ -125,12 +125,11 @@
});
trackError(e, Submit.OrganizationCreate);
}
}
async function create() {
try {
let org: Organization | CreateOrgAuth;
let org: Organization | OrganizationError;
if (billingPlan === BillingPlan.FREE) {
org = await sdk.forConsole.billing.createOrganization(
@@ -162,39 +161,14 @@
const invite = collaborators[index];
params.append('invites', invite);
}
await confirmPayment('', clientSecret, paymentMethodId, '/console/create-organization?'+params.toString());
await confirmPayment(
'',
clientSecret,
paymentMethodId,
'/console/create-organization?' + params.toString()
);
await validate(org.teamId, collaborators);
}
//Add budget
// if (billingBudget && isOrganization(org)) {
// await sdk.forConsole.billing.updateBudget(org.$id, billingBudget, [75]);
// }
// //Add coupon
// if (couponData?.code) {
// await sdk.forConsole.billing.addCredit(org.$id, couponData.code);
// trackEvent(Submit.CreditRedeem);
// }
// //Add collaborators
// if (collaborators?.length) {
// collaborators.forEach(async (collaborator) => {
// await sdk.forConsole.teams.createMembership(
// org.$id,
// ['owner'],
// collaborator,
// undefined,
// undefined,
// `${$page.url.origin}/console/organization-${org.$id}`
// );
// });
// }
// Add tax ID
// if (taxId) {
// await sdk.forConsole.billing.updateTaxId(org.$id, taxId);
// }
}
trackEvent(Submit.OrganizationCreate, {
@@ -203,7 +177,7 @@
members_invited: collaborators?.length
});
if(isOrganization(org)) {
if (isOrganization(org)) {
await invalidate(Dependencies.ACCOUNT);
await preloadData(`${base}/console/organization-${org.$id}`);
await goto(`${base}/console/organization-${org.$id}`);