Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions src/routes/(console)/project-[region]-[project]/sites/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import { isServiceLimited } from '$lib/stores/billing';
import { organization } from '$lib/stores/organization';
import { canWriteSites } from '$lib/stores/roles.js';
import { Icon, Layout } from '@appwrite.io/pink-svelte';
import { Icon, Layout, Tooltip } from '@appwrite.io/pink-svelte';
import { Button } from '$lib/elements/forms';
import { app } from '$lib/stores/app';
import CreateSiteModal from './createSiteModal.svelte';
Expand All @@ -27,20 +27,25 @@
import { Dependencies } from '$lib/constants';
import { realtime } from '$lib/stores/sdk';
import { page } from '$app/state';
import {
BODY_TOOLTIP_MAX_WIDTH,
BODY_TOOLTIP_WRAPPER_STYLE_PRELINE
} from '$lib/helpers/tooltipContent';

export let data;

let show = false;

$: isLimited = isServiceLimited('sites', $organization, data.siteList?.total);

$: $registerCommands([
{
label: 'Create site',
callback: () => {
show = true;
},
keys: ['c'],
disabled:
isServiceLimited('sites', $organization, data.siteList?.total) || !$canWriteSites,
disabled: isLimited || !$canWriteSites,
icon: IconPlus,
group: 'sites'
}
Expand Down Expand Up @@ -70,10 +75,25 @@
hideColumns
hideView={!data.siteList.total} />
{#if $canWriteSites}
<Button on:mousedown={() => (show = true)} event="create_site" size="s">
<Icon icon={IconPlus} slot="start" size="s" />
Create site
</Button>
<Tooltip disabled={!isLimited} maxWidth={BODY_TOOLTIP_MAX_WIDTH}>
<div>
<Button
disabled={isLimited}
on:mousedown={() => {
if (!isLimited) show = true;
}}
event="create_site"
size="s">
<Icon icon={IconPlus} slot="start" size="s" />
Create site
</Button>
</div>
<svelte:fragment slot="tooltip">
<div style={BODY_TOOLTIP_WRAPPER_STYLE_PRELINE}>
You have reached the maximum number of sites for your plan.
</div>
</svelte:fragment>
</Tooltip>
{/if}
</Layout.Stack>
</Layout.Stack>
Expand All @@ -93,12 +113,14 @@
{:else}
<Empty
single
allowCreate={$canWriteSites}
allowCreate={$canWriteSites && !isLimited}
href="https://appwrite.io/docs/products/sites"
description="Deploy and manage your web applications with Sites. "
target="site"
src={$app.themeInUse === 'dark' ? EmptyDark : EmptyLight}
on:click={() => (show = true)}>
on:click={() => {
if (!isLimited) show = true;
}}>
</Empty>
{/if}
</Container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@
import { regionalConsoleVariables } from '$routes/(console)/project-[region]-[project]/store';
import { getTemplateSourceUrl } from '$lib/helpers/templateSource';
import { validateVariables } from '$lib/helpers/variables';
import { isServiceLimited } from '$lib/stores/billing';
import { organization } from '$lib/stores/organization';
import { isCloud } from '$lib/system';

export let data;

$: sitesLimited =
isCloud && isServiceLimited('sites', $organization, data.siteList?.total ?? 0);

let showExitModal = false;
let isCreatingRepository = false;
let hasInstallations = !!data?.installations?.total;
Expand Down Expand Up @@ -81,6 +87,15 @@
});

async function createRepository() {
if (sitesLimited) {
addNotification({
type: 'error',
message:
'The maximum number of sites allowed for the selected plan has been reached. Upgrade to increase the limit.'
});
return;
}

try {
isCreatingRepository = true;
const repo = await sdk
Expand Down Expand Up @@ -294,7 +309,8 @@
on:click={createRepository}
forceShowLoader
submissionLoader={isCreatingRepository}
disabled={!repositoryName ||
disabled={sitesLimited ||
!repositoryName ||
!$installation?.$id ||
isCreatingRepository}>
Create
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { sdk } from '$lib/stores/sdk';
import { ID } from '@appwrite.io/console';
import { ID, Query } from '@appwrite.io/console';
import { buildVerboseDomain } from '../../store.js';

export const load = async ({ parent, params }) => {
const { installations, frameworks, project, organization, regionalConsoleVariables } =
await parent();
const template = await sdk
.forProject(params.region, params.project)
.sites.getTemplate({ templateId: params.template });
const projectSdk = sdk.forProject(params.region, params.project);
const [template, siteList] = await Promise.all([
projectSdk.sites.getTemplate({ templateId: params.template }),
projectSdk.sites.list({ queries: [Query.limit(1)] })
]);
const domain = await buildVerboseDomain(
regionalConsoleVariables._APP_DOMAIN_SITES,
template.name,
Expand All @@ -20,6 +22,7 @@ export const load = async ({ parent, params }) => {
installations,
frameworks,
template,
domain
domain,
siteList
};
};