diff --git a/src/routes/console/+layout.svelte b/src/routes/console/+layout.svelte
index 3e0fbc038..8eeaf0560 100644
--- a/src/routes/console/+layout.svelte
+++ b/src/routes/console/+layout.svelte
@@ -8,7 +8,7 @@
import Shell from '$lib/layout/shell.svelte';
import { app } from '$lib/stores/app';
import { log } from '$lib/stores/logs';
- import { newOrgModal } from '$lib/stores/organization';
+ import { newOrgModal, organization } from '$lib/stores/organization';
import { wizard } from '$lib/stores/wizard';
import { onMount } from 'svelte';
import { loading, requestedMigration } from '../store';
@@ -23,11 +23,13 @@
import { AIPanel, OrganizationsPanel, ProjectsPanel } from '$lib/commandCenter/panels';
import { orgSearcher, projectsSearcher } from '$lib/commandCenter/searchers';
import { addSubPanel } from '$lib/commandCenter/subPanels';
- import { addNotification } from '$lib/stores/notifications';
+ import { addNotification, notifications } from '$lib/stores/notifications';
import { openMigrationWizard } from './(migration-wizard)';
import { project } from './project-[project]/store';
import { feedback } from '$lib/stores/feedback';
import { consoleVariables } from './store';
+ import { isCloud } from '$lib/system';
+ import { sdk } from '$lib/stores/sdk';
function kebabToSentenceCase(str: string) {
return str
@@ -245,6 +247,82 @@
}
}
+ organization.subscribe(() => {
+ if (isCloud) {
+ checkForTrialEnding();
+ paymentExpired();
+ }
+ });
+
+ function checkForTrialEnding() {
+ if (
+ localStorage.getItem('trialEndingNotification') === 'true' &&
+ $organization?.billingTrialDays
+ )
+ return;
+ if ($organization?.billingTrialDays >= 5) {
+ const expirationDate = new Date(
+ new Date().getTime() + 5 * 24 * 60 * 60 * 1000
+ ).toString();
+ addNotification({
+ type: 'info',
+ isHtml: true,
+ message: `We hope you've been enjoying the Pro plan.
+ You will be billed on a recurring 30 day cycle after your trial period ends on ${toLocaleDate(
+ expirationDate
+ )}`
+ });
+ localStorage.setItem('trialEndingNotification', 'true');
+ }
+ }
+
+ async function paymentExpired() {
+ if (!$organization?.paymentMethodId) return;
+ const payment = await sdk.forConsole.billing.getPaymentMethod(
+ $organization.paymentMethodId
+ );
+ const year = new Date().getFullYear();
+ const month = new Date().getMonth();
+ const expiredMessage = `The default payment method for ${$organization.name} has expired`;
+ const expiringMessage = `The default payment method for ${$organization.name} will expire soon`;
+ const expiredNotification = $notifications.some((n) => n.message === expiredMessage);
+ const expiringNotification = $notifications.some((n) => n.message === expiringMessage);
+ if (payment.expired && !expiredNotification) {
+ addNotification({
+ type: 'error',
+ isHtml: true,
+ timeout: 0,
+ message: expiredMessage,
+ buttons: [
+ {
+ name: 'Update payment details',
+ method: () => {
+ goto(`${base}/console/account/payments`);
+ }
+ }
+ ]
+ });
+ } else if (
+ !expiringNotification &&
+ (payment.expiryYear < year ||
+ (payment.expiryYear === year && payment.expiryMonth < month))
+ ) {
+ addNotification({
+ type: 'warning',
+ isHtml: true,
+ message: expiringMessage,
+ buttons: [
+ {
+ name: 'Update payment details',
+ method: () => {
+ goto(`${base}/console/account/payments`);
+ }
+ }
+ ]
+ });
+ }
+ }
+
$: if (!$log.show) {
$log.data = null;
$log.func = null;
diff --git a/src/routes/console/organization-[organization]/+layout.svelte b/src/routes/console/organization-[organization]/+layout.svelte
index d01e2fdf9..77dcfa320 100644
--- a/src/routes/console/organization-[organization]/+layout.svelte
+++ b/src/routes/console/organization-[organization]/+layout.svelte
@@ -1,95 +1,13 @@