Fix: alerts and update history after validation

This commit is contained in:
Damodar Lohani committed 2025-03-24 05:59:21 +00:00
1 parent bbad6365c0
commit 9d73ecc74c
5 files changed
+62 -13

No files matched your search

+24 -12
View File
@@ -33,6 +33,7 @@ import { canSeeBilling } from './roles';
import { sdk } from './sdk';
import { user } from './user';
import BudgetLimitAlert from '$routes/(console)/organization-[organization]/budgetLimitAlert.svelte';
import TeamReadonlyAlert from '$routes/(console)/organization-[organization]/teamReadonlyAlert.svelte';
export type Tier = 'tier-0' | 'tier-1' | 'tier-2' | 'auto-1' | 'cont-1' | 'ent-1';
@@ -59,6 +60,9 @@ export const roles = [
}
];
export const teamStatusReadonly = 'readonly';
export const billingLimitOutstandingInvoice = 'outstanding_invoice';
export const paymentMethods = derived(page, ($page) => $page.data.paymentMethods as PaymentList);
export const addressList = derived(page, ($page) => $page.data.addressList as AddressesList);
export const plansInfo = derived(page, ($page) => $page.data.plansInfo as PlansMap);
@@ -270,27 +274,35 @@ export function calculateTrialDay(org: Organization) {
}
export async function checkForUsageLimit(org: Organization) {
if (!org?.billingLimits) {
if (org?.status === teamStatusReadonly && org?.remarks === billingLimitOutstandingInvoice) {
headerAlert.add({
id: 'teamReadOnlyFailedInvoices',
component: TeamReadonlyAlert,
show: true,
importance: 11
});
readOnly.set(true);
return;
}
if (!org?.billingLimits && org?.status !== teamStatusReadonly) {
readOnly.set(false);
return;
}
if (org?.billingPlan !== BillingPlan.FREE) {
const { budgetLimit } = org?.billingLimits ?? {};
if (!budgetLimit || budgetLimit < 100) {
if (budgetLimit && budgetLimit >= 100) {
readOnly.set(false);
headerAlert.add({
id: 'budgetLimit',
component: BudgetLimitAlert,
show: true,
importance: 10
});
readOnly.set(true);
return;
}
headerAlert.add({
id: 'budgetLimit',
component: BudgetLimitAlert,
show: true,
importance: 10
});
readOnly.set(true);
return;
}
const { bandwidth, documents, executions, storage, users } = org?.billingLimits ?? {};
const resources = [
+2
View File
@@ -32,6 +32,8 @@ export type Organization = Models.Team<Record<string, unknown>> & {
billingPlanDowngrade?: Tier;
billingAggregationId: string;
billingInvoiceId: string;
status: string;
remarks: string;
};
export type OrganizationList = {
@@ -64,6 +64,7 @@
const invoiceId = $page.url.searchParams.get('invoice');
await sdk.forConsole.billing.validateInvoice($organization.$id, invoiceId);
invalidate(Dependencies.INVOICES);
invalidate(Dependencies.ORGANIZATION);
}
if (
@@ -51,6 +51,11 @@
]);
}
$: if ($page.url.searchParams.get('type') === 'validate-invoice') {
window.history.replaceState({}, '', $page.url.pathname);
request();
}
function retryPayment(invoice: Invoice) {
$selectedInvoice = invoice;
$showRetryModal = true;
@@ -62,7 +67,7 @@
</script>
<CardGrid>
<Heading tag="h2" size="6">Payment history</Heading>
<Heading id="payment-history" tag="h2" size="6">Payment history</Heading>
<p class="text">
Transaction history for this organization. Download invoices for more details about your
@@ -0,0 +1,29 @@
<script lang="ts">
import { page } from '$app/stores';
import { Button } from '$lib/elements/forms';
import { organization } from '$lib/stores/organization';
import { HeaderAlert } from '$lib/layout';
import {
billingLimitOutstandingInvoice,
hideBillingHeaderRoutes,
readOnly,
teamStatusReadonly
} from '$lib/stores/billing';
import { base } from '$app/paths';
$: redirectUrl = `${base}/organization-${$organization.$id}/billing#payment-history`;
</script>
{#if $organization?.$id && $organization?.status === teamStatusReadonly && $organization?.remarks === billingLimitOutstandingInvoice && $readOnly && !hideBillingHeaderRoutes.includes($page.url.pathname)}
<HeaderAlert type="error" title="Access restricted">
<svelte:fragment>
Access to your organization resources has been restricted as you have unpaid invoices.
Please pay the invoice to restore access.
</svelte:fragment>
<svelte:fragment slot="buttons">
<Button secondary fullWidthMobile href={redirectUrl}>
<span class="text">View invoices</span>
</Button>
</svelte:fragment>
</HeaderAlert>
{/if}