diff --git a/src/lib/components/studio/sidebarOrganization.svelte b/src/lib/components/studio/sidebarOrganization.svelte new file mode 100644 index 000000000..84e7b405a --- /dev/null +++ b/src/lib/components/studio/sidebarOrganization.svelte @@ -0,0 +1,37 @@ + + + + + diff --git a/src/routes/(studio)/+layout.svelte b/src/routes/(studio)/+layout.svelte new file mode 100644 index 000000000..a205adf30 --- /dev/null +++ b/src/routes/(studio)/+layout.svelte @@ -0,0 +1,74 @@ + + +
+ +
+ + + + +
+
+ +
+
+ + diff --git a/src/routes/(studio)/+layout.ts b/src/routes/(studio)/+layout.ts new file mode 100644 index 000000000..d51edd31e --- /dev/null +++ b/src/routes/(studio)/+layout.ts @@ -0,0 +1,70 @@ +import { Dependencies } from '$lib/constants'; +import type { Plan } from '$lib/sdk/billing'; +import type { Tier } from '$lib/stores/billing'; +import { sdk } from '$lib/stores/sdk'; +import { isCloud } from '$lib/system'; +import type { LayoutLoad } from './$types'; +import { Query } from '@appwrite.io/console'; + +export const load: LayoutLoad = async ({ params, fetch, depends, parent }) => { + await parent(); + depends(Dependencies.RUNTIMES); + depends(Dependencies.CONSOLE_VARIABLES); + depends(Dependencies.ORGANIZATION); + + const prefs = await sdk.forConsole.account.getPrefs(); + + const { endpoint, project } = sdk.forConsole.client.config; + const versionPromise = fetch(`${endpoint}/health/version`, { + headers: { + 'X-Appwrite-Project': project + } + }).then((response) => response.json() as { version?: string }); + + const variablesPromise = sdk.forConsole.console.variables(); + + const [data, variables] = await Promise.all([versionPromise, variablesPromise]); + + let plansInfo = new Map(); + if (isCloud) { + const plansArray = await sdk.forConsole.billing.getPlansInfo(); + plansInfo = plansArray.plans.reduce((map, plan) => { + map.set(plan.$id as Tier, plan); + return map; + }, new Map()); + } + + const organizations = !isCloud + ? await sdk.forConsole.teams.list() + : await sdk.forConsole.billing.listOrganization(); + + let projects = []; + let currentOrgId = params.organization ? params.organization : prefs.organization; + + if (!currentOrgId && organizations.teams.length > 0) { + currentOrgId = organizations.teams[0].$id; + } + if (currentOrgId) { + const orgProjects = await sdk.forConsole.projects.list([ + Query.equal('teamId', currentOrgId), + Query.limit(100), + Query.orderDesc('$updatedAt') + ]); + projects = orgProjects.projects.length > 0 ? orgProjects.projects : []; + } + + const selectedOrganizationId = + params && params.organization ? params.organization : prefs.organization; + + return { + consoleVariables: variables, + version: data?.version ?? null, + plansInfo, + roles: [], + scopes: [], + projects: projects, + currentProjectId: params.project ?? '', + organizations: organizations, + currentOrganization: organizations.teams.find((org) => org.$id === selectedOrganizationId) + }; +}; diff --git a/src/routes/(studio)/org-[organization]/+page.svelte b/src/routes/(studio)/org-[organization]/+page.svelte index f35e3e4e7..f55e2f435 100644 --- a/src/routes/(studio)/org-[organization]/+page.svelte +++ b/src/routes/(studio)/org-[organization]/+page.svelte @@ -1 +1,5 @@ -Hey studio! + + +dus