|
23 | 23 | import { Icon, Tooltip, Typography } from '@appwrite.io/pink-svelte';
|
24 | 24 | import { IconPlus } from '@appwrite.io/pink-icons-svelte';
|
25 | 25 |
|
26 |
| - export let data: PageData; |
27 |
| - let addOrganization = false; |
| 26 | + const { |
| 27 | + data |
| 28 | + }: { |
| 29 | + data: PageData; |
| 30 | + } = $props(); |
28 | 31 |
|
29 |
| - const getMemberships = async (teamId: string) => { |
| 32 | + let addOrganization = $state(false); |
| 33 | +
|
| 34 | + async function getMemberships(teamId: string): Promise<string[]> { |
30 | 35 | const memberships = await sdk.forConsole.teams.listMemberships({ teamId });
|
31 | 36 | return memberships.memberships.map((team) => team.userName || team.userEmail);
|
32 |
| - }; |
| 37 | + } |
| 38 | +
|
| 39 | + function isOrganizationOnTrial(organization: Organization): boolean { |
| 40 | + if (!organization?.billingTrialStartDate) return false; |
| 41 | + if ($daysLeftInTrial <= 0) return false; |
| 42 | + if (organization.billingPlan === BillingPlan.FREE) return false; |
| 43 | +
|
| 44 | + return !!$plansInfo.get(organization.billingPlan)?.trialDays; |
| 45 | + } |
| 46 | +
|
| 47 | + function isNonPayingOrganization(organization: Organization): boolean { |
| 48 | + return ( |
| 49 | + organization?.billingPlan === BillingPlan.FREE || |
| 50 | + organization?.billingPlan === BillingPlan.GITHUB_EDUCATION |
| 51 | + ); |
| 52 | + } |
| 53 | +
|
| 54 | + function isPayingOrganization(team: Models.Preferences | Organization): Organization | null { |
| 55 | + const isPayingOrganization = |
| 56 | + isCloudOrg(team) && !isOrganizationOnTrial(team) && !isNonPayingOrganization(team); |
| 57 | +
|
| 58 | + if (isPayingOrganization) return team as Organization; |
| 59 | + else return null; |
| 60 | + } |
33 | 61 |
|
34 | 62 | function isCloudOrg(
|
35 | 63 | data: Partial<Models.TeamList<Models.Preferences>> | Organization
|
|
56 | 84 |
|
57 | 85 | {#if data.organizations.teams.length}
|
58 | 86 | <CardContainer
|
59 |
| - total={data.organizations.total} |
60 |
| - offset={data.offset} |
61 | 87 | event="organization"
|
62 |
| - on:click={createOrg}> |
| 88 | + offset={data.offset} |
| 89 | + on:click={createOrg} |
| 90 | + disableEmpty={false} |
| 91 | + total={data.organizations.total}> |
63 | 92 | {#each data.organizations.teams as organization}
|
64 | 93 | {@const avatarList = getMemberships(organization.$id)}
|
| 94 | + {@const payingOrg = isPayingOrganization(organization)} |
| 95 | + |
65 | 96 | <GridItem1 href={`${base}/organization-${organization.$id}`}>
|
66 | 97 | <svelte:fragment slot="eyebrow">
|
67 | 98 | {organization?.total}
|
|
72 | 103 | </svelte:fragment>
|
73 | 104 | <svelte:fragment slot="status">
|
74 | 105 | {#if isCloudOrg(organization)}
|
75 |
| - {#if organization?.billingPlan === BillingPlan.FREE || organization?.billingPlan === BillingPlan.GITHUB_EDUCATION} |
| 106 | + {#if isNonPayingOrganization(organization)} |
76 | 107 | <Tooltip>
|
77 |
| - <div class="u-flex u-cross-center"> |
78 |
| - <Badge |
79 |
| - variant="secondary" |
80 |
| - content={tierToPlan(organization?.billingPlan)?.name} |
81 |
| - class="eyebrow-heading-3" /> |
82 |
| - </div> |
83 |
| - <span slot="tooltip" |
84 |
| - >You are limited to 1 free organization per account</span> |
| 108 | + <Badge |
| 109 | + size="xs" |
| 110 | + variant="secondary" |
| 111 | + content={tierToPlan(organization?.billingPlan)?.name} /> |
| 112 | + |
| 113 | + <span slot="tooltip"> |
| 114 | + You are limited to 1 free organization per account |
| 115 | + </span> |
85 | 116 | </Tooltip>
|
86 | 117 | {/if}
|
87 |
| - {#if organization?.billingTrialStartDate && $daysLeftInTrial > 0 && organization.billingPlan !== BillingPlan.FREE && $plansInfo.get(organization.billingPlan)?.trialDays} |
| 118 | + |
| 119 | + {#if isOrganizationOnTrial(organization)} |
88 | 120 | <Tooltip>
|
89 | 121 | <div class="u-flex u-cross-center">
|
90 | 122 | <Badge
|
|
98 | 130 | )}. ${$daysLeftInTrial} days remaining.`}</span>
|
99 | 131 | </Tooltip>
|
100 | 132 | {/if}
|
| 133 | + |
| 134 | + {#if payingOrg} |
| 135 | + <Badge |
| 136 | + size="xs" |
| 137 | + type="success" |
| 138 | + variant="secondary" |
| 139 | + content={tierToPlan(payingOrg?.billingPlan)?.name} /> |
| 140 | + {/if} |
101 | 141 | {/if}
|
102 | 142 | </svelte:fragment>
|
103 | 143 | {#await avatarList}
|
|
0 commit comments