Merge remote-tracking branch 'origin/main' into spatial-type-attributes
No files matched your search
@@ -1,5 +1,5 @@
|
||||
PUBLIC_CONSOLE_MODE=self-hosted
|
||||
PUBLIC_CONSOLE_FEATURE_FLAGS=sites,index-lengths
|
||||
PUBLIC_CONSOLE_FEATURE_FLAGS=
|
||||
PUBLIC_APPWRITE_MULTI_REGION=false
|
||||
PUBLIC_APPWRITE_ENDPOINT=http://localhost/v1
|
||||
PUBLIC_STRIPE_KEY=
|
||||
|
||||
@@ -39,7 +39,7 @@ jobs:
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
build-args: |
|
||||
"PUBLIC_CONSOLE_MODE=cloud"
|
||||
"PUBLIC_CONSOLE_FEATURE_FLAGS=sites"
|
||||
"PUBLIC_CONSOLE_FEATURE_FLAGS="
|
||||
"PUBLIC_APPWRITE_MULTI_REGION=true"
|
||||
"PUBLIC_GROWTH_ENDPOINT=${{ secrets.PUBLIC_GROWTH_ENDPOINT }}"
|
||||
"PUBLIC_STRIPE_KEY=${{ secrets.PUBLIC_STRIPE_KEY }}"
|
||||
@@ -79,7 +79,7 @@ jobs:
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
build-args: |
|
||||
"PUBLIC_CONSOLE_MODE=cloud"
|
||||
"PUBLIC_CONSOLE_FEATURE_FLAGS=sites,index-lengths"
|
||||
"PUBLIC_CONSOLE_FEATURE_FLAGS="
|
||||
"PUBLIC_APPWRITE_MULTI_REGION=true"
|
||||
"PUBLIC_GROWTH_ENDPOINT=${{ secrets.PUBLIC_GROWTH_ENDPOINT }}"
|
||||
"PUBLIC_STRIPE_KEY=${{ secrets.PUBLIC_STRIPE_KEY_STAGE }}"
|
||||
@@ -118,7 +118,7 @@ jobs:
|
||||
build-args: |
|
||||
"PUBLIC_CONSOLE_MODE=self-hosted"
|
||||
"PUBLIC_APPWRITE_MULTI_REGION=false"
|
||||
"PUBLIC_CONSOLE_FEATURE_FLAGS=sites,index-lengths"
|
||||
"PUBLIC_CONSOLE_FEATURE_FLAGS="
|
||||
"PUBLIC_GROWTH_ENDPOINT=${{ secrets.PUBLIC_GROWTH_ENDPOINT }}"
|
||||
|
||||
publish-cloud-no-regions:
|
||||
@@ -156,6 +156,6 @@ jobs:
|
||||
build-args: |
|
||||
"PUBLIC_CONSOLE_MODE=cloud"
|
||||
"PUBLIC_APPWRITE_MULTI_REGION=false"
|
||||
"PUBLIC_CONSOLE_FEATURE_FLAGS=sites,index-lengths"
|
||||
"PUBLIC_CONSOLE_FEATURE_FLAGS="
|
||||
"PUBLIC_STRIPE_KEY=${{ secrets.PUBLIC_STRIPE_KEY_STAGE }}"
|
||||
"PUBLIC_GROWTH_ENDPOINT=${{ secrets.PUBLIC_GROWTH_ENDPOINT }}"
|
||||
@@ -6,12 +6,6 @@ server {
|
||||
|
||||
root /usr/share/nginx/html;
|
||||
|
||||
# Security headers for all locations
|
||||
add_header X-UA-Compatible "IE=Edge";
|
||||
add_header X-Frame-Options SAMEORIGIN;
|
||||
add_header X-XSS-Protection "1; mode=block;";
|
||||
add_header X-Content-Type-Options nosniff;
|
||||
|
||||
# Only cache files in /console/_app/immutable/ for 1 year
|
||||
location /console/_app/immutable/ {
|
||||
try_files $uri =404;
|
||||
@@ -35,6 +29,12 @@ server {
|
||||
expires 0;
|
||||
add_header Cache-Control "no-cache, no-store";
|
||||
add_header Pragma "no-cache";
|
||||
|
||||
# Security headers
|
||||
add_header X-UA-Compatible "IE=Edge";
|
||||
add_header X-Frame-Options SAMEORIGIN;
|
||||
add_header X-XSS-Protection "1; mode=block;";
|
||||
add_header X-Content-Type-Options nosniff;
|
||||
}
|
||||
|
||||
location / {
|
||||
|
||||
@@ -10,7 +10,6 @@ test('upgrade - free tier', async ({ page }) => {
|
||||
await page.getByRole('link', { name: 'Upgrade', exact: true }).click();
|
||||
await page.waitForURL(/\/organization-[^/]+\/change-plan/);
|
||||
await page.locator('input[value="tier-1"]').click();
|
||||
await page.getByRole('button', { name: 'add' }).first().click();
|
||||
|
||||
await enterCreditCard(page);
|
||||
|
||||
|
||||
@@ -7,12 +7,15 @@ type Metadata = {
|
||||
};
|
||||
|
||||
export async function enterCreditCard(page: Page) {
|
||||
const dialog = page.locator('.modal').filter({
|
||||
hasText: 'add payment method'
|
||||
});
|
||||
await dialog.waitFor({
|
||||
state: 'visible'
|
||||
});
|
||||
// click the `add` button inside correct view layer
|
||||
await page
|
||||
.locator('#no-payments-card-stack')
|
||||
.getByRole('button', { name: 'add' })
|
||||
.first()
|
||||
.click();
|
||||
|
||||
const dialog = page.locator('.modal').filter({ hasText: 'add payment method' });
|
||||
await dialog.waitFor({ state: 'visible' });
|
||||
await page.getByPlaceholder('cardholder').fill('Test User');
|
||||
const stripe = page.locator('[title="Secure payment input frame"]').nth(0).contentFrame();
|
||||
await stripe.locator('id=Field-numberInput').fill('4242424242424242');
|
||||
@@ -35,7 +38,6 @@ export async function createProProject(page: Page): Promise<Metadata> {
|
||||
await page.getByRole('radio', { name: /^Pro\b/ }).check();
|
||||
// `create organization` because there's already free created on start!
|
||||
await page.getByRole('button', { name: 'create organization' }).click();
|
||||
await page.getByRole('button', { name: 'add' }).first().click();
|
||||
await enterCreditCard(page);
|
||||
// skip members
|
||||
await page.getByRole('button', { name: 'create organization' }).click();
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
"@ai-sdk/svelte": "^1.1.24",
|
||||
"@appwrite.io/console": "https://pkg.pr.new/appwrite-labs/cloud/@appwrite.io/console@6d2d4ec",
|
||||
"@appwrite.io/pink-icons": "0.25.0",
|
||||
"@appwrite.io/pink-icons-svelte": "^2.0.0-RC.1",
|
||||
"@appwrite.io/pink-icons-svelte": "https://pkg.vc/-/@appwrite/@appwrite.io/pink-icons-svelte@2cf27e0",
|
||||
"@appwrite.io/pink-legacy": "^1.0.3",
|
||||
"@appwrite.io/pink-svelte": "https://pkg.vc/-/@appwrite/@appwrite.io/pink-svelte@0f90bf1",
|
||||
"@appwrite.io/pink-svelte": "https://pkg.vc/-/@appwrite/@appwrite.io/pink-svelte@40fb564",
|
||||
"@faker-js/faker": "^9.9.0",
|
||||
"@popperjs/core": "^2.11.8",
|
||||
"@sentry/sveltekit": "^8.38.0",
|
||||
@@ -95,5 +95,5 @@
|
||||
"svelte-preprocess"
|
||||
]
|
||||
},
|
||||
"packageManager": "pnpm@10.15.0"
|
||||
"packageManager": "pnpm@10.15.1"
|
||||
}
|
||||
@@ -18,14 +18,14 @@ importers:
|
||||
specifier: 0.25.0
|
||||
version: 0.25.0
|
||||
'@appwrite.io/pink-icons-svelte':
|
||||
specifier: ^2.0.0-RC.1
|
||||
version: https://try-module.cloud/module/@appwrite/%40appwrite.io%2Fpink-icons-svelte@12707b9(svelte@5.25.3)
|
||||
specifier: https://pkg.vc/-/@appwrite/@appwrite.io/pink-icons-svelte@2cf27e0
|
||||
version: https://pkg.vc/-/@appwrite/@appwrite.io/pink-icons-svelte@2cf27e0(svelte@5.25.3)
|
||||
'@appwrite.io/pink-legacy':
|
||||
specifier: ^1.0.3
|
||||
version: 1.0.3
|
||||
'@appwrite.io/pink-svelte':
|
||||
specifier: https://pkg.vc/-/@appwrite/@appwrite.io/pink-svelte@0f90bf1
|
||||
version: https://pkg.vc/-/@appwrite/@appwrite.io/pink-svelte@0f90bf1(svelte@5.25.3)
|
||||
specifier: https://pkg.vc/-/@appwrite/@appwrite.io/pink-svelte@40fb564
|
||||
version: https://pkg.vc/-/@appwrite/@appwrite.io/pink-svelte@40fb564(svelte@5.25.3)
|
||||
'@faker-js/faker':
|
||||
specifier: ^9.9.0
|
||||
version: 9.9.0
|
||||
@@ -269,8 +269,8 @@ packages:
|
||||
peerDependencies:
|
||||
svelte: ^4.0.0
|
||||
|
||||
'@appwrite.io/pink-icons-svelte@https://try-module.cloud/module/@appwrite/%40appwrite.io%2Fpink-icons-svelte@12707b9':
|
||||
resolution: {tarball: https://try-module.cloud/module/@appwrite/%40appwrite.io%2Fpink-icons-svelte@12707b9}
|
||||
'@appwrite.io/pink-icons-svelte@https://pkg.vc/-/@appwrite/@appwrite.io/pink-icons-svelte@2cf27e0':
|
||||
resolution: {tarball: https://pkg.vc/-/@appwrite/@appwrite.io/pink-icons-svelte@2cf27e0}
|
||||
version: 2.0.0-RC.1
|
||||
peerDependencies:
|
||||
svelte: ^4.0.0
|
||||
@@ -284,8 +284,8 @@ packages:
|
||||
'@appwrite.io/pink-legacy@1.0.3':
|
||||
resolution: {integrity: sha512-GGde5fmPhs+s6/3aFeMPc/kKADG/gTFkYQSy6oBN8pK0y0XNCLrZZgBv+EBbdhwdtqVEWXa0X85Mv9w7jcIlwQ==}
|
||||
|
||||
'@appwrite.io/pink-svelte@https://pkg.vc/-/@appwrite/@appwrite.io/pink-svelte@0f90bf1':
|
||||
resolution: {tarball: https://pkg.vc/-/@appwrite/@appwrite.io/pink-svelte@0f90bf1}
|
||||
'@appwrite.io/pink-svelte@https://pkg.vc/-/@appwrite/@appwrite.io/pink-svelte@40fb564':
|
||||
resolution: {tarball: https://pkg.vc/-/@appwrite/@appwrite.io/pink-svelte@40fb564}
|
||||
version: 2.0.0-RC.2
|
||||
peerDependencies:
|
||||
svelte: ^4.0.0
|
||||
@@ -3706,7 +3706,7 @@ snapshots:
|
||||
dependencies:
|
||||
svelte: 5.25.3
|
||||
|
||||
'@appwrite.io/pink-icons-svelte@https://try-module.cloud/module/@appwrite/%40appwrite.io%2Fpink-icons-svelte@12707b9(svelte@5.25.3)':
|
||||
'@appwrite.io/pink-icons-svelte@https://pkg.vc/-/@appwrite/@appwrite.io/pink-icons-svelte@2cf27e0(svelte@5.25.3)':
|
||||
dependencies:
|
||||
svelte: 5.25.3
|
||||
|
||||
@@ -3719,7 +3719,7 @@ snapshots:
|
||||
'@appwrite.io/pink-icons': 1.0.0
|
||||
the-new-css-reset: 1.11.3
|
||||
|
||||
'@appwrite.io/pink-svelte@https://pkg.vc/-/@appwrite/@appwrite.io/pink-svelte@0f90bf1(svelte@5.25.3)':
|
||||
'@appwrite.io/pink-svelte@https://pkg.vc/-/@appwrite/@appwrite.io/pink-svelte@40fb564(svelte@5.25.3)':
|
||||
dependencies:
|
||||
'@appwrite.io/pink-icons-svelte': 2.0.0-RC.1(svelte@5.25.3)
|
||||
'@floating-ui/dom': 1.6.13
|
||||
|
||||
@@ -0,0 +1,384 @@
|
||||
<script lang="ts">
|
||||
import { Button, InputText } from '$lib/elements/forms';
|
||||
import { DropList, GridItem1, CardContainer, Modal } from '$lib/components';
|
||||
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
|
||||
import {
|
||||
Badge,
|
||||
Icon,
|
||||
Typography,
|
||||
Tag,
|
||||
Accordion,
|
||||
ActionMenu,
|
||||
Popover,
|
||||
Layout,
|
||||
Divider
|
||||
} from '@appwrite.io/pink-svelte';
|
||||
import {
|
||||
IconAndroid,
|
||||
IconApple,
|
||||
IconCode,
|
||||
IconFlutter,
|
||||
IconReact,
|
||||
IconUnity,
|
||||
IconInfo,
|
||||
IconDotsHorizontal,
|
||||
IconInboxIn,
|
||||
IconSwitchHorizontal,
|
||||
IconTrash
|
||||
} from '@appwrite.io/pink-icons-svelte';
|
||||
import { getPlatformInfo } from '$lib/helpers/platform';
|
||||
import { Status, type Models } from '@appwrite.io/console';
|
||||
import type { ComponentType } from 'svelte';
|
||||
import { BillingPlan } from '$lib/constants';
|
||||
import { goto } from '$app/navigation';
|
||||
import { base } from '$app/paths';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { invalidate } from '$app/navigation';
|
||||
import { Dependencies } from '$lib/constants';
|
||||
|
||||
import { isSmallViewport } from '$lib/stores/viewport';
|
||||
import { isCloud } from '$lib/system';
|
||||
import { regions as regionsStore } from '$lib/stores/organization';
|
||||
import type { Organization } from '$lib/stores/organization';
|
||||
import type { Plan } from '$lib/sdk/billing';
|
||||
|
||||
// props
|
||||
interface Props {
|
||||
projectsToArchive: Models.Project[];
|
||||
organization: Organization;
|
||||
currentPlan: Plan;
|
||||
}
|
||||
|
||||
let { projectsToArchive, organization, currentPlan }: Props = $props();
|
||||
|
||||
// Track Read-only info droplist per archived project
|
||||
let readOnlyInfoOpen = $state<Record<string, boolean>>({});
|
||||
let showUnarchiveModal = $state(false);
|
||||
let projectToUnarchive = $state<Models.Project | null>(null);
|
||||
let showDeleteModal = $state(false);
|
||||
let projectToDelete = $state<Models.Project | null>(null);
|
||||
let deleteProjectName = $state<string | null>(null);
|
||||
let deleteError = $state<string | null>(null);
|
||||
|
||||
function resetDeleteState() {
|
||||
showDeleteModal = false;
|
||||
projectToDelete = null;
|
||||
deleteProjectName = null;
|
||||
deleteError = null;
|
||||
}
|
||||
|
||||
function filterPlatforms(platforms: { name: string; icon: string }[]) {
|
||||
return platforms.filter(
|
||||
(value, index, self) => index === self.findIndex((t) => t.name === value.name)
|
||||
);
|
||||
}
|
||||
|
||||
function getIconForPlatform(platform: string): ComponentType {
|
||||
switch (platform) {
|
||||
case 'code':
|
||||
return IconCode;
|
||||
case 'flutter':
|
||||
return IconFlutter;
|
||||
case 'apple':
|
||||
return IconApple;
|
||||
case 'android':
|
||||
return IconAndroid;
|
||||
case 'react-native':
|
||||
return IconReact;
|
||||
case 'unity':
|
||||
return IconUnity;
|
||||
default:
|
||||
return IconCode;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if unarchive should be disabled
|
||||
function isUnarchiveDisabled(): boolean {
|
||||
if (!organization || !currentPlan) return true;
|
||||
|
||||
if (organization.billingPlan === BillingPlan.FREE) {
|
||||
const currentProjectCount = organization.projects?.length || 0;
|
||||
const projectLimit = currentPlan.projects || 0;
|
||||
|
||||
return currentProjectCount >= projectLimit;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function handleMigrateProject(project: Models.Project) {
|
||||
goto(`${base}/project-${project.region}-${project.$id}/settings/migrations`);
|
||||
}
|
||||
|
||||
// Handle unarchive project action
|
||||
async function handleUnarchiveProject(project: Models.Project) {
|
||||
projectToUnarchive = project;
|
||||
showUnarchiveModal = true;
|
||||
}
|
||||
|
||||
function handleDeleteProject(project: Models.Project) {
|
||||
projectToDelete = project;
|
||||
deleteProjectName = null;
|
||||
showDeleteModal = true;
|
||||
}
|
||||
|
||||
// Confirm unarchive action
|
||||
async function confirmUnarchive() {
|
||||
if (!projectToUnarchive) return;
|
||||
|
||||
try {
|
||||
if (!organization) {
|
||||
addNotification({
|
||||
type: 'error',
|
||||
message: 'Organization not found'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
await sdk.forConsole.projects.updateStatus(projectToUnarchive.$id, Status.Active);
|
||||
|
||||
await invalidate(Dependencies.ORGANIZATION);
|
||||
|
||||
addNotification({
|
||||
type: 'success',
|
||||
message: `${projectToUnarchive.name} has been unarchived`
|
||||
});
|
||||
|
||||
showUnarchiveModal = false;
|
||||
projectToUnarchive = null;
|
||||
} catch (error) {
|
||||
const msg =
|
||||
error && typeof error === 'object' && 'message' in error
|
||||
? String((error as { message: string }).message)
|
||||
: 'Failed to unarchive project';
|
||||
addNotification({ type: 'error', message: msg });
|
||||
}
|
||||
}
|
||||
|
||||
function cancelUnarchive() {
|
||||
showUnarchiveModal = false;
|
||||
projectToUnarchive = null;
|
||||
}
|
||||
|
||||
async function confirmDelete() {
|
||||
if (!projectToDelete) return;
|
||||
|
||||
try {
|
||||
await sdk.forConsoleIn(projectToDelete.region).projects.delete({
|
||||
projectId: projectToDelete.$id
|
||||
});
|
||||
|
||||
await invalidate(Dependencies.ORGANIZATION);
|
||||
|
||||
trackEvent(Submit.ProjectDelete);
|
||||
addNotification({
|
||||
type: 'success',
|
||||
message: `${projectToDelete.name} has been deleted`
|
||||
});
|
||||
|
||||
resetDeleteState();
|
||||
} catch (error) {
|
||||
deleteError = error.message;
|
||||
trackError(error, Submit.ProjectDelete);
|
||||
}
|
||||
}
|
||||
|
||||
function findRegion(project: Models.Project) {
|
||||
return $regionsStore.regions.find((region) => region.$id === project.region);
|
||||
}
|
||||
|
||||
import { formatName as formatNameHelper } from '$lib/helpers/string';
|
||||
function formatName(name: string, limit: number = 19) {
|
||||
return formatNameHelper(name, limit, $isSmallViewport);
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if projectsToArchive.length > 0}
|
||||
<div class="archive-projects-margin-top">
|
||||
<Accordion title="Archived projects" badge={`${projectsToArchive.length}`}>
|
||||
<Typography.Text tag="p" size="s">
|
||||
These projects have been archived and are read-only. You can view and migrate their
|
||||
data.
|
||||
</Typography.Text>
|
||||
|
||||
<div class="archive-projects-margin">
|
||||
<CardContainer disableEmpty={true} total={projectsToArchive.length}>
|
||||
{#each projectsToArchive as project}
|
||||
{@const platforms = filterPlatforms(
|
||||
project.platforms.map((platform) => getPlatformInfo(platform.type))
|
||||
)}
|
||||
{@const formatted = formatName(project.name)}
|
||||
<GridItem1>
|
||||
<svelte:fragment slot="eyebrow">
|
||||
{project?.platforms?.length ? project?.platforms?.length : 'No'} apps
|
||||
</svelte:fragment>
|
||||
<svelte:fragment slot="title">{formatted}</svelte:fragment>
|
||||
<svelte:fragment slot="status">
|
||||
<div class="status-container">
|
||||
<DropList
|
||||
bind:show={readOnlyInfoOpen[project.$id]}
|
||||
placement="bottom-start"
|
||||
noArrow>
|
||||
<Tag
|
||||
size="s"
|
||||
style="white-space: nowrap;"
|
||||
on:click={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
readOnlyInfoOpen = {
|
||||
...readOnlyInfoOpen,
|
||||
[project.$id]: !readOnlyInfoOpen[project.$id]
|
||||
};
|
||||
}}>
|
||||
<Icon icon={IconInfo} size="s" />
|
||||
<span>Read only</span>
|
||||
</Tag>
|
||||
<svelte:fragment slot="list">
|
||||
<li
|
||||
class="drop-list-item u-width-250"
|
||||
style="padding: var(--space-5, 12px) var(--space-6, 16px)">
|
||||
<span class="u-block u-mb-8">
|
||||
Archived projects are read-only. You can view
|
||||
and migrate their data, but they no longer
|
||||
accept edits or requests.
|
||||
</span>
|
||||
</li>
|
||||
</svelte:fragment>
|
||||
</DropList>
|
||||
<Popover let:toggle padding="none" placement="bottom-end">
|
||||
<Button
|
||||
text
|
||||
icon
|
||||
size="s"
|
||||
ariaLabel="more options"
|
||||
on:click={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
toggle(e);
|
||||
}}>
|
||||
<Icon icon={IconDotsHorizontal} size="s" />
|
||||
</Button>
|
||||
<ActionMenu.Root slot="tooltip">
|
||||
<ActionMenu.Item.Button
|
||||
leadingIcon={IconInboxIn}
|
||||
disabled={isUnarchiveDisabled()}
|
||||
on:click={() => handleUnarchiveProject(project)}
|
||||
>Unarchive project</ActionMenu.Item.Button>
|
||||
<ActionMenu.Item.Button
|
||||
leadingIcon={IconSwitchHorizontal}
|
||||
on:click={() => handleMigrateProject(project)}
|
||||
>Migrate project</ActionMenu.Item.Button>
|
||||
<div class="action-menu-divider">
|
||||
<Divider />
|
||||
</div>
|
||||
<ActionMenu.Item.Button
|
||||
status="danger"
|
||||
leadingIcon={IconTrash}
|
||||
on:click={() => handleDeleteProject(project)}
|
||||
>Delete project</ActionMenu.Item.Button>
|
||||
</ActionMenu.Root>
|
||||
</Popover>
|
||||
</div>
|
||||
</svelte:fragment>
|
||||
|
||||
{#each platforms.slice(0, 2) as platform}
|
||||
{@const icon = getIconForPlatform(platform.icon)}
|
||||
<Badge
|
||||
variant="secondary"
|
||||
content={platform.name}
|
||||
style="width: max-content;">
|
||||
<Icon {icon} size="s" slot="start" />
|
||||
</Badge>
|
||||
{/each}
|
||||
|
||||
{#if platforms.length > 3}
|
||||
<Badge
|
||||
variant="secondary"
|
||||
content={`+${platforms.length - 2}`}
|
||||
style="width: max-content;" />
|
||||
{/if}
|
||||
|
||||
<svelte:fragment slot="icons">
|
||||
{#if isCloud && $regionsStore?.regions}
|
||||
{@const region = findRegion(project)}
|
||||
<Typography.Text>{region?.name}</Typography.Text>
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
</GridItem1>
|
||||
{/each}
|
||||
</CardContainer>
|
||||
</div>
|
||||
</Accordion>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Unarchive Confirmation Modal -->
|
||||
<Modal bind:show={showUnarchiveModal} title="Unarchive project" size="s">
|
||||
<p>Are you sure you want to unarchive <strong>{projectToUnarchive?.name}</strong>?</p>
|
||||
<p>This will move the project back to your active projects list.</p>
|
||||
|
||||
<svelte:fragment slot="footer">
|
||||
<Layout.Stack direction="row" gap="s" justifyContent="flex-end">
|
||||
<Button secondary on:click={cancelUnarchive}>Cancel</Button>
|
||||
<Button on:click={confirmUnarchive}>Unarchive</Button>
|
||||
</Layout.Stack>
|
||||
</svelte:fragment>
|
||||
</Modal>
|
||||
|
||||
<!-- Delete Confirmation Modal -->
|
||||
<Modal
|
||||
size="s"
|
||||
bind:show={showDeleteModal}
|
||||
title="Delete project"
|
||||
onSubmit={confirmDelete}
|
||||
bind:error={deleteError}>
|
||||
<svelte:fragment slot="description">
|
||||
The archived project <strong>{projectToDelete?.name}</strong> will be deleted along with all
|
||||
of its metadata, stats, and other resources.
|
||||
<b>This action is irreversible.</b>
|
||||
</svelte:fragment>
|
||||
|
||||
<InputText
|
||||
label={`Enter "${projectToDelete?.name}" to continue`}
|
||||
placeholder="Enter name"
|
||||
id="delete-project-name"
|
||||
autofocus
|
||||
required
|
||||
bind:value={deleteProjectName} />
|
||||
|
||||
<svelte:fragment slot="footer">
|
||||
<Button
|
||||
text
|
||||
on:click={() => {
|
||||
resetDeleteState();
|
||||
}}>Cancel</Button>
|
||||
<Button
|
||||
submissionLoader
|
||||
submit
|
||||
disabled={(deleteProjectName ?? '') !== projectToDelete?.name}>
|
||||
Delete
|
||||
</Button>
|
||||
</svelte:fragment>
|
||||
</Modal>
|
||||
|
||||
<style>
|
||||
.archive-projects-margin-top {
|
||||
margin-top: 36px;
|
||||
}
|
||||
.action-menu-divider {
|
||||
margin-inline: -1rem;
|
||||
padding-block-start: 0.25rem;
|
||||
padding-block-end: 0.25rem;
|
||||
}
|
||||
|
||||
.archive-projects-margin {
|
||||
margin-top: 16px;
|
||||
margin-bottom: 36px;
|
||||
}
|
||||
.status-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
</style>
|
||||
@@ -20,9 +20,14 @@
|
||||
plan. Consider upgrading to increase your resource usage.
|
||||
</svelte:fragment>
|
||||
<svelte:fragment slot="buttons">
|
||||
<Button href={`${base}/organization-${$organization.$id}/usage`} text fullWidthMobile>
|
||||
<span class="text">View usage</span>
|
||||
</Button>
|
||||
{#if !page.data.currentPlan?.usagePerProject}
|
||||
<Button
|
||||
href={`${base}/organization-${$organization.$id}/usage`}
|
||||
text
|
||||
fullWidthMobile>
|
||||
<span class="text">View usage</span>
|
||||
</Button>
|
||||
{/if}
|
||||
<Button
|
||||
href={$upgradeURL}
|
||||
on:click={() => {
|
||||
|
||||
@@ -3,12 +3,8 @@
|
||||
import { Click } from '$lib/actions/analytics';
|
||||
import { Button } from '$lib/elements/forms';
|
||||
import { HeaderAlert } from '$lib/layout';
|
||||
import {
|
||||
billingProjectsLimitDate,
|
||||
hideBillingHeaderRoutes,
|
||||
upgradeURL
|
||||
} from '$lib/stores/billing';
|
||||
import { currentPlan } from '$lib/stores/organization';
|
||||
import { hideBillingHeaderRoutes, upgradeURL } from '$lib/stores/billing';
|
||||
import { currentPlan, organization } from '$lib/stores/organization';
|
||||
import SelectProjectCloud from './selectProjectCloud.svelte';
|
||||
import { toLocaleDate } from '$lib/helpers/date';
|
||||
|
||||
@@ -31,8 +27,9 @@
|
||||
type="warning"
|
||||
title="Action required: You have more than {$currentPlan.projects} projects.">
|
||||
<svelte:fragment>
|
||||
Choose which projects to keep before {toLocaleDate(billingProjectsLimitDate)} or upgrade
|
||||
to Pro. Projects over the limit will be blocked after this date.
|
||||
Choose which projects to keep before {toLocaleDate(
|
||||
$organization.billingNextInvoiceDate
|
||||
)} or upgrade to Pro. Projects over the limit will be blocked after this date.
|
||||
</svelte:fragment>
|
||||
<svelte:fragment slot="buttons">
|
||||
<Button
|
||||
|
||||
@@ -6,9 +6,8 @@
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { invalidate } from '$app/navigation';
|
||||
import { Dependencies } from '$lib/constants';
|
||||
import { billingProjectsLimitDate } from '$lib/stores/billing';
|
||||
import { toLocaleDate, toLocaleDateTime } from '$lib/helpers/date';
|
||||
import { currentPlan } from '$lib/stores/organization';
|
||||
import { currentPlan, organization } from '$lib/stores/organization';
|
||||
|
||||
let {
|
||||
showSelectProject = $bindable(false),
|
||||
@@ -149,9 +148,12 @@
|
||||
{/if}
|
||||
|
||||
{#if selectedProjects.length === $currentPlan?.projects}
|
||||
{@const difference = projects.length - selectedProjects.length}
|
||||
{@const messagePrefix =
|
||||
difference > 1 ? `${difference} projects` : `${difference} project`}
|
||||
<Alert.Inline
|
||||
status="warning"
|
||||
title={`${projects.length - selectedProjects.length} projects will be archived on ${toLocaleDate(billingProjectsLimitDate)}`}>
|
||||
title={`${messagePrefix} will be archived on ${toLocaleDate($organization.billingNextInvoiceDate)}`}>
|
||||
<span>
|
||||
{@html formatProjectsToArchive()}
|
||||
will be archived.
|
||||
|
||||
@@ -90,6 +90,7 @@
|
||||
<Typography.Text>Everything in the Free plan, plus:</Typography.Text>
|
||||
<ul class="un-order-list">
|
||||
<li>Unlimited databases, buckets, functions</li>
|
||||
<li>Unlimited seats</li>
|
||||
<li>{plan.bandwidth}GB bandwidth</li>
|
||||
<li>{plan.storage}GB storage</li>
|
||||
<li>{formatNum(plan.executions)} executions</li>
|
||||
|
||||
@@ -1,16 +1,22 @@
|
||||
<script lang="ts">
|
||||
import { calculateExcess, plansInfo, tierToPlan, type Tier } from '$lib/stores/billing';
|
||||
import {
|
||||
calculateExcess,
|
||||
plansInfo,
|
||||
tierToPlan,
|
||||
getServiceLimit,
|
||||
type Tier
|
||||
} from '$lib/stores/billing';
|
||||
import { organization } from '$lib/stores/organization';
|
||||
import { toLocaleDate } from '$lib/helpers/date';
|
||||
import { humanFileSize } from '$lib/helpers/sizeConvertion';
|
||||
import { abbreviateNumber } from '$lib/helpers/numbers';
|
||||
import { formatNum } from '$lib/helpers/string';
|
||||
import { onMount } from 'svelte';
|
||||
import type { Aggregation } from '$lib/sdk/billing';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { BillingPlan } from '$lib/constants';
|
||||
import { Alert, Icon, Table, Tooltip } from '@appwrite.io/pink-svelte';
|
||||
import { IconInfo } from '@appwrite.io/pink-icons-svelte';
|
||||
import type { AggregationTeam } from '$lib/sdk/billing';
|
||||
|
||||
export let tier: Tier;
|
||||
|
||||
@@ -22,7 +28,7 @@
|
||||
executions?: number;
|
||||
members?: number;
|
||||
} = null;
|
||||
let aggregation: Aggregation = null;
|
||||
let aggregation: AggregationTeam = null;
|
||||
let showExcess = false;
|
||||
|
||||
onMount(async () => {
|
||||
@@ -64,7 +70,7 @@
|
||||
{#if excess?.members}
|
||||
<Table.Row.Base {root}>
|
||||
<Table.Cell {root}>Organization members</Table.Cell>
|
||||
<Table.Cell {root}>{plan.addons.seats.limit} members</Table.Cell>
|
||||
<Table.Cell {root}>{getServiceLimit('members', tier)} members</Table.Cell>
|
||||
<Table.Cell {root}>
|
||||
<p class="u-color-text-danger u-flex u-cross-center u-gap-4">
|
||||
<span class="icon-arrow-up"></span>
|
||||
|
||||
@@ -1,77 +1,46 @@
|
||||
<script lang="ts">
|
||||
import { BASE_BILLING_PLANS, BillingPlan } from '$lib/constants';
|
||||
import { BillingPlan } from '$lib/constants';
|
||||
import { formatCurrency } from '$lib/helpers/numbers';
|
||||
import { plansInfo, type Tier, tierFree, tierPro, tierScale } from '$lib/stores/billing';
|
||||
import { currentPlan, organization } from '$lib/stores/organization';
|
||||
import { Badge, Layout, Typography } from '@appwrite.io/pink-svelte';
|
||||
import { LabelCard } from '..';
|
||||
import type { Plan } from '$lib/sdk/billing';
|
||||
import { page } from '$app/state';
|
||||
|
||||
export let billingPlan: Tier;
|
||||
export let billingPlan: BillingPlan;
|
||||
export let isNewOrg = false;
|
||||
export let selfService = true;
|
||||
export let anyOrgFree = false;
|
||||
|
||||
$: freePlan = $plansInfo.get(BillingPlan.FREE);
|
||||
$: proPlan = $plansInfo.get(BillingPlan.PRO);
|
||||
$: scalePlan = $plansInfo.get(BillingPlan.SCALE);
|
||||
|
||||
$: isBasePlan = BASE_BILLING_PLANS.includes($currentPlan?.$id);
|
||||
$: plans = Object.values(page.data.plans.plans) as Plan[];
|
||||
$: currentPlanInList = plans.some((plan) => plan.$id === $currentPlan?.$id);
|
||||
</script>
|
||||
|
||||
<Layout.Stack>
|
||||
<LabelCard
|
||||
name="plan"
|
||||
bind:group={billingPlan}
|
||||
disabled={!selfService}
|
||||
value={BillingPlan.FREE}
|
||||
title={tierFree.name}>
|
||||
<svelte:fragment slot="action">
|
||||
{#if $organization?.billingPlan === BillingPlan.FREE && !isNewOrg}
|
||||
<Badge variant="secondary" size="xs" content="Current plan" />
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
<Typography.Caption variant="400">
|
||||
{tierFree.description}
|
||||
</Typography.Caption>
|
||||
<Typography.Text>
|
||||
{formatCurrency(freePlan?.price ?? 0)}
|
||||
</Typography.Text>
|
||||
</LabelCard>
|
||||
<LabelCard
|
||||
name="plan"
|
||||
disabled={!selfService}
|
||||
bind:group={billingPlan}
|
||||
value={BillingPlan.PRO}
|
||||
title={tierPro.name}>
|
||||
<svelte:fragment slot="action">
|
||||
{#if $organization?.billingPlan === BillingPlan.PRO && !isNewOrg}
|
||||
<Badge variant="secondary" size="xs" content="Current plan" />
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
<Typography.Caption variant="400">
|
||||
{tierPro.description}
|
||||
</Typography.Caption>
|
||||
<Typography.Text>
|
||||
{formatCurrency(proPlan?.price ?? 0)} per month + usage
|
||||
</Typography.Text>
|
||||
</LabelCard>
|
||||
<LabelCard
|
||||
name="plan"
|
||||
bind:group={billingPlan}
|
||||
value={BillingPlan.SCALE}
|
||||
title={tierScale.name}>
|
||||
<svelte:fragment slot="action">
|
||||
{#if $organization?.billingPlan === BillingPlan.SCALE && !isNewOrg}
|
||||
<Badge variant="secondary" size="xs" content="Current plan" />
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
<Typography.Caption variant="400">
|
||||
{tierScale.description}
|
||||
</Typography.Caption>
|
||||
<Typography.Text>
|
||||
{formatCurrency(scalePlan?.price ?? 0)} per month + usage
|
||||
</Typography.Text>
|
||||
</LabelCard>
|
||||
{#if $currentPlan && !isBasePlan}
|
||||
{#each plans as plan}
|
||||
<LabelCard
|
||||
name="plan"
|
||||
bind:group={billingPlan}
|
||||
disabled={!selfService || (plan.$id === BillingPlan.FREE && anyOrgFree)}
|
||||
tooltipShow={plan.$id === BillingPlan.FREE && anyOrgFree}
|
||||
value={plan.$id}
|
||||
title={plan.name}>
|
||||
<svelte:fragment slot="action">
|
||||
{#if $organization?.billingPlan === plan.$id && !isNewOrg}
|
||||
<Badge variant="secondary" size="xs" content="Current plan" />
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
<Typography.Caption variant="400">
|
||||
{plan.desc}
|
||||
</Typography.Caption>
|
||||
<Typography.Text>
|
||||
{@const isZeroPrice = (plan.price ?? 0) <= 0}
|
||||
{@const price = formatCurrency(plan.price ?? 0)}
|
||||
{isZeroPrice ? price : `${price} per month + usage`}
|
||||
</Typography.Text>
|
||||
</LabelCard>
|
||||
{/each}
|
||||
{#if $currentPlan && !currentPlanInList}
|
||||
<LabelCard
|
||||
name="plan"
|
||||
bind:group={billingPlan}
|
||||
|
||||
@@ -78,7 +78,7 @@
|
||||
</Layout.Stack>
|
||||
{:else}
|
||||
<Card.Base variant="secondary" radius="s" padding="xs">
|
||||
<Layout.Stack direction="row">
|
||||
<Layout.Stack direction="row" id="no-payments-card-stack">
|
||||
<Layout.Stack direction="row" gap="xxs" alignItems="center">
|
||||
<Icon
|
||||
icon={IconExclamationCircle}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import { toLocaleDate } from '$lib/helpers/date';
|
||||
import { type Organization } from '$lib/stores/organization';
|
||||
import { plansInfo } from '$lib/stores/billing';
|
||||
import { abbreviateNumber, formatCurrency } from '$lib/helpers/numbers';
|
||||
import { abbreviateNumber, formatCurrency, isWithinSafeRange } from '$lib/helpers/numbers';
|
||||
import { BillingPlan } from '$lib/constants';
|
||||
import { Table, Typography } from '@appwrite.io/pink-svelte';
|
||||
|
||||
@@ -21,9 +21,9 @@
|
||||
|
||||
// equal or above means unlimited!
|
||||
const getCorrectSeatsCountValue = (count: number): string | number => {
|
||||
// php int max is always larger than js
|
||||
const exceedsSafeLimit = count >= Number.MAX_SAFE_INTEGER;
|
||||
return exceedsSafeLimit ? 'Unlimited' : count || 0;
|
||||
// Check for Infinity or very large numbers
|
||||
const isUnlimited = count === Infinity || !isWithinSafeRange(count);
|
||||
return isUnlimited ? 'Unlimited' : count || 0;
|
||||
};
|
||||
|
||||
function getPlanLimit(key: string): number | false {
|
||||
|
||||
@@ -20,11 +20,12 @@
|
||||
import { isCloud } from '$lib/system';
|
||||
import { goto } from '$app/navigation';
|
||||
import { base } from '$app/paths';
|
||||
import { currentPlan, newOrgModal } from '$lib/stores/organization';
|
||||
import { currentPlan, newOrgModal, organization } from '$lib/stores/organization';
|
||||
import { Click, trackEvent } from '$lib/actions/analytics';
|
||||
import { type Models, Query } from '@appwrite.io/console';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { page } from '$app/state';
|
||||
import { BillingPlan } from '$lib/constants';
|
||||
|
||||
type Organization = {
|
||||
name: string;
|
||||
@@ -226,6 +227,10 @@
|
||||
$: if (shouldReloadProjects) {
|
||||
projectsBottomSheet = createProjectsBottomSheet(selectedOrg);
|
||||
}
|
||||
|
||||
let badgeType: 'success' | undefined;
|
||||
$: badgeType =
|
||||
$organization && $organization.billingPlan !== BillingPlan.FREE ? 'success' : undefined;
|
||||
</script>
|
||||
|
||||
<svelte:window on:resize={onResize} />
|
||||
@@ -240,10 +245,13 @@
|
||||
use:melt={$triggerOrganizations}
|
||||
aria-label="Open organizations tab">
|
||||
<span class="orgName">{selectedOrg?.name ?? 'Organization'}</span>
|
||||
<span class="not-mobile"
|
||||
<span class="not-mobile" style="padding-inline-start: 2px"
|
||||
>{#if correctPlanName}<Badge
|
||||
size="xs"
|
||||
variant="secondary"
|
||||
content={correctPlanName} />{/if}</span>
|
||||
type={badgeType}
|
||||
content={correctPlanName} />
|
||||
{/if}</span>
|
||||
<Icon icon={IconChevronDown} size="s" color="--fgcolor-neutral-secondary" />
|
||||
</button>
|
||||
{:else}
|
||||
@@ -257,7 +265,11 @@
|
||||
<span class="orgName" class:noProjects={!currentProject}
|
||||
>{selectedOrg?.name ?? 'Organization'}</span>
|
||||
<span class="not-mobile"
|
||||
><Badge variant="secondary" content={correctPlanName ?? ''} /></span>
|
||||
><Badge
|
||||
size="xs"
|
||||
variant="secondary"
|
||||
type={badgeType}
|
||||
content={correctPlanName ?? ''} /></span>
|
||||
<Icon icon={IconChevronDown} size="s" color="--fgcolor-neutral-secondary" />
|
||||
</button>
|
||||
{/if}
|
||||
@@ -476,6 +488,7 @@
|
||||
border-radius: var(--border-radius-S, 8px);
|
||||
background: var(--overlay-neutral-hover, rgba(25, 25, 28, 0.03));
|
||||
}
|
||||
|
||||
.trigger {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -59,23 +59,23 @@
|
||||
};
|
||||
|
||||
const saveColumnPreferences = () => {
|
||||
const shownColumns = $columns.filter((n) => n.hide === true).map((n) => n.id);
|
||||
const hiddenColumns = $columns.filter((n) => n.hide === true).map((n) => n.id);
|
||||
|
||||
if (isCustomTable) {
|
||||
onPreferencesUpdated?.();
|
||||
preferences.setCustomTableColumns(page.params.table, shownColumns);
|
||||
preferences.setCustomTableColumns(page.params.table, hiddenColumns);
|
||||
} else {
|
||||
preferences.setColumns(shownColumns);
|
||||
preferences.setColumns(hiddenColumns);
|
||||
}
|
||||
};
|
||||
|
||||
onMount(() => {
|
||||
if (isCustomTable) {
|
||||
const shownColumns = preferences.getCustomTableColumns(page.params.table);
|
||||
const hiddenColumns = preferences.getCustomTableColumns(page.params.table);
|
||||
|
||||
columns.update((n) =>
|
||||
n.map((column) => {
|
||||
column.hide = shownColumns?.includes(column.id) ?? false;
|
||||
column.hide = hiddenColumns?.includes(column.id) ?? false;
|
||||
return column;
|
||||
})
|
||||
);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
export let disabled: boolean = false;
|
||||
export let submissionLoader = false;
|
||||
export let confirmDeletion: boolean = false;
|
||||
export let confirmDeletionLabel: string = 'I understand and confirm';
|
||||
export let onSubmit: (e: SubmitEvent) => Promise<void> | void = function () {
|
||||
return;
|
||||
};
|
||||
@@ -46,7 +47,7 @@
|
||||
required
|
||||
id={checkboxId}
|
||||
bind:checked={confirm}
|
||||
label="I understand and confirm" />
|
||||
label={confirmDeletionLabel} />
|
||||
{/if}
|
||||
</Layout.Stack>
|
||||
</Layout.Stack>
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
{/if}
|
||||
</Layout.Stack>
|
||||
<Typography.Text variant="m-400">
|
||||
Add the following nameservers on your DNS provider. Note that DNS changes may take time to
|
||||
propagate fully.
|
||||
Add the following nameservers on your DNS provider. Note that changes may take up to 48
|
||||
hours to propagate fully.
|
||||
</Typography.Text>
|
||||
</Layout.Stack>
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
import { menuOpen } from '$lib/components/menu/store';
|
||||
|
||||
export let time: string | null = null;
|
||||
export let showDatetime: boolean = false;
|
||||
export let canShowPopover: boolean = true;
|
||||
export let placement: ComponentProps<Popover>['placement'] = 'bottom';
|
||||
|
||||
@@ -85,7 +86,7 @@
|
||||
}
|
||||
}}
|
||||
on:mouseleave={() => hidePopover(hide)}>
|
||||
<slot>{capitalize(timeFromNow(time))}</slot>
|
||||
<slot>{showDatetime ? toLocaleDateTime(time) : capitalize(timeFromNow(time))}</slot>
|
||||
</button>
|
||||
|
||||
<div
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<script lang="ts">
|
||||
import { Layout, Card } from '@appwrite.io/pink-svelte';
|
||||
export let gap: 'none' | 'xxxs' | 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl' | 'xxxl' = 'l';
|
||||
</script>
|
||||
|
||||
<Card.Base>
|
||||
<Layout.Stack {gap}>
|
||||
<slot />
|
||||
</Layout.Stack>
|
||||
</Card.Base>
|
||||
@@ -63,7 +63,7 @@ function initQueries(initialValue = new Map<TagValue, string>()) {
|
||||
const currentLocation = window.location.pathname;
|
||||
|
||||
if (usableQueries.size) {
|
||||
const queryParam = mapToQueryParams(get(queries));
|
||||
const queryParam = mapToQueryParams(usableQueries);
|
||||
goto(`${currentLocation}?query=${queryParam}`, { noScroll: true });
|
||||
} else {
|
||||
goto(currentLocation, { noScroll: true });
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { Card, Layout, Typography } from '@appwrite.io/pink-svelte';
|
||||
export let href: string;
|
||||
export let href: string = null;
|
||||
</script>
|
||||
|
||||
<Card.Link class="card" {href}>
|
||||
|
||||
@@ -84,5 +84,6 @@ export { default as UsageCard } from './usageCard.svelte';
|
||||
export { default as ViewToggle } from './viewToggle.svelte';
|
||||
export { default as RegionEndpoint } from './regionEndpoint.svelte';
|
||||
export { default as ExpirationInput } from './expirationInput.svelte';
|
||||
export { default as EstimatedCard } from './estimatedCard.svelte';
|
||||
export { default as EmailVerificationBanner } from './alerts/emailVerificationBanner.svelte';
|
||||
export { default as SortButton, type SortDirection } from './sortButton.svelte';
|
||||
@@ -45,7 +45,7 @@
|
||||
</script>
|
||||
|
||||
<Tooltip maxWidth={tooltipWidth} disabled={!tooltipText || !tooltipShow}>
|
||||
<div style:cursor={disabled ? 'pointer' : ''}>
|
||||
<div style:cursor={disabled ? 'pointer' : ''} style:z-index="1">
|
||||
<Card.Selector
|
||||
{name}
|
||||
{src}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
const url = new URL(pageStore.url);
|
||||
const previousLimit = Number(url.searchParams.get('limit'));
|
||||
url.searchParams.set('limit', limit.toString());
|
||||
preferences.setLimit(limit);
|
||||
await preferences.setLimit(limit);
|
||||
|
||||
if (url.searchParams.has('page')) {
|
||||
const page = Number(url.searchParams.get('page'));
|
||||
|
||||
@@ -0,0 +1,354 @@
|
||||
<script lang="ts">
|
||||
import { Button } from '$lib/elements/forms';
|
||||
import { getServiceLimit, plansInfo } from '$lib/stores/billing';
|
||||
import { BillingPlan } from '$lib/constants';
|
||||
import { Click, trackEvent } from '$lib/actions/analytics';
|
||||
import { Badge, Icon, Layout, Table, Typography, Tooltip } from '@appwrite.io/pink-svelte';
|
||||
import { IconArrowUp, IconInfo } from '@appwrite.io/pink-icons-svelte';
|
||||
|
||||
import { formatNumberWithCommas } from '$lib/helpers/numbers';
|
||||
import { Modal } from '$lib/components';
|
||||
import { Alert } from '@appwrite.io/pink-svelte';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { toLocaleDate, toLocaleDateTime } from '$lib/helpers/date';
|
||||
import { organization, type Organization } from '$lib/stores/organization';
|
||||
import type { Models } from '@appwrite.io/console';
|
||||
|
||||
// Props
|
||||
type Props = {
|
||||
organization: Organization;
|
||||
projects?: Models.Project[];
|
||||
members?: Models.Membership[];
|
||||
storageUsage?: number;
|
||||
};
|
||||
|
||||
const { projects = [], members = [], storageUsage = 0 }: Props = $props();
|
||||
|
||||
let showSelectProject = $state(false);
|
||||
let selectedProjects = $state<string[]>([]);
|
||||
let error = $state<string | null>(null);
|
||||
let showSelectionReminder = $state(false);
|
||||
|
||||
// Derived state using runes
|
||||
let freePlanLimits = $derived({
|
||||
projects: $plansInfo?.get(BillingPlan.FREE)?.projects,
|
||||
members: getServiceLimit('members', BillingPlan.FREE),
|
||||
storage: getServiceLimit('storage', BillingPlan.FREE)
|
||||
});
|
||||
|
||||
// When preparing to downgrade to Free, enforce Free plan limit locally (2)
|
||||
let allowedProjectsToKeep = $derived(freePlanLimits.projects);
|
||||
|
||||
let currentUsage = $derived({
|
||||
projects: projects?.length || 0,
|
||||
members: members?.length || 0,
|
||||
storage: storageUsage || 0
|
||||
});
|
||||
|
||||
let storageUsageGB = $derived(storageUsage / (1024 * 1024 * 1024));
|
||||
|
||||
let isLimitExceeded = $derived({
|
||||
projects: currentUsage.projects > freePlanLimits.projects,
|
||||
members: currentUsage.members > freePlanLimits.members,
|
||||
storage: storageUsageGB > freePlanLimits.storage
|
||||
});
|
||||
|
||||
let excessUsage = $derived({
|
||||
projects: Math.max(0, currentUsage.projects),
|
||||
members: Math.max(0, currentUsage.members - freePlanLimits.members),
|
||||
storage: Math.max(0, storageUsageGB - freePlanLimits.storage)
|
||||
});
|
||||
|
||||
// projects that would be archived with the current selection
|
||||
let projectsToArchive = $derived(
|
||||
projects.filter((project) => !selectedProjects.includes(project.$id))
|
||||
);
|
||||
|
||||
function formatProjectsToArchive(): string {
|
||||
let result = '';
|
||||
projectsToArchive.forEach((project, index) => {
|
||||
const isLast = index === projectsToArchive.length - 1;
|
||||
const isSecondLast = index === projectsToArchive.length - 2;
|
||||
|
||||
result += `${index === 0 ? '' : ' '}${project.name}`;
|
||||
|
||||
if (!isLast) {
|
||||
if (isSecondLast) result += ' and';
|
||||
else result += ',';
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
function formatNumber(num: number): string {
|
||||
return formatNumberWithCommas(num);
|
||||
}
|
||||
|
||||
function handleManageProjects() {
|
||||
showSelectProject = true;
|
||||
showSelectionReminder = false;
|
||||
trackEvent(Click.OrganizationClickUpgrade, { source: 'usage_limits_manage_projects' });
|
||||
}
|
||||
|
||||
// Expose validation for parent to call before submitting downgrade
|
||||
export function validateOrAlert(): boolean {
|
||||
const filteredSelection = selectedProjects.filter((id) =>
|
||||
projects.some((p) => p.$id === id)
|
||||
);
|
||||
const isValid = filteredSelection.length === allowedProjectsToKeep;
|
||||
showSelectionReminder = !isValid && isLimitExceeded.projects;
|
||||
return isValid;
|
||||
}
|
||||
|
||||
export function getSelectedProjects(): string[] {
|
||||
return selectedProjects.filter((id) => projects.some((p) => p.$id === id));
|
||||
}
|
||||
|
||||
function updateSelected() {
|
||||
error = null;
|
||||
const filteredSelection = selectedProjects.filter((id) =>
|
||||
projects.some((p) => p.$id === id)
|
||||
);
|
||||
if (filteredSelection.length !== allowedProjectsToKeep) {
|
||||
error = `You must select exactly ${allowedProjectsToKeep} projects to keep.`;
|
||||
return;
|
||||
}
|
||||
// Keep selection locally; parent flow will apply after plan change
|
||||
showSelectProject = false;
|
||||
showSelectionReminder = false;
|
||||
addNotification({ type: 'success', message: `Projects selected for archiving` });
|
||||
}
|
||||
</script>
|
||||
|
||||
<Layout.Stack gap="l">
|
||||
{#if showSelectionReminder}
|
||||
<Alert.Inline status="warning" title="Choose projects to keep">
|
||||
The Free plan lets you keep {allowedProjectsToKeep} projects. Select them before continuing.
|
||||
<Layout.Stack
|
||||
direction="row"
|
||||
justifyContent="flex-start"
|
||||
gap="xs"
|
||||
style="position: relative; z-index: 10; pointer-events: auto;">
|
||||
<Button compact on:click={handleManageProjects}>Manage projects</Button>
|
||||
</Layout.Stack>
|
||||
</Alert.Inline>
|
||||
{/if}
|
||||
|
||||
<div class="responsive-table">
|
||||
<Table.Root
|
||||
columns={[
|
||||
{ id: 'resource', width: { min: 215 } },
|
||||
{ id: 'freeLimit', width: { min: 100 } },
|
||||
{ id: 'excessUsage', width: { min: 120 } },
|
||||
{ id: 'manage', width: { min: 110 } }
|
||||
]}
|
||||
let:root>
|
||||
<svelte:fragment slot="header" let:root>
|
||||
<Table.Header.Cell column="resource" {root}>Resource</Table.Header.Cell>
|
||||
<Table.Header.Cell column="freeLimit" {root}>Free limit</Table.Header.Cell>
|
||||
<Table.Header.Cell column="excessUsage" {root}>
|
||||
<Layout.Stack direction="row" alignItems="center" gap="xs">
|
||||
<Typography.Text>Excess usage</Typography.Text>
|
||||
<Tooltip placement="bottom" portal>
|
||||
<Icon icon={IconInfo} size="s" />
|
||||
<span slot="tooltip">Usage beyond the Free plan limits.</span>
|
||||
</Tooltip>
|
||||
</Layout.Stack>
|
||||
</Table.Header.Cell>
|
||||
<Table.Header.Cell column="manage" {root}></Table.Header.Cell>
|
||||
</svelte:fragment>
|
||||
|
||||
<!-- Projects Row -->
|
||||
<Table.Row.Base {root}>
|
||||
<Table.Cell column="resource" {root}>
|
||||
<Layout.Stack direction="row" alignItems="center" gap="xs">
|
||||
<Typography.Text>Projects</Typography.Text>
|
||||
{#if isLimitExceeded.projects}
|
||||
<Badge
|
||||
size="xs"
|
||||
content="Action required"
|
||||
variant="secondary"
|
||||
type="warning" />
|
||||
{/if}
|
||||
</Layout.Stack>
|
||||
</Table.Cell>
|
||||
<Table.Cell column="freeLimit" {root}>
|
||||
<Typography.Text
|
||||
>{formatNumber(allowedProjectsToKeep)} projects</Typography.Text>
|
||||
</Table.Cell>
|
||||
<Table.Cell column="excessUsage" {root}>
|
||||
{#if isLimitExceeded.projects}
|
||||
<Layout.Stack direction="row" alignItems="center" gap="xs">
|
||||
<Icon icon={IconArrowUp} size="s" color="--fgcolor-error" />
|
||||
<Typography.Text color="--fgcolor-error">
|
||||
{formatNumber(excessUsage.projects)} projects
|
||||
</Typography.Text>
|
||||
</Layout.Stack>
|
||||
{:else}
|
||||
<Typography.Text color="--fgcolor-neutral-secondary">
|
||||
{formatNumber(currentUsage.projects)} / {formatNumber(
|
||||
allowedProjectsToKeep
|
||||
)}
|
||||
</Typography.Text>
|
||||
{/if}
|
||||
</Table.Cell>
|
||||
<Table.Cell column="manage" {root}>
|
||||
{#if isLimitExceeded.projects}
|
||||
<Layout.Stack direction="row" justifyContent="flex-end">
|
||||
<Button size="xs" secondary on:click={handleManageProjects}
|
||||
>Manage projects</Button>
|
||||
</Layout.Stack>
|
||||
{/if}
|
||||
</Table.Cell>
|
||||
</Table.Row.Base>
|
||||
|
||||
<!-- Organization Members Row -->
|
||||
<Table.Row.Base {root}>
|
||||
<Table.Cell column="resource" {root}>
|
||||
<Typography.Text>Organization members</Typography.Text>
|
||||
</Table.Cell>
|
||||
<Table.Cell column="freeLimit" {root}>
|
||||
<Typography.Text>{formatNumber(freePlanLimits.members)} member</Typography.Text>
|
||||
</Table.Cell>
|
||||
<Table.Cell column="excessUsage" {root}>
|
||||
{#if isLimitExceeded.members}
|
||||
<Layout.Stack direction="row" alignItems="center" gap="xs">
|
||||
<Icon icon={IconArrowUp} size="s" color="--fgcolor-error" />
|
||||
<Typography.Text color="--fgcolor-error">
|
||||
{formatNumber(excessUsage.members)} members
|
||||
</Typography.Text>
|
||||
</Layout.Stack>
|
||||
{:else}
|
||||
<Typography.Text color="--fgcolor-neutral-secondary">
|
||||
{formatNumber(currentUsage.members)} / {formatNumber(
|
||||
freePlanLimits.members
|
||||
)}
|
||||
</Typography.Text>
|
||||
{/if}
|
||||
</Table.Cell>
|
||||
<Table.Cell column="manage" {root}></Table.Cell>
|
||||
</Table.Row.Base>
|
||||
|
||||
<!-- Storage Row -->
|
||||
<Table.Row.Base {root}>
|
||||
<Table.Cell column="resource" {root}>
|
||||
<Typography.Text>Storage</Typography.Text>
|
||||
</Table.Cell>
|
||||
<Table.Cell column="freeLimit" {root}>
|
||||
<Typography.Text>{freePlanLimits.storage} GB</Typography.Text>
|
||||
</Table.Cell>
|
||||
<Table.Cell column="excessUsage" {root}>
|
||||
{#if isLimitExceeded.storage}
|
||||
<Layout.Stack direction="row" alignItems="center" gap="xs">
|
||||
<Icon icon={IconArrowUp} size="s" color="--fgcolor-error" />
|
||||
<Typography.Text color="--fgcolor-error">
|
||||
{excessUsage.storage.toFixed(2)} GB
|
||||
</Typography.Text>
|
||||
</Layout.Stack>
|
||||
{:else}
|
||||
<Typography.Text color="--fgcolor-neutral-secondary">
|
||||
{storageUsageGB.toFixed(2)} / {freePlanLimits.storage} GB
|
||||
</Typography.Text>
|
||||
{/if}
|
||||
</Table.Cell>
|
||||
<Table.Cell column="manage" {root}></Table.Cell>
|
||||
</Table.Row.Base>
|
||||
</Table.Root>
|
||||
</div>
|
||||
</Layout.Stack>
|
||||
|
||||
{#if showSelectProject}
|
||||
<Modal bind:show={showSelectProject} title="Manage projects" onSubmit={updateSelected}>
|
||||
<svelte:fragment slot="description">
|
||||
Choose which {freePlanLimits.projects} projects to keep. Projects over the limit will be
|
||||
blocked after your billing cycle ends on {toLocaleDate(
|
||||
$organization.billingNextInvoiceDate
|
||||
)}.
|
||||
</svelte:fragment>
|
||||
|
||||
{#if error}
|
||||
<Alert.Inline status="error" title="Error">{error}</Alert.Inline>
|
||||
{/if}
|
||||
|
||||
<div>
|
||||
<Table.Root
|
||||
let:root
|
||||
allowSelection
|
||||
bind:selectedRows={selectedProjects}
|
||||
columns={[{ id: 'name' }, { id: 'created' }]}>
|
||||
<svelte:fragment slot="header" let:root>
|
||||
<Table.Header.Cell column="name" {root}>Project Name</Table.Header.Cell>
|
||||
<Table.Header.Cell column="created" {root}>Created</Table.Header.Cell>
|
||||
</svelte:fragment>
|
||||
{#each projects as project}
|
||||
<Table.Row.Base {root} id={project.$id}>
|
||||
<Table.Cell column="name" {root}
|
||||
><Typography.Text truncate>{project.name}</Typography.Text></Table.Cell>
|
||||
<Table.Cell column="created" {root}>
|
||||
{toLocaleDateTime(project.$createdAt)}
|
||||
</Table.Cell>
|
||||
</Table.Row.Base>
|
||||
{/each}
|
||||
</Table.Root>
|
||||
</div>
|
||||
{#if selectedProjects.length === allowedProjectsToKeep}
|
||||
{@const difference = projects.length - selectedProjects.length}
|
||||
{@const messagePrefix =
|
||||
difference > 1 ? `${difference} projects` : `${difference} project`}
|
||||
<Alert.Inline
|
||||
status="warning"
|
||||
title={`${messagePrefix} will be archived on ${toLocaleDate($organization.billingNextInvoiceDate)}`}>
|
||||
{formatProjectsToArchive()} will be archived
|
||||
</Alert.Inline>
|
||||
{/if}
|
||||
|
||||
<svelte:fragment slot="footer">
|
||||
<Button secondary on:click={() => (showSelectProject = false)}>Cancel</Button>
|
||||
<Button submit disabled={selectedProjects.length !== allowedProjectsToKeep}
|
||||
>Save</Button>
|
||||
</svelte:fragment>
|
||||
</Modal>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
/* Responsive table container */
|
||||
.responsive-table {
|
||||
overflow-x: auto;
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
scrollbar-width: thin;
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
/* Small viewport optimizations */
|
||||
@media (max-width: 640px) {
|
||||
.responsive-table {
|
||||
margin-inline: -1rem;
|
||||
padding-inline: 1rem;
|
||||
z-index: 5;
|
||||
}
|
||||
|
||||
.responsive-table :global(td),
|
||||
.responsive-table :global(th) {
|
||||
padding: 0.5rem 0.25rem;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.responsive-table :global(td:nth-child(1) .badge) {
|
||||
white-space: nowrap;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.responsive-table :global(td:nth-child(1) .layout-stack) {
|
||||
flex-wrap: nowrap;
|
||||
gap: 6px !important;
|
||||
}
|
||||
|
||||
.responsive-table :global(th:nth-child(4)),
|
||||
.responsive-table :global(td:nth-child(4)) {
|
||||
width: 96px;
|
||||
min-width: 96px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -66,6 +66,7 @@
|
||||
{:else}
|
||||
<Layout.Stack direction="row" inline>
|
||||
<Button.Button
|
||||
type="button"
|
||||
size="s"
|
||||
variant="compact"
|
||||
on:click={prev}
|
||||
@@ -75,6 +76,7 @@
|
||||
</Button.Button>
|
||||
|
||||
<Button.Button
|
||||
type="button"
|
||||
size="s"
|
||||
variant="compact"
|
||||
on:click={next}
|
||||
|
||||
@@ -66,6 +66,7 @@
|
||||
flex-direction: row;
|
||||
gap: 2px;
|
||||
margin-top: 1rem;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
&__content {
|
||||
|
||||
@@ -1,19 +1,29 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/state';
|
||||
import { goto } from '$app/navigation';
|
||||
import { onDestroy } from 'svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
import { trackEvent } from '$lib/actions/analytics';
|
||||
import { Icon, Input } from '@appwrite.io/pink-svelte';
|
||||
import { IconSearch, IconX } from '@appwrite.io/pink-icons-svelte';
|
||||
import { debounce as createDebounce } from '$lib/helpers/debounce.js';
|
||||
|
||||
export let placeholder = '';
|
||||
export let debounce = 250;
|
||||
export let required = false;
|
||||
export let disabled = false;
|
||||
export let autofocus = false;
|
||||
interface Props {
|
||||
placeholder?: string;
|
||||
debounce?: number;
|
||||
required?: boolean;
|
||||
disabled?: boolean;
|
||||
autofocus?: boolean;
|
||||
}
|
||||
|
||||
let inputValue = page.url.searchParams.get('search') ?? '';
|
||||
let {
|
||||
placeholder = '',
|
||||
debounce = 250,
|
||||
required = false,
|
||||
disabled = false,
|
||||
autofocus = false
|
||||
}: Props = $props();
|
||||
|
||||
let inputValue = $state(page.url.searchParams.get('search') ?? '');
|
||||
|
||||
const runSearch = createDebounce((value: string) => {
|
||||
const trimmed = value.trim();
|
||||
@@ -36,15 +46,21 @@
|
||||
goto(url, { keepFocus: true });
|
||||
}, debounce);
|
||||
|
||||
$: runSearch(inputValue);
|
||||
|
||||
function clearInput() {
|
||||
export function clearInput() {
|
||||
inputValue = '';
|
||||
}
|
||||
|
||||
onDestroy(() => {
|
||||
runSearch.cancel?.();
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
const urlSearch = page.url.searchParams.get('search') ?? '';
|
||||
|
||||
if (urlSearch !== inputValue) {
|
||||
runSearch(inputValue);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<div style:max-width="360px" style:width="100%">
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
import { showSupportModal } from '$routes/(console)/wizard/support/store';
|
||||
import MobileSupportModal from '$routes/(console)/wizard/support/mobileSupportModal.svelte';
|
||||
import MobileFeedbackModal from '$routes/(console)/wizard/feedback/mobileFeedbackModal.svelte';
|
||||
import { getSidebarState, updateSidebarState } from '$lib/helpers/sidebar';
|
||||
import { getSidebarState, isInDatabasesRoute, updateSidebarState } from '$lib/helpers/sidebar';
|
||||
import { isTabletViewport, isSmallViewport } from '$lib/stores/viewport';
|
||||
import { Click, trackEvent } from '$lib/actions/analytics';
|
||||
import { bannerSpacing } from '$lib/layout/headerAlert.svelte';
|
||||
@@ -73,8 +73,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: state = $isTabletViewport ? 'closed' : getSidebarState();
|
||||
|
||||
const projectOptions = [
|
||||
{ name: 'Auth', icon: IconUserGroup, slug: 'auth', category: 'build' },
|
||||
{ name: 'Databases', icon: IconDatabase, slug: 'databases', category: 'build' },
|
||||
@@ -93,6 +91,13 @@
|
||||
const isSelected = (service: string): boolean => {
|
||||
return $page.route.id?.includes(service);
|
||||
};
|
||||
|
||||
$: state = $isTabletViewport
|
||||
? 'closed'
|
||||
: // example: manual resize
|
||||
isInDatabasesRoute($page.route)
|
||||
? 'icons'
|
||||
: getSidebarState();
|
||||
</script>
|
||||
|
||||
<div
|
||||
@@ -245,8 +250,6 @@
|
||||
</Tooltip>
|
||||
{/each}
|
||||
{#if project && $isSmallViewport}
|
||||
<Divider />
|
||||
|
||||
<div class="mobile-tablet-settings">
|
||||
<Tooltip placement="right" disabled={state !== 'icons'}>
|
||||
<a
|
||||
@@ -359,15 +362,16 @@
|
||||
</Sidebar.Base>
|
||||
</div>
|
||||
|
||||
{#if subNavigation}
|
||||
<div
|
||||
class="sub-navigation"
|
||||
class:icons={state === 'icons'}
|
||||
class:no-transitions={$noWidthTransition}
|
||||
style:--banner-spacing={$bannerSpacing ? $bannerSpacing : undefined}>
|
||||
<svelte:component this={subNavigation} />
|
||||
</div>
|
||||
{/if}
|
||||
<div style:--banner-spacing={$bannerSpacing ? $bannerSpacing : undefined}>
|
||||
{#if subNavigation}
|
||||
<div
|
||||
class="sub-navigation"
|
||||
class:icons={state === 'icons'}
|
||||
class:no-transitions={$noWidthTransition}>
|
||||
<svelte:component this={subNavigation} />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style lang="scss">
|
||||
.sidebar {
|
||||
@@ -587,6 +591,7 @@
|
||||
@media (min-width: 1024px) {
|
||||
width: 166px;
|
||||
}
|
||||
|
||||
.info {
|
||||
position: absolute;
|
||||
display: flex;
|
||||
@@ -634,7 +639,7 @@
|
||||
background-color: var(--bgcolor-neutral-primary, #fff);
|
||||
z-index: 14;
|
||||
position: fixed;
|
||||
top: 48px;
|
||||
top: var(--banner-spacing, 48px);
|
||||
transition: width 0.2s linear;
|
||||
|
||||
&.icons {
|
||||
|
||||
@@ -18,19 +18,6 @@
|
||||
|
||||
let error: string;
|
||||
|
||||
function coerceToNumber(event: Event & { currentTarget: EventTarget & HTMLInputElement }) {
|
||||
const raw = event.currentTarget?.value ?? '';
|
||||
if (raw === '') {
|
||||
value = nullable ? null : (undefined as unknown as number);
|
||||
return;
|
||||
}
|
||||
|
||||
const parsed = Number(raw);
|
||||
if (Number.isFinite(parsed)) {
|
||||
value = parsed;
|
||||
}
|
||||
}
|
||||
|
||||
const handleInvalid = (event: Event & { currentTarget: EventTarget & HTMLInputElement }) => {
|
||||
event.preventDefault();
|
||||
|
||||
@@ -73,9 +60,7 @@
|
||||
autofocus={autofocus || undefined}
|
||||
helper={error || helper}
|
||||
state={error ? 'error' : 'default'}
|
||||
on:invalid={handleInvalid}
|
||||
on:input={coerceToNumber}
|
||||
on:change={coerceToNumber}>
|
||||
on:invalid={handleInvalid}>
|
||||
<svelte:fragment slot="info">
|
||||
<slot name="info" slot="info" />
|
||||
</svelte:fragment>
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { Organization } from './stores/organization';
|
||||
// Parse feature flags from env as a string array (exact match only)
|
||||
const flagsRaw = (env.PUBLIC_CONSOLE_FEATURE_FLAGS ?? '').split(',');
|
||||
|
||||
// @ts-expect-error: unused method!
|
||||
function isFlagEnabled(name: string) {
|
||||
// loose generic to allow safe access while retaining type safety
|
||||
return <T extends { account?: Account; organization?: Organization }>(data: T) => {
|
||||
@@ -18,6 +19,4 @@ function isFlagEnabled(name: string) {
|
||||
};
|
||||
}
|
||||
|
||||
export const flags = {
|
||||
showSites: isFlagEnabled('sites')
|
||||
};
|
||||
export const flags = {};
|
||||
@@ -2,6 +2,7 @@ import { faker } from '@faker-js/faker';
|
||||
import type { Columns } from '$routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/store';
|
||||
import { ID, type Models } from '@appwrite.io/console';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { isWithinSafeRange } from '$lib/helpers/numbers';
|
||||
|
||||
export async function generateColumns(
|
||||
project: Models.Project,
|
||||
@@ -54,7 +55,9 @@ export function generateFakeRecords(
|
||||
} {
|
||||
if (count <= 0) return { ids: [], rows: [] };
|
||||
|
||||
const filteredColumns = columns.filter((col) => col.type !== 'relationship');
|
||||
const filteredColumns = columns.filter(
|
||||
(col) => col.type !== 'relationship' && col.status === 'available'
|
||||
);
|
||||
|
||||
const ids: string[] = [];
|
||||
const rows: Models.Row[] = [];
|
||||
@@ -148,6 +151,14 @@ function generateSingleValue(column: Columns): string | number | boolean | null
|
||||
case 'url': {
|
||||
return faker.internet.url();
|
||||
}
|
||||
|
||||
case 'enum': {
|
||||
const enumAttr = column as Models.ColumnEnum;
|
||||
if (enumAttr.elements?.length > 0) {
|
||||
return faker.helpers.arrayElement(enumAttr.elements);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
} else {
|
||||
@@ -159,19 +170,18 @@ function generateSingleValue(column: Columns): string | number | boolean | null
|
||||
|
||||
case 'integer': {
|
||||
const intAttr = column as Models.ColumnInteger;
|
||||
const min = intAttr.min ?? 0;
|
||||
const max = intAttr.max ?? 10000;
|
||||
const min = !isWithinSafeRange(intAttr.min) ? 0 : intAttr.min;
|
||||
const max = !isWithinSafeRange(intAttr.max) ? 100 : intAttr.max;
|
||||
return faker.number.int({ min, max });
|
||||
}
|
||||
|
||||
case 'float': {
|
||||
case 'double': {
|
||||
const floatAttr = column as Models.ColumnFloat;
|
||||
const min = floatAttr.min ?? 0;
|
||||
const max = floatAttr.max ?? 1000000;
|
||||
const precision = 2;
|
||||
return parseFloat(
|
||||
faker.number.float({ min, max, fractionDigits: precision }).toFixed(precision)
|
||||
);
|
||||
const min = !isWithinSafeRange(floatAttr.min) ? 0 : floatAttr.min;
|
||||
const max = !isWithinSafeRange(floatAttr.max) ? 100 : floatAttr.max;
|
||||
const precision = 4;
|
||||
|
||||
return faker.number.float({ min, max, fractionDigits: precision });
|
||||
}
|
||||
|
||||
case 'boolean': {
|
||||
@@ -182,14 +192,6 @@ function generateSingleValue(column: Columns): string | number | boolean | null
|
||||
return faker.date.recent({ days: 365 }).toISOString();
|
||||
}
|
||||
|
||||
case 'enum': {
|
||||
const enumAttr = column as Models.ColumnEnum;
|
||||
if (enumAttr.elements && enumAttr.elements.length > 0) {
|
||||
return faker.helpers.arrayElement(enumAttr.elements);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
default: {
|
||||
return faker.lorem.word();
|
||||
}
|
||||
|
||||
@@ -32,3 +32,7 @@ export function formatCurrency(number: number, locale = 'en-US', currency = 'USD
|
||||
});
|
||||
return formatter.format(number);
|
||||
}
|
||||
|
||||
export function isWithinSafeRange(val: number) {
|
||||
return Math.abs(val) < Number.MAX_SAFE_INTEGER;
|
||||
}
|
||||
@@ -49,6 +49,19 @@ export function formatNum(number: number): string {
|
||||
return formatter.format(number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a string with optional mobile-aware truncation.
|
||||
*/
|
||||
export function formatName(
|
||||
name: string,
|
||||
limit: number = 19,
|
||||
isSmallViewport: boolean = false
|
||||
): string {
|
||||
const mobileLimit = 16;
|
||||
const actualLimit = isSmallViewport ? mobileLimit : limit;
|
||||
return name ? (name.length > actualLimit ? `${name.slice(0, actualLimit)}...` : name) : '-';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a regex to check hostname validity. Supports wildcards too!
|
||||
*/
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { type Account } from '$lib/stores/user';
|
||||
|
||||
export const joinWaitlistSites = (user: Account) => {
|
||||
const prefs = user.prefs;
|
||||
const newPrefs = {
|
||||
...prefs,
|
||||
joinWaitlistSites: true
|
||||
};
|
||||
|
||||
sdk.forConsole.account.updatePrefs({ prefs: newPrefs });
|
||||
|
||||
if (sessionStorage) {
|
||||
sessionStorage.setItem('joinWaitlistSites', 'true');
|
||||
}
|
||||
};
|
||||
|
||||
export const isOnWaitlistSites = (user: Account): boolean => {
|
||||
const prefs = user.prefs;
|
||||
const joinedInPrefs = 'joinWaitlistSites' in prefs;
|
||||
|
||||
let joinedInSession = false;
|
||||
if (sessionStorage) {
|
||||
joinedInSession = sessionStorage.getItem('joinWaitlistSites') === 'true';
|
||||
}
|
||||
|
||||
return joinedInSession || joinedInPrefs;
|
||||
};
|
||||
|
Before Width: | Height: | Size: 1.2 MiB |
|
Before Width: | Height: | Size: 1.0 MiB |
|
After Width: | Height: | Size: 202 KiB |
|
After Width: | Height: | Size: 152 KiB |
|
After Width: | Height: | Size: 272 KiB |
|
After Width: | Height: | Size: 167 KiB |
|
Before Width: | Height: | Size: 534 KiB |
|
Before Width: | Height: | Size: 349 KiB |
@@ -3,24 +3,32 @@
|
||||
import { IconChevronLeft } from '@appwrite.io/pink-icons-svelte';
|
||||
import { Button, Icon, Layout } from '@appwrite.io/pink-svelte';
|
||||
import type { Snippet } from 'svelte';
|
||||
import type { HTMLAttributes } from 'svelte/elements';
|
||||
|
||||
let {
|
||||
href = null,
|
||||
collapsed = false,
|
||||
children
|
||||
children,
|
||||
...restProps
|
||||
}: {
|
||||
href?: string | null;
|
||||
collapsed?: boolean;
|
||||
children: Snippet;
|
||||
} = $props();
|
||||
} & HTMLAttributes<HTMLDivElement> = $props();
|
||||
|
||||
const buttonSize = $derived(collapsed ? 'xs' : 's');
|
||||
const currentLineHeight = $derived(collapsed ? '130%' : '140%');
|
||||
const currentLetterSpacing = $derived(collapsed ? '0' : '-0.144px');
|
||||
const currentFontSize = $derived(collapsed ? 'var(--font-size-l)' : 'var(--font-size-xxxl)');
|
||||
const currentFontSize = $derived(collapsed ? 'var(--font-size-l)' : 'var(--font-size-xxl)');
|
||||
</script>
|
||||
|
||||
<Layout.Stack justifyContent="center" alignItems="center" direction="row" gap="xs" inline>
|
||||
<Layout.Stack
|
||||
inline
|
||||
gap="xs"
|
||||
direction="row"
|
||||
alignItems="center"
|
||||
justifyContent="center"
|
||||
{...restProps}>
|
||||
{#if href && !$isSmallViewport}
|
||||
<span style:position="relative">
|
||||
<Button.Anchor size={buttonSize} icon variant="text" {href} aria-label="page back">
|
||||
|
||||
@@ -1,34 +1,56 @@
|
||||
<script lang="ts">
|
||||
import { Layout } from '@appwrite.io/pink-svelte';
|
||||
import type { Snippet } from 'svelte';
|
||||
import type { HTMLAttributes } from 'svelte/elements';
|
||||
|
||||
// TODO: needs better props
|
||||
let {
|
||||
expanded = false,
|
||||
slotSpacing = false,
|
||||
overlapCover = false,
|
||||
paddingInlineEnd = true,
|
||||
paddingInlineEndDouble = false,
|
||||
insideSideSheet = false,
|
||||
databasesScreen = false,
|
||||
databasesMainScreen = false,
|
||||
expandHeightButton = false,
|
||||
size = null,
|
||||
children,
|
||||
...restProps
|
||||
}: {
|
||||
expanded?: boolean;
|
||||
slotSpacing?: boolean;
|
||||
overlapCover?: boolean;
|
||||
paddingInlineEnd?: boolean;
|
||||
paddingInlineEndDouble?: boolean;
|
||||
insideSideSheet?: boolean;
|
||||
databasesScreen?: boolean;
|
||||
databasesMainScreen?: boolean;
|
||||
expandHeightButton?: boolean;
|
||||
children?: Snippet;
|
||||
size?: 'small' | 'medium' | 'large' | 'xl' | 'xxl' | 'xxxl' | null;
|
||||
} & HTMLAttributes<HTMLDivElement> = $props();
|
||||
|
||||
export let expanded = false;
|
||||
export let slotSpacing = false;
|
||||
export let overlapCover = false;
|
||||
export let paddingInlineEnd = true;
|
||||
export let insideSideSheet = false;
|
||||
export let databasesScreen = false;
|
||||
export let expandHeightButton = false;
|
||||
export let size: 'small' | 'medium' | 'large' | 'xl' | 'xxl' | 'xxxl' = null;
|
||||
|
||||
$: style = size
|
||||
? `--p-container-max-size: var(--container-max-size, var(--container-size-${size}))`
|
||||
: '';
|
||||
const style = $derived(
|
||||
size
|
||||
? `--p-container-max-size: var(--container-max-size, var(--container-size-${size}))`
|
||||
: ''
|
||||
);
|
||||
</script>
|
||||
|
||||
<div style:container-type="inline-size" class:overlap-cover={overlapCover} {...$$restProps}>
|
||||
<div style:container-type="inline-size" class:overlap-cover={overlapCover} {...restProps}>
|
||||
<div
|
||||
{style}
|
||||
class:expanded
|
||||
class:slotSpacing
|
||||
class:databasesScreen
|
||||
class:insideSideSheet
|
||||
class:databasesScreen
|
||||
class:expandHeightButton
|
||||
class:databasesMainScreen
|
||||
class="console-container"
|
||||
class:paddingInlineEndDouble
|
||||
class:paddingInlineEnd={!paddingInlineEnd}>
|
||||
<Layout.Stack gap="l">
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</Layout.Stack>
|
||||
</div>
|
||||
</div>
|
||||
@@ -90,6 +112,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
&.paddingInlineEndDouble {
|
||||
@media (min-width: 1024px) {
|
||||
padding-inline-end: calc(2 * 2.75rem) !important;
|
||||
}
|
||||
}
|
||||
|
||||
&.databasesScreen {
|
||||
@media (min-width: 1440px) {
|
||||
min-width: 1070px;
|
||||
@@ -102,6 +130,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
&.databasesMainScreen {
|
||||
@media (min-width: 1440px) {
|
||||
max-width: 1200px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 360px) {
|
||||
margin-inline: 1rem;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
export let expanded: boolean = false;
|
||||
export let animate: boolean = false;
|
||||
export let collapsed: boolean = false;
|
||||
export let databasesMainScreen: boolean = false;
|
||||
|
||||
let isAnimating = false;
|
||||
let animationTimeout: ReturnType<typeof setTimeout>;
|
||||
@@ -43,6 +44,7 @@
|
||||
class="cover-container"
|
||||
{style}
|
||||
class:expanded
|
||||
class:databasesMainScreen
|
||||
class:collapsed={animate && collapsed}
|
||||
class:animating={isAnimating}>
|
||||
<Layout.Stack direction="row" alignItems="baseline">
|
||||
@@ -119,6 +121,12 @@
|
||||
&.animating {
|
||||
transition: all 300ms cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
&.databasesMainScreen {
|
||||
@media (min-width: 1440px) {
|
||||
max-width: 1200px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.expanded-slot {
|
||||
|
||||
@@ -3,10 +3,16 @@
|
||||
import { IconChevronLeft } from '@appwrite.io/pink-icons-svelte';
|
||||
import { Typography, Button, Icon, Layout } from '@appwrite.io/pink-svelte';
|
||||
|
||||
export let href: string = null;
|
||||
export let href: string | null = null;
|
||||
</script>
|
||||
|
||||
<Layout.Stack justifyContent="center" alignItems="center" direction="row" gap="xs" inline>
|
||||
<Layout.Stack
|
||||
inline
|
||||
gap="xs"
|
||||
direction="row"
|
||||
alignItems="center"
|
||||
justifyContent="center"
|
||||
{...$$restProps}>
|
||||
{#if href}
|
||||
<span style:position="relative">
|
||||
<Button.Anchor size="s" icon variant="text" {href} aria-label="page back">
|
||||
@@ -14,6 +20,7 @@
|
||||
</Button.Anchor>
|
||||
</span>
|
||||
{/if}
|
||||
|
||||
<Typography.Title
|
||||
truncate
|
||||
color="--fgcolor-neutral-primary"
|
||||
|
||||
@@ -4,13 +4,15 @@
|
||||
import { CustomId } from '$lib/components/index.js';
|
||||
import { getFlagUrl } from '$lib/helpers/flag';
|
||||
import { isCloud } from '$lib/system.js';
|
||||
import { currentPlan } from '$lib/stores/organization';
|
||||
import { currentPlan, organization } from '$lib/stores/organization';
|
||||
import { Button } from '$lib/elements/forms';
|
||||
import { base } from '$app/paths';
|
||||
import { page } from '$app/state';
|
||||
import type { Models } from '@appwrite.io/console';
|
||||
import { filterRegions } from '$lib/helpers/regions';
|
||||
import type { Snippet } from 'svelte';
|
||||
import { BillingPlan } from '$lib/constants';
|
||||
import { formatCurrency } from '$lib/helpers/numbers';
|
||||
|
||||
let {
|
||||
projectName = $bindable(''),
|
||||
@@ -18,6 +20,7 @@
|
||||
regions = [],
|
||||
region = $bindable(''),
|
||||
showTitle = true,
|
||||
billingPlan = undefined,
|
||||
projects = undefined,
|
||||
submit
|
||||
}: {
|
||||
@@ -26,14 +29,21 @@
|
||||
regions: Array<Models.ConsoleRegion>;
|
||||
region: string;
|
||||
showTitle: boolean;
|
||||
billingPlan?: BillingPlan;
|
||||
projects?: number;
|
||||
submit?: Snippet;
|
||||
} = $props();
|
||||
|
||||
let showCustomId = $state(false);
|
||||
let isProPlan = $derived((billingPlan ?? $organization?.billingPlan) === BillingPlan.PRO);
|
||||
let projectsLimited = $derived(
|
||||
$currentPlan?.projects > 0 && projects && projects >= $currentPlan?.projects
|
||||
);
|
||||
let isAddonProject = $derived(
|
||||
$currentPlan?.addons?.projects?.supported &&
|
||||
projects &&
|
||||
projects >= $currentPlan?.addons?.projects?.planIncluded
|
||||
);
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
@@ -46,26 +56,12 @@
|
||||
{#if showTitle}
|
||||
<Typography.Title size="l">Create your project</Typography.Title>
|
||||
{/if}
|
||||
{#if projectsLimited}
|
||||
<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
|
||||
compact
|
||||
size="s"
|
||||
href={`${base}/organization-${page.params.organization}/billing`}
|
||||
external
|
||||
text>Upgrade</Button>
|
||||
</svelte:fragment>
|
||||
</Alert.Inline>
|
||||
{/if}
|
||||
|
||||
<Layout.Stack direction="column" gap="xxl">
|
||||
<Layout.Stack direction="column" gap="xxl">
|
||||
<Layout.Stack direction="column" gap="s">
|
||||
<Input.Text
|
||||
disabled={projectsLimited}
|
||||
disabled={!isProPlan && projectsLimited}
|
||||
label="Name"
|
||||
placeholder="Project name"
|
||||
required
|
||||
@@ -82,10 +78,11 @@
|
||||
{/if}
|
||||
<CustomId bind:show={showCustomId} name="Project" isProject bind:id />
|
||||
</Layout.Stack>
|
||||
|
||||
{#if isCloud && regions.length > 0}
|
||||
<Layout.Stack gap="xs">
|
||||
<Input.Select
|
||||
disabled={projectsLimited}
|
||||
disabled={!isProPlan && projectsLimited}
|
||||
required
|
||||
bind:value={region}
|
||||
placeholder="Select a region"
|
||||
@@ -94,6 +91,29 @@
|
||||
<Typography.Text>Region cannot be changed after creation</Typography.Text>
|
||||
</Layout.Stack>
|
||||
{/if}
|
||||
{#if isAddonProject}
|
||||
<Alert.Inline
|
||||
status="info"
|
||||
title="Expand for {formatCurrency(
|
||||
$currentPlan?.addons?.projects?.price || 15
|
||||
)}/project per month">
|
||||
Each added project comes with its own dedicated pool of resources.
|
||||
</Alert.Inline>
|
||||
{/if}
|
||||
{#if projectsLimited}
|
||||
<Alert.Inline
|
||||
status="warning"
|
||||
title={`You've reached your limit of ${$currentPlan?.projects} projects`}>
|
||||
Extra projects are available on paid plans for an additional fee
|
||||
<svelte:fragment slot="actions">
|
||||
<Button
|
||||
compact
|
||||
size="s"
|
||||
href={`${base}/organization-${page.params.organization}/billing`}
|
||||
external>Upgrade</Button>
|
||||
</svelte:fragment>
|
||||
</Alert.Inline>
|
||||
{/if}
|
||||
</Layout.Stack>
|
||||
</Layout.Stack>
|
||||
{@render submit?.()}
|
||||
|
||||
@@ -11,11 +11,18 @@
|
||||
import { Button } from '$lib/elements/forms';
|
||||
import { Icon } from '@appwrite.io/pink-svelte';
|
||||
import { IconX } from '@appwrite.io/pink-icons-svelte';
|
||||
import { afterNavigate } from '$app/navigation';
|
||||
|
||||
export let title: string;
|
||||
export let type: 'info' | 'success' | 'warning' | 'error' | 'default' = 'info';
|
||||
export let dismissible = false;
|
||||
|
||||
/**
|
||||
* This is needed because when the
|
||||
* slot's height gets changed, sometimes the update doesn't come through!
|
||||
*/
|
||||
let resizeObserver: ResizeObserver;
|
||||
|
||||
let container: HTMLElement | null = null;
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
@@ -25,16 +32,23 @@
|
||||
const sidebar: HTMLElement = document.querySelector('main > div > nav');
|
||||
const contentSection: HTMLElement = document.querySelector('main > div > section');
|
||||
|
||||
if (alertHeight) {
|
||||
// for sidebar and sub-navigation!
|
||||
bannerSpacing.set(`${alertHeight}px`);
|
||||
} else {
|
||||
bannerSpacing.set(undefined);
|
||||
}
|
||||
|
||||
if (header) {
|
||||
header.style.top = `${alertHeight}px`;
|
||||
}
|
||||
|
||||
if (sidebar) {
|
||||
sidebar.style.top = `${alertHeight + ($isTabletViewport ? 0 : header.getBoundingClientRect().height)}px`;
|
||||
sidebar.style.height = `calc(100vh - (${alertHeight + ($isTabletViewport ? 0 : header.getBoundingClientRect().height)}px))`;
|
||||
const headerHeight = header?.getBoundingClientRect().height ?? 0;
|
||||
const topOffset = alertHeight + ($isTabletViewport ? 0 : headerHeight);
|
||||
|
||||
// for sidebar and sub-navigation!
|
||||
bannerSpacing.set(`${alertHeight}px`);
|
||||
sidebar.style.top = `${topOffset}px`;
|
||||
sidebar.style.height = `calc(100vh - ${topOffset}px)`;
|
||||
}
|
||||
|
||||
if (contentSection) {
|
||||
@@ -43,16 +57,24 @@
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
setNavigationHeight();
|
||||
if (container) {
|
||||
resizeObserver = new ResizeObserver(setNavigationHeight);
|
||||
resizeObserver.observe(container);
|
||||
}
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
container = null;
|
||||
setNavigationHeight();
|
||||
});
|
||||
</script>
|
||||
|
||||
<svelte:window on:resize={setNavigationHeight} />
|
||||
// remove observer!
|
||||
if (resizeObserver) {
|
||||
resizeObserver.disconnect();
|
||||
}
|
||||
});
|
||||
|
||||
afterNavigate(() => setNavigationHeight());
|
||||
</script>
|
||||
|
||||
<section
|
||||
bind:this={container}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
import { page } from '$app/stores';
|
||||
import type { Models } from '@appwrite.io/console';
|
||||
import { getSidebarState, isInDatabasesRoute, updateSidebarState } from '$lib/helpers/sidebar';
|
||||
import { isTabletViewport } from '$lib/stores/viewport';
|
||||
|
||||
export let showHeader = true;
|
||||
export let showFooter = true;
|
||||
@@ -100,8 +101,15 @@
|
||||
*
|
||||
* This needs to be handled like this because
|
||||
* the setup around the sidebar is very tightly configured with 2 states sync.
|
||||
*
|
||||
* The sidebar is **always closed** on mobile and tablet devices!
|
||||
*/
|
||||
afterNavigate((navigation) => {
|
||||
if ($isTabletViewport) {
|
||||
state = 'closed';
|
||||
return;
|
||||
}
|
||||
|
||||
const isEnteringDatabase = isInDatabasesRoute(navigation.to.route);
|
||||
const isLeavingDatabase =
|
||||
isInDatabasesRoute(navigation.from.route) && !isInDatabasesRoute(navigation.to.route);
|
||||
|
||||
@@ -151,6 +151,79 @@ export type CreditList = {
|
||||
total: number;
|
||||
};
|
||||
|
||||
export type AggregationTeam = {
|
||||
$id: string;
|
||||
/**
|
||||
* Aggregation creation time in ISO 8601 format.
|
||||
*/
|
||||
$createdAt: string;
|
||||
/**
|
||||
* Aggregation update date in ISO 8601 format.
|
||||
*/
|
||||
$updatedAt: string;
|
||||
/**
|
||||
* Beginning date of the invoice.
|
||||
*/
|
||||
from: string;
|
||||
/**
|
||||
* End date of the invoice.
|
||||
*/
|
||||
to: string;
|
||||
/**
|
||||
* Total amount of the invoice.
|
||||
*/
|
||||
amount: number;
|
||||
additionalMembers: number;
|
||||
|
||||
/**
|
||||
* Price for additional members
|
||||
*/
|
||||
additionalMemberAmount: number;
|
||||
/**
|
||||
* Total storage usage.
|
||||
*/
|
||||
usageStorage: number;
|
||||
/**
|
||||
* Total active users for the billing period.
|
||||
*/
|
||||
usageUsers: number;
|
||||
/**
|
||||
* Total number of executions for the billing period.
|
||||
*/
|
||||
usageExecutions: number;
|
||||
/**
|
||||
* Total bandwidth usage for the billing period.
|
||||
*/
|
||||
usageBandwidth: number;
|
||||
/**
|
||||
* Total realtime usage for the billing period.
|
||||
*/
|
||||
usageRealtime: number;
|
||||
/**
|
||||
* Usage logs for the billing period.
|
||||
*/
|
||||
resources: InvoiceUsage[];
|
||||
/**
|
||||
* Aggregation billing plan
|
||||
*/
|
||||
plan: string;
|
||||
breakdown: AggregationBreakdown[];
|
||||
};
|
||||
|
||||
export type AggregationBreakdown = {
|
||||
$id: string;
|
||||
name: string;
|
||||
amount: number;
|
||||
region: string;
|
||||
resources: InvoiceUsage[];
|
||||
};
|
||||
|
||||
export type InvoiceUsage = {
|
||||
resourceId: string;
|
||||
value: number;
|
||||
amount: number;
|
||||
};
|
||||
|
||||
export type AvailableCredit = {
|
||||
available: number;
|
||||
};
|
||||
@@ -299,6 +372,7 @@ export type PlanAddon = {
|
||||
limit: number;
|
||||
value: number;
|
||||
type: string;
|
||||
planIncluded: number;
|
||||
};
|
||||
|
||||
export type Plan = {
|
||||
@@ -316,10 +390,13 @@ export type Plan = {
|
||||
projects: number;
|
||||
databases: number;
|
||||
databasesAllowEncrypt: boolean;
|
||||
databasesReads: number;
|
||||
databasesWrites: number;
|
||||
buckets: number;
|
||||
fileSize: number;
|
||||
functions: number;
|
||||
executions: number;
|
||||
GBHours: number;
|
||||
realtime: number;
|
||||
logs: number;
|
||||
authPhone: number;
|
||||
@@ -330,9 +407,14 @@ export type Plan = {
|
||||
realtime: AdditionalResource;
|
||||
storage: AdditionalResource;
|
||||
users: AdditionalResource;
|
||||
databasesReads: AdditionalResource;
|
||||
databasesWrites: AdditionalResource;
|
||||
GBHours: AdditionalResource;
|
||||
imageTransformations: AdditionalResource;
|
||||
};
|
||||
addons: {
|
||||
seats: PlanAddon;
|
||||
projects: PlanAddon;
|
||||
};
|
||||
trialDays: number;
|
||||
budgetCapEnabled: boolean;
|
||||
@@ -348,6 +430,7 @@ export type Plan = {
|
||||
supportsOrganizationRoles: boolean;
|
||||
buildSize: number; // in MB
|
||||
deploymentSize: number; // in MB
|
||||
usagePerProject: boolean;
|
||||
};
|
||||
|
||||
export type PlanList = {
|
||||
@@ -355,7 +438,7 @@ export type PlanList = {
|
||||
total: number;
|
||||
};
|
||||
|
||||
export type PlansMap = Map<Tier, Plan>;
|
||||
export type PlansMap = Map<string, Plan>;
|
||||
|
||||
export type Roles = {
|
||||
scopes: string[];
|
||||
@@ -492,6 +575,22 @@ export class Billing {
|
||||
});
|
||||
}
|
||||
|
||||
async listPlans(queries: string[] = []): Promise<PlanList> {
|
||||
const path = `/console/plans`;
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
const params = {
|
||||
queries
|
||||
};
|
||||
return await this.client.call(
|
||||
'get',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async getPlan(planId: string): Promise<Plan> {
|
||||
const path = `/console/plans/${planId}`;
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
@@ -835,7 +934,7 @@ export class Billing {
|
||||
);
|
||||
}
|
||||
|
||||
async getAggregation(organizationId: string, aggregationId: string): Promise<Aggregation> {
|
||||
async getAggregation(organizationId: string, aggregationId: string): Promise<AggregationTeam> {
|
||||
const path = `/organizations/${organizationId}/aggregations/${aggregationId}`;
|
||||
const params = {
|
||||
organizationId,
|
||||
|
||||
@@ -14,7 +14,7 @@ import { cachedStore } from '$lib/helpers/cache';
|
||||
import { type Size, sizeToBytes } from '$lib/helpers/sizeConvertion';
|
||||
import type {
|
||||
AddressesList,
|
||||
Aggregation,
|
||||
AggregationTeam,
|
||||
Invoice,
|
||||
InvoiceList,
|
||||
PaymentList,
|
||||
@@ -69,7 +69,6 @@ export const roles = [
|
||||
|
||||
export const teamStatusReadonly = 'readonly';
|
||||
export const billingLimitOutstandingInvoice = 'outstanding_invoice';
|
||||
export const billingProjectsLimitDate = '2025-09-01';
|
||||
|
||||
export const paymentMethods = derived(page, ($page) => $page.data.paymentMethods as PaymentList);
|
||||
export const addressList = derived(page, ($page) => $page.data.addressList as AddressesList);
|
||||
@@ -139,6 +138,7 @@ export type PlanServices =
|
||||
| 'logs'
|
||||
| 'memberAddon'
|
||||
| 'members'
|
||||
| 'projects'
|
||||
| 'platforms'
|
||||
| 'realtime'
|
||||
| 'realtimeAddon'
|
||||
@@ -155,15 +155,23 @@ export type PlanServices =
|
||||
export function getServiceLimit(serviceId: PlanServices, tier: Tier = null, plan?: Plan): number {
|
||||
if (!isCloud) return 0;
|
||||
if (!serviceId) return 0;
|
||||
const info = get(plansInfo);
|
||||
if (!info) return 0;
|
||||
plan ??= info.get(tier ?? get(organization)?.billingPlan);
|
||||
// members are no longer a variable on plan itself!
|
||||
// the correct info for members/seats, resides in `addons`.
|
||||
// plan > addons > seats/others
|
||||
|
||||
plan ??= get(currentPlan);
|
||||
|
||||
if (tier) {
|
||||
const info = get(plansInfo);
|
||||
if (!info) return 0;
|
||||
plan ??= info.get(tier);
|
||||
}
|
||||
|
||||
if (serviceId === 'members') {
|
||||
// some don't include `limit`, so we fallback!
|
||||
return plan?.['addons']['seats']['limit'] ?? 1;
|
||||
if (!plan?.addons?.seats) return Infinity;
|
||||
return plan.addons.seats?.limit ?? 1;
|
||||
}
|
||||
|
||||
if (serviceId === 'projects') {
|
||||
if (!plan?.addons?.projects) return Infinity;
|
||||
return plan.addons.projects?.limit ?? 1;
|
||||
}
|
||||
|
||||
return plan?.[serviceId] ?? 0;
|
||||
@@ -235,6 +243,7 @@ export const tierEnterprise: TierData = {
|
||||
};
|
||||
|
||||
export const showUsageRatesModal = writable<boolean>(false);
|
||||
export const useNewPricingModal = derived(currentPlan, ($plan) => $plan?.usagePerProject === true);
|
||||
|
||||
export function checkForUsageFees(plan: Tier, id: PlanServices) {
|
||||
if (plan === BillingPlan.PRO || plan === BillingPlan.SCALE) {
|
||||
@@ -253,11 +262,19 @@ export function checkForUsageFees(plan: Tier, id: PlanServices) {
|
||||
}
|
||||
|
||||
export function checkForProjectLimitation(id: PlanServices) {
|
||||
// Members are no longer limited on Pro and Scale plans (unlimited seats)
|
||||
if (id === 'members') {
|
||||
const currentTier = get(organization)?.billingPlan;
|
||||
if (currentTier === BillingPlan.PRO || currentTier === BillingPlan.SCALE) {
|
||||
return false; // No project limitation for members on Pro/Scale plans
|
||||
}
|
||||
}
|
||||
|
||||
switch (id) {
|
||||
case 'databases':
|
||||
case 'functions':
|
||||
case 'buckets':
|
||||
case 'members':
|
||||
case 'members': // Only applies to Free plan now
|
||||
case 'platforms':
|
||||
case 'webhooks':
|
||||
case 'teams':
|
||||
@@ -325,7 +342,8 @@ export async function checkForProjectsLimit(org: Organization, orgProjectCount?:
|
||||
if (!plan) return;
|
||||
|
||||
if (plan.$id !== BillingPlan.FREE) return;
|
||||
if (org.projects?.length > 0) return;
|
||||
if (!org.projects) return;
|
||||
if (org.projects.length > 0) return;
|
||||
|
||||
const projectCount = orgProjectCount;
|
||||
if (projectCount === undefined) return;
|
||||
@@ -383,13 +401,8 @@ export async function checkForUsageLimit(org: Organization) {
|
||||
];
|
||||
|
||||
const members = org.total;
|
||||
const plan = get(currentPlan);
|
||||
const membersOverflow =
|
||||
// `plan` can be null on `onboarding/create-organization` route.
|
||||
// nested null checks needed: GitHub Education plan have empty addons.
|
||||
members > plan?.addons?.seats?.limit
|
||||
? members - (plan?.addons?.seats?.limit || members)
|
||||
: 0;
|
||||
const memberLimit = getServiceLimit('members');
|
||||
const membersOverflow = memberLimit === Infinity ? 0 : Math.max(0, members - memberLimit);
|
||||
|
||||
if (resources.some((r) => r.value >= 100) || membersOverflow > 0) {
|
||||
readOnly.set(true);
|
||||
@@ -609,7 +622,7 @@ export const billingURL = derived(
|
||||
|
||||
export const hideBillingHeaderRoutes = ['/console/create-organization', '/console/account'];
|
||||
|
||||
export function calculateExcess(addon: Aggregation, plan: Plan) {
|
||||
export function calculateExcess(addon: AggregationTeam, plan: Plan) {
|
||||
return {
|
||||
bandwidth: calculateResourceSurplus(addon.usageBandwidth, plan.bandwidth),
|
||||
storage: calculateResourceSurplus(addon.usageStorage, plan.storage, 'GB'),
|
||||
|
||||
@@ -66,6 +66,21 @@ function safePrefsKey(widthPreferences: TeamPreferences['widths'], from: string,
|
||||
}
|
||||
}
|
||||
|
||||
// rare cases where the value was an array, probably due to PHP backend.
|
||||
function ensureObjectProperty<T extends Record<string, unknown>, K extends keyof T>(
|
||||
obj: T | null | undefined,
|
||||
key: K
|
||||
): T {
|
||||
if (!obj || typeof obj !== 'object') {
|
||||
obj = {} as T;
|
||||
}
|
||||
if (obj[key] == null || typeof obj[key] !== 'object' || Array.isArray(obj[key])) {
|
||||
obj[key] = {} as T[K];
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
function createPreferences() {
|
||||
const { subscribe, set, update } = writable<ConsolePreferencesStore>({});
|
||||
let preferences: ConsolePreferencesStore = {};
|
||||
@@ -121,7 +136,7 @@ function createPreferences() {
|
||||
});
|
||||
|
||||
if (deepEqual(oldPrefsSnapshot, newPrefsSnapshot)) {
|
||||
return;
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
// sync the preferences.
|
||||
@@ -150,11 +165,7 @@ function createPreferences() {
|
||||
setLimit: (limit: ConsolePreferences['limit']) =>
|
||||
updateAndSync((n) => {
|
||||
const path = page.route.id;
|
||||
|
||||
if (!n?.[path]) {
|
||||
n ??= {};
|
||||
n[path] ??= {};
|
||||
}
|
||||
n = ensureObjectProperty(n, path);
|
||||
|
||||
n[path].limit = limit;
|
||||
|
||||
@@ -164,48 +175,32 @@ function createPreferences() {
|
||||
setView: (view: ConsolePreferences['view']) =>
|
||||
updateAndSync((n) => {
|
||||
const path = page.route.id;
|
||||
|
||||
if (!n?.[path]) {
|
||||
n ??= {};
|
||||
n[path] ??= {};
|
||||
}
|
||||
n = ensureObjectProperty(n, path);
|
||||
|
||||
n[path].view = view;
|
||||
|
||||
return n;
|
||||
}),
|
||||
|
||||
setColumns: (columns: ConsolePreferences['columns']) =>
|
||||
updateAndSync((n) => {
|
||||
const path = page.route.id;
|
||||
|
||||
if (!n?.[path]) {
|
||||
n ??= {};
|
||||
n[path] ??= {};
|
||||
}
|
||||
n = ensureObjectProperty(n, path);
|
||||
|
||||
n[path].columns = columns;
|
||||
|
||||
return n;
|
||||
}),
|
||||
|
||||
setCustomTableColumns: (tableId: string, columns: ConsolePreferences['columns']) =>
|
||||
updateAndSync((n) => {
|
||||
n ??= {};
|
||||
n.tables ??= {};
|
||||
|
||||
n.tables[tableId] = Array.from(new Set(columns));
|
||||
n = ensureObjectProperty(n, 'tables');
|
||||
n.tables[tableId] = Array.from(new Set(columns ?? []));
|
||||
return n;
|
||||
}),
|
||||
|
||||
deleteTableDetails: async (orgId: string, tableId: string) => {
|
||||
// remove from account preferences
|
||||
const removeCustomTableColumns = updateAndSync((n) => {
|
||||
if (!n?.tables) {
|
||||
n ??= {};
|
||||
n.tables ??= {};
|
||||
}
|
||||
|
||||
n = ensureObjectProperty(n, 'tables');
|
||||
delete n.tables[tableId];
|
||||
return n;
|
||||
});
|
||||
@@ -233,10 +228,7 @@ function createPreferences() {
|
||||
tableId: string,
|
||||
displayNames: TeamPreferences['names']
|
||||
) => {
|
||||
if (!teamPreferences.displayNames) {
|
||||
teamPreferences.displayNames = {};
|
||||
}
|
||||
|
||||
teamPreferences = ensureObjectProperty(teamPreferences, 'displayNames');
|
||||
teamPreferences.displayNames[tableId] = displayNames;
|
||||
|
||||
await sdk.forConsole.teams.updatePrefs({
|
||||
@@ -250,9 +242,7 @@ function createPreferences() {
|
||||
},
|
||||
|
||||
async saveColumnOrder(orgId: string, tableId: string, columnIds: TeamPreferences['order']) {
|
||||
if (!teamPreferences.columnOrder) {
|
||||
teamPreferences.columnOrder = {};
|
||||
}
|
||||
teamPreferences = ensureObjectProperty(teamPreferences, 'columnOrder');
|
||||
|
||||
teamPreferences.columnOrder[tableId] = columnIds;
|
||||
|
||||
@@ -269,9 +259,7 @@ function createPreferences() {
|
||||
},
|
||||
|
||||
async saveColumnWidths(orgId: string, tableId: string, width: TeamPreferences['widths']) {
|
||||
if (!teamPreferences.columnWidths) {
|
||||
teamPreferences.columnWidths = {};
|
||||
}
|
||||
teamPreferences = ensureObjectProperty(teamPreferences, 'columnWidths');
|
||||
|
||||
teamPreferences.columnWidths[tableId] = {
|
||||
...teamPreferences.columnWidths[tableId],
|
||||
@@ -295,11 +283,7 @@ function createPreferences() {
|
||||
|
||||
async setKey(key: string, value: string | number | boolean) {
|
||||
await updateAndSync((n) => {
|
||||
if (!n?.miscellaneous) {
|
||||
n ??= {};
|
||||
n.miscellaneous ??= {};
|
||||
}
|
||||
|
||||
n = ensureObjectProperty(n, 'miscellaneous');
|
||||
n.miscellaneous[key] = value;
|
||||
return n;
|
||||
});
|
||||
|
||||
@@ -2,10 +2,26 @@ import { redirect } from '@sveltejs/kit';
|
||||
import { base } from '$app/paths';
|
||||
import type { LayoutLoad } from './$types';
|
||||
|
||||
export const load: LayoutLoad = async ({ parent }) => {
|
||||
export const load: LayoutLoad = async ({ parent, url }) => {
|
||||
const { account } = await parent();
|
||||
|
||||
if (!account) {
|
||||
redirect(303, base);
|
||||
const projectId = url.searchParams.get('projectId');
|
||||
const repositoryId = url.searchParams.get('repositoryId');
|
||||
const installationId = url.searchParams.get('installationId');
|
||||
const providerPullRequestId = url.searchParams.get('providerPullRequestId');
|
||||
|
||||
if (!installationId || !repositoryId || !providerPullRequestId) {
|
||||
redirect(303, `${base}`);
|
||||
}
|
||||
|
||||
if (!account) {
|
||||
redirect(303, `${base}`);
|
||||
}
|
||||
|
||||
return {
|
||||
projectId,
|
||||
repositoryId,
|
||||
installationId,
|
||||
providerPullRequestId
|
||||
};
|
||||
};
|
||||
@@ -1,5 +1,4 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/state';
|
||||
import { app } from '$lib/stores/app';
|
||||
import AppwriteLogoDark from '$lib/images/appwrite-logo-dark.svg';
|
||||
import AppwriteLogoLight from '$lib/images/appwrite-logo-light.svg';
|
||||
@@ -7,6 +6,8 @@
|
||||
import { onMount } from 'svelte';
|
||||
import { getApiEndpoint } from '$lib/stores/sdk';
|
||||
|
||||
export let data;
|
||||
|
||||
const endpoint = getApiEndpoint();
|
||||
const client = new Client();
|
||||
const vcs = new Vcs(client);
|
||||
@@ -15,17 +16,16 @@
|
||||
let repositoryId: string;
|
||||
let providerPullRequestId: string;
|
||||
|
||||
let loading = false;
|
||||
let error = '';
|
||||
let success = '';
|
||||
let loading = false;
|
||||
|
||||
onMount(async () => {
|
||||
const projectId = page.url.searchParams.get('projectId');
|
||||
client.setEndpoint(endpoint).setProject(projectId).setMode('admin');
|
||||
repositoryId = data.repositoryId;
|
||||
installationId = data.installationId;
|
||||
providerPullRequestId = data.providerPullRequestId;
|
||||
|
||||
installationId = page.url.searchParams.get('installationId');
|
||||
repositoryId = page.url.searchParams.get('repositoryId');
|
||||
providerPullRequestId = page.url.searchParams.get('providerPullRequestId') + '';
|
||||
client.setEndpoint(endpoint).setProject(data.projectId).setMode('admin');
|
||||
});
|
||||
|
||||
async function approveDeployment() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Dependencies } from '$lib/constants';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { isCloud } from '$lib/system';
|
||||
import type { LayoutLoad } from './$types';
|
||||
import { Dependencies } from '$lib/constants';
|
||||
import type { Tier } from '$lib/stores/billing';
|
||||
import type { Plan, PlanList } from '$lib/sdk/billing';
|
||||
import { Query } from '@appwrite.io/console';
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
function isCloudOrg(
|
||||
data: Partial<Models.TeamList<Models.Preferences>> | Organization
|
||||
): data is Organization {
|
||||
return isCloud && 'billingPlan' in data ? true : false;
|
||||
return isCloud && 'billingPlan' in data;
|
||||
}
|
||||
|
||||
function createOrg() {
|
||||
|
||||
@@ -123,7 +123,7 @@
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
if (!couponForm.checkValidity()) return;
|
||||
if (couponForm && !couponForm.checkValidity()) return;
|
||||
isSubmitting.set(true);
|
||||
try {
|
||||
let org: Organization | OrganizationError;
|
||||
@@ -392,7 +392,7 @@
|
||||
<Button
|
||||
fullWidthMobile
|
||||
on:click={() => {
|
||||
if (formComponent.checkValidity() && couponForm.checkValidity()) {
|
||||
if (formComponent.checkValidity() && (!couponForm || couponForm.checkValidity())) {
|
||||
handleSubmit();
|
||||
}
|
||||
}}
|
||||
|
||||
@@ -3,10 +3,10 @@ import { isSameDay } from '$lib/helpers/date';
|
||||
import { type BottomModalAlertItem, showBottomModalAlert } from '$lib/stores/bottom-alerts';
|
||||
import TablesApiLight from '$lib/images/promos/tables-api-light.png';
|
||||
import TablesApiDark from '$lib/images/promos/tables-api-dark.png';
|
||||
import TimestampOverridesDark from '$lib/images/promos/timestamp-overrides-dark.png';
|
||||
import TimestampOverridesLight from '$lib/images/promos/timestamp-overrides-light.png';
|
||||
import AppwriteGeneralAvailabiltyLight from '$lib/images/promos/appwrite-general-availability-light.png';
|
||||
import AppwriteGeneralAvailabiltyDark from '$lib/images/promos/appwrite-general-availability-dark.png';
|
||||
import InversionQueriesDark from '$lib/images/promos/inversion-queries-dark.png';
|
||||
import InversionQueriesLight from '$lib/images/promos/inversion-queries-light.png';
|
||||
import TimeHelperQueriesDark from '$lib/images/promos/time-helper-queries-dark.png';
|
||||
import TimeHelperQueriesLight from '$lib/images/promos/time-helper-queries-light.png';
|
||||
|
||||
const listOfPromotions: BottomModalAlertItem[] = [];
|
||||
|
||||
@@ -32,48 +32,46 @@ if (isCloud) {
|
||||
show: true
|
||||
};
|
||||
|
||||
const timestampOverridesPromo: BottomModalAlertItem = {
|
||||
id: 'modal:timestamp_overrides_announcement',
|
||||
const inversionQueriesPromo: BottomModalAlertItem = {
|
||||
id: 'modal:inversion_queries_announcement',
|
||||
src: {
|
||||
dark: TimestampOverridesDark,
|
||||
light: TimestampOverridesLight
|
||||
dark: InversionQueriesDark,
|
||||
light: InversionQueriesLight
|
||||
},
|
||||
title: 'Announcing Timestamp Overrides',
|
||||
message:
|
||||
'Move historical data into Appwrite without losing context or disrupting chronological accuracy.',
|
||||
title: 'Announcing inversion queries',
|
||||
message: 'New NOT operators to exclude data directly in queries.',
|
||||
plan: 'free',
|
||||
importance: 8,
|
||||
scope: 'project',
|
||||
cta: {
|
||||
text: 'Read announcement',
|
||||
link: () => 'https://appwrite.io/blog/post/announcing-timestamp-overrides',
|
||||
link: () => 'https://appwrite.io/blog/post/announcing-inversion-queries',
|
||||
external: true,
|
||||
hideOnClick: true
|
||||
},
|
||||
show: true
|
||||
};
|
||||
|
||||
const appwriteGeneralAvailabiltyPromo: BottomModalAlertItem = {
|
||||
id: 'modal:appwrite_general_availability_announcement',
|
||||
const timeHelperQueriesPromo: BottomModalAlertItem = {
|
||||
id: 'modal:time_helper_queries_announcement',
|
||||
src: {
|
||||
dark: AppwriteGeneralAvailabiltyDark,
|
||||
light: AppwriteGeneralAvailabiltyLight
|
||||
dark: TimeHelperQueriesDark,
|
||||
light: TimeHelperQueriesLight
|
||||
},
|
||||
title: 'Now Generally Available',
|
||||
message: 'After 26 months of Appwrite Cloud, we are ready to remove the beta tag.',
|
||||
title: 'Announcing Time helper queries',
|
||||
message: 'New before/after filters for simpler time-based queries.',
|
||||
plan: 'free',
|
||||
importance: 8,
|
||||
scope: 'everywhere',
|
||||
scope: 'project',
|
||||
cta: {
|
||||
text: 'Learn more',
|
||||
link: () => 'https://apwr.dev/ygTXfxA',
|
||||
text: 'Read announcement',
|
||||
link: () => 'https://appwrite.io/blog/post/announcing-time-helper-queries',
|
||||
external: true,
|
||||
hideOnClick: true
|
||||
},
|
||||
show: true
|
||||
};
|
||||
|
||||
listOfPromotions.push(tablesApiPromo, timestampOverridesPromo, appwriteGeneralAvailabiltyPromo);
|
||||
listOfPromotions.push(inversionQueriesPromo, timeHelperQueriesPromo, tablesApiPromo);
|
||||
}
|
||||
|
||||
export function addBottomModalAlerts() {
|
||||
|
||||
@@ -7,10 +7,10 @@ import type { Organization } from '$lib/stores/organization';
|
||||
export const load: PageLoad = async ({ url, parent, depends }) => {
|
||||
const { organizations } = await parent();
|
||||
depends(Dependencies.ORGANIZATIONS);
|
||||
|
||||
const [coupon, paymentMethods] = await Promise.all([
|
||||
const [coupon, paymentMethods, plans] = await Promise.all([
|
||||
getCoupon(url),
|
||||
sdk.forConsole.billing.listPaymentMethods()
|
||||
sdk.forConsole.billing.listPaymentMethods(),
|
||||
sdk.forConsole.billing.listPlans()
|
||||
]);
|
||||
let plan = getPlanFromUrl(url);
|
||||
const hasFreeOrganizations = organizations.teams?.some(
|
||||
@@ -24,6 +24,7 @@ export const load: PageLoad = async ({ url, parent, depends }) => {
|
||||
return {
|
||||
plan,
|
||||
coupon,
|
||||
plans,
|
||||
hasFreeOrganizations,
|
||||
paymentMethods,
|
||||
name: url.searchParams.get('name') ?? ''
|
||||
|
||||
@@ -7,25 +7,22 @@
|
||||
import { GRACE_PERIOD_OVERRIDE, isCloud } from '$lib/system';
|
||||
import { page } from '$app/state';
|
||||
import { registerCommands } from '$lib/commandCenter';
|
||||
import { formatName as formatNameHelper } from '$lib/helpers/string';
|
||||
import {
|
||||
CardContainer,
|
||||
DropList,
|
||||
DropListItem,
|
||||
Empty,
|
||||
EmptySearch,
|
||||
GridItem1,
|
||||
PaginationWithLimit
|
||||
PaginationWithLimit,
|
||||
SearchQuery
|
||||
} from '$lib/components';
|
||||
import { goto } from '$app/navigation';
|
||||
import { Submit, trackError, trackEvent, Click } from '$lib/actions/analytics';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { loading } from '$routes/store';
|
||||
import { ID, Region, type Models } from '@appwrite.io/console';
|
||||
import { openImportWizard } from '../project-[region]-[project]/settings/migrations/(import)';
|
||||
import { billingProjectsLimitDate, readOnly, upgradeURL } from '$lib/stores/billing';
|
||||
import { trackEvent, Click } from '$lib/actions/analytics';
|
||||
import { type Models } from '@appwrite.io/console';
|
||||
import { getServiceLimit, readOnly, upgradeURL } from '$lib/stores/billing';
|
||||
import { onMount, type ComponentType } from 'svelte';
|
||||
import { canWriteProjects } from '$lib/stores/roles';
|
||||
import { checkPricingRefAndRedirect } from '$lib/helpers/pricingRedirect';
|
||||
import { Badge, Icon, Typography, Alert, Tag, Tooltip } from '@appwrite.io/pink-svelte';
|
||||
import { Alert, Badge, Icon, Layout, Tag, Tooltip, Typography } from '@appwrite.io/pink-svelte';
|
||||
import { isSmallViewport } from '$lib/stores/viewport';
|
||||
import {
|
||||
IconAndroid,
|
||||
@@ -40,14 +37,16 @@
|
||||
import CreateProjectCloud from './createProjectCloud.svelte';
|
||||
import { currentPlan, regions as regionsStore } from '$lib/stores/organization';
|
||||
import SelectProjectCloud from '$lib/components/billing/alerts/selectProjectCloud.svelte';
|
||||
import { toLocaleDate } from '$lib/helpers/date';
|
||||
import ArchiveProject from '$lib/components/archiveProject.svelte';
|
||||
|
||||
export let data;
|
||||
|
||||
let showCreate = false;
|
||||
let showCreateProjectCloud = false;
|
||||
let addOrganization = false;
|
||||
let showSelectProject = false;
|
||||
let showCreateProjectCloud = false;
|
||||
|
||||
let searchQuery: SearchQuery;
|
||||
|
||||
function filterPlatforms(platforms: { name: string; icon: string }[]) {
|
||||
return platforms.filter(
|
||||
@@ -80,6 +79,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: projectCreationDisabled =
|
||||
(isCloud && getServiceLimit('projects') <= data.allProjectsCount) ||
|
||||
(isCloud && $readOnly && !GRACE_PERIOD_OVERRIDE) ||
|
||||
!$canWriteProjects;
|
||||
|
||||
$: $registerCommands([
|
||||
{
|
||||
label: 'Create project',
|
||||
@@ -87,34 +91,12 @@
|
||||
showCreate = true;
|
||||
},
|
||||
keys: ['c'],
|
||||
disabled: ($readOnly && !GRACE_PERIOD_OVERRIDE) || !$canWriteProjects,
|
||||
disabled: projectCreationDisabled,
|
||||
group: 'projects',
|
||||
icon: IconPlus
|
||||
}
|
||||
]);
|
||||
|
||||
let showDropdown = false;
|
||||
|
||||
const importProject = async () => {
|
||||
try {
|
||||
loading.set(true);
|
||||
const project = await sdk.forConsole.projects.create({
|
||||
projectId: ID.unique(),
|
||||
name: `Imported project ${new Date().toISOString()}`,
|
||||
teamId: page.params.organization,
|
||||
region: Region.Fra
|
||||
});
|
||||
trackEvent(Submit.ProjectCreate, {
|
||||
teamId: page.params.organization
|
||||
});
|
||||
await goto(`${base}/project-${project.region}-${project.$id}/settings/migrations`);
|
||||
openImportWizard();
|
||||
loading.set(false);
|
||||
} catch (e) {
|
||||
trackError(e, Submit.ProjectCreate);
|
||||
}
|
||||
};
|
||||
|
||||
onMount(async () => checkPricingRefAndRedirect(page.url.searchParams));
|
||||
|
||||
function findRegion(project: Models.Project) {
|
||||
@@ -123,20 +105,18 @@
|
||||
|
||||
function isSetToArchive(project: Models.Project): boolean {
|
||||
if (!isCloud) return false;
|
||||
if (data.organization.projects?.length === 0) return false;
|
||||
if (!project || !project.$id) return false;
|
||||
return !data.organization.projects?.includes(project.$id);
|
||||
return project.status === 'archived';
|
||||
}
|
||||
|
||||
function formatName(name: string, limit: number = 19) {
|
||||
const mobileLimit = 16;
|
||||
const actualLimit = $isSmallViewport ? mobileLimit : limit;
|
||||
return name ? (name.length > actualLimit ? `${name.slice(0, actualLimit)}...` : name) : '-';
|
||||
}
|
||||
$: projectsToArchive = isCloud
|
||||
? data.projects.projects.filter((project) => project.status === 'archived')
|
||||
: [];
|
||||
|
||||
$: projectsToArchive = data.projects.projects.filter(
|
||||
(project) => !data.organization.projects?.includes(project.$id)
|
||||
);
|
||||
$: activeProjects = data.projects.projects.filter((project) => project.status !== 'archived');
|
||||
function clearSearch() {
|
||||
searchQuery?.clearInput();
|
||||
}
|
||||
</script>
|
||||
|
||||
<SelectProjectCloud
|
||||
@@ -145,48 +125,29 @@
|
||||
selectedProjects={data.organization.projects || []} />
|
||||
|
||||
<Container>
|
||||
<div class="u-flex u-gap-12 common-section u-main-space-between">
|
||||
<Typography.Title>Projects</Typography.Title>
|
||||
<Layout.Stack direction="row" justifyContent="space-between" class="common-section">
|
||||
<SearchQuery bind:this={searchQuery} placeholder="Search by name or ID" />
|
||||
|
||||
<DropList bind:show={showDropdown} placement="bottom-end">
|
||||
{#if $canWriteProjects}
|
||||
<Button
|
||||
on:click={handleCreateProject}
|
||||
event="create_project"
|
||||
disabled={$readOnly && !GRACE_PERIOD_OVERRIDE}>
|
||||
<Icon icon={IconPlus} slot="start" size="s" />
|
||||
Create project
|
||||
</Button>
|
||||
{/if}
|
||||
<svelte:fragment slot="list">
|
||||
<DropListItem on:click={() => (showCreate = true)}>Empty project</DropListItem>
|
||||
<DropListItem on:click={importProject}>
|
||||
<div class="u-flex u-gap-8 u-cross-center">
|
||||
Import project <span class="tag eyebrow-heading-3">Experimental</span>
|
||||
</div>
|
||||
</DropListItem>
|
||||
</svelte:fragment>
|
||||
</DropList>
|
||||
</div>
|
||||
{#if $canWriteProjects}
|
||||
<Button
|
||||
on:click={handleCreateProject}
|
||||
event="create_project"
|
||||
disabled={projectCreationDisabled}>
|
||||
<Icon icon={IconPlus} slot="start" size="s" />
|
||||
Create project
|
||||
</Button>
|
||||
{/if}
|
||||
</Layout.Stack>
|
||||
|
||||
{#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>
|
||||
{#each projectsToArchive as project, index}{@const text = `<b>${project.name}</b>`}
|
||||
{@html text}{index == projectsToArchive.length - 2
|
||||
? ', and '
|
||||
: index < projectsToArchive.length - 1
|
||||
? ', '
|
||||
: ''}
|
||||
{/each}
|
||||
will be archived
|
||||
</Typography.Text>
|
||||
{#if isCloud && $currentPlan?.projects && $currentPlan?.projects > 0 && data.organization.projects.length > 0 && $canWriteProjects && (projectsToArchive.length > 0 || data.projects.total > $currentPlan.projects)}
|
||||
{@const difference = projectsToArchive.length}
|
||||
{@const messagePrefix =
|
||||
difference !== 1 ? `${difference} projects are` : `${difference} project is`}
|
||||
<Alert.Inline title={`${messagePrefix} archived`}>
|
||||
<Typography.Text>Upgrade your plan to restore archived projects</Typography.Text>
|
||||
<svelte:fragment slot="actions">
|
||||
<Button secondary size="s" on:click={() => (showSelectProject = true)}>
|
||||
Manage projects
|
||||
</Button>
|
||||
<Button
|
||||
compact
|
||||
size="s"
|
||||
href={$upgradeURL}
|
||||
on:click={() => {
|
||||
@@ -201,18 +162,18 @@
|
||||
</Alert.Inline>
|
||||
{/if}
|
||||
|
||||
{#if data.projects.total}
|
||||
{#if activeProjects.length > 0}
|
||||
<CardContainer
|
||||
disableEmpty={!$canWriteProjects}
|
||||
total={data.projects.total}
|
||||
offset={data.offset}
|
||||
on:click={handleCreateProject}>
|
||||
{#each data.projects.projects as project}
|
||||
{#each activeProjects as project}
|
||||
{@const platforms = filterPlatforms(
|
||||
project.platforms.map((platform) => getPlatformInfo(platform.type))
|
||||
)}
|
||||
{@const formatted = isSetToArchive(project)
|
||||
? formatName(project.name)
|
||||
? formatNameHelper(project.name, isSmallViewport ? 19 : 25)
|
||||
: project.name}
|
||||
<GridItem1
|
||||
href={`${base}/project-${project.region}-${project.$id}/overview/platforms`}>
|
||||
@@ -272,6 +233,10 @@
|
||||
<p>Create a new project</p>
|
||||
</svelte:fragment>
|
||||
</CardContainer>
|
||||
{:else if data.search}
|
||||
<EmptySearch target="projects" hidePagination>
|
||||
<Button size="s" secondary on:click={clearSearch}>Clear search</Button>
|
||||
</EmptySearch>
|
||||
{:else}
|
||||
<Empty
|
||||
single
|
||||
@@ -286,8 +251,13 @@
|
||||
limit={data.limit}
|
||||
offset={data.offset}
|
||||
total={data.projects.total} />
|
||||
</Container>
|
||||
|
||||
<!-- Archived Projects Section -->
|
||||
<ArchiveProject
|
||||
{projectsToArchive}
|
||||
organization={data.organization}
|
||||
currentPlan={$currentPlan} />
|
||||
</Container>
|
||||
<CreateOrganization bind:show={addOrganization} />
|
||||
<CreateProject bind:show={showCreate} teamId={page.params.organization} />
|
||||
<CreateProjectCloud
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Query } from '@appwrite.io/console';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { getLimit, getPage, pageToOffset } from '$lib/helpers/load';
|
||||
import { getLimit, getPage, getSearch, pageToOffset } from '$lib/helpers/load';
|
||||
import { CARD_LIMIT, Dependencies } from '$lib/constants';
|
||||
import type { PageLoad } from './$types';
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
@@ -16,6 +16,7 @@ export const load: PageLoad = async ({ params, url, route, depends, parent }) =>
|
||||
const page = getPage(url);
|
||||
const limit = getLimit(url, route, CARD_LIMIT);
|
||||
const offset = pageToOffset(page, limit);
|
||||
const search = getSearch(url);
|
||||
|
||||
const projects = await sdk.forConsole.projects.list({
|
||||
queries: [
|
||||
@@ -23,7 +24,8 @@ export const load: PageLoad = async ({ params, url, route, depends, parent }) =>
|
||||
Query.equal('teamId', params.organization),
|
||||
Query.limit(limit),
|
||||
Query.orderDesc('')
|
||||
]
|
||||
],
|
||||
search: search || undefined
|
||||
});
|
||||
|
||||
// set `default` if no region!
|
||||
@@ -34,6 +36,7 @@ export const load: PageLoad = async ({ params, url, route, depends, parent }) =>
|
||||
return {
|
||||
offset,
|
||||
limit,
|
||||
projects
|
||||
projects,
|
||||
search
|
||||
};
|
||||
};
|
||||
@@ -2,12 +2,13 @@
|
||||
import { Container } from '$lib/layout';
|
||||
import BudgetCap from './budgetCap.svelte';
|
||||
import PlanSummary from './planSummary.svelte';
|
||||
import PlanSummaryOld from './planSummaryOld.svelte';
|
||||
import BillingAddress from './billingAddress.svelte';
|
||||
import PaymentMethods from './paymentMethods.svelte';
|
||||
import AvailableCredit from './availableCredit.svelte';
|
||||
import PaymentHistory from './paymentHistory.svelte';
|
||||
import TaxId from './taxId.svelte';
|
||||
import { failedInvoice, tierToPlan, upgradeURL } from '$lib/stores/billing';
|
||||
import { failedInvoice, tierToPlan, upgradeURL, useNewPricingModal } from '$lib/stores/billing';
|
||||
import type { PaymentMethodData } from '$lib/sdk/billing';
|
||||
import { onMount } from 'svelte';
|
||||
import { page } from '$app/state';
|
||||
@@ -17,7 +18,7 @@
|
||||
import RetryPaymentModal from './retryPaymentModal.svelte';
|
||||
import { selectedInvoice, showRetryModal } from './store';
|
||||
import { Button } from '$lib/elements/forms';
|
||||
import { Alert, Typography } from '@appwrite.io/pink-svelte';
|
||||
import { Alert } from '@appwrite.io/pink-svelte';
|
||||
import { goto, invalidate } from '$app/navigation';
|
||||
import { Dependencies } from '$lib/constants';
|
||||
import { base } from '$app/paths';
|
||||
@@ -127,12 +128,19 @@
|
||||
until your billing period ends on {toLocaleDate(organization.billingNextInvoiceDate)}.
|
||||
</Alert.Inline>
|
||||
{/if}
|
||||
<Typography.Title>Billing</Typography.Title>
|
||||
<PlanSummary
|
||||
availableCredit={data?.availableCredit}
|
||||
currentPlan={data?.currentPlan}
|
||||
currentAggregation={data?.billingAggregation}
|
||||
currentInvoice={data?.billingInvoice} />
|
||||
{#if $useNewPricingModal}
|
||||
<PlanSummary
|
||||
availableCredit={data?.availableCredit}
|
||||
currentPlan={data?.currentPlan}
|
||||
nextPlan={data?.nextPlan}
|
||||
currentAggregation={data?.billingAggregation} />
|
||||
{:else}
|
||||
<PlanSummaryOld
|
||||
availableCredit={data?.availableCredit}
|
||||
currentPlan={data?.currentPlan}
|
||||
currentAggregation={data?.billingAggregation}
|
||||
currentInvoice={data?.billingInvoice} />
|
||||
{/if}
|
||||
<PaymentHistory />
|
||||
<PaymentMethods organization={data?.organization} methods={data?.paymentMethods} />
|
||||
<BillingAddress
|
||||
|
||||
@@ -57,12 +57,18 @@ export const load: PageLoad = async ({ parent, depends }) => {
|
||||
organization?.billingPlan !== BillingPlan.GITHUB_EDUCATION))
|
||||
: false;
|
||||
|
||||
const [paymentMethods, addressList, billingAddress, availableCredit] = await Promise.all([
|
||||
sdk.forConsole.billing.listPaymentMethods(),
|
||||
sdk.forConsole.billing.listAddresses(),
|
||||
billingAddressPromise,
|
||||
areCreditsSupported ? sdk.forConsole.billing.getAvailableCredit(organization.$id) : null
|
||||
]);
|
||||
const [paymentMethods, addressList, billingAddress, availableCredit, billingPlanDowngrade] =
|
||||
await Promise.all([
|
||||
sdk.forConsole.billing.listPaymentMethods(),
|
||||
sdk.forConsole.billing.listAddresses(),
|
||||
billingAddressPromise,
|
||||
areCreditsSupported
|
||||
? sdk.forConsole.billing.getAvailableCredit(organization.$id)
|
||||
: null,
|
||||
organization.billingPlanDowngrade
|
||||
? sdk.forConsole.billing.getPlan(organization.billingPlanDowngrade)
|
||||
: null
|
||||
]);
|
||||
|
||||
// make number
|
||||
const credits = availableCredit ? availableCredit.available : null;
|
||||
@@ -76,6 +82,7 @@ export const load: PageLoad = async ({ parent, depends }) => {
|
||||
billingInvoice,
|
||||
areCreditsSupported,
|
||||
countryList,
|
||||
locale
|
||||
locale,
|
||||
nextPlan: billingPlanDowngrade
|
||||
};
|
||||
};
|
||||
@@ -36,7 +36,7 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<Modal bind:show title="Add credits" onSubmit={redeem} bind:error>
|
||||
<Modal bind:show title="Add credits" onSubmit={redeem} bind:error size="s">
|
||||
<svelte:fragment slot="description">
|
||||
Apply Appwrite credits to your organization.
|
||||
</svelte:fragment>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
import { wizard } from '$lib/stores/wizard';
|
||||
import { Query } from '@appwrite.io/console';
|
||||
import { onMount } from 'svelte';
|
||||
import AddCreditWizard from './addCreditWizard.svelte';
|
||||
import { Button } from '$lib/elements/forms';
|
||||
import AddCreditModal from './addCreditModal.svelte';
|
||||
import { formatCurrency } from '$lib/helpers/numbers';
|
||||
@@ -33,15 +32,6 @@
|
||||
|
||||
const limit = 5;
|
||||
|
||||
function handleCredits() {
|
||||
if ($organization?.paymentMethodId || $organization?.backupPaymentMethodId) {
|
||||
show = true;
|
||||
} else {
|
||||
wizard.start(AddCreditWizard);
|
||||
reloadOnWizardClose = true;
|
||||
}
|
||||
}
|
||||
|
||||
async function request() {
|
||||
if (!$organization?.$id) return;
|
||||
|
||||
@@ -116,7 +106,7 @@
|
||||
content={formatCurrency(creditList.available)} />
|
||||
</div>
|
||||
{#if creditList?.total}
|
||||
<Button secondary on:click={handleCredits}>
|
||||
<Button secondary on:click={() => (show = true)}>
|
||||
<Icon icon={IconPlus} slot="start" size="s" />
|
||||
Add credits
|
||||
</Button>
|
||||
@@ -176,7 +166,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
{:else}
|
||||
<Empty target="credits" on:click={handleCredits}>Add credits</Empty>
|
||||
<Empty target="credits" on:click={() => (show = true)}>Add credits</Empty>
|
||||
{/if}
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
|
||||
@@ -28,7 +28,12 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<Modal title="Cancel plan change" onSubmit={cancelDowngrade} bind:show={showCancel} bind:error>
|
||||
<Modal
|
||||
title="Cancel plan change"
|
||||
onSubmit={cancelDowngrade}
|
||||
bind:show={showCancel}
|
||||
bind:error
|
||||
size="s">
|
||||
<p>
|
||||
Your organization is set to change to <strong>
|
||||
{tierToPlan($organization?.billingPlanDowngrade).name}</strong>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/state';
|
||||
import { onMount } from 'svelte';
|
||||
import { CardGrid, PaginationInline } from '$lib/components';
|
||||
import { Button } from '$lib/elements/forms';
|
||||
import { toLocaleDate } from '$lib/helpers/date';
|
||||
@@ -28,6 +29,7 @@
|
||||
IconRefresh
|
||||
} from '@appwrite.io/pink-icons-svelte';
|
||||
|
||||
let limit = $state(5);
|
||||
let offset = $state(0);
|
||||
let isLoadingInvoices = $state(false);
|
||||
let invoiceList: InvoiceList = $state({
|
||||
@@ -35,16 +37,29 @@
|
||||
total: 0
|
||||
});
|
||||
|
||||
const limit = 5;
|
||||
const endpoint = getApiEndpoint();
|
||||
const hasPaymentError = $derived(invoiceList?.invoices.some((invoice) => invoice?.lastError));
|
||||
|
||||
async function request() {
|
||||
/**
|
||||
* Special case handling for the first page!
|
||||
*
|
||||
* As per Damodar - `there is some logic to **hide current cycle invoice** in the endpoint`.
|
||||
*
|
||||
* Due to this, the first page always loads `limit - 1` invoices which is inconsistent!
|
||||
* Therefore, we load `limit + 1` to counter that so the returned invoices are consistent.
|
||||
*/
|
||||
onMount(() => request(true));
|
||||
|
||||
async function request(patchQuery: boolean = false) {
|
||||
isLoadingInvoices = true;
|
||||
invoiceList = await sdk.forConsole.billing.listInvoices(page.params.organization, [
|
||||
Query.limit(limit),
|
||||
Query.offset(offset),
|
||||
Query.orderDesc('$createdAt')
|
||||
Query.orderDesc('$createdAt'),
|
||||
|
||||
// first page extra must have an extra limit!
|
||||
Query.limit(patchQuery ? limit + 1 : limit),
|
||||
|
||||
// so an invoice isn't repeated on 2nd page!
|
||||
Query.offset(patchQuery ? offset : offset + 1)
|
||||
]);
|
||||
|
||||
isLoadingInvoices = false;
|
||||
@@ -62,17 +77,11 @@
|
||||
}
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
if (offset !== null) {
|
||||
request();
|
||||
}
|
||||
});
|
||||
|
||||
const columns = $derived([
|
||||
{ id: 'dueDate', width: { min: 120 } },
|
||||
{ id: 'status', width: { min: hasPaymentError ? 200 : 100 } },
|
||||
{ id: 'amount', width: { min: 120 } },
|
||||
{ id: 'action', width: 40 }
|
||||
{ id: 'actions', width: 40 }
|
||||
]);
|
||||
</script>
|
||||
|
||||
@@ -86,11 +95,11 @@
|
||||
<Table.Header.Cell column="dueDate" {root}>Due date</Table.Header.Cell>
|
||||
<Table.Header.Cell column="status" {root}>Status</Table.Header.Cell>
|
||||
<Table.Header.Cell column="amount" {root}>Amount due</Table.Header.Cell>
|
||||
<Table.Header.Cell column="action" {root} />
|
||||
<Table.Header.Cell column="actions" {root} />
|
||||
</svelte:fragment>
|
||||
|
||||
{#if isLoadingInvoices}
|
||||
{#each Array.from({ length: 2 }).keys() as index (index)}
|
||||
{#each Array.from({ length: 5 }).keys() as index (index)}
|
||||
<Table.Row.Base {root}>
|
||||
{#each columns as column}
|
||||
<Table.Cell column={column.id} {root}>
|
||||
@@ -99,91 +108,95 @@
|
||||
{/each}
|
||||
</Table.Row.Base>
|
||||
{/each}
|
||||
{/if}
|
||||
|
||||
{#each invoiceList?.invoices as invoice}
|
||||
{@const status = invoice.status}
|
||||
<Table.Row.Base {root}>
|
||||
<Table.Cell column="dueDate" {root}>
|
||||
{toLocaleDate(invoice.dueAt)}
|
||||
</Table.Cell>
|
||||
<Table.Cell column="status" {root}>
|
||||
{@const isDanger =
|
||||
status === 'overdue' ||
|
||||
status === 'failed' ||
|
||||
status === 'requires_authentication'}
|
||||
{@const isSuccess = status === 'paid' || status === 'succeeded'}
|
||||
{@const isWarning = status === 'pending'}
|
||||
<Layout.Stack direction="row" gap="s">
|
||||
<Badge
|
||||
variant="secondary"
|
||||
content={status === 'requires_authentication'
|
||||
? 'failed'
|
||||
: status}
|
||||
type={isDanger
|
||||
? 'error'
|
||||
: isWarning
|
||||
? 'warning'
|
||||
: isSuccess
|
||||
? 'success'
|
||||
: undefined} />
|
||||
{#if invoice?.lastError}
|
||||
<Popover let:toggle>
|
||||
<Link.Button on:click={toggle}>Details</Link.Button>
|
||||
<svelte:fragment slot="tooltip">
|
||||
The scheduled payment has failed.
|
||||
<Link.Button on:click={() => retryPayment(invoice)}
|
||||
>Try again
|
||||
</Link.Button>
|
||||
</svelte:fragment>
|
||||
</Popover>
|
||||
{/if}
|
||||
</Layout.Stack>
|
||||
</Table.Cell>
|
||||
<Table.Cell column="amount" {root}>
|
||||
{formatCurrency(invoice.grossAmount)}
|
||||
</Table.Cell>
|
||||
<Table.Cell column="status" {root}>
|
||||
<Popover let:toggle placement="bottom-start" padding="none">
|
||||
<Button text icon ariaLabel="more options" on:click={toggle}>
|
||||
<Icon icon={IconDotsHorizontal} size="s" />
|
||||
</Button>
|
||||
<ActionMenu.Root slot="tooltip">
|
||||
<!-- todo: add missing event -->
|
||||
<ActionMenu.Item.Anchor
|
||||
leadingIcon={IconExternalLink}
|
||||
external
|
||||
href={`${endpoint}/organizations/${page.params.organization}/invoices/${invoice.$id}/view`}>
|
||||
View invoice
|
||||
</ActionMenu.Item.Anchor>
|
||||
<ActionMenu.Item.Anchor
|
||||
leadingIcon={IconDownload}
|
||||
href={`${endpoint}/organizations/${page.params.organization}/invoices/${invoice.$id}/download`}>
|
||||
Download PDF
|
||||
</ActionMenu.Item.Anchor>
|
||||
{#if status === 'overdue' || status === 'failed' || status === 'abandoned'}
|
||||
<ActionMenu.Item.Button
|
||||
leadingIcon={IconRefresh}
|
||||
on:click={() => {
|
||||
retryPayment(invoice);
|
||||
trackEvent(`click_retry_payment`, {
|
||||
from: 'button',
|
||||
source: 'billing_invoice_menu'
|
||||
});
|
||||
}}>
|
||||
Retry payment
|
||||
</ActionMenu.Item.Button>
|
||||
{:else}
|
||||
{#each invoiceList?.invoices as invoice (invoice.$id)}
|
||||
{@const status = invoice.status}
|
||||
<Table.Row.Base {root}>
|
||||
<Table.Cell column="dueDate" {root}
|
||||
>{toLocaleDate(invoice.dueAt)}</Table.Cell>
|
||||
<Table.Cell column="status" {root}>
|
||||
{@const isDanger =
|
||||
status === 'overdue' ||
|
||||
status === 'failed' ||
|
||||
status === 'requires_authentication'}
|
||||
{@const isSuccess = status === 'paid' || status === 'succeeded'}
|
||||
{@const isWarning = status === 'pending'}
|
||||
<Layout.Stack direction="row" gap="s">
|
||||
<Badge
|
||||
variant="secondary"
|
||||
content={status === 'requires_authentication'
|
||||
? 'failed'
|
||||
: status}
|
||||
type={isDanger
|
||||
? 'error'
|
||||
: isWarning
|
||||
? 'warning'
|
||||
: isSuccess
|
||||
? 'success'
|
||||
: undefined} />
|
||||
{#if invoice?.lastError}
|
||||
<Popover let:toggle>
|
||||
<Link.Button on:click={toggle}>Details</Link.Button>
|
||||
<svelte:fragment slot="tooltip">
|
||||
The scheduled payment has failed.
|
||||
<Link.Button on:click={() => retryPayment(invoice)}
|
||||
>Try again
|
||||
</Link.Button>
|
||||
</svelte:fragment>
|
||||
</Popover>
|
||||
{/if}
|
||||
</ActionMenu.Root>
|
||||
</Popover>
|
||||
</Table.Cell>
|
||||
</Table.Row.Base>
|
||||
{/each}
|
||||
</Layout.Stack>
|
||||
</Table.Cell>
|
||||
<Table.Cell column="amount" {root}>
|
||||
{formatCurrency(invoice.grossAmount)}
|
||||
</Table.Cell>
|
||||
<Table.Cell column="actions" {root}>
|
||||
<Popover let:toggle placement="bottom-start" padding="none">
|
||||
<Button text icon ariaLabel="more options" on:click={toggle}>
|
||||
<Icon icon={IconDotsHorizontal} size="s" />
|
||||
</Button>
|
||||
<ActionMenu.Root slot="tooltip">
|
||||
<!-- todo: add missing event -->
|
||||
<ActionMenu.Item.Anchor
|
||||
leadingIcon={IconExternalLink}
|
||||
external
|
||||
href={`${endpoint}/organizations/${page.params.organization}/invoices/${invoice.$id}/view`}>
|
||||
View invoice
|
||||
</ActionMenu.Item.Anchor>
|
||||
<ActionMenu.Item.Anchor
|
||||
leadingIcon={IconDownload}
|
||||
href={`${endpoint}/organizations/${page.params.organization}/invoices/${invoice.$id}/download`}>
|
||||
Download PDF
|
||||
</ActionMenu.Item.Anchor>
|
||||
{#if status === 'overdue' || status === 'failed' || status === 'abandoned'}
|
||||
<ActionMenu.Item.Button
|
||||
leadingIcon={IconRefresh}
|
||||
on:click={() => {
|
||||
retryPayment(invoice);
|
||||
trackEvent(`click_retry_payment`, {
|
||||
from: 'button',
|
||||
source: 'billing_invoice_menu'
|
||||
});
|
||||
}}>
|
||||
Retry payment
|
||||
</ActionMenu.Item.Button>
|
||||
{/if}
|
||||
</ActionMenu.Root>
|
||||
</Popover>
|
||||
</Table.Cell>
|
||||
</Table.Row.Base>
|
||||
{/each}
|
||||
{/if}
|
||||
</Table.Root>
|
||||
{#if invoiceList.total > limit}
|
||||
{#if invoiceList.total >= limit}
|
||||
<Layout.Stack direction="row" justifyContent="space-between" alignItems="center">
|
||||
<p class="text">Total results: {invoiceList.total}</p>
|
||||
<PaginationInline {limit} bind:offset total={invoiceList.total} hidePages />
|
||||
<PaginationInline
|
||||
{limit}
|
||||
hidePages
|
||||
bind:offset
|
||||
total={invoiceList.total}
|
||||
on:change={() => request()} />
|
||||
</Layout.Stack>
|
||||
{/if}
|
||||
{:else}
|
||||
|
||||
@@ -1,180 +1,510 @@
|
||||
<script lang="ts">
|
||||
import { base } from '$app/paths';
|
||||
import { CardGrid } from '$lib/components';
|
||||
import { EstimatedCard } from '$lib/components';
|
||||
import { Button } from '$lib/elements/forms';
|
||||
import { toLocaleDate } from '$lib/helpers/date';
|
||||
import { plansInfo, upgradeURL } from '$lib/stores/billing';
|
||||
import { upgradeURL } from '$lib/stores/billing';
|
||||
import { organization } from '$lib/stores/organization';
|
||||
import type { Aggregation, Invoice, Plan } from '$lib/sdk/billing';
|
||||
import { abbreviateNumber, formatCurrency, formatNumberWithCommas } from '$lib/helpers/numbers';
|
||||
import type { AggregationTeam, Plan } from '$lib/sdk/billing';
|
||||
import { formatCurrency } from '$lib/helpers/numbers';
|
||||
import { BillingPlan } from '$lib/constants';
|
||||
import { Click, trackEvent } from '$lib/actions/analytics';
|
||||
import {
|
||||
Accordion,
|
||||
Card,
|
||||
Divider,
|
||||
Typography,
|
||||
Expandable as ExpandableTable,
|
||||
Icon,
|
||||
Layout,
|
||||
Tooltip,
|
||||
Typography
|
||||
Divider
|
||||
} from '@appwrite.io/pink-svelte';
|
||||
import { IconInfo, IconTag } from '@appwrite.io/pink-icons-svelte';
|
||||
import { humanFileSize } from '$lib/helpers/sizeConvertion';
|
||||
import { formatNum } from '$lib/helpers/string';
|
||||
import { ProgressBar } from '$lib/components';
|
||||
import { isSmallViewport, isTabletViewport } from '$lib/stores/viewport';
|
||||
import CancelDowngradeModel from './cancelDowngradeModal.svelte';
|
||||
import { IconTag } from '@appwrite.io/pink-icons-svelte';
|
||||
|
||||
export let currentPlan: Plan;
|
||||
export let currentInvoice: Invoice | undefined = undefined;
|
||||
export let nextPlan: Plan | null = null;
|
||||
export let availableCredit: number | undefined = undefined;
|
||||
export let currentAggregation: Aggregation | undefined = undefined;
|
||||
export let currentAggregation: AggregationTeam | undefined = undefined;
|
||||
|
||||
let showCancel: boolean = false;
|
||||
|
||||
const today = new Date();
|
||||
const isTrial =
|
||||
new Date($organization?.billingStartDate).getTime() - today.getTime() > 0 &&
|
||||
$plansInfo.get($organization.billingPlan)?.trialDays;
|
||||
const extraUsage = currentInvoice ? currentInvoice.amount - currentPlan?.price : 0;
|
||||
// define columns for the expandable table
|
||||
const columns = [
|
||||
{ id: 'item', align: 'left' as const, width: '10fr' },
|
||||
{ id: 'usage', align: 'left' as const, width: '20fr' },
|
||||
{ id: 'price', align: 'right' as const, width: '0fr' }
|
||||
];
|
||||
|
||||
function formatHumanSize(bytes: number): string {
|
||||
const size = humanFileSize(bytes || 0);
|
||||
return `${size.value} ${size.unit}`;
|
||||
}
|
||||
|
||||
function formatBandwidthUsage(currentBytes: number, maxGB?: number): string {
|
||||
const currentSize = humanFileSize(currentBytes || 0);
|
||||
if (!maxGB) {
|
||||
return `${currentSize.value} ${currentSize.unit} / Unlimited`;
|
||||
}
|
||||
const maxSize = humanFileSize(maxGB * 1000 * 1000 * 1000);
|
||||
return `${currentSize.value} ${currentSize.unit} / ${maxSize.value} ${maxSize.unit}`;
|
||||
}
|
||||
|
||||
function truncateForSmall(name: string): string {
|
||||
if (!name) return name;
|
||||
return name.length > 12 ? `${name.slice(0, 12)}…` : name;
|
||||
}
|
||||
|
||||
function createProgressData(
|
||||
currentValue: number,
|
||||
maxValue: number | string
|
||||
): Array<{ size: number; color: string; tooltip?: { title: string; label: string } }> {
|
||||
if (
|
||||
maxValue === null ||
|
||||
maxValue === undefined ||
|
||||
(typeof maxValue === 'number' && maxValue <= 0)
|
||||
) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const max = typeof maxValue === 'string' ? parseFloat(maxValue) : maxValue;
|
||||
if (max <= 0) return [];
|
||||
|
||||
const percentage = Math.min((currentValue / max) * 100, 100);
|
||||
const progressColor = 'var(--bgcolor-neutral-invert)';
|
||||
|
||||
return [
|
||||
{
|
||||
size: currentValue,
|
||||
color: progressColor,
|
||||
tooltip: {
|
||||
title: `${percentage.toFixed(1)}% used`,
|
||||
label: `${currentValue.toLocaleString()} of ${max.toLocaleString()}`
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
function createStorageProgressData(
|
||||
currentBytes: number,
|
||||
maxGB: number
|
||||
): Array<{ size: number; color: string; tooltip?: { title: string; label: string } }> {
|
||||
if (maxGB <= 0) return [];
|
||||
|
||||
const maxBytes = maxGB * 1000 * 1000 * 1000;
|
||||
const percentage = Math.min((currentBytes / maxBytes) * 100, 100);
|
||||
const progressColor = 'var(--bgcolor-neutral-invert)';
|
||||
|
||||
const currentSize = humanFileSize(currentBytes);
|
||||
|
||||
return [
|
||||
{
|
||||
size: currentBytes,
|
||||
color: progressColor,
|
||||
tooltip: {
|
||||
title: `${percentage.toFixed(0)}% used`,
|
||||
label: `${currentSize.value} ${currentSize.unit} of ${maxGB} GB`
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
function getProjectsList(currentAggregation) {
|
||||
return (
|
||||
currentAggregation?.breakdown?.map((projectData) => ({
|
||||
projectId: projectData.$id,
|
||||
name: projectData.name,
|
||||
region: projectData.region,
|
||||
amount: projectData.amount,
|
||||
storage: projectData?.resources?.find((res) => res.resourceId === 'storage'),
|
||||
executions: projectData?.resources?.find(
|
||||
(resource) => resource.resourceId === 'executions'
|
||||
),
|
||||
gbHours: projectData?.resources?.find(
|
||||
(resource) => resource.resourceId === 'GBHours'
|
||||
),
|
||||
imageTransformations: projectData?.resources?.find(
|
||||
(resource) => resource.resourceId === 'imageTransformations'
|
||||
),
|
||||
bandwidth: projectData?.resources?.find(
|
||||
(resource) => resource.resourceId === 'bandwidth'
|
||||
),
|
||||
databasesReads: projectData?.resources?.find(
|
||||
(resource) => resource.resourceId === 'databasesReads'
|
||||
),
|
||||
databasesWrites: projectData?.resources?.find(
|
||||
(resource) => resource.resourceId === 'databasesWrites'
|
||||
),
|
||||
users: projectData?.resources?.find((resource) => resource.resourceId === 'users'),
|
||||
authPhone: projectData?.resources?.find(
|
||||
(resource) => resource.resourceId === 'authPhone'
|
||||
)
|
||||
})) || []
|
||||
);
|
||||
}
|
||||
|
||||
function getBillingData(currentPlan, currentAggregation, isSmallViewport) {
|
||||
const projectsList = getProjectsList(currentAggregation);
|
||||
const base = {
|
||||
id: 'base-plan',
|
||||
expandable: false,
|
||||
cells: {
|
||||
item: 'Base plan',
|
||||
usage: '',
|
||||
price: formatCurrency(nextPlan?.price ?? currentPlan?.price ?? 0)
|
||||
},
|
||||
children: []
|
||||
};
|
||||
const addons = (currentAggregation?.resources || [])
|
||||
.filter(
|
||||
(r) =>
|
||||
r.amount &&
|
||||
r.amount > 0 &&
|
||||
Object.keys(currentPlan?.addons || {}).includes(r.resourceId) &&
|
||||
currentPlan.addons[r.resourceId]?.price > 0
|
||||
)
|
||||
.map((excess) => ({
|
||||
id: `addon-${excess.resourceId}`,
|
||||
expandable: false,
|
||||
cells: {
|
||||
item:
|
||||
excess.resourceId === 'seats'
|
||||
? 'Additional members'
|
||||
: excess.resourceId === 'projects'
|
||||
? `Additional Projects (${formatNum(excess.value)})`
|
||||
: `${excess.resourceId} overage (${formatNum(excess.value)})`,
|
||||
usage: '',
|
||||
price: formatCurrency(excess.amount)
|
||||
},
|
||||
children: []
|
||||
}));
|
||||
const projects = projectsList.map((project) => ({
|
||||
id: `project-${project.projectId}`,
|
||||
expandable: true,
|
||||
cells: {
|
||||
item: isSmallViewport
|
||||
? truncateForSmall(project.name)
|
||||
: project.name || `Project ${project.projectId}`,
|
||||
usage: '',
|
||||
price: formatCurrency(project.amount || 0)
|
||||
},
|
||||
children: [
|
||||
{
|
||||
id: `bandwidth`,
|
||||
cells: {
|
||||
item: 'Bandwidth',
|
||||
usage: `${formatBandwidthUsage(project.bandwidth.value, currentPlan?.bandwidth)}`,
|
||||
price: formatCurrency(project.bandwidth.amount || 0)
|
||||
},
|
||||
progressData: createStorageProgressData(
|
||||
project.bandwidth.value || 0,
|
||||
currentPlan?.bandwidth || 0
|
||||
),
|
||||
maxValue: currentPlan?.bandwidth
|
||||
? currentPlan.bandwidth * 1000 * 1000 * 1000
|
||||
: 0
|
||||
},
|
||||
{
|
||||
id: `users`,
|
||||
cells: {
|
||||
item: 'Users',
|
||||
usage: `${formatNum(project.users.value || 0)} / ${currentPlan?.users ? formatNum(currentPlan.users) : 'Unlimited'}`,
|
||||
price: formatCurrency(project.users.amount || 0)
|
||||
},
|
||||
progressData: createProgressData(project.users.value || 0, currentPlan?.users),
|
||||
maxValue: currentPlan?.users
|
||||
},
|
||||
{
|
||||
id: `reads`,
|
||||
cells: {
|
||||
item: 'Database reads',
|
||||
usage: `${formatNum(project.databasesReads.value || 0)} / ${currentPlan?.databasesReads ? formatNum(currentPlan.databasesReads) : 'Unlimited'}`,
|
||||
price: formatCurrency(project.databasesReads.amount || 0)
|
||||
},
|
||||
progressData: createProgressData(
|
||||
project.databasesReads.value || 0,
|
||||
currentPlan?.databasesReads
|
||||
),
|
||||
maxValue: currentPlan?.databasesReads
|
||||
},
|
||||
{
|
||||
id: `writes`,
|
||||
cells: {
|
||||
item: 'Database writes',
|
||||
usage: `${formatNum(project.databasesWrites.value || 0)} / ${currentPlan?.databasesWrites ? formatNum(currentPlan.databasesWrites) : 'Unlimited'}`,
|
||||
price: formatCurrency(project.databasesWrites.amount || 0)
|
||||
},
|
||||
progressData: createProgressData(
|
||||
project.databasesWrites.value || 0,
|
||||
currentPlan?.databasesWrites
|
||||
),
|
||||
maxValue: currentPlan?.databasesWrites
|
||||
},
|
||||
{
|
||||
id: `executions`,
|
||||
cells: {
|
||||
item: 'Executions',
|
||||
usage: `${formatNum(project.executions.value || 0)} / ${currentPlan?.executions ? formatNum(currentPlan.executions) : 'Unlimited'}`,
|
||||
price: formatCurrency(project.executions.amount || 0)
|
||||
},
|
||||
progressData: createProgressData(
|
||||
project.executions.value || 0,
|
||||
currentPlan?.executions
|
||||
),
|
||||
maxValue: currentPlan?.executions
|
||||
},
|
||||
{
|
||||
id: `storage`,
|
||||
cells: {
|
||||
item: 'Storage',
|
||||
usage: `${formatHumanSize(project.storage.value || 0)} / ${currentPlan?.storage?.toString() || '0'} GB`,
|
||||
price: formatCurrency(project.storage.amount || 0)
|
||||
},
|
||||
progressData: createStorageProgressData(
|
||||
project.storage.value || 0,
|
||||
currentPlan?.storage || 0
|
||||
),
|
||||
maxValue: currentPlan?.storage ? currentPlan.storage * 1000 * 1000 * 1000 : 0
|
||||
},
|
||||
{
|
||||
id: `image-transformations`,
|
||||
cells: {
|
||||
item: 'Image transformations',
|
||||
usage: `${formatNum(project.imageTransformations.value || 0)} / ${currentPlan?.imageTransformations ? formatNum(currentPlan.imageTransformations) : 'Unlimited'}`,
|
||||
price: formatCurrency(project.imageTransformations.amount || 0)
|
||||
},
|
||||
progressData: createProgressData(
|
||||
project.imageTransformations.value || 0,
|
||||
currentPlan?.imageTransformations
|
||||
),
|
||||
maxValue: currentPlan?.imageTransformations
|
||||
},
|
||||
{
|
||||
id: `gb-hours`,
|
||||
cells: {
|
||||
item: 'GB-hours',
|
||||
usage: `${formatNum(project.gbHours.value || 0)} / ${currentPlan?.GBHours ? formatNum(currentPlan.GBHours) : 'Unlimited'}`,
|
||||
price: formatCurrency(project.gbHours.amount || 0)
|
||||
},
|
||||
progressData: currentPlan?.GBHours
|
||||
? createProgressData(project.gbHours.value || 0, currentPlan.GBHours)
|
||||
: [],
|
||||
maxValue: currentPlan?.GBHours ? currentPlan.GBHours : null
|
||||
},
|
||||
{
|
||||
id: `sms`,
|
||||
cells: {
|
||||
item: 'Phone OTP',
|
||||
usage: `${formatNum(project.authPhone.value || 0)} SMS messages`,
|
||||
price: formatCurrency(project.authPhone.amount || 0)
|
||||
}
|
||||
},
|
||||
{
|
||||
id: `usage-details`,
|
||||
cells: {
|
||||
item: `<a href="/console/project-${String(project.region || 'default')}-${project.projectId}/settings/usage" style="text-decoration: underline; color: var(--fgcolor-accent-neutral);">Usage details</a>`,
|
||||
usage: '',
|
||||
price: ''
|
||||
}
|
||||
}
|
||||
]
|
||||
}));
|
||||
const noProjects = [];
|
||||
return [base, ...addons, ...projects, ...noProjects];
|
||||
}
|
||||
|
||||
$: billingData = getBillingData(currentPlan, currentAggregation, $isSmallViewport);
|
||||
|
||||
$: totalAmount = Math.max(currentAggregation?.amount - creditsApplied, 0);
|
||||
|
||||
$: creditsApplied = Math.min(
|
||||
currentAggregation?.amount ?? currentPlan?.price ?? 0,
|
||||
availableCredit
|
||||
);
|
||||
</script>
|
||||
|
||||
{#if $organization}
|
||||
<CardGrid>
|
||||
<svelte:fragment slot="title">Payment estimates</svelte:fragment>
|
||||
A breakdown of your estimated upcoming payment for the current billing period. Totals displayed
|
||||
exclude accumulated credits and applicable taxes.
|
||||
<svelte:fragment slot="aside">
|
||||
<p class="text u-bold">
|
||||
Due at: {toLocaleDate($organization?.billingNextInvoiceDate)}
|
||||
</p>
|
||||
<Card.Base variant="secondary" padding="s">
|
||||
<Layout.Stack>
|
||||
<Layout.Stack direction="row" justifyContent="space-between">
|
||||
<Typography.Text color="--fgcolor-neutral-primary">
|
||||
{currentPlan.name} plan
|
||||
</Typography.Text>
|
||||
<Typography.Text>
|
||||
{isTrial || $organization?.billingPlan === BillingPlan.GITHUB_EDUCATION
|
||||
? formatCurrency(0)
|
||||
: currentPlan
|
||||
? formatCurrency(currentPlan?.price)
|
||||
: ''}
|
||||
</Typography.Text>
|
||||
</Layout.Stack>
|
||||
<EstimatedCard>
|
||||
<Typography.Title size="s" gap="s">{currentPlan.name} plan</Typography.Title>
|
||||
|
||||
{#if currentPlan.budgeting && extraUsage > 0}
|
||||
<Accordion
|
||||
hideDivider
|
||||
title="Add-ons"
|
||||
badge={(currentAggregation.additionalMembers > 0
|
||||
? currentInvoice.usage.length + 1
|
||||
: currentInvoice.usage.length
|
||||
).toString()}>
|
||||
<svelte:fragment slot="end">
|
||||
{formatCurrency(extraUsage >= 0 ? extraUsage : 0)}
|
||||
</svelte:fragment>
|
||||
<Layout.Stack gap="xs">
|
||||
{#if currentAggregation.additionalMembers}
|
||||
<Layout.Stack gap="xxxs">
|
||||
<Layout.Stack
|
||||
direction="row"
|
||||
justifyContent="space-between">
|
||||
<Typography.Text color="--fgcolor-neutral-primary"
|
||||
>Additional members</Typography.Text>
|
||||
<Typography.Text>
|
||||
{formatCurrency(
|
||||
currentAggregation.additionalMemberAmount
|
||||
)}
|
||||
</Typography.Text>
|
||||
</Layout.Stack>
|
||||
<Layout.Stack direction="row">
|
||||
<Typography.Text
|
||||
>{currentAggregation.additionalMembers}</Typography.Text>
|
||||
</Layout.Stack>
|
||||
</Layout.Stack>
|
||||
{#if totalAmount > 0}
|
||||
<Typography.Text color="--fgcolor-neutral-secondary">
|
||||
Next payment of <span class="text --fgcolor-neutral-primary u-bold"
|
||||
>{formatCurrency(totalAmount)}</span>
|
||||
will occur on
|
||||
<span class="text --fgcolor-neutral-primary u-bold"
|
||||
>{toLocaleDate($organization?.billingNextInvoiceDate)}</span
|
||||
>.
|
||||
</Typography.Text>
|
||||
{/if}
|
||||
<Divider />
|
||||
<div class="billing-cycle-header">
|
||||
<Typography.Text color="--fgcolor-neutral-secondary" variant="m-500">
|
||||
Current billing cycle ({new Date(
|
||||
$organization?.billingCurrentInvoiceDate
|
||||
).toLocaleDateString('en', { day: 'numeric', month: 'short' })}-{new Date(
|
||||
$organization?.billingNextInvoiceDate
|
||||
).toLocaleDateString('en', { day: 'numeric', month: 'short' })})
|
||||
</Typography.Text>
|
||||
<Typography.Text color="--fgcolor-neutral-tertiary" variant="m-400">
|
||||
Estimate, subject to change based on usage.
|
||||
</Typography.Text>
|
||||
</div>
|
||||
<!-- Billing breakdown table -->
|
||||
<div class="table-wrapper" class:is-mobile={$isSmallViewport}>
|
||||
<ExpandableTable.Root {columns} showHeader={false} let:root>
|
||||
{#each billingData as row}
|
||||
<ExpandableTable.Row {root} id={row.id} expandable={row.expandable ?? false}>
|
||||
{#each columns as col}
|
||||
<ExpandableTable.Cell
|
||||
{root}
|
||||
column={col.id}
|
||||
expandable={row.expandable ?? false}>
|
||||
{#if col.id === 'item'}
|
||||
<div class="cell-item-text">
|
||||
<Typography.Text>
|
||||
{row.cells?.[col.id] ?? ''}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
{:else}
|
||||
<Typography.Text>
|
||||
{row.cells?.[col.id] ?? ''}
|
||||
</Typography.Text>
|
||||
{/if}
|
||||
{#if currentInvoice?.usage}
|
||||
{#each currentInvoice.usage as excess, i}
|
||||
{#if i > 0 || currentAggregation.additionalMembers}
|
||||
<Divider />
|
||||
{/if}
|
||||
</ExpandableTable.Cell>
|
||||
{/each}
|
||||
|
||||
<Layout.Stack gap="xxxs">
|
||||
<Layout.Stack
|
||||
direction="row"
|
||||
justifyContent="space-between">
|
||||
<Typography.Text color="--fgcolor-neutral-primary">
|
||||
{excess.name}
|
||||
</Typography.Text>
|
||||
<Typography.Text>
|
||||
{formatCurrency(excess.amount)}
|
||||
</Typography.Text>
|
||||
</Layout.Stack>
|
||||
<Layout.Stack direction="row">
|
||||
<Tooltip
|
||||
placement="bottom"
|
||||
disabled={excess.value <= 1000}>
|
||||
<svelte:fragment slot="tooltip">
|
||||
{formatNumberWithCommas(excess.value)}
|
||||
</svelte:fragment>
|
||||
<span>{abbreviateNumber(excess.value)}</span>
|
||||
</Tooltip>
|
||||
</Layout.Stack>
|
||||
</Layout.Stack>
|
||||
{/each}
|
||||
{/if}
|
||||
</Layout.Stack>
|
||||
</Accordion>
|
||||
{/if}
|
||||
<svelte:fragment slot="summary">
|
||||
{#if row.children}
|
||||
{#each row.children as child (child.id)}
|
||||
<div
|
||||
class="child-row"
|
||||
class:is-tablet={$isTabletViewport && !$isSmallViewport}
|
||||
style="grid-template-columns: {root.childGridTemplate}; --original-grid-template: {root.childGridTemplate};">
|
||||
{#each columns as col}
|
||||
<div
|
||||
class="child-cell"
|
||||
class:price={col.id === 'price'}
|
||||
class:is-mobile={$isSmallViewport}
|
||||
style="justify-content: {root.alignment(
|
||||
col.align
|
||||
)};">
|
||||
{#if child.cells?.[col.id]?.includes('<a href=')}
|
||||
{@html child.cells?.[col.id] ?? ''}
|
||||
{:else if col.id === 'usage'}
|
||||
<div
|
||||
class="usage-cell-content"
|
||||
class:is-mobile={$isSmallViewport}
|
||||
class:is-tablet={$isTabletViewport &&
|
||||
!$isSmallViewport}>
|
||||
<div class="usage-progress-section">
|
||||
{#if child.progressData && child.progressData.length > 0 && child.maxValue}
|
||||
<ProgressBar
|
||||
maxSize={child.maxValue}
|
||||
data={child.progressData} />
|
||||
{/if}
|
||||
</div>
|
||||
<div class="usage-text-section">
|
||||
{#if child.cells?.[col.id]?.includes(' / ')}
|
||||
{@const usageParts = (
|
||||
child.cells?.[col.id] ?? ''
|
||||
).split(' / ')}
|
||||
<Typography.Text
|
||||
variant="m-400"
|
||||
color="--fgcolor-neutral-secondary">
|
||||
{usageParts[0]}
|
||||
</Typography.Text>
|
||||
<Typography.Text
|
||||
variant="m-400"
|
||||
color="--fgcolor-neutral-tertiary">
|
||||
{' / '}
|
||||
</Typography.Text>
|
||||
<Typography.Text
|
||||
variant="m-400"
|
||||
color="--fgcolor-neutral-tertiary">
|
||||
{usageParts[1]}
|
||||
</Typography.Text>
|
||||
{:else}
|
||||
<Typography.Text
|
||||
variant="m-400"
|
||||
color="--fgcolor-neutral-secondary">
|
||||
{child.cells?.[col.id] ?? ''}
|
||||
</Typography.Text>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
<Typography.Text
|
||||
variant="m-400"
|
||||
color="--fgcolor-neutral-secondary">
|
||||
{child.cells?.[col.id] ?? ''}
|
||||
</Typography.Text>
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/each}
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
</ExpandableTable.Row>
|
||||
{/each}
|
||||
{#if availableCredit > 0}
|
||||
<ExpandableTable.Row {root} id="total-row" expandable={false}>
|
||||
<ExpandableTable.Cell {root} column="item" expandable={false}>
|
||||
<Layout.Stack
|
||||
inline
|
||||
direction="row"
|
||||
gap="xxs"
|
||||
alignItems="center"
|
||||
alignContent="center">
|
||||
<Icon icon={IconTag} color="--fgcolor-success" size="s" />
|
||||
|
||||
{#if currentPlan.supportsCredits && availableCredit > 0}
|
||||
<Layout.Stack direction="row" justifyContent="space-between">
|
||||
<Layout.Stack direction="row" alignItems="center" gap="xxs">
|
||||
<Icon size="s" icon={IconTag} color="--fgcolor-success" />
|
||||
<Typography.Text color="--fgcolor-neutral-primary"
|
||||
>Credits to be applied</Typography.Text>
|
||||
>Credits</Typography.Text>
|
||||
</Layout.Stack>
|
||||
<Typography.Text color="--fgcolor-success">
|
||||
-{formatCurrency(
|
||||
Math.min(availableCredit, currentInvoice?.amount ?? 0)
|
||||
)}
|
||||
</ExpandableTable.Cell>
|
||||
<ExpandableTable.Cell {root} column="usage" expandable={false}>
|
||||
<Typography.Text variant="m-500" color="--fgcolor-neutral-primary">
|
||||
</Typography.Text>
|
||||
</Layout.Stack>
|
||||
{/if}
|
||||
</ExpandableTable.Cell>
|
||||
<ExpandableTable.Cell {root} column="price" expandable={false}>
|
||||
<Typography.Text variant="m-500" color="--fgcolor-neutral-primary">
|
||||
-{formatCurrency(creditsApplied)}
|
||||
</Typography.Text>
|
||||
</ExpandableTable.Cell>
|
||||
</ExpandableTable.Row>
|
||||
{/if}
|
||||
|
||||
{#if $organization?.billingPlan !== BillingPlan.FREE && $organization?.billingPlan !== BillingPlan.GITHUB_EDUCATION}
|
||||
<Divider />
|
||||
<Layout.Stack direction="row" justifyContent="space-between">
|
||||
<Typography.Text color="--fgcolor-neutral-primary" variant="m-500">
|
||||
<Layout.Stack direction="row" alignItems="center" gap="s">
|
||||
Current total (USD)
|
||||
<Tooltip>
|
||||
<Icon icon={IconInfo} />
|
||||
<svelte:fragment slot="tooltip">
|
||||
Estimates are updated daily and may differ from your
|
||||
final invoice.
|
||||
</svelte:fragment>
|
||||
</Tooltip>
|
||||
</Layout.Stack>
|
||||
</Typography.Text>
|
||||
<Typography.Text color="--fgcolor-neutral-primary" variant="m-500">
|
||||
{formatCurrency(
|
||||
Math.max(
|
||||
(currentInvoice?.amount ?? 0) -
|
||||
Math.min(availableCredit, currentInvoice?.amount ?? 0),
|
||||
0
|
||||
)
|
||||
)}
|
||||
</Typography.Text>
|
||||
</Layout.Stack>
|
||||
{/if}
|
||||
</Layout.Stack>
|
||||
</Card.Base>
|
||||
</svelte:fragment>
|
||||
<svelte:fragment slot="actions">
|
||||
<ExpandableTable.Row {root} id="total-row" expandable={false}>
|
||||
<ExpandableTable.Cell {root} column="item" expandable={false}>
|
||||
<Typography.Text variant="m-500" color="--fgcolor-neutral-primary">
|
||||
Total
|
||||
</Typography.Text>
|
||||
</ExpandableTable.Cell>
|
||||
<ExpandableTable.Cell {root} column="usage" expandable={false}>
|
||||
<Typography.Text variant="m-500" color="--fgcolor-neutral-primary">
|
||||
</Typography.Text>
|
||||
</ExpandableTable.Cell>
|
||||
<ExpandableTable.Cell {root} column="price" expandable={false}>
|
||||
<Typography.Text variant="m-500" color="--fgcolor-neutral-primary">
|
||||
{formatCurrency(totalAmount)}
|
||||
</Typography.Text>
|
||||
</ExpandableTable.Cell>
|
||||
</ExpandableTable.Row>
|
||||
</ExpandableTable.Root>
|
||||
</div>
|
||||
|
||||
<!-- Actions -->
|
||||
<div class="actions-container">
|
||||
{#if $organization?.billingPlan === BillingPlan.FREE || $organization?.billingPlan === BillingPlan.GITHUB_EDUCATION}
|
||||
<div
|
||||
class="u-flex u-flex-vertical-mobile u-cross-center u-gap-16 u-flex-wrap u-width-full-line u-main-end">
|
||||
<Button text href={`${base}/organization-${$organization?.$id}/usage`}>
|
||||
View estimated usage
|
||||
</Button>
|
||||
class="u-flex u-cross-center u-gap-8 u-flex-wrap u-width-full-line u-main-end actions-mobile">
|
||||
{#if !currentPlan?.usagePerProject}
|
||||
<Button text href={`${base}/organization-${$organization?.$id}/usage`}>
|
||||
View estimated usage
|
||||
</Button>
|
||||
{/if}
|
||||
<Button
|
||||
disabled={$organization?.markedForDeletion}
|
||||
href={$upgradeURL}
|
||||
@@ -188,7 +518,7 @@
|
||||
</div>
|
||||
{:else}
|
||||
<div
|
||||
class="u-flex u-flex-vertical-mobile u-cross-center u-gap-16 u-flex-wrap u-width-full-line u-main-end">
|
||||
class="u-flex u-cross-center u-gap-8 u-flex-wrap u-width-full-line u-main-end actions-mobile">
|
||||
{#if $organization?.billingPlanDowngrade !== null}
|
||||
<Button text on:click={() => (showCancel = true)}>Cancel change</Button>
|
||||
{:else}
|
||||
@@ -204,20 +534,24 @@
|
||||
Change plan
|
||||
</Button>
|
||||
{/if}
|
||||
<Button secondary href={`${base}/organization-${$organization?.$id}/usage`}>
|
||||
View estimated usage
|
||||
</Button>
|
||||
{#if !currentPlan?.usagePerProject}
|
||||
<Button secondary href={`${base}/organization-${$organization?.$id}/usage`}>
|
||||
View estimated usage
|
||||
</Button>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
</div>
|
||||
</EstimatedCard>
|
||||
{/if}
|
||||
|
||||
<CancelDowngradeModel bind:showCancel />
|
||||
|
||||
<style>
|
||||
:root {
|
||||
--billing-card-border-color: hsl(var(--color-neutral-10));
|
||||
.billing-cycle-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
:global(.card-only-on-desktop) {
|
||||
@@ -236,7 +570,159 @@
|
||||
border-block-start: solid 0.0625rem hsl(var(--p-toggle-border-color));
|
||||
}
|
||||
|
||||
/* indent child rows on tablet */
|
||||
:global(.child-row.is-tablet) {
|
||||
padding-left: 0.5rem;
|
||||
padding-right: 0.5rem;
|
||||
}
|
||||
|
||||
/* prevent wrapping on desktop; truncate on small/tablet */
|
||||
.cell-item-text {
|
||||
max-width: 100%;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
:global(.theme-dark) .cell-item-text,
|
||||
:global(.theme-light) .cell-item-text {
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* Small and tablet: allow truncation to avoid multi-line wrapping */
|
||||
@media (max-width: 1000px) {
|
||||
.cell-item-text {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
}
|
||||
|
||||
.usage-cell-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
padding-left: 1.5rem;
|
||||
gap: 0.75rem;
|
||||
width: 100%;
|
||||
min-height: 2rem;
|
||||
}
|
||||
|
||||
/* tablet tweaks */
|
||||
:global(.usage-cell-content.is-tablet) {
|
||||
padding-left: 1rem;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
/* mobile tweaks: compact inline layout with proper spacing */
|
||||
:global(.usage-cell-content.is-mobile) {
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding-left: 0;
|
||||
min-height: 2rem;
|
||||
flex-wrap: nowrap;
|
||||
}
|
||||
|
||||
.usage-text-section {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
padding-left: 1rem;
|
||||
flex: 1;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
:global(.usage-cell-content.is-mobile .usage-text-section),
|
||||
:global(.usage-cell-content.is-tablet .usage-text-section) {
|
||||
padding-left: 0;
|
||||
}
|
||||
|
||||
.usage-progress-section {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
width: 264px;
|
||||
}
|
||||
|
||||
:global(.usage-progress-section .progressbar__container) {
|
||||
margin-top: 0;
|
||||
width: 264px;
|
||||
max-width: 264px;
|
||||
/* Neutral background for unfilled track */
|
||||
--progressbar-background-color: var(--bgcolor-neutral-tertiary);
|
||||
}
|
||||
|
||||
/* smaller bars for tablet/mobile */
|
||||
:global(.usage-cell-content.is-tablet .usage-progress-section .progressbar__container) {
|
||||
width: 200px;
|
||||
max-width: 200px;
|
||||
}
|
||||
:global(.usage-cell-content.is-mobile .usage-progress-section .progressbar__container) {
|
||||
width: 120px;
|
||||
max-width: 120px;
|
||||
}
|
||||
|
||||
:global(.usage-cell-content.is-mobile .usage-progress-section) {
|
||||
width: 120px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* mobile table wrapper for horizontal scroll */
|
||||
.table-wrapper.is-mobile {
|
||||
overflow-x: auto;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
margin: 0 -1rem;
|
||||
padding: 0 1rem;
|
||||
}
|
||||
|
||||
/* reset mobile overrides - use desktop layout in scrollable container */
|
||||
.table-wrapper.is-mobile :global(.child-row) {
|
||||
grid-template-columns: var(--original-grid-template) !important;
|
||||
min-width: 600px; /* ensure minimum width for proper layout */
|
||||
}
|
||||
|
||||
.table-wrapper.is-mobile :global(.usage-cell-content) {
|
||||
flex-direction: row !important;
|
||||
align-items: center !important;
|
||||
gap: 0.75rem !important;
|
||||
padding-left: 1rem !important;
|
||||
min-height: 2rem !important;
|
||||
}
|
||||
|
||||
.table-wrapper.is-mobile :global(.usage-progress-section) {
|
||||
width: 200px !important;
|
||||
flex-shrink: 0 !important;
|
||||
}
|
||||
|
||||
.table-wrapper.is-mobile :global(.usage-progress-section .progressbar__container) {
|
||||
width: 200px !important;
|
||||
max-width: 200px !important;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.actions-mobile {
|
||||
justify-content: flex-start !important;
|
||||
gap: 8px !important;
|
||||
}
|
||||
|
||||
.actions-mobile :global(a),
|
||||
.actions-mobile :global(button) {
|
||||
padding: 6px 12px !important;
|
||||
font-size: 14px !important;
|
||||
border-radius: 8px !important;
|
||||
}
|
||||
.billing-cycle-header {
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
:global([data-expandable-row-id='additional-projects']),
|
||||
:global([data-expandable-row-id^='addon-']) {
|
||||
background-color: var(--bgcolor-neutral-tertiary);
|
||||
border-left: 3px solid var(--bgcolor-accent-neutral);
|
||||
}
|
||||
|
||||
:global(.card-only-on-desktop) {
|
||||
padding: 0.5rem;
|
||||
box-shadow: unset;
|
||||
|
||||
@@ -0,0 +1,254 @@
|
||||
<script lang="ts">
|
||||
import { base } from '$app/paths';
|
||||
import { CardGrid } from '$lib/components';
|
||||
import { Button } from '$lib/elements/forms';
|
||||
import { toLocaleDate } from '$lib/helpers/date';
|
||||
import { plansInfo, upgradeURL } from '$lib/stores/billing';
|
||||
import { organization } from '$lib/stores/organization';
|
||||
import type { Aggregation, Invoice, Plan } from '$lib/sdk/billing';
|
||||
import { abbreviateNumber, formatCurrency, formatNumberWithCommas } from '$lib/helpers/numbers';
|
||||
import { BillingPlan } from '$lib/constants';
|
||||
import { Click, trackEvent } from '$lib/actions/analytics';
|
||||
import {
|
||||
Accordion,
|
||||
Card,
|
||||
Divider,
|
||||
Icon,
|
||||
Layout,
|
||||
Tooltip,
|
||||
Typography
|
||||
} from '@appwrite.io/pink-svelte';
|
||||
import { IconInfo, IconTag } from '@appwrite.io/pink-icons-svelte';
|
||||
import CancelDowngradeModel from './cancelDowngradeModal.svelte';
|
||||
|
||||
export let currentPlan: Plan;
|
||||
export let currentInvoice: Invoice | undefined = undefined;
|
||||
export let availableCredit: number | undefined = undefined;
|
||||
export let currentAggregation: Aggregation | undefined = undefined;
|
||||
|
||||
let showCancel: boolean = false;
|
||||
|
||||
const today = new Date();
|
||||
const isTrial =
|
||||
new Date($organization?.billingStartDate).getTime() - today.getTime() > 0 &&
|
||||
$plansInfo.get($organization.billingPlan)?.trialDays;
|
||||
const extraUsage = currentInvoice ? currentInvoice.amount - currentPlan?.price : 0;
|
||||
</script>
|
||||
|
||||
{#if $organization}
|
||||
<CardGrid>
|
||||
<svelte:fragment slot="title">Payment estimates</svelte:fragment>
|
||||
A breakdown of your estimated upcoming payment for the current billing period. Totals displayed
|
||||
exclude accumulated credits and applicable taxes.
|
||||
<svelte:fragment slot="aside">
|
||||
<p class="text u-bold">
|
||||
Due at: {toLocaleDate($organization?.billingNextInvoiceDate)}
|
||||
</p>
|
||||
<Card.Base variant="secondary" padding="s">
|
||||
<Layout.Stack>
|
||||
<Layout.Stack direction="row" justifyContent="space-between">
|
||||
<Typography.Text color="--fgcolor-neutral-primary">
|
||||
{currentPlan.name} plan
|
||||
</Typography.Text>
|
||||
<Typography.Text>
|
||||
{isTrial || $organization?.billingPlan === BillingPlan.GITHUB_EDUCATION
|
||||
? formatCurrency(0)
|
||||
: currentPlan
|
||||
? formatCurrency(currentPlan?.price)
|
||||
: ''}
|
||||
</Typography.Text>
|
||||
</Layout.Stack>
|
||||
|
||||
{#if currentPlan.budgeting && extraUsage > 0}
|
||||
<Accordion
|
||||
hideDivider
|
||||
title="Add-ons"
|
||||
badge={(currentAggregation.additionalMembers > 0
|
||||
? currentInvoice.usage.length + 1
|
||||
: currentInvoice.usage.length
|
||||
).toString()}>
|
||||
<svelte:fragment slot="end">
|
||||
{formatCurrency(extraUsage >= 0 ? extraUsage : 0)}
|
||||
</svelte:fragment>
|
||||
<Layout.Stack gap="xs">
|
||||
{#if currentAggregation.additionalMembers}
|
||||
<Layout.Stack gap="xxxs">
|
||||
<Layout.Stack
|
||||
direction="row"
|
||||
justifyContent="space-between">
|
||||
<Typography.Text color="--fgcolor-neutral-primary"
|
||||
>Additional members</Typography.Text>
|
||||
<Typography.Text>
|
||||
{formatCurrency(
|
||||
currentAggregation.additionalMemberAmount
|
||||
)}
|
||||
</Typography.Text>
|
||||
</Layout.Stack>
|
||||
<Layout.Stack direction="row">
|
||||
<Typography.Text
|
||||
>{currentAggregation.additionalMembers}</Typography.Text>
|
||||
</Layout.Stack>
|
||||
</Layout.Stack>
|
||||
{/if}
|
||||
{#if currentInvoice?.usage}
|
||||
{#each currentInvoice.usage as excess, i}
|
||||
{#if i > 0 || currentAggregation.additionalMembers}
|
||||
<Divider />
|
||||
{/if}
|
||||
|
||||
<Layout.Stack gap="xxxs">
|
||||
<Layout.Stack
|
||||
direction="row"
|
||||
justifyContent="space-between">
|
||||
<Typography.Text color="--fgcolor-neutral-primary">
|
||||
{excess.name}
|
||||
</Typography.Text>
|
||||
<Typography.Text>
|
||||
{formatCurrency(excess.amount)}
|
||||
</Typography.Text>
|
||||
</Layout.Stack>
|
||||
<Layout.Stack direction="row">
|
||||
<Tooltip
|
||||
placement="bottom"
|
||||
disabled={excess.value <= 1000}>
|
||||
<svelte:fragment slot="tooltip">
|
||||
{formatNumberWithCommas(excess.value)}
|
||||
</svelte:fragment>
|
||||
<span>{abbreviateNumber(excess.value)}</span>
|
||||
</Tooltip>
|
||||
</Layout.Stack>
|
||||
</Layout.Stack>
|
||||
{/each}
|
||||
{/if}
|
||||
</Layout.Stack>
|
||||
</Accordion>
|
||||
{/if}
|
||||
|
||||
{#if currentPlan.supportsCredits && availableCredit > 0}
|
||||
<Layout.Stack direction="row" justifyContent="space-between">
|
||||
<Layout.Stack direction="row" alignItems="center" gap="xxs">
|
||||
<Icon size="s" icon={IconTag} color="--fgcolor-success" />
|
||||
<Typography.Text color="--fgcolor-neutral-primary"
|
||||
>Credits to be applied</Typography.Text>
|
||||
</Layout.Stack>
|
||||
<Typography.Text color="--fgcolor-success">
|
||||
-{formatCurrency(
|
||||
Math.min(availableCredit, currentInvoice?.amount ?? 0)
|
||||
)}
|
||||
</Typography.Text>
|
||||
</Layout.Stack>
|
||||
{/if}
|
||||
|
||||
{#if $organization?.billingPlan !== BillingPlan.FREE && $organization?.billingPlan !== BillingPlan.GITHUB_EDUCATION}
|
||||
<Divider />
|
||||
<Layout.Stack direction="row" justifyContent="space-between">
|
||||
<Typography.Text color="--fgcolor-neutral-primary" variant="m-500">
|
||||
<Layout.Stack direction="row" alignItems="center" gap="s">
|
||||
Current total (USD)
|
||||
<Tooltip>
|
||||
<Icon icon={IconInfo} />
|
||||
<svelte:fragment slot="tooltip">
|
||||
Estimates are updated daily and may differ from your
|
||||
final invoice.
|
||||
</svelte:fragment>
|
||||
</Tooltip>
|
||||
</Layout.Stack>
|
||||
</Typography.Text>
|
||||
<Typography.Text color="--fgcolor-neutral-primary" variant="m-500">
|
||||
{formatCurrency(
|
||||
Math.max(
|
||||
(currentInvoice?.amount ?? 0) -
|
||||
Math.min(availableCredit, currentInvoice?.amount ?? 0),
|
||||
0
|
||||
)
|
||||
)}
|
||||
</Typography.Text>
|
||||
</Layout.Stack>
|
||||
{/if}
|
||||
</Layout.Stack>
|
||||
</Card.Base>
|
||||
</svelte:fragment>
|
||||
<svelte:fragment slot="actions">
|
||||
{#if $organization?.billingPlan === BillingPlan.FREE || $organization?.billingPlan === BillingPlan.GITHUB_EDUCATION}
|
||||
<div
|
||||
class="u-flex u-flex-vertical-mobile u-cross-center u-gap-16 u-flex-wrap u-width-full-line u-main-end">
|
||||
{#if !currentPlan?.usagePerProject}
|
||||
<Button text href={`${base}/organization-${$organization?.$id}/usage`}>
|
||||
View estimated usage
|
||||
</Button>
|
||||
{/if}
|
||||
<Button
|
||||
disabled={$organization?.markedForDeletion}
|
||||
href={$upgradeURL}
|
||||
on:click={() =>
|
||||
trackEvent(Click.OrganizationClickUpgrade, {
|
||||
from: 'button',
|
||||
source: 'billing_tab'
|
||||
})}>
|
||||
Upgrade
|
||||
</Button>
|
||||
</div>
|
||||
{:else}
|
||||
<div
|
||||
class="u-flex u-flex-vertical-mobile u-cross-center u-gap-16 u-flex-wrap u-width-full-line u-main-end">
|
||||
{#if $organization?.billingPlanDowngrade !== null}
|
||||
<Button text on:click={() => (showCancel = true)}>Cancel change</Button>
|
||||
{:else}
|
||||
<Button
|
||||
text
|
||||
disabled={$organization?.markedForDeletion}
|
||||
href={$upgradeURL}
|
||||
on:click={() =>
|
||||
trackEvent('click_organization_plan_update', {
|
||||
from: 'button',
|
||||
source: 'billing_tab'
|
||||
})}>
|
||||
Change plan
|
||||
</Button>
|
||||
{/if}
|
||||
{#if !currentPlan?.usagePerProject}
|
||||
<Button secondary href={`${base}/organization-${$organization?.$id}/usage`}>
|
||||
View estimated usage
|
||||
</Button>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
{/if}
|
||||
|
||||
<CancelDowngradeModel bind:showCancel />
|
||||
|
||||
<style>
|
||||
:root {
|
||||
--billing-card-border-color: hsl(var(--color-neutral-10));
|
||||
}
|
||||
|
||||
:global(.card-only-on-desktop) {
|
||||
background: hsl(var(--color-neutral-5));
|
||||
border-radius: var(--corner-radius-medium, 8px);
|
||||
border: 1px solid var(--billing-card-border-color);
|
||||
}
|
||||
|
||||
:global(.theme-dark .card-only-on-desktop) {
|
||||
background: #2c2c2f;
|
||||
--billing-card-border-color: #424248;
|
||||
}
|
||||
|
||||
:global(.card-only-on-desktop .collapsible-item:only-of-type) {
|
||||
margin-block-start: 0.5rem;
|
||||
border-block-start: solid 0.0625rem hsl(var(--p-toggle-border-color));
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
:global(.card-only-on-desktop) {
|
||||
padding: 0.5rem;
|
||||
box-shadow: unset;
|
||||
border-radius: unset;
|
||||
|
||||
/* yes, these `!important`s are needed */
|
||||
border: unset !important;
|
||||
background: unset !important;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -17,9 +17,14 @@
|
||||
Appwrite services, update the budget limit.
|
||||
</svelte:fragment>
|
||||
<svelte:fragment slot="buttons">
|
||||
<Button href={`${base}/organization-${$organization.$id}/usage`} text fullWidthMobile>
|
||||
<span class="text">View usage</span>
|
||||
</Button>
|
||||
{#if !page.data.currentPlan?.usagePerProject}
|
||||
<Button
|
||||
href={`${base}/organization-${$organization.$id}/usage`}
|
||||
text
|
||||
fullWidthMobile>
|
||||
<span class="text">View usage</span>
|
||||
</Button>
|
||||
{/if}
|
||||
<Button secondary fullWidthMobile href={redirectUrl}>
|
||||
<span class="text">Update limit</span>
|
||||
</Button>
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
import { page } from '$app/state';
|
||||
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
|
||||
import { PlanComparisonBox, PlanSelection, SelectPaymentMethod } from '$lib/components/billing';
|
||||
import PlanExcess from '$lib/components/billing/planExcess.svelte';
|
||||
import ValidateCreditModal from '$lib/components/billing/validateCreditModal.svelte';
|
||||
import { BillingPlan, Dependencies, feedbackDowngradeOptions } from '$lib/constants';
|
||||
import { Button, Form, InputSelect, InputTags, InputTextarea } from '$lib/elements/forms';
|
||||
@@ -33,7 +32,11 @@
|
||||
import { onMount } from 'svelte';
|
||||
import { loadAvailableRegions } from '$routes/(console)/regions';
|
||||
import EstimatedTotalBox from '$lib/components/billing/estimatedTotalBox.svelte';
|
||||
import OrganizationUsageLimits from '$lib/components/organizationUsageLimits.svelte';
|
||||
import { Query } from '@appwrite.io/console';
|
||||
import type { OrganizationUsage } from '$lib/sdk/billing';
|
||||
import type { Models } from '@appwrite.io/console';
|
||||
import { toLocaleDate } from '$lib/helpers/date';
|
||||
|
||||
export let data;
|
||||
|
||||
@@ -43,6 +46,9 @@
|
||||
let previousPage: string = base;
|
||||
let showExitModal = false;
|
||||
let formComponent: Form;
|
||||
let usageLimitsComponent:
|
||||
| { validateOrAlert: () => boolean; getSelectedProjects: () => string[] }
|
||||
| undefined;
|
||||
let isSubmitting = writable(false);
|
||||
let collaborators: string[] =
|
||||
data?.members?.memberships
|
||||
@@ -55,6 +61,8 @@
|
||||
let showCreditModal = false;
|
||||
let feedbackDowngradeReason: string;
|
||||
let feedbackMessage: string;
|
||||
let orgUsage: OrganizationUsage;
|
||||
let allProjects: { projects: Models.Project[] } | undefined;
|
||||
|
||||
$: paymentMethods = null;
|
||||
|
||||
@@ -91,6 +99,21 @@
|
||||
|
||||
selectedPlan =
|
||||
$currentPlan?.$id === BillingPlan.SCALE ? BillingPlan.SCALE : BillingPlan.PRO;
|
||||
|
||||
try {
|
||||
orgUsage = await sdk.forConsole.billing.listUsage(data.organization.$id);
|
||||
} catch {
|
||||
orgUsage = undefined;
|
||||
}
|
||||
|
||||
try {
|
||||
allProjects = await sdk.forConsole.projects.list([
|
||||
Query.equal('teamId', data.organization.$id),
|
||||
Query.limit(1000)
|
||||
]);
|
||||
} catch {
|
||||
allProjects = { projects: [] };
|
||||
}
|
||||
});
|
||||
|
||||
async function loadPaymentMethods() {
|
||||
@@ -100,6 +123,16 @@
|
||||
|
||||
async function handleSubmit() {
|
||||
if (isDowngrade) {
|
||||
// If target plan has a non-zero project limit, ensure selection made
|
||||
const targetProjectsLimit = $plansInfo?.get(selectedPlan)?.projects ?? 0;
|
||||
const shouldShowProjectSelector =
|
||||
targetProjectsLimit > 0 && allProjects.projects.length > targetProjectsLimit;
|
||||
|
||||
if (shouldShowProjectSelector && usageLimitsComponent?.validateOrAlert) {
|
||||
const ok = usageLimitsComponent.validateOrAlert();
|
||||
if (!ok) return;
|
||||
}
|
||||
|
||||
await downgrade();
|
||||
} else if (isUpgrade) {
|
||||
await upgrade();
|
||||
@@ -136,6 +169,7 @@
|
||||
|
||||
async function downgrade() {
|
||||
try {
|
||||
// 1) update the plan first
|
||||
await sdk.forConsole.billing.updatePlan(
|
||||
data.organization.$id,
|
||||
selectedPlan,
|
||||
@@ -143,11 +177,26 @@
|
||||
null
|
||||
);
|
||||
|
||||
trackDowngradeFeedback();
|
||||
// 2) If the target plan has a project limit, apply selected projects now
|
||||
const targetProjectsLimit = $plansInfo?.get(selectedPlan)?.projects ?? 0;
|
||||
if (targetProjectsLimit > 0 && usageLimitsComponent) {
|
||||
const selected = usageLimitsComponent.getSelectedProjects();
|
||||
if (selected?.length) {
|
||||
try {
|
||||
await sdk.forConsole.billing.updateSelectedProjects(
|
||||
data.organization.$id,
|
||||
selected
|
||||
);
|
||||
} catch (projectError) {
|
||||
console.warn('Project selection failed after plan update:', projectError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await invalidate(Dependencies.ORGANIZATION);
|
||||
await Promise.all([trackDowngradeFeedback(), invalidate(Dependencies.ORGANIZATION)]);
|
||||
|
||||
await goto(previousPage);
|
||||
|
||||
addNotification({
|
||||
type: 'success',
|
||||
message: `${$organization.name} plan has been successfully updated.`
|
||||
@@ -299,24 +348,25 @@
|
||||
<Alert.Inline
|
||||
status="warning"
|
||||
title="You can only have one free organization per account">
|
||||
To downgrade this organization, first migrate or delete one of your
|
||||
existing paid organizations.
|
||||
<Button
|
||||
compact
|
||||
href="https://appwrite.io/docs/advanced/migrations/cloud"
|
||||
>Migration guide</Button>
|
||||
To downgrade this organization, first migrate or delete your existing
|
||||
free organization.
|
||||
<Layout.Stack gap="xs" direction="row" justifyContent="flex-start">
|
||||
<Button
|
||||
compact
|
||||
external
|
||||
href="https://appwrite.io/docs/advanced/migrations/cloud"
|
||||
>Migration guide</Button>
|
||||
</Layout.Stack>
|
||||
</Alert.Inline>
|
||||
{/if}
|
||||
|
||||
{#if isDowngrade}
|
||||
{#if selectedPlan === BillingPlan.FREE && !data.hasFreeOrgs}
|
||||
<PlanExcess tier={BillingPlan.FREE} />
|
||||
{:else if selectedPlan === BillingPlan.PRO && data.organization.billingPlan === BillingPlan.SCALE && collaborators?.length > 0}
|
||||
{@const extraMembers = collaborators?.length ?? 0}
|
||||
{@const price = formatCurrency(
|
||||
extraMembers *
|
||||
($plansInfo?.get(selectedPlan)?.addons?.seats?.price ?? 0)
|
||||
)}
|
||||
{@const extraMembers = collaborators?.length ?? 0}
|
||||
{@const price = formatCurrency(
|
||||
extraMembers *
|
||||
($plansInfo?.get(selectedPlan)?.addons?.seats?.price ?? 0)
|
||||
)}
|
||||
{#if selectedPlan === BillingPlan.PRO}
|
||||
<Alert.Inline status="error">
|
||||
<svelte:fragment slot="title">
|
||||
Your monthly payments will be adjusted for the Pro plan
|
||||
@@ -326,7 +376,26 @@
|
||||
>you will be charged {price} monthly for {extraMembers} team members.</b>
|
||||
This will be reflected in your next invoice.
|
||||
</Alert.Inline>
|
||||
{:else if selectedPlan === BillingPlan.FREE}
|
||||
<Alert.Inline
|
||||
status="error"
|
||||
title={`Your organization will switch to ${tierToPlan(selectedPlan).name} plan on ${toLocaleDate(
|
||||
$organization.billingNextInvoiceDate
|
||||
)}`}>
|
||||
You will retain access to {tierToPlan($organization.billingPlan)
|
||||
.name} plan features until your billing period ends. After that,
|
||||
<span class="u-bold"
|
||||
>all team members except the owner will be removed,</span>
|
||||
and service disruptions may occur if usage exceeds Free plan limits.
|
||||
</Alert.Inline>
|
||||
{/if}
|
||||
|
||||
<OrganizationUsageLimits
|
||||
bind:this={usageLimitsComponent}
|
||||
organization={data.organization}
|
||||
projects={allProjects?.projects || []}
|
||||
members={data.members?.memberships || []}
|
||||
storageUsage={orgUsage?.storageTotal ?? 0} />
|
||||
{/if}
|
||||
</Layout.Stack>
|
||||
</Fieldset>
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
import type { PageLoad } from './$types';
|
||||
import type { Organization } from '$lib/stores/organization';
|
||||
import { BillingPlan, Dependencies } from '$lib/constants';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
|
||||
export const load: PageLoad = async ({ depends, parent }) => {
|
||||
const { members, currentPlan, organizations } = await parent();
|
||||
depends(Dependencies.UPGRADE_PLAN);
|
||||
|
||||
let plans;
|
||||
try {
|
||||
plans = await sdk.forConsole.billing.listPlans();
|
||||
} catch (error) {
|
||||
console.error('Failed to load billing plans:', error);
|
||||
plans = { plans: {} };
|
||||
}
|
||||
|
||||
let plan: BillingPlan;
|
||||
|
||||
if (currentPlan?.$id === BillingPlan.SCALE) {
|
||||
@@ -22,6 +31,7 @@ export const load: PageLoad = async ({ depends, parent }) => {
|
||||
return {
|
||||
members,
|
||||
plan,
|
||||
plans,
|
||||
selfService,
|
||||
hasFreeOrgs
|
||||
};
|
||||
|
||||
@@ -84,8 +84,8 @@
|
||||
{/if}
|
||||
</Layout.Stack>
|
||||
<Typography.Text variant="m-400">
|
||||
Add the following nameservers on your DNS provider. Note that DNS changes may take
|
||||
time to propagate fully.
|
||||
Add the following nameservers on your DNS provider. Note that changes may take up to
|
||||
48 hours to propagate fully.
|
||||
</Typography.Text>
|
||||
</Layout.Stack>
|
||||
|
||||
|
||||
@@ -64,8 +64,8 @@
|
||||
>{selectedDomain.domain}</Typography.Text>
|
||||
</Layout.Stack>
|
||||
<Typography.Text variant="m-400">
|
||||
Add the following nameservers on your DNS provider. Note that DNS changes may take time
|
||||
to propagate fully.
|
||||
Add the following nameservers on your DNS provider. Note that changes may take up to 48
|
||||
hours to propagate fully.
|
||||
</Typography.Text>
|
||||
</Layout.Stack>
|
||||
|
||||
|
||||
@@ -66,7 +66,11 @@
|
||||
event: 'usage',
|
||||
title: 'Usage',
|
||||
hasChildren: true,
|
||||
disabled: !(isCloud && ($isOwner || $isBilling))
|
||||
disabled: !(
|
||||
isCloud &&
|
||||
($isOwner || $isBilling) &&
|
||||
!page.data.currentPlan?.usagePerProject
|
||||
)
|
||||
},
|
||||
{
|
||||
href: `${path}/billing`,
|
||||
|
||||
@@ -47,9 +47,7 @@
|
||||
// Calculate if button should be disabled and tooltip should show
|
||||
$: memberCount = data.organizationMembers?.total ?? 0;
|
||||
$: isFreeWithMembers = $organization?.billingPlan === BillingPlan.FREE && memberCount >= 1;
|
||||
$: isButtonDisabled = isCloud
|
||||
? isFreeWithMembers || !$currentPlan?.addons?.seats?.supported
|
||||
: false;
|
||||
$: isButtonDisabled = isCloud ? isFreeWithMembers : false;
|
||||
|
||||
const resend = async (member: Models.Membership) => {
|
||||
try {
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
getServiceLimit,
|
||||
showUsageRatesModal,
|
||||
type Tier,
|
||||
upgradeURL
|
||||
upgradeURL,
|
||||
useNewPricingModal
|
||||
} from '$lib/stores/billing';
|
||||
import { organization } from '$lib/stores/organization';
|
||||
import ProjectBreakdown from './ProjectBreakdown.svelte';
|
||||
@@ -76,14 +77,32 @@
|
||||
{#if $organization.billingPlan === BillingPlan.SCALE}
|
||||
<p class="text">
|
||||
On the Scale plan, you'll be charged only for any usage that exceeds the thresholds per
|
||||
resource listed below. <Link.Button on:click={() => ($showUsageRatesModal = true)}
|
||||
>Learn more</Link.Button>
|
||||
resource listed below.
|
||||
{#if $useNewPricingModal}
|
||||
<Link.Button on:click={() => ($showUsageRatesModal = true)}>Learn more</Link.Button>
|
||||
{:else}
|
||||
<Link.Anchor
|
||||
href="https://appwrite.io/pricing"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer">
|
||||
Learn more
|
||||
</Link.Anchor>
|
||||
{/if}
|
||||
</p>
|
||||
{:else if $organization.billingPlan === BillingPlan.PRO}
|
||||
<p class="text">
|
||||
On the Pro plan, you'll be charged only for any usage that exceeds the thresholds per
|
||||
resource listed below. <Link.Button on:click={() => ($showUsageRatesModal = true)}
|
||||
>Learn more</Link.Button>
|
||||
resource listed below.
|
||||
{#if $useNewPricingModal}
|
||||
<Link.Button on:click={() => ($showUsageRatesModal = true)}>Learn more</Link.Button>
|
||||
{:else}
|
||||
<Link.Anchor
|
||||
href="https://appwrite.io/pricing"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer">
|
||||
Learn more
|
||||
</Link.Anchor>
|
||||
{/if}
|
||||
</p>
|
||||
{:else if $organization.billingPlan === BillingPlan.FREE}
|
||||
<p class="text">
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
const databaseId = page.params.database;
|
||||
</script>
|
||||
|
||||
<Container paddingInlineEnd={false}>
|
||||
<Container databasesMainScreen>
|
||||
<Layout.Stack direction="row" justifyContent="space-between">
|
||||
<Layout.Stack direction="row" alignItems="center">
|
||||
<SearchQuery placeholder="Search by name or ID" />
|
||||
|
||||
@@ -177,7 +177,7 @@
|
||||
});
|
||||
</script>
|
||||
|
||||
<Container size="xxl">
|
||||
<Container size="xxl" databasesMainScreen>
|
||||
<div class="u-flex u-gap-32 u-flex-vertical-mobile">
|
||||
{#if !isDisabled}
|
||||
<div class="u-flex-vertical u-gap-16 policies-holder-card">
|
||||
|
||||
@@ -38,11 +38,14 @@
|
||||
].filter((tab) => !tab.disabled);
|
||||
</script>
|
||||
|
||||
<Cover expanded>
|
||||
<Cover databasesMainScreen>
|
||||
<svelte:fragment slot="header">
|
||||
<CoverTitle href={`${base}/project-${page.params.region}-${projectId}/databases`}>
|
||||
<CoverTitle
|
||||
style="margin-inline-start: -2.5rem;"
|
||||
href={`${base}/project-${page.params.region}-${projectId}/databases`}>
|
||||
{$database.name}
|
||||
</CoverTitle>
|
||||
|
||||
<Id value={$database.$id}>{$database.$id}</Id>
|
||||
</svelte:fragment>
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@
|
||||
</script>
|
||||
|
||||
{#if $database}
|
||||
<Container>
|
||||
<Container databasesMainScreen>
|
||||
<CardGrid>
|
||||
<svelte:fragment slot="title">{$database.name}</svelte:fragment>
|
||||
<svelte:fragment slot="aside">
|
||||
|
||||
@@ -2,6 +2,7 @@ import { page } from '$app/stores';
|
||||
import type { Column } from '$lib/helpers/types';
|
||||
import type { Models } from '@appwrite.io/console';
|
||||
import { derived, writable } from 'svelte/store';
|
||||
import { IconChartBar, IconCloudUpload, IconCog } from '@appwrite.io/pink-icons-svelte';
|
||||
|
||||
export const database = derived(page, ($page) => $page.data.database as Models.Database);
|
||||
export const showCreate = writable(false);
|
||||
@@ -29,3 +30,9 @@ export const customRetainingOptions = [
|
||||
{ label: 'Weeks', value: 7, max: 4 },
|
||||
{ label: 'Months', value: 30, max: 12 }
|
||||
];
|
||||
|
||||
export const databaseSubNavigationItems = [
|
||||
{ title: 'Backups', href: 'backups', icon: IconCloudUpload },
|
||||
{ title: 'Usage', href: 'usage', icon: IconChartBar },
|
||||
{ title: 'Settings', href: 'settings', icon: IconCog }
|
||||
];
|
||||
@@ -1,10 +1,18 @@
|
||||
<script lang="ts">
|
||||
import { base } from '$app/paths';
|
||||
import { page } from '$app/state';
|
||||
import { showCreate } from './store';
|
||||
import { showCreate, databaseSubNavigationItems } from './store';
|
||||
import type { PageData } from './$types';
|
||||
import { showSubNavigation } from '$lib/stores/layout';
|
||||
import { Icon, Sidebar, Navbar, Layout, Link, Typography } from '@appwrite.io/pink-svelte';
|
||||
import {
|
||||
Icon,
|
||||
Sidebar,
|
||||
Navbar,
|
||||
Layout,
|
||||
Link,
|
||||
Typography,
|
||||
Divider
|
||||
} from '@appwrite.io/pink-svelte';
|
||||
import {
|
||||
IconChevronDown,
|
||||
IconDatabase,
|
||||
@@ -41,6 +49,10 @@
|
||||
sortedTables?.find((table: Models.Table) => table.$id === tableId)
|
||||
);
|
||||
|
||||
const isTablesScreen = $derived(page.route.id.endsWith('table-[table]'));
|
||||
|
||||
const isMainDatabaseScreen = $derived(page.route.id.endsWith('database-[database]'));
|
||||
|
||||
async function loadTables() {
|
||||
tables = await sdk.forProject(region, project).tablesDB.listTables({
|
||||
databaseId: databaseId,
|
||||
@@ -66,12 +78,14 @@
|
||||
<Sidebar.Base state="open" resizable={false}>
|
||||
<section class="list-container" slot="top" style:width="100%">
|
||||
<a
|
||||
class:is-selected={!isTablesScreen}
|
||||
href={`${base}/project-${region}-${project}/databases/database-${databaseId}`}
|
||||
class="database-name u-flex u-cross-center body-text-2 u-gap-8 is-not-mobile is-selected">
|
||||
class="database-name u-flex u-cross-center body-text-2 u-gap-8 is-not-mobile u-padding-block-8 u-padding-inline-start-4">
|
||||
<Icon icon={IconDatabase} size="s" color="--fgcolor-neutral-weak" />
|
||||
|
||||
{data.database?.name}
|
||||
</a>
|
||||
<div class="collection-content">
|
||||
<div class="table-content">
|
||||
{#if tables?.total}
|
||||
<ul class="drop-list u-margin-inline-start-8 u-margin-block-start-4">
|
||||
{#each sortedTables as table, index}
|
||||
@@ -94,7 +108,7 @@
|
||||
color={isSelected
|
||||
? '--fgcolor-neutral-tertiary'
|
||||
: '--fgcolor-neutral-weak'} />
|
||||
<span class="text collection-name" data-private
|
||||
<span class="text table-name" data-private
|
||||
>{table.name}</span>
|
||||
</a>
|
||||
</li>
|
||||
@@ -132,9 +146,37 @@
|
||||
</Button>
|
||||
</Layout.Stack>
|
||||
</div>
|
||||
|
||||
<Layout.Stack direction="column" gap="xxs" style="bottom: 1rem; position: sticky;">
|
||||
<div class="action-menu-divider">
|
||||
<Divider />
|
||||
</div>
|
||||
|
||||
<ul
|
||||
style="margin-inline-start: -1.25rem"
|
||||
class="drop-list bottom-nav u-margin-block-start-4">
|
||||
{#each databaseSubNavigationItems as action}
|
||||
{@const href = `${base}/project-${region}-${project}/databases/database-${databaseId}/${action.href}`}
|
||||
|
||||
<Layout.Stack gap="s" direction="row" alignItems="center">
|
||||
<li>
|
||||
<a
|
||||
{href}
|
||||
class="u-padding-block-8 u-padding-inline-end-4 u-padding-inline-start-8 u-flex u-cross-center u-gap-8">
|
||||
<Icon
|
||||
size="s"
|
||||
icon={action.icon}
|
||||
color="--fgcolor-neutral-weak" />
|
||||
<span class="text table-name">{action.title}</span>
|
||||
</a>
|
||||
</li>
|
||||
</Layout.Stack>
|
||||
{/each}
|
||||
</ul>
|
||||
</Layout.Stack>
|
||||
</section>
|
||||
</Sidebar.Base>
|
||||
{:else}
|
||||
{:else if data?.database?.name && !isMainDatabaseScreen}
|
||||
<Navbar.Base>
|
||||
<div slot="left">
|
||||
<Layout.Stack direction="row" alignItems="center" gap="s">
|
||||
@@ -194,12 +236,18 @@
|
||||
}
|
||||
|
||||
.database-name {
|
||||
margin-block-end: 8px;
|
||||
margin-block-end: 4px;
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--fgcolor-neutral-secondary);
|
||||
|
||||
&:hover {
|
||||
color: var(--fgcolor-neutral-primary);
|
||||
border-radius: var(--border-radius-s, 6px);
|
||||
background: var(--bgcolor-neutral-secondary);
|
||||
}
|
||||
}
|
||||
|
||||
.collection-content {
|
||||
.table-content {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
@@ -232,13 +280,13 @@
|
||||
|
||||
.drop-list {
|
||||
flex: 1;
|
||||
gap: 8px;
|
||||
gap: 4px;
|
||||
padding-left: 4px;
|
||||
position: relative;
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--fgcolor-neutral-secondary);
|
||||
|
||||
&::before {
|
||||
&:not(.bottom-nav)::before {
|
||||
content: '';
|
||||
right: 99%;
|
||||
top: 0.2rem;
|
||||
@@ -248,37 +296,36 @@
|
||||
}
|
||||
|
||||
// first item
|
||||
&:has(li.is-first)::before {
|
||||
&:not(.bottom-nav):has(li.is-first)::before {
|
||||
top: 0.8rem;
|
||||
}
|
||||
|
||||
// last item
|
||||
&:has(li.is-last)::before {
|
||||
&:not(.bottom-nav):has(li.is-last)::before {
|
||||
bottom: 0.85rem;
|
||||
}
|
||||
|
||||
// the only item
|
||||
&:has(li.is-first.is-last)::before {
|
||||
&:not(.bottom-nav):has(li.is-first.is-last)::before {
|
||||
top: 0.6rem;
|
||||
bottom: 0.6rem;
|
||||
}
|
||||
|
||||
li {
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
padding-inline-end: 0.5rem;
|
||||
margin-inline-start: 0.5rem;
|
||||
}
|
||||
|
||||
.is-selected,
|
||||
li:hover {
|
||||
width: 100%;
|
||||
color: var(--fgcolor-neutral-primary);
|
||||
border-radius: var(--border-radius-xs, 4px);
|
||||
border-radius: var(--border-radius-s, 6px);
|
||||
background: var(--bgcolor-neutral-secondary);
|
||||
}
|
||||
|
||||
.collection-name {
|
||||
.table-name {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
@@ -287,6 +334,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
.is-selected {
|
||||
color: var(--fgcolor-neutral-primary);
|
||||
border-radius: var(--border-radius-s, 6px);
|
||||
background: var(--bgcolor-neutral-secondary);
|
||||
}
|
||||
|
||||
:global(.sub-navigation header) {
|
||||
top: 48px !important;
|
||||
}
|
||||
@@ -310,4 +363,9 @@
|
||||
font-weight: 400;
|
||||
line-height: 150%; /* 21px */
|
||||
}
|
||||
|
||||
.action-menu-divider {
|
||||
margin-inline: -1.2rem;
|
||||
padding-block-end: 0.25rem;
|
||||
}
|
||||
</style>
|
||||
@@ -60,7 +60,7 @@
|
||||
import CreateIndex from './indexes/createIndex.svelte';
|
||||
import { hash } from '$lib/helpers/string';
|
||||
import { preferences } from '$lib/stores/preferences';
|
||||
import { isRelationship } from './rows/store';
|
||||
import { buildRowUrl, isRelationship } from './rows/store';
|
||||
import { chunks } from '$lib/helpers/array';
|
||||
|
||||
let editRow: EditRow;
|
||||
@@ -252,8 +252,9 @@
|
||||
|
||||
let columns = $table.columns;
|
||||
const hasAnyRelationships = columns.some((column) => isRelationship(column));
|
||||
const filteredColumns = columns.filter((col) => col.type !== 'relationship');
|
||||
|
||||
if (!columns.length) {
|
||||
if (!filteredColumns.length) {
|
||||
try {
|
||||
columns = await generateColumns($project, page.params.database, page.params.table);
|
||||
|
||||
@@ -382,6 +383,12 @@
|
||||
text: 'Update',
|
||||
disabled: editRow?.isDisabled(),
|
||||
onClick: async () => await editRow?.update()
|
||||
}}
|
||||
topAction={{
|
||||
mode: 'copy-tag',
|
||||
text: 'Row URL',
|
||||
show: !!($databaseRowSheetOptions.rowId ?? $databaseRowSheetOptions.row?.$id),
|
||||
value: buildRowUrl($databaseRowSheetOptions.rowId ?? $databaseRowSheetOptions.row?.$id)
|
||||
}}>
|
||||
<EditRow
|
||||
bind:this={editRow}
|
||||
|
||||
@@ -51,12 +51,25 @@
|
||||
}));
|
||||
}
|
||||
|
||||
function createFilterableColumns(columns: Column[], selected: string[] = []): Column[] {
|
||||
const idColumn = [{ id: '$id', title: '$id', type: 'string' as ColumnType }].filter(
|
||||
(col) => !selected.includes(col.id)
|
||||
);
|
||||
|
||||
const systemColumns = [
|
||||
{ id: '$createdAt', title: '$createdAt', type: 'datetime' as ColumnType },
|
||||
{ id: '$updatedAt', title: '$updatedAt', type: 'datetime' as ColumnType }
|
||||
].filter((col) => !!selected.includes(col.id));
|
||||
|
||||
return [...idColumn, ...columns.filter((column) => !column.isAction), ...systemColumns];
|
||||
}
|
||||
|
||||
$: selected = preferences.getCustomTableColumns(page.params.table);
|
||||
|
||||
$: if ($table.columns) {
|
||||
const freshColumns = createTableColumns($table.columns, selected);
|
||||
tableColumns.set(freshColumns);
|
||||
filterColumns.set(freshColumns.filter((column) => !column.isAction));
|
||||
filterColumns.set(createFilterableColumns(freshColumns, selected));
|
||||
}
|
||||
|
||||
$: hasColumns = !!$table.columns.length;
|
||||
|
||||
@@ -30,6 +30,7 @@ export const load: PageLoad = async ({ params, depends, url, route, parent }) =>
|
||||
view,
|
||||
query,
|
||||
currentSort,
|
||||
parsedQueries,
|
||||
rows: await sdk.forProject(params.region, params.project).tablesDB.listRows({
|
||||
databaseId: params.database,
|
||||
tableId: params.table,
|
||||
|
||||
@@ -71,7 +71,7 @@
|
||||
key: '$createdAt',
|
||||
type: 'datetime',
|
||||
required: true,
|
||||
name: 'createdAt',
|
||||
name: '$createdAt',
|
||||
selectable: false,
|
||||
system: true
|
||||
} as Models.ColumnDatetime & {
|
||||
@@ -83,7 +83,7 @@
|
||||
key: '$updatedAt',
|
||||
type: 'datetime',
|
||||
required: true,
|
||||
name: 'updatedAt',
|
||||
name: '$updatedAt',
|
||||
selectable: false,
|
||||
system: true
|
||||
} as Models.ColumnDatetime & {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { invalidate } from '$app/navigation';
|
||||
import { page } from '$app/state';
|
||||
import { InputChoice } from '$lib/elements/forms';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { table } from '../store';
|
||||
import type { Columns } from '../store';
|
||||
@@ -21,7 +20,6 @@
|
||||
selectedColumn: Columns | string[];
|
||||
} = $props();
|
||||
|
||||
let checked = $state(false);
|
||||
let error = $state<string | null>(null);
|
||||
|
||||
const selectedColumns = $derived(
|
||||
@@ -38,8 +36,6 @@
|
||||
.some((col) => isRelationship(col) && col.twoWay)
|
||||
);
|
||||
|
||||
const isDeleteBtnDisabled = $derived(requiresTwoWayConfirm && !checked);
|
||||
|
||||
async function handleDelete() {
|
||||
try {
|
||||
const client = sdk.forProject(page.params.region, page.params.project);
|
||||
@@ -75,6 +71,16 @@
|
||||
function getAsRelationship(column: string | Columns): Models.ColumnRelationship {
|
||||
return column as Models.ColumnRelationship;
|
||||
}
|
||||
|
||||
const relatedColumn = $derived(
|
||||
requiresTwoWayConfirm ? getAsRelationship(selectedColumns[0]) : undefined
|
||||
);
|
||||
|
||||
const confirmDeletionLabel = $derived(
|
||||
!requiresTwoWayConfirm
|
||||
? 'I understand and confirm'
|
||||
: `Delete relationship between ${relatedColumn.key} to ${relatedColumn.twoWayKey}`
|
||||
);
|
||||
</script>
|
||||
|
||||
<Confirm
|
||||
@@ -83,7 +89,7 @@
|
||||
title="Delete column"
|
||||
bind:error
|
||||
confirmDeletion
|
||||
disabled={isDeleteBtnDisabled}>
|
||||
{confirmDeletionLabel}>
|
||||
{#if selectedColumns.length === 1}
|
||||
<p>
|
||||
Are you sure you want to delete <b data-private>{selectedKeys[0]}</b> from
|
||||
@@ -98,19 +104,12 @@
|
||||
|
||||
{#if requiresTwoWayConfirm}
|
||||
<!-- not allowed on multi selections, safe to assume that this isn't a string! -->
|
||||
{@const column = getAsRelationship(selectedColumns[0])}
|
||||
<Layout.Stack direction="column" gap="xl">
|
||||
<p>
|
||||
This is a two way relationship and the corresponding relationship will also be
|
||||
deleted.
|
||||
</p>
|
||||
<p><b>This action is irreversible.</b></p>
|
||||
<ul>
|
||||
<InputChoice id="delete" label="Delete" showLabel={false} bind:value={checked}>
|
||||
Delete relationship between <b data-private>{column.key}</b> to
|
||||
<b data-private>{column.twoWayKey}</b>
|
||||
</InputChoice>
|
||||
</ul>
|
||||
</Layout.Stack>
|
||||
{/if}
|
||||
</Confirm>
|
||||
@@ -19,6 +19,8 @@
|
||||
expandTabs
|
||||
} from '../store';
|
||||
import SpreadsheetContainer from './spreadsheet.svelte';
|
||||
import { onDestroy, onMount } from 'svelte';
|
||||
import { debounce } from '$lib/helpers/debounce';
|
||||
|
||||
type Mode = 'rows' | 'rows-filtered' | 'indexes';
|
||||
|
||||
@@ -47,7 +49,9 @@
|
||||
|
||||
let spreadsheetContainer: HTMLElement;
|
||||
let headerElement: HTMLElement | null = null;
|
||||
let dynamicOverlayHeight = $state('70.5vh');
|
||||
|
||||
let resizeObserver: ResizeObserver;
|
||||
let dynamicOverlayHeight = $state('60.5vh');
|
||||
|
||||
const baseColProps = { draggable: false, resizable: false };
|
||||
|
||||
@@ -70,7 +74,21 @@
|
||||
}
|
||||
};
|
||||
|
||||
updateOverlayHeight();
|
||||
// the first render is in a pretty quick succession, delay helps!
|
||||
const debouncedUpdateOverlayHeight = debounce(() => updateOverlayHeight(), 250);
|
||||
|
||||
onMount(async () => {
|
||||
if (spreadsheetContainer) {
|
||||
resizeObserver = new ResizeObserver(debouncedUpdateOverlayHeight);
|
||||
resizeObserver.observe(spreadsheetContainer);
|
||||
}
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
if (resizeObserver) {
|
||||
resizeObserver.disconnect();
|
||||
}
|
||||
});
|
||||
|
||||
const getCustomColumns = (): Column[] =>
|
||||
customColumns.map((col: Column) => ({
|
||||
@@ -141,8 +159,6 @@
|
||||
const emptyCells = $derived(($isSmallViewport ? 14 : 17) + (!$expandTabs ? 2 : 0));
|
||||
</script>
|
||||
|
||||
<svelte:window on:resize={updateOverlayHeight} />
|
||||
|
||||
<div
|
||||
class="databases-spreadsheet spreadsheet-container-outer"
|
||||
data-mode={mode}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<script lang="ts">
|
||||
import type { Snippet } from 'svelte';
|
||||
import { Button, Form } from '$lib/elements/forms';
|
||||
import { Badge, Divider, Layout, Sheet, Typography } from '@appwrite.io/pink-svelte';
|
||||
import { Badge, Divider, Layout, Sheet, Tag, Typography } from '@appwrite.io/pink-svelte';
|
||||
import { Copy } from '$lib/components';
|
||||
|
||||
let {
|
||||
show = $bindable(false),
|
||||
@@ -10,12 +11,22 @@
|
||||
submit,
|
||||
children = null,
|
||||
footer = null,
|
||||
titleBadge = null
|
||||
titleBadge = null,
|
||||
topAction = null
|
||||
}: {
|
||||
show: boolean;
|
||||
title: string;
|
||||
titleBadge?: string;
|
||||
closeOnBlur?: boolean;
|
||||
topAction?:
|
||||
| {
|
||||
text: string;
|
||||
value: string;
|
||||
show?: boolean;
|
||||
mode?: 'copy-tag' | 'plaintext';
|
||||
onClick?: () => string | Promise<string>;
|
||||
}
|
||||
| undefined;
|
||||
submit?:
|
||||
| {
|
||||
text: string;
|
||||
@@ -26,6 +37,8 @@
|
||||
children?: Snippet;
|
||||
footer?: Snippet | null;
|
||||
} = $props();
|
||||
|
||||
let copyText = $state(undefined);
|
||||
</script>
|
||||
|
||||
<div class="sheet-container">
|
||||
@@ -37,6 +50,24 @@
|
||||
{#if titleBadge}
|
||||
<Badge variant="secondary" content={titleBadge} size="s" />
|
||||
{/if}
|
||||
|
||||
{#if topAction && topAction.text && topAction.show}
|
||||
{#if topAction.mode === 'copy-tag'}
|
||||
<Copy value={topAction.value} {copyText}>
|
||||
<Tag size="xs" variant="code">
|
||||
{topAction.text}
|
||||
</Tag>
|
||||
</Copy>
|
||||
{:else}
|
||||
<Button
|
||||
extraCompact
|
||||
text
|
||||
size="xs"
|
||||
on:click={topAction.onClick ?? undefined}>
|
||||
{topAction.text}
|
||||
</Button>
|
||||
{/if}
|
||||
{/if}
|
||||
</Layout.Stack>
|
||||
</Layout.Stack>
|
||||
</div>
|
||||
|
||||
@@ -10,11 +10,13 @@
|
||||
row = $bindable(null),
|
||||
onChange = null,
|
||||
onRevert = null,
|
||||
noInlineEdit = false,
|
||||
openSideSheet = null,
|
||||
onRowStructureUpdate = null
|
||||
}: {
|
||||
row: Models.Row;
|
||||
column: Columns;
|
||||
noInlineEdit?: boolean;
|
||||
openSideSheet?: () => void;
|
||||
onChange?: (row: Models.DefaultRow) => void;
|
||||
onRevert?: (row: Models.DefaultRow) => void;
|
||||
@@ -27,6 +29,11 @@
|
||||
onMount(() => {
|
||||
original = structuredClone(row);
|
||||
|
||||
if (noInlineEdit) {
|
||||
openSideSheet?.();
|
||||
return;
|
||||
}
|
||||
|
||||
const trigger = wrapperEl.querySelector('button.input') as HTMLButtonElement;
|
||||
if (trigger) {
|
||||
trigger.click();
|
||||
@@ -62,5 +69,5 @@
|
||||
fromSpreadsheet
|
||||
label={undefined}
|
||||
bind:formValues={row}
|
||||
on:click={openSideSheet} />
|
||||
on:click={() => openSideSheet?.()} />
|
||||
</div>
|
||||
@@ -14,39 +14,19 @@
|
||||
optionalText = undefined;
|
||||
}
|
||||
|
||||
const onChange = (event: CustomEvent) => {
|
||||
if (limited) {
|
||||
value = event.detail as boolean;
|
||||
}
|
||||
};
|
||||
$: options = [
|
||||
!column.required && { label: 'NULL', value: null },
|
||||
{ label: limited ? 'true' : 'True', value: true },
|
||||
{ label: limited ? 'false' : 'False', value: false }
|
||||
].filter(Boolean);
|
||||
</script>
|
||||
|
||||
{#if limited}
|
||||
<InputSelect
|
||||
{id}
|
||||
{label}
|
||||
{value}
|
||||
{optionalText}
|
||||
autofocus={limited}
|
||||
placeholder="Select a value"
|
||||
required={column.required}
|
||||
options={[
|
||||
{ label: 'True', value: true },
|
||||
{ label: 'False', value: false }
|
||||
].filter(Boolean)}
|
||||
on:change={onChange} />
|
||||
{:else}
|
||||
<InputSelect
|
||||
{id}
|
||||
{label}
|
||||
bind:value
|
||||
{optionalText}
|
||||
autofocus={limited}
|
||||
placeholder="Select a value"
|
||||
required={column.required}
|
||||
options={[
|
||||
!column.required && { label: 'NULL', value: null },
|
||||
{ label: 'True', value: true },
|
||||
{ label: 'False', value: false }
|
||||
].filter(Boolean)} />
|
||||
{/if}
|
||||
<InputSelect
|
||||
{id}
|
||||
{label}
|
||||
bind:value
|
||||
{options}
|
||||
{optionalText}
|
||||
autofocus={limited}
|
||||
placeholder="Select a value"
|
||||
required={column.required} />
|
||||
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { InputNumber } from '$lib/elements/forms';
|
||||
import type { Models } from '@appwrite.io/console';
|
||||
import { isWithinSafeRange } from '$lib/helpers/numbers';
|
||||
|
||||
export let id: string;
|
||||
export let label: string;
|
||||
@@ -13,6 +14,11 @@
|
||||
$: if (limited) {
|
||||
label = undefined;
|
||||
}
|
||||
|
||||
$: {
|
||||
column.min = isWithinSafeRange(column.min) ? column.min : Number.MIN_SAFE_INTEGER;
|
||||
column.max = isWithinSafeRange(column.max) ? column.max : Number.MAX_SAFE_INTEGER;
|
||||
}
|
||||
</script>
|
||||
|
||||
<InputNumber
|
||||
|
||||
@@ -122,8 +122,7 @@
|
||||
function generateOptions(
|
||||
loading: boolean,
|
||||
rows: Models.Row[] | undefined,
|
||||
column: Models.ColumnRelationship,
|
||||
editing: boolean
|
||||
column: Models.ColumnRelationship
|
||||
): SelectOption[] {
|
||||
if (loading) {
|
||||
return [{ label: 'Loading...', value: null, disabled: true }];
|
||||
@@ -139,15 +138,11 @@
|
||||
.map((name) => row?.[name])
|
||||
.filter((value) => value != null && typeof value === 'string' && value !== '');
|
||||
|
||||
const displayValues = !editing
|
||||
? values
|
||||
: values.map((value) => (value.length > 5 ? value.slice(0, 5) + '...' : value));
|
||||
|
||||
let label: string;
|
||||
if (!values.length) {
|
||||
label = row.$id;
|
||||
} else {
|
||||
label = `${row.$id} (${displayValues.join(' | ')})`;
|
||||
label = `${values.join(' | ')} (...${row.$id.slice(-5)})`;
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -183,7 +178,7 @@
|
||||
|
||||
$: totalCount = relatedList?.length ?? 0;
|
||||
|
||||
$: options = generateOptions(loadingRelationships, rowList?.rows, column, editing);
|
||||
$: options = generateOptions(loadingRelationships, rowList?.rows, column);
|
||||
|
||||
$: hasItems = totalCount > 0;
|
||||
|
||||
|
||||
@@ -168,7 +168,7 @@
|
||||
</div>
|
||||
{:else if $table.columns?.length && work}
|
||||
<div bind:this={columnFormWrapper}>
|
||||
<Layout.Stack direction="column" gap="l">
|
||||
<Layout.Stack direction="column" gap="xl">
|
||||
{#each $table.columns as column}
|
||||
{@const label = column.key}
|
||||
<ColumnItem
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
import { page } from '$app/state';
|
||||
import type { Columns } from '../store';
|
||||
import { type Models, Query } from '@appwrite.io/console';
|
||||
|
||||
export function isRelationshipToMany(column: Models.ColumnRelationship) {
|
||||
if (!column) return false;
|
||||
export function isRelationshipToMany(col: Columns) {
|
||||
if (!col) return false;
|
||||
if (!isRelationship(col)) return false;
|
||||
|
||||
const column = col as Models.ColumnRelationship;
|
||||
|
||||
if (!column?.relationType) return false;
|
||||
if (column?.side === 'child') {
|
||||
return !['oneToOne', 'oneToMany'].includes(column?.relationType);
|
||||
@@ -43,3 +48,7 @@ export function buildWildcardColumnsQuery(table: Models.Table | null = null): st
|
||||
Query.select(['*'])
|
||||
];
|
||||
}
|
||||
|
||||
export function buildRowUrl(rowId: string) {
|
||||
return `${page.url}/row-${rowId}`;
|
||||
}
|
||||