diff --git a/src/lib/commandCenter/panels/ai.svelte b/src/lib/commandCenter/panels/ai.svelte index e44d0e28e..58407c678 100644 --- a/src/lib/commandCenter/panels/ai.svelte +++ b/src/lib/commandCenter/panels/ai.svelte @@ -148,7 +148,12 @@ })} clearOnCallback={false} on:keydown={(e) => { - if (e.detail.key !== 'Escape') { + const showingExamples = !$isLoading && !answer; + if (e.detail.key === 'Enter' && $input.trim()) { + e.detail.cancel(); + return; + } + if (e.detail.key !== 'Escape' && !showingExamples) { e.detail.cancel(); } }} @@ -302,15 +307,27 @@ } } - :global(.answer ul), - :global(.answer ol) { - gap: 1rem; + :global(.answer ul) { + padding-inline-start: 1rem; + list-style-type: disc; display: grid; + gap: 1rem; + } + + :global(.answer ol) { + padding-inline-start: 1.1rem; + list-style-type: decimal; + display: grid; + gap: 1rem; } :global(.answer a) { text-decoration: underline; } + + :global(.answer a:hover) { + opacity: 0.8; + } } .experimental { diff --git a/src/lib/components/bottomModalAlert.svelte b/src/lib/components/bottomModalAlert.svelte index 406b40222..1c0f24a9f 100644 --- a/src/lib/components/bottomModalAlert.svelte +++ b/src/lib/components/bottomModalAlert.svelte @@ -3,7 +3,6 @@ import { hideNotification, shouldShowNotification } from '$lib/helpers/notifications'; import { app } from '$lib/stores/app'; import { - type BottomModalAlertAction, type BottomModalAlertItem, bottomModalAlertsConfig, dismissBottomModalAlert, @@ -20,18 +19,18 @@ import { goto } from '$app/navigation'; import { Typography } from '@appwrite.io/pink-svelte'; - let currentIndex = 0; - let openModalOnMobile = false; + let currentIndex = $state(0); + let openModalOnMobile = $state(false); - function getPageScope(pathname: string) { - const isProjectPage = pathname.includes('project-[region]-[project]'); - const isOrganizationPage = pathname.includes('organization-[organization]'); + function getPageScope(route: string) { + const isProjectPage = route.includes('project-[region]-[project]'); + const isOrganizationPage = route.includes('organization-[organization]'); return { isProjectPage, isOrganizationPage }; } - function filterModalAlerts(alerts: BottomModalAlertItem[], pathname: string) { - const { isProjectPage, isOrganizationPage } = getPageScope(pathname); + function filterModalAlerts(alerts: BottomModalAlertItem[], route: string) { + const { isProjectPage, isOrganizationPage } = getPageScope(route); return alerts .sort((a, b) => b.importance - a.importance) @@ -51,19 +50,32 @@ }); } - $: filteredModalAlerts = filterModalAlerts($bottomModalAlertsConfig.alerts, page.route.id); + const bottomModalAlerts = $derived($bottomModalAlertsConfig.alerts); - $: currentModalAlert = filteredModalAlerts[currentIndex] as BottomModalAlertItem; + const filteredModalAlerts = $derived(filterModalAlerts(bottomModalAlerts, page.route.id)); - $: hasOnlyPrimaryCta = typeof currentModalAlert?.learnMore === 'undefined'; + const currentModalAlert = $derived(filteredModalAlerts[currentIndex] as BottomModalAlertItem); - function handleClose() { - filteredModalAlerts.forEach((alert) => { + const hasOnlyPrimaryCta = $derived(typeof currentModalAlert?.learnMore === 'undefined'); + + const isOnOnboarding = $derived(page.route.id.includes('(console)/onboarding')); + + function handleClose(id: string | null = null) { + const alerts = !id + ? filteredModalAlerts + : filteredModalAlerts.filter((alert) => alert.id === id); + + alerts.forEach((alert) => { const modalAlert = alert; dismissBottomModalAlert(modalAlert.id); hideNotification(modalAlert.id, { coolOffPeriod: 24 * 365 }); if (modalAlert.closed) modalAlert.closed(); }); + + // reset `currentIndex` if we removed the last item + if (currentIndex >= filteredModalAlerts.length - 1) { + currentIndex = Math.max(0, filteredModalAlerts.length - 2); + } } function showNext() { @@ -114,8 +126,13 @@ } // the button component cannot have both href and on:click! - function triggerWindowLink(alertAction: BottomModalAlertAction, event?: string) { + function triggerWindowLink(alert: BottomModalAlertItem, event?: string) { + const alertAction = alert.cta; const shouldShowUpgrade = showUpgrade(); + + // for correct event tracking after removal + const currentModalId = currentModalAlert.id; + const url = shouldShowUpgrade ? $upgradeURL : alertAction.link({ @@ -130,14 +147,12 @@ } if (alertAction?.hideOnClick === true) { - // be careful of this one. - // once clicked, its gone! - handleClose(); + handleClose(alert.id); // gone! } trackEvent(Click.PromoClick, { - promo: currentModalAlert.id, - type: shouldShowUpgrade ? 'upgrade' : (event ?? `cta_click_${currentModalAlert.id}`) + promo: currentModalId, + type: shouldShowUpgrade ? 'upgrade' : (event ?? `cta_click_${currentModalId}`) }); } @@ -156,12 +171,10 @@ } } - onMount(() => { - addBottomModalAlerts(); - }); + onMount(addBottomModalAlerts); -{#if filteredModalAlerts.length > 0 && currentModalAlert && !page.url.pathname.includes('console/onboarding')} +{#if !isOnOnboarding && filteredModalAlerts.length > 0 && currentModalAlert} {@const shouldShowUpgrade = showUpgrade()}
@@ -170,7 +183,7 @@ @@ -243,7 +261,7 @@ fullWidthMobile secondary={!hasOnlyPrimaryCta} class={`${hasOnlyPrimaryCta ? 'only-primary-cta' : ''}`} - on:click={() => triggerWindowLink(currentModalAlert.cta)}> + on:click={() => triggerWindowLink(currentModalAlert)}> {currentModalAlert.cta.text} @@ -276,7 +294,7 @@
diff --git a/src/lib/components/columnSelector.svelte b/src/lib/components/columnSelector.svelte index 42db1b9b5..a899fe9e4 100644 --- a/src/lib/components/columnSelector.svelte +++ b/src/lib/components/columnSelector.svelte @@ -20,6 +20,7 @@ let maxHeight = $state('none'); let containerRef = $state(null); + const collectionId = $derived(page.params.collection); const calcMaxHeight = () => { if (containerRef) { @@ -32,10 +33,10 @@ }; const saveColumnPreferences = () => { - const shownColumns = $columns.filter((n) => n.hide !== true).map((n) => n.id); + const shownColumns = $columns.filter((n) => n.hide === true).map((n) => n.id); if (isCustomCollection) { - preferences.setCustomCollectionColumns(page.params.collection, shownColumns); + preferences.setCustomCollectionColumns(collectionId, shownColumns); } else { preferences.setColumns(shownColumns); } @@ -43,24 +44,24 @@ onMount(() => { if (isCustomCollection) { - const shownColumns = preferences.getCustomCollectionColumns(page.params.collection); + const shownColumns = preferences.getCustomCollectionColumns(collectionId); - columns.update((columns) => { - return columns.map((column) => { - column.hide = !shownColumns.includes(column.id); + columns.update((n) => + n.map((column) => { + column.hide = shownColumns?.includes(column.id) ?? false; return column; - }); - }); + }) + ); } else { const prefs = preferences.get(page.route); - if (prefs?.columns && prefs.columns.length > 0) { - columns.update((cols) => { - return cols.map((column) => { - column.hide = !prefs.columns.includes(column.id); + if (prefs?.columns) { + columns.update((n) => + n.map((column) => { + column.hide = prefs.columns?.includes(column.id) ?? false; return column; - }); - }); + }) + ); } } @@ -79,7 +80,7 @@ columns.update((cols) => cols.map((col) => { if (col.id === column.id) { - col.hide = !column.hide; + column.hide = !column.hide; } return col; }) @@ -90,6 +91,7 @@ + {#if $columns?.length} {@render children(toggle, selectedColumnsNumber)} diff --git a/src/lib/components/permissions/team.svelte b/src/lib/components/permissions/team.svelte index 23f3ae0ea..5774857e9 100644 --- a/src/lib/components/permissions/team.svelte +++ b/src/lib/components/permissions/team.svelte @@ -88,11 +88,13 @@ {@const exists = $groups.has(role)} onSelection(role)} disabled={exists}> - +
+ +
diff --git a/src/lib/components/permissions/user.svelte b/src/lib/components/permissions/user.svelte index 8c30e7968..c1242fc0c 100644 --- a/src/lib/components/permissions/user.svelte +++ b/src/lib/components/permissions/user.svelte @@ -90,11 +90,13 @@ {@const exists = $groups.has(role)} onSelection(role)} disabled={exists}> - +
+ +
diff --git a/src/lib/constants.ts b/src/lib/constants.ts index cd9dc4364..7414a2ffa 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -18,7 +18,7 @@ export enum Dependencies { INVOICES = 'dependency:invoices', ADDRESS = 'dependency:address', UPGRADE_PLAN = 'dependency:upgrade_plan', - CREATE_ORGANIZATION = 'dependency:create_organization', + ORGANIZATIONS = 'dependency:organizations', PAYMENT_METHODS = 'dependency:paymentMethods', ORGANIZATION = 'dependency:organization', MEMBERS = 'dependency:members', diff --git a/src/lib/images/promos/bulk-api-dark.png b/src/lib/images/promos/bulk-api-dark.png new file mode 100644 index 000000000..c4b94deb4 Binary files /dev/null and b/src/lib/images/promos/bulk-api-dark.png differ diff --git a/src/lib/images/promos/bulk-api-light.png b/src/lib/images/promos/bulk-api-light.png new file mode 100644 index 000000000..60ef70ef9 Binary files /dev/null and b/src/lib/images/promos/bulk-api-light.png differ diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index 0fc0d6dd9..5df55b9fd 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -287,6 +287,7 @@ export function checkForEnterpriseTrial(org: Organization) { } export function calculateEnterpriseTrial(org: Organization) { + if (!org || !org.billingNextInvoiceDate) return 0; const endDate = new Date(org.billingNextInvoiceDate); const startDate = new Date(org.billingCurrentInvoiceDate); const today = new Date(); diff --git a/src/lib/stores/preferences.ts b/src/lib/stores/preferences.ts index 98911f7a7..c552158a2 100644 --- a/src/lib/stores/preferences.ts +++ b/src/lib/stores/preferences.ts @@ -176,7 +176,7 @@ function createPreferences() { names: TeamPreferences['names'] ) => { let teamPrefs: Models.Preferences; - update((n) => { + await updateAndSync((n) => { if (!n?.displayNames) { n ??= {}; n.displayNames ??= {}; diff --git a/src/routes/(console)/account/payments/addressModal.svelte b/src/routes/(console)/account/payments/addressModal.svelte index 4c64e3cf1..9bdcc2784 100644 --- a/src/routes/(console)/account/payments/addressModal.svelte +++ b/src/routes/(console)/account/payments/addressModal.svelte @@ -56,7 +56,7 @@ if (organization) { org = await sdk.forConsole.billing.setBillingAddress(organization, response.$id); trackEvent(Submit.OrganizationBillingAddressUpdate); - await invalidate(Dependencies.ORGANIZATION); + await invalidate(Dependencies.ORGANIZATIONS); } await invalidate(Dependencies.ADDRESS); diff --git a/src/routes/(console)/bottomAlerts.ts b/src/routes/(console)/bottomAlerts.ts index 18ad41d33..e9a39a717 100644 --- a/src/routes/(console)/bottomAlerts.ts +++ b/src/routes/(console)/bottomAlerts.ts @@ -1,10 +1,9 @@ import { isCloud } from '$lib/system'; import { isSameDay } from '$lib/helpers/date'; -import { - type BottomModalAlertItem, - showBottomModalAlert, - setMobileSingleAlertLayout -} from '$lib/stores/bottom-alerts'; +import { type BottomModalAlertItem, showBottomModalAlert } from '$lib/stores/bottom-alerts'; + +import BulkApiDark from '$lib/images/promos/bulk-api-dark.png'; +import BulkApiLight from '$lib/images/promos/bulk-api-light.png'; import CSVImportDark from '$lib/images/promos/csv-import-placeholder-dark.png'; import CSVImportLight from '$lib/images/promos/csv-import-placeholder-light.png'; @@ -33,18 +32,28 @@ if (isCloud) { show: true }; - listOfPromotions.push(csvImportPromo); - - setMobileSingleAlertLayout({ - title: csvImportPromo.title, - message: csvImportPromo.message, - enabled: true, + const bulkApiPromo: BottomModalAlertItem = { + id: 'modal:bulk_api_announcement', + src: { + dark: BulkApiDark, + light: BulkApiLight + }, + title: 'Introducing Bulk API', + message: + 'A new Appwrite Databases feature, explicitly designed to handle heavy write workloads.', + plan: 'free', + importance: 8, + scope: 'project', cta: { - link: csvImportPromo.cta.link, - external: csvImportPromo.cta.external, - hideOnClick: csvImportPromo.cta.hideOnClick - } - }); + text: 'Read announcement', + link: () => 'https://appwrite.io/blog/post/announcing-bulk-api', + external: true, + hideOnClick: true + }, + show: true + }; + + listOfPromotions.push(bulkApiPromo, csvImportPromo); } export function addBottomModalAlerts() { diff --git a/src/routes/(console)/create-organization/+page.ts b/src/routes/(console)/create-organization/+page.ts index 9aba3aefd..690baa2bb 100644 --- a/src/routes/(console)/create-organization/+page.ts +++ b/src/routes/(console)/create-organization/+page.ts @@ -6,7 +6,7 @@ import type { Organization } from '$lib/stores/organization'; export const load: PageLoad = async ({ url, parent, depends }) => { const { organizations } = await parent(); - depends(Dependencies.CREATE_ORGANIZATION); + depends(Dependencies.ORGANIZATIONS); const [coupon, paymentMethods] = await Promise.all([ getCoupon(url), diff --git a/src/routes/(console)/onboarding/create-organization/+page.svelte b/src/routes/(console)/onboarding/create-organization/+page.svelte index b765cbd6a..b29ff6f44 100644 --- a/src/routes/(console)/onboarding/create-organization/+page.svelte +++ b/src/routes/(console)/onboarding/create-organization/+page.svelte @@ -50,7 +50,7 @@ // fixes an edge case where // the org is not available for some reason! - await invalidate(Dependencies.CREATE_ORGANIZATION); + await invalidate(Dependencies.ORGANIZATIONS); } isLoading = false; } diff --git a/src/routes/(console)/organization-[organization]/billing/+page.svelte b/src/routes/(console)/organization-[organization]/billing/+page.svelte index 59a4f64d9..ae2674465 100644 --- a/src/routes/(console)/organization-[organization]/billing/+page.svelte +++ b/src/routes/(console)/organization-[organization]/billing/+page.svelte @@ -1,6 +1,5 @@ @@ -93,7 +93,7 @@ {#if $failedInvoice} {#if $failedInvoice?.lastError} - The scheduled payment for {$organization.name} failed due to following error: {$failedInvoice.lastError} + The scheduled payment for {organization.name} failed due to following error: {$failedInvoice.lastError} {:else} - + {/if} - 0} /> + 0} /> diff --git a/src/routes/(console)/organization-[organization]/billing/paymentMethods.svelte b/src/routes/(console)/organization-[organization]/billing/paymentMethods.svelte index b98c45bb2..14407a2e7 100644 --- a/src/routes/(console)/organization-[organization]/billing/paymentMethods.svelte +++ b/src/routes/(console)/organization-[organization]/billing/paymentMethods.svelte @@ -5,7 +5,7 @@ import { CardGrid, CreditCardBrandImage, CreditCardInfo } from '$lib/components'; import { BillingPlan, Dependencies } from '$lib/constants'; import { addNotification } from '$lib/stores/notifications'; - import { organization } from '$lib/stores/organization'; + import { type Organization } from '$lib/stores/organization'; import { Button } from '$lib/elements/forms'; import { hasStripePublicKey, isCloud } from '$lib/system'; import type { PaymentList, PaymentMethodData } from '$lib/sdk/billing'; @@ -34,6 +34,7 @@ IconTrash } from '@appwrite.io/pink-icons-svelte'; + export let organization: Organization; export let methods: PaymentList; let showPayment = false; @@ -47,12 +48,12 @@ async function addPaymentMethod(paymentMethodId: string) { try { await sdk.forConsole.billing.setOrganizationPaymentMethod( - $organization.$id, + organization.$id, paymentMethodId ); addNotification({ type: 'success', - message: `A new payment method has been added to ${$organization.name}` + message: `A new payment method has been added to ${organization.name}` }); trackEvent(Submit.OrganizationPaymentUpdate); invalidate(Dependencies.ORGANIZATION); @@ -68,12 +69,12 @@ async function addBackupPaymentMethod(paymentMethodId: string) { try { await sdk.forConsole.billing.setOrganizationPaymentMethodBackup( - $organization.$id, + organization.$id, paymentMethodId ); addNotification({ type: 'success', - message: `A new payment method has been added to ${$organization.name}` + message: `A new payment method has been added to ${organization.name}` }); invalidate(Dependencies.ORGANIZATION); } catch (error) { @@ -85,15 +86,15 @@ } } - $: if ($organization?.backupPaymentMethodId) { + $: if (organization?.backupPaymentMethodId) { sdk.forConsole.billing - .getOrganizationPaymentMethod($organization.$id, $organization.backupPaymentMethodId) + .getOrganizationPaymentMethod(organization.$id, organization.backupPaymentMethodId) .then((res) => (backupPaymentMethod = res)); } - $: if ($organization?.paymentMethodId) { + $: if (organization?.paymentMethodId) { sdk.forConsole.billing - .getOrganizationPaymentMethod($organization.$id, $organization.paymentMethodId) + .getOrganizationPaymentMethod(organization.$id, organization.paymentMethodId) .then((res) => (defaultPaymentMethod = res)); } @@ -112,7 +113,7 @@ Payment methods View or update your organization payment methods here. - {#if $organization?.paymentMethodId} + {#if organization?.paymentMethodId} - {#if $organization?.backupPaymentMethodId} + {#if organization?.backupPaymentMethodId} @@ -209,9 +210,9 @@ {/if} - {#if !$organization?.backupPaymentMethodId} + {#if !organization?.backupPaymentMethodId} {@const filteredPaymentMethods = methods.paymentMethods.filter( - (o) => !!o.last4 && o.$id !== $organization?.paymentMethodId + (o) => !!o.last4 && o.$id !== organization?.paymentMethodId )}
@@ -264,7 +265,7 @@ {/if} {:else} {@const filteredPaymentMethods = methods.paymentMethods.filter( - (o) => !!o.last4 && o.$id !== $organization?.backupPaymentMethodId + (o) => !!o.last4 && o.$id !== organization?.backupPaymentMethodId )} @@ -319,15 +320,15 @@ bind:show={showEdit} /> {/if} {#if isCloud && hasStripePublicKey} - + {/if} {#if showDelete && isCloud && hasStripePublicKey} {@const hasOtherMethod = isSelectedBackup - ? !!$organization?.paymentMethodId - : !!$organization?.backupPaymentMethodId} + ? !!organization?.paymentMethodId + : !!organization?.backupPaymentMethodId} + disabled={organization?.billingPlan !== BillingPlan.FREE && !hasOtherMethod} /> {/if} diff --git a/src/routes/(console)/organization-[organization]/billing/removeAddress.svelte b/src/routes/(console)/organization-[organization]/billing/removeAddress.svelte index 72d8eb100..0a913b851 100644 --- a/src/routes/(console)/organization-[organization]/billing/removeAddress.svelte +++ b/src/routes/(console)/organization-[organization]/billing/removeAddress.svelte @@ -20,7 +20,7 @@ message: `The billing address has been removed from ${$organization.name}` }); trackEvent(Submit.OrganizationBillingAddressDelete); - invalidate(Dependencies.ORGANIZATION); + invalidate(Dependencies.ORGANIZATIONS); show = false; } catch (e) { error = e.message; diff --git a/src/routes/(console)/organization-[organization]/billing/replaceCard.svelte b/src/routes/(console)/organization-[organization]/billing/replaceCard.svelte index faf49fc8c..9adbb514e 100644 --- a/src/routes/(console)/organization-[organization]/billing/replaceCard.svelte +++ b/src/routes/(console)/organization-[organization]/billing/replaceCard.svelte @@ -3,7 +3,7 @@ import { FakeModal } from '$lib/components'; import { Button } from '$lib/elements/forms'; import { sdk } from '$lib/stores/sdk'; - import { organization } from '$lib/stores/organization'; + import type { Organization } from '$lib/stores/organization'; import { Dependencies } from '$lib/constants'; import { submitStripeCard } from '$lib/stores/stripe'; import { onMount } from 'svelte'; @@ -12,6 +12,7 @@ import { Submit, trackError, trackEvent } from '$lib/actions/analytics'; import { PaymentBoxes } from '$lib/components/billing'; + export let organization: Organization; export let show = false; export let isBackup = false; export let methods: PaymentList; @@ -21,12 +22,12 @@ let selectedPaymentMethodId: string; onMount(async () => { - if (!$organization.paymentMethodId && !$organization.backupPaymentMethodId) { + if (!organization.paymentMethodId && !organization.backupPaymentMethodId) { selectedPaymentMethodId = methods?.total ? methods.paymentMethods[0].$id : null; } else { selectedPaymentMethodId = isBackup - ? $organization.backupPaymentMethodId - : $organization.paymentMethodId; + ? organization.backupPaymentMethodId + : organization.paymentMethodId; // If the selected payment method does not belong to the current user, select the first one. if ( methods?.total && @@ -40,7 +41,7 @@ async function handleSubmit() { try { if (selectedPaymentMethodId === '$new') { - const method = await submitStripeCard(name, $organization.$id); + const method = await submitStripeCard(name, organization.$id); selectedPaymentMethodId = method.$id; } isBackup @@ -68,7 +69,7 @@ async function addPaymentMethod(paymentMethodId: string) { try { await sdk.forConsole.billing.setOrganizationPaymentMethod( - $organization.$id, + organization.$id, paymentMethodId ); } catch (e) { @@ -79,7 +80,7 @@ async function addBackupPaymentMethod(paymentMethodId: string) { try { await sdk.forConsole.billing.setOrganizationPaymentMethodBackup( - $organization.$id, + organization.$id, paymentMethodId ); } catch (e) { @@ -97,18 +98,18 @@ methods={filteredMethods} bind:name bind:group={selectedPaymentMethodId} - defaultMethod={$organization?.paymentMethodId} - backupMethod={$organization?.backupPaymentMethodId} + defaultMethod={organization?.paymentMethodId} + backupMethod={organization?.backupPaymentMethodId} disabledCondition={isBackup - ? $organization.paymentMethodId - : $organization.backupPaymentMethodId} /> + ? organization.paymentMethodId + : organization.backupPaymentMethodId} /> diff --git a/src/routes/(console)/organization-[organization]/header.svelte b/src/routes/(console)/organization-[organization]/header.svelte index 01b2687aa..f114dcc22 100644 --- a/src/routes/(console)/organization-[organization]/header.svelte +++ b/src/routes/(console)/organization-[organization]/header.svelte @@ -7,7 +7,13 @@ import { toLocaleDate } from '$lib/helpers/date'; import { isTabSelected } from '$lib/helpers/load'; import { Cover } from '$lib/layout'; - import { daysLeftInTrial, getServiceLimit, plansInfo, readOnly } from '$lib/stores/billing'; + import { + daysLeftInTrial, + getServiceLimit, + plansInfo, + readOnly, + tierToPlan + } from '$lib/stores/billing'; import { members, newMemberModal, type Organization } from '$lib/stores/organization'; import { canSeeBilling, @@ -114,14 +120,25 @@ {/if} {#if $isOwner} - + +
+ +
+
+ {organization?.billingPlan === BillingPlan.FREE + ? 'Upgrade to add more members' + : `You've reached the members limit for the ${ + tierToPlan(organization?.billingPlan)?.name + } plan`} +
+
{/if}
diff --git a/src/routes/(console)/organization-[organization]/members/+page.svelte b/src/routes/(console)/organization-[organization]/members/+page.svelte index c906ece51..abc2360b3 100644 --- a/src/routes/(console)/organization-[organization]/members/+page.svelte +++ b/src/routes/(console)/organization-[organization]/members/+page.svelte @@ -31,8 +31,11 @@ Icon, Typography, Popover, - ActionMenu + ActionMenu, + Tooltip } from '@appwrite.io/pink-svelte'; + import { BillingPlan } from '$lib/constants'; + import { tierToPlan } from '$lib/stores/billing'; export let data; @@ -41,6 +44,13 @@ let showEdit = false; let showDropdown = []; + // 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; + const resend = async (member: Models.Membership) => { try { await sdk.forConsole.teams.createMembership( @@ -70,14 +80,25 @@ Members - newMemberModal.set(true)} - disabled={isCloud ? !$currentPlan?.addons?.seats?.supported : false}> - - Invite - + +
+ newMemberModal.set(true)} + disabled={isButtonDisabled}> + + Invite + +
+
+ {$organization?.billingPlan === BillingPlan.FREE + ? 'Upgrade to add more members' + : `You've reached the members limit for the ${ + tierToPlan($organization?.billingPlan)?.name + } plan`} +
+
{ policies.forEach((policy) => { @@ -103,10 +102,6 @@ trackError(error, Submit.DatabaseCreate); } }; - - $: if (!showCreate) { - showPlanUpgradeAlert = true; - } @@ -132,18 +127,12 @@ {#if isCloud} {#if $organization?.billingPlan === BillingPlan.FREE} - {#if showPlanUpgradeAlert} - (showPlanUpgradeAlert = false)}> - Upgrade your plan to ensure your data stays safe and backed up. - - - - - {/if} + + Upgrade your plan to ensure your data stays safe and backed up. + + + + {:else} ([]); $: selected = preferences.getCustomCollectionColumns(page.params.collection); + $: columns.set( $collection.attributes.map((attribute) => ({ id: attribute.key, title: attribute.key, type: attribute.type as ColumnType, - hide: !selected?.includes(attribute.key), + hide: !!selected?.includes(attribute.key), array: attribute?.array, format: 'format' in attribute && attribute?.format === 'enum' ? attribute.format : null, elements: 'elements' in attribute ? attribute.elements : null @@ -50,7 +51,7 @@ ...['$id', '$createdAt', '$updatedAt'].map((id) => ({ id, title: id, - hide: false, + show: true, type: (id === '$id' ? 'string' : 'datetime') as ColumnType })) ]); diff --git a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/attributes/deleteAttribute.svelte b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/attributes/deleteAttribute.svelte index 11e02ae81..d51641c73 100644 --- a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/attributes/deleteAttribute.svelte +++ b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/attributes/deleteAttribute.svelte @@ -1,5 +1,5 @@ {#if data?.length} {#snippet children(paginatedItems: typeof data)} - ({ id }))]}> + Document ID {#if args?.length} diff --git a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/settings/displayName.svelte b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/settings/displayName.svelte index fa36903b7..46b972b03 100644 --- a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/settings/displayName.svelte +++ b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/settings/displayName.svelte @@ -15,12 +15,24 @@ import { organization } from '$lib/stores/organization'; const collectionId = page.params.collection; - let names: string[] = [...(preferences.getDisplayNames()?.[collectionId] ?? [])]; + + function getDisplayNames() { + return [...(preferences.getDisplayNames()?.[collectionId] ?? [])].filter( + (name) => name !== '$id' + ); // edge case with `$id`? got saved during tests! + } + + let names: string[] = $state(getDisplayNames()); async function updateDisplayName() { try { - await preferences.setDisplayNames($organization.$id, collectionId, names); - names = [...(preferences.getDisplayNames()?.[collectionId] ?? [])]; + // $state makes proxy, + // structuredClone doesn't work + const regularArray = [...names]; + + await preferences.setDisplayNames($organization.$id, collectionId, regularArray); + names = getDisplayNames(); + await invalidate(Dependencies.TEAM); addNotification({ message: 'Display names has been updated', @@ -36,23 +48,32 @@ } } - $: options = ($attributes as Models.AttributeString[]) - .filter( - (attr) => - attr.type === 'string' && !attr?.array && !names?.some((name) => name === attr.key) - ) - .map((attr) => { - return { + function getValidAttributes() { + return ($attributes as Models.AttributeString[]).filter( + (attr) => attr.type === 'string' && !attr?.array + ); + } + + function getOptions(index: number) { + const current = names?.[index]; + return getValidAttributes() + .filter((attr) => !names?.includes(attr.key) || attr.key === current) + .map((attr) => ({ value: attr.key, label: attr.key - }; - }); + })); + } - $: addAttributeDisabled = names?.length >= 5 || (names?.length && !names[names?.length - 1]); + const addAttributeDisabled = $derived( + names?.length >= 5 || (names?.length && !names[names?.length - 1]) + ); - $: updateBtnDisabled = + const updateBtnDisabled = $derived( !symmetricDifference(names, preferences.getDisplayNames()?.[collectionId] ?? [])?.length || - (names?.length && !last(names)); + (names?.length && !last(names)) + ); + + const hasExhaustedOptions = $derived(getValidAttributes().length === names?.length);
@@ -72,19 +93,22 @@ {#if names?.length} - {#each names as name, i} + {#each names as name, index} + {@const options = getOptions(index)} + {@const disabled = + (!!names[index] && names.length > index + 1) || hasExhaustedOptions} i + 1} - {options} /> + {options} + {disabled} + bind:value={names[index]} + placeholder="Select attribute" /> -
+ + + {#if !hasExhaustedOptions} +
+ +
+ {/if} diff --git a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/table.svelte b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/table.svelte index 569ad5798..a798ed2bf 100644 --- a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/table.svelte +++ b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/table.svelte @@ -10,7 +10,7 @@ import { preferences } from '$lib/stores/preferences'; import { sdk } from '$lib/stores/sdk'; import type { Models } from '@appwrite.io/console'; - import { afterUpdate, onMount } from 'svelte'; + import { onMount } from 'svelte'; import type { PageData } from './$types'; import { isRelationship, @@ -38,30 +38,16 @@ const databaseId = page.params.database; const collectionId = page.params.collection; + + let displayNames = {}; let showRelationships = false; let selectedRelationship: Models.AttributeRelationship = null; let relationshipData: Partial[]; - let displayNames = {}; onMount(async () => { displayNames = preferences.getDisplayNames(); - updateMaxWidth(); }); - afterUpdate(() => updateMaxWidth()); - - function updateMaxWidth() { - const tableCells = Array.from(document.querySelectorAll('.less-width-truncated')); - - const visibleColumnsCount = $columns.filter((col) => !col.hide).length; - const newMaxWidth = Math.max(50 - (visibleColumnsCount - 1) * 5, 25); - - tableCells.forEach((cell) => { - const cellItem = cell as HTMLElement; - cellItem.style.maxWidth = `${newMaxWidth}vw`; - }); - } - function formatArray(array: unknown[]) { if (array.length === 0) return '[ ]'; @@ -108,7 +94,7 @@ id: attribute.key, title: attribute.key, type: attribute.type as ColumnType, - hide: !selected?.includes(attribute.key), + hide: !!selected?.includes(attribute.key), array: attribute?.array, width: { min: 168 }, format: diff --git a/src/routes/(console)/project-[region]-[project]/overview/platforms/createWeb.svelte b/src/routes/(console)/project-[region]-[project]/overview/platforms/createWeb.svelte index 82d2c479a..2a75050fa 100644 --- a/src/routes/(console)/project-[region]-[project]/overview/platforms/createWeb.svelte +++ b/src/routes/(console)/project-[region]-[project]/overview/platforms/createWeb.svelte @@ -44,7 +44,7 @@ AngularFrameworkIcon, JavascriptFrameworkIcon } from './components/index'; - import { hostnameRegex } from '$lib/helpers/string'; + import { extendedHostnameRegex } from '$lib/helpers/string'; export let key; @@ -143,7 +143,7 @@ ${prefix}APPWRITE_ENDPOINT = "${sdk.forProject(page.params.region, page.params.p $: selectedFrameworkIcon = selectedFramework ? selectedFramework.icon : NoFrameworkIcon; async function createWebPlatform() { - hostnameError = hostname !== '' ? !new RegExp(hostnameRegex).test(hostname) : null; + hostnameError = hostname !== '' ? !new RegExp(extendedHostnameRegex).test(hostname) : null; if (hostnameError) { return; diff --git a/src/routes/+layout.ts b/src/routes/+layout.ts index 21fe42dde..46b84cc98 100644 --- a/src/routes/+layout.ts +++ b/src/routes/+layout.ts @@ -16,7 +16,7 @@ export const ssr = false; export const load: LayoutLoad = async ({ depends, url, route }) => { depends(Dependencies.ACCOUNT); - depends(Dependencies.CREATE_ORGANIZATION); + depends(Dependencies.ORGANIZATIONS); const [account, error] = (await sdk.forConsole.account .get()