Skip to content

fix: correct project limit warnings for multi-organization users #2194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 11, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
7 changes: 5 additions & 2 deletions src/lib/components/billing/alerts/selectProjectCloud.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
let error = $state<string | null>(null);

onMount(() => {
projects = page.data.allProjects?.projects || [];
const currentOrgId = page.data.organization?.$id;
projects =
page.data.currentOrgId === currentOrgId ? page.data.allProjects?.projects || [] : [];
Copy link
Preview

Copilot AI Aug 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The ternary operator condition could be clearer. Consider extracting this logic into a well-named variable or function to improve readability and make the organization filtering intent more explicit.

Suggested change
page.data.currentOrgId === currentOrgId ? page.data.allProjects?.projects || [] : [];
const isCurrentOrganizationSelected = page.data.currentOrgId === currentOrgId;
projects =
isCurrentOrganizationSelected ? page.data.allProjects?.projects || [] : [];

Copilot uses AI. Check for mistakes.

});

let projectsToArchive = $derived(
Expand Down Expand Up @@ -71,7 +73,8 @@

<Modal bind:show={showSelectProject} title={'Manage projects'} onSubmit={updateSelected}>
<svelte:fragment slot="description">
Choose which two projects to keep. Projects over the limit will be blocked after this date.
Choose which {$currentPlan?.projects || 2} projects to keep. Projects over the limit will be
blocked after this date.
</svelte:fragment>
{#if error}
<Alert.Inline status="error" title="Error">{error}</Alert.Inline>
Expand Down
4 changes: 3 additions & 1 deletion src/lib/layout/createProject.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
<Typography.Title size="l">Create your project</Typography.Title>
{/if}
{#if projectsLimited}
<Alert.Inline status="warning" title="You've reached your limit of 2 projects">
<Alert.Inline
status="warning"
title={`You've reached your limit of ${$currentPlan?.projects || 2} projects`}>
Extra projects are available on paid plans for an additional fee
<svelte:fragment slot="actions">
<Button
Expand Down
9 changes: 6 additions & 3 deletions src/lib/stores/billing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,18 @@
return days;
}

export async function checkForProjectsLimit(org: Organization, projects: number) {
export async function checkForProjectsLimit(org: Organization, orgProjectCount?: number) {
if (!isCloud) return;
if (!org || !projects) return;
if (!org) return;
const plan = await sdk.forConsole.billing.getOrganizationPlan(org.$id);
if (!plan) return;
if (plan.$id !== BillingPlan.FREE) return;
if (org.projects?.length > 0) return;

if (plan.projects > 0 && projects > plan.projects) {
let projectCount = orgProjectCount;

Check failure on line 328 in src/lib/stores/billing.ts

View workflow job for this annotation

GitHub Actions / build

'projectCount' is never reassigned. Use 'const' instead
if (projectCount === undefined) return;
Copy link
Preview

Copilot AI Aug 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Early return when projectCount is undefined may silently skip important project limit checks. Consider logging this condition or providing a fallback mechanism to fetch the project count when it's not provided.

Suggested change
if (projectCount === undefined) return;
if (projectCount === undefined) {
console.warn('checkForProjectsLimit: projectCount is undefined, attempting to fetch project count for org', org?.$id);
try {
// Attempt to fetch the project count as a fallback
const projectsList = await sdk.forConsole.projects.list([Query.equal('organizationId', org.$id)]);
projectCount = projectsList?.total ?? projectsList?.projects?.length ?? 0;
} catch (err) {
console.error('checkForProjectsLimit: Failed to fetch project count for org', org?.$id, err);
return;
}
}

Copilot uses AI. Check for mistakes.


if (plan.projects > 0 && projectCount > plan.projects) {
headerAlert.add({
id: 'projectsLimitReached',
component: ProjectsLimit,
Expand Down
6 changes: 5 additions & 1 deletion src/routes/(console)/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,11 @@
if (currentOrganizationId === org.$id) return;
if (isCloud) {
currentOrganizationId = org.$id;
checkForProjectsLimit(org, data.allProjects?.projects?.length || 0);
const orgProjectCount =
data.allProjects && data.currentOrgId === org.$id
? data.allProjects.projects.length
: undefined;
checkForProjectsLimit(org, orgProjectCount);
checkForEnterpriseTrial(org);
await checkForUsageLimit(org);
checkForMarkedForDeletion(org);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
</DropList>
</div>

{#if isCloud && $currentPlan?.projects && $currentPlan?.projects > 0 && data.organization.projects.length > 0 && data.projects.total > 2 && $canWriteProjects}
{#if isCloud && $currentPlan?.projects && $currentPlan?.projects > 0 && data.organization.projects.length > 0 && data.projects.total > $currentPlan.projects && $canWriteProjects}
<Alert.Inline
title={`${data.projects.total - data.organization.projects.length} projects will be archived on ${toLocaleDate(billingProjectsLimitDate)}`}>
<Typography.Text>
Expand Down
Loading