fix(dashboard): restrict data if trial ended
This commit is contained in:
@@ -135,7 +135,8 @@ export default function LayoutMenu({
|
|||||||
<div className="flex-1 col gap-0.5">
|
<div className="flex-1 col gap-0.5">
|
||||||
<div className="font-medium">Subscription expired</div>
|
<div className="font-medium">Subscription expired</div>
|
||||||
<div className="text-sm opacity-80">
|
<div className="text-sm opacity-80">
|
||||||
{differenceInDays(new Date(), subscriptionEndsAt)} days ago
|
You can still use OpenPanel but you won't have access to new
|
||||||
|
incoming data.
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</ProjectLink>
|
</ProjectLink>
|
||||||
|
|||||||
@@ -237,3 +237,22 @@ export const getOrganizationBillingEventsCountSerieCached = cacheable(
|
|||||||
getOrganizationBillingEventsCountSerie,
|
getOrganizationBillingEventsCountSerie,
|
||||||
60 * 10,
|
60 * 10,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export async function getOrganizationSubscriptionChartEndDate(
|
||||||
|
projectId: string,
|
||||||
|
endDate: string,
|
||||||
|
) {
|
||||||
|
const organization = await getOrganizationByProjectIdCached(projectId);
|
||||||
|
if (!organization) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// If the current period end date is after the subscription chart end date, we need to use the subscription chart end date
|
||||||
|
if (
|
||||||
|
organization.subscriptionChartEndDate &&
|
||||||
|
new Date(endDate) > organization.subscriptionChartEndDate
|
||||||
|
) {
|
||||||
|
return organization.subscriptionChartEndDate.toISOString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return endDate;
|
||||||
|
}
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import {
|
|||||||
getEventFiltersWhereClause,
|
getEventFiltersWhereClause,
|
||||||
getOrganizationByProjectId,
|
getOrganizationByProjectId,
|
||||||
getOrganizationByProjectIdCached,
|
getOrganizationByProjectIdCached,
|
||||||
|
getOrganizationSubscriptionChartEndDate,
|
||||||
getProfiles,
|
getProfiles,
|
||||||
} from '@openpanel/db';
|
} from '@openpanel/db';
|
||||||
import type {
|
import type {
|
||||||
@@ -509,23 +510,16 @@ export async function getChartSeries(input: IChartInputWithDates) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getChart(input: IChartInput) {
|
export async function getChart(input: IChartInput) {
|
||||||
const organization = await getOrganizationByProjectIdCached(input.projectId);
|
|
||||||
|
|
||||||
if (!organization) {
|
|
||||||
throw TRPCNotFoundError(
|
|
||||||
`Organization not found by project id ${input.projectId} in getChart`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const currentPeriod = getChartStartEndDate(input);
|
const currentPeriod = getChartStartEndDate(input);
|
||||||
const previousPeriod = getChartPrevStartEndDate(currentPeriod);
|
const previousPeriod = getChartPrevStartEndDate(currentPeriod);
|
||||||
|
|
||||||
// If the current period end date is after the subscription chart end date, we need to use the subscription chart end date
|
const endDate = await getOrganizationSubscriptionChartEndDate(
|
||||||
if (
|
input.projectId,
|
||||||
organization.subscriptionChartEndDate &&
|
currentPeriod.endDate,
|
||||||
new Date(currentPeriod.endDate) > organization.subscriptionChartEndDate
|
);
|
||||||
) {
|
|
||||||
currentPeriod.endDate = organization.subscriptionChartEndDate.toISOString();
|
if (endDate) {
|
||||||
|
currentPeriod.endDate = endDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
const promises = [getChartSeries({ ...input, ...currentPeriod })];
|
const promises = [getChartSeries({ ...input, ...currentPeriod })];
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
import {
|
import {
|
||||||
|
getOrganizationByProjectIdCached,
|
||||||
|
getOrganizationSubscriptionChartEndDate,
|
||||||
overviewService,
|
overviewService,
|
||||||
zGetMetricsInput,
|
zGetMetricsInput,
|
||||||
zGetTopGenericInput,
|
zGetTopGenericInput,
|
||||||
zGetTopPagesInput,
|
zGetTopPagesInput,
|
||||||
} from '@openpanel/db';
|
} from '@openpanel/db';
|
||||||
import { type IChartRange, zRange } from '@openpanel/validation';
|
import { type IChartRange, zRange } from '@openpanel/validation';
|
||||||
|
import { TRPCError } from '@trpc/server';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { cacheMiddleware, createTRPCRouter, publicProcedure } from '../trpc';
|
import { cacheMiddleware, createTRPCRouter, publicProcedure } from '../trpc';
|
||||||
import {
|
import {
|
||||||
@@ -29,6 +32,7 @@ function getCurrentAndPrevious<
|
|||||||
startDate?: string | null;
|
startDate?: string | null;
|
||||||
endDate?: string | null;
|
endDate?: string | null;
|
||||||
range: IChartRange;
|
range: IChartRange;
|
||||||
|
projectId: string;
|
||||||
},
|
},
|
||||||
>(input: T, fetchPrevious = false) {
|
>(input: T, fetchPrevious = false) {
|
||||||
const current = getChartStartEndDate(input);
|
const current = getChartStartEndDate(input);
|
||||||
@@ -40,6 +44,13 @@ function getCurrentAndPrevious<
|
|||||||
current: R;
|
current: R;
|
||||||
previous: R | null;
|
previous: R | null;
|
||||||
}> => {
|
}> => {
|
||||||
|
const endDate = await getOrganizationSubscriptionChartEndDate(
|
||||||
|
input.projectId,
|
||||||
|
current.endDate,
|
||||||
|
);
|
||||||
|
if (endDate) {
|
||||||
|
current.endDate = endDate;
|
||||||
|
}
|
||||||
const res = await Promise.all([
|
const res = await Promise.all([
|
||||||
fn({
|
fn({
|
||||||
...input,
|
...input,
|
||||||
|
|||||||
Reference in New Issue
Block a user