diff --git a/src/routes/(console)/account/organizations/+page.svelte b/src/routes/(console)/account/organizations/+page.svelte index e1e9565d4..a08500bb7 100644 --- a/src/routes/(console)/account/organizations/+page.svelte +++ b/src/routes/(console)/account/organizations/+page.svelte @@ -23,13 +23,41 @@ import { Icon, Tooltip, Typography } from '@appwrite.io/pink-svelte'; import { IconPlus } from '@appwrite.io/pink-icons-svelte'; - export let data: PageData; - let addOrganization = false; + const { + data + }: { + data: PageData; + } = $props(); - const getMemberships = async (teamId: string) => { + let addOrganization = $state(false); + + async function getMemberships(teamId: string): Promise { const memberships = await sdk.forConsole.teams.listMemberships({ teamId }); return memberships.memberships.map((team) => team.userName || team.userEmail); - }; + } + + function isOrganizationOnTrial(organization: Organization): boolean { + if (!organization?.billingTrialStartDate) return false; + if ($daysLeftInTrial <= 0) return false; + if (organization.billingPlan === BillingPlan.FREE) return false; + + return !!$plansInfo.get(organization.billingPlan)?.trialDays; + } + + function isNonPayingOrganization(organization: Organization): boolean { + return ( + organization?.billingPlan === BillingPlan.FREE || + organization?.billingPlan === BillingPlan.GITHUB_EDUCATION + ); + } + + function isPayingOrganization(team: Models.Preferences | Organization): Organization | null { + const isPayingOrganization = + isCloudOrg(team) && !isOrganizationOnTrial(team) && !isNonPayingOrganization(team); + + if (isPayingOrganization) return team as Organization; + else return null; + } function isCloudOrg( data: Partial> | Organization @@ -56,12 +84,15 @@ {#if data.organizations.teams.length} + offset={data.offset} + on:click={createOrg} + disableEmpty={false} + total={data.organizations.total}> {#each data.organizations.teams as organization} {@const avatarList = getMemberships(organization.$id)} + {@const payingOrg = isPayingOrganization(organization)} + {organization?.total} @@ -72,19 +103,20 @@ {#if isCloudOrg(organization)} - {#if organization?.billingPlan === BillingPlan.FREE || organization?.billingPlan === BillingPlan.GITHUB_EDUCATION} + {#if isNonPayingOrganization(organization)} -
- -
- You are limited to 1 free organization per account + + + + You are limited to 1 free organization per account +
{/if} - {#if organization?.billingTrialStartDate && $daysLeftInTrial > 0 && organization.billingPlan !== BillingPlan.FREE && $plansInfo.get(organization.billingPlan)?.trialDays} + + {#if isOrganizationOnTrial(organization)}
{/if} + + {#if payingOrg} + + {/if} {/if} {#await avatarList}