fix: code improvements suggested by code rabbit

This commit is contained in:
Harsh Mahajan
2025-08-29 17:20:11 +05:30
parent 2b937ca894
commit 4e92e3bf2e
9 changed files with 56 additions and 35 deletions
+10 -7
View File
@@ -116,8 +116,10 @@
return;
}
const currentSelectedProjects = org.projects || [];
const updatedProjects = [...currentSelectedProjects, projectToUnarchive.$id];
const currentSelectedProjects = org.projects ?? [];
const updatedProjects = Array.from(
new Set([...currentSelectedProjects, projectToUnarchive.$id])
);
await sdk.forConsole.billing.updateSelectedProjects(org.$id, updatedProjects);
@@ -131,10 +133,11 @@
showUnarchiveModal = false;
projectToUnarchive = null;
} catch (error) {
addNotification({
type: 'error',
message: error.message || 'Failed to unarchive project'
});
const msg =
error && typeof error === 'object' && 'message' in error
? String((error as any).message)
: 'Failed to unarchive project';
addNotification({ type: 'error', message: msg });
}
}
@@ -253,7 +256,7 @@
<svelte:fragment slot="icons">
{#if isCloud && $regionsStore?.regions}
{@const region = findRegion(project)}
<Typography.Text>{region.name}</Typography.Text>
<Typography.Text>{region?.name}</Typography.Text>
{/if}
</svelte:fragment>
</GridItem1>
@@ -1,14 +1,13 @@
<script lang="ts">
import { BillingPlan } from '$lib/constants';
import { formatCurrency } from '$lib/helpers/numbers';
import { type Tier } 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;
+2 -5
View File
@@ -11,7 +11,6 @@
getServiceLimit,
readOnly,
showUsageRatesModal,
useNewPricingModal,
tierToPlan,
upgradeURL,
type PlanServices
@@ -104,7 +103,7 @@
<Alert.Inline status="info">
<span class="text">
You've reached the {services} limit for the {tier} plan.
<Link on:mousedown={() => ($showUsageRatesModal = $useNewPricingModal)}
<Link on:mousedown={() => ($showUsageRatesModal = true)}
>Excess usage fees will apply</Link
>.
</span>
@@ -162,9 +161,7 @@
<p class="text">
You are limited to {limit}
{title.toLocaleLowerCase()} per organization on the {tier} plan.
<Link
on:mousedown={() =>
($showUsageRatesModal = $useNewPricingModal)}
<Link on:mousedown={() => ($showUsageRatesModal = true)}
>Excess usage fees will apply</Link
>.
</p>
@@ -4,7 +4,7 @@
import { CardGrid } from '$lib/components';
import { BillingPlan, Dependencies } from '$lib/constants';
import { Button, Form, InputNumber, InputSwitch } from '$lib/elements/forms';
import { showUsageRatesModal, upgradeURL, useNewPricingModal } from '$lib/stores/billing';
import { showUsageRatesModal, upgradeURL } from '$lib/stores/billing';
import { addNotification } from '$lib/stores/notifications';
import { type Organization } from '$lib/stores/organization';
import { sdk } from '$lib/stores/sdk';
@@ -72,7 +72,7 @@
Budget cap limits do not include the base amount of your plan. <button
class="link"
type="button"
on:click={() => ($showUsageRatesModal = $useNewPricingModal)}
on:click={() => ($showUsageRatesModal = true)}
>Learn more about usage rates.
</button>
</svelte:fragment>
@@ -362,10 +362,13 @@
];
$: totalAmount = billingData.reduce((sum, item) => {
const itemPrice = parseFloat(item.cells.price.replace(/[^0-9.-]+/g, ''));
let itemPrice = parseFloat(item.cells.price.replace(/[^0-9.-]+/g, ''));
if (isNaN(itemPrice)) itemPrice = 0;
const childrenPrice =
item.children?.reduce((childSum, child) => {
const childPrice = parseFloat(child.cells.price.replace(/[^0-9.-]+/g, ''));
let childPrice = parseFloat(child.cells.price.replace(/[^0-9.-]+/g, ''));
if (isNaN(childPrice)) childPrice = 0;
return childSum + childPrice;
}, 0) || 0;
return sum + itemPrice + childrenPrice;
@@ -36,6 +36,7 @@
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';
export let data;
@@ -61,7 +62,7 @@
let feedbackDowngradeReason: string;
let feedbackMessage: string;
let orgUsage: OrganizationUsage;
let allProjects: { projects: any[] } | undefined;
let allProjects: { projects: Models.Project[] } | undefined;
$: paymentMethods = null;
@@ -111,7 +112,7 @@
Query.limit(1000)
]);
} catch {
allProjects = { projects: [] } as any;
allProjects = { projects: [] };
}
});
@@ -7,7 +7,14 @@ export const load: PageLoad = async ({ depends, parent }) => {
const { members, currentPlan, organizations } = await parent();
depends(Dependencies.UPGRADE_PLAN);
const [plans] = await Promise.all([sdk.forConsole.billing.listPlans()]);
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) {
@@ -77,16 +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 = $useNewPricingModal)}
>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 = $useNewPricingModal)}
>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">
@@ -1,12 +1,7 @@
<script lang="ts">
import { Container } from '$lib/layout';
import { CardGrid, Card, ProgressBarBig } from '$lib/components';
import {
showUsageRatesModal,
tierToPlan,
upgradeURL,
useNewPricingModal
} from '$lib/stores/billing';
import { showUsageRatesModal, tierToPlan, upgradeURL } from '$lib/stores/billing';
import { organization } from '$lib/stores/organization';
import { Button } from '$lib/elements/forms';
import { bytesToSize, humanFileSize, mbSecondsToGBHours } from '$lib/helpers/sizeConvertion';
@@ -68,14 +63,14 @@
<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 = $useNewPricingModal)}
on:click={() => ($showUsageRatesModal = true)}
>Learn more about plan usage limits.</Link.Button>
</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 = $useNewPricingModal)}
on:click={() => ($showUsageRatesModal = true)}
>Learn more about plan usage limits.</Link.Button>
</p>
{:else if $organization.billingPlan === BillingPlan.FREE}