Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

DATE_RANGE_INTERVAL_PRESETS

Steven Tey2203f5d01ebf
diff --git a/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/links/page-client.tsx b/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/links/page-client.tsx
index b1a10983c6..a94712b288 100644
--- a/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/links/page-client.tsx
+++ b/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/links/page-client.tsx
@@ -1,8 +1,8 @@
"use client";
import {
+ DATE_RANGE_INTERVAL_PRESETS,
DUB_PARTNERS_ANALYTICS_INTERVAL,
- intervals,
} from "@/lib/analytics/constants";
import { IntervalOptions } from "@/lib/analytics/types";
import usePartnerLinks from "@/lib/swr/use-partner-links";
@@ -18,7 +18,7 @@ import { PartnerLinkCard } from "./partner-link-card";
const PartnerLinksContext = createContext<{
start?: Date;
end?: Date;
- interval: (typeof intervals)[number];
+ interval: (typeof DATE_RANGE_INTERVAL_PRESETS)[number];
} | null>(null);
export function usePartnerLinksContext() {
diff --git a/apps/web/lib/analytics/constants.ts b/apps/web/lib/analytics/constants.ts
index 9e6a336749..36b036a251 100644
--- a/apps/web/lib/analytics/constants.ts
+++ b/apps/web/lib/analytics/constants.ts
@@ -1,18 +1,6 @@
import { THE_BEGINNING_OF_TIME } from "@dub/utils";
-export const intervals = [
- "24h",
- "7d",
- "30d",
- "90d",
- "1y",
- "mtd",
- "qtd",
- "ytd",
- "all",
-] as const;
-
-export const eventIntervals = [
+export const DATE_RANGE_INTERVAL_PRESETS = [
"24h",
"7d",
"30d",
diff --git a/apps/web/lib/analytics/types.ts b/apps/web/lib/analytics/types.ts
index 53fcff011d..54b462380f 100644
--- a/apps/web/lib/analytics/types.ts
+++ b/apps/web/lib/analytics/types.ts
@@ -7,12 +7,12 @@ import { getPartnerEarningsTimeseriesSchema } from "../zod/schemas/partner-profi
import {
ANALYTICS_SALE_UNIT,
ANALYTICS_VIEWS,
+ DATE_RANGE_INTERVAL_PRESETS,
EVENT_TYPES,
VALID_ANALYTICS_ENDPOINTS,
- intervals,
} from "./constants";
-export type IntervalOptions = (typeof intervals)[number];
+export type IntervalOptions = (typeof DATE_RANGE_INTERVAL_PRESETS)[number];
export type AnalyticsGroupByOptions =
(typeof VALID_ANALYTICS_ENDPOINTS)[number];
diff --git a/apps/web/lib/zod/schemas/analytics.ts b/apps/web/lib/zod/schemas/analytics.ts
index 978ebc9a98..68d069dd7a 100644
--- a/apps/web/lib/zod/schemas/analytics.ts
+++ b/apps/web/lib/zod/schemas/analytics.ts
@@ -1,11 +1,10 @@
import {
+ DATE_RANGE_INTERVAL_PRESETS,
EVENT_TYPES,
OLD_ANALYTICS_ENDPOINTS,
OLD_TO_NEW_ANALYTICS_ENDPOINTS,
TRIGGER_TYPES,
VALID_ANALYTICS_ENDPOINTS,
- eventIntervals,
- intervals,
} from "@/lib/analytics/constants";
import { prefixWorkspaceId } from "@/lib/api/workspace-id";
import z from "@/lib/zod";
@@ -106,7 +105,7 @@ export const analyticsQuerySchema = z
.optional()
.describe("The ID of the customer to retrieve analytics for."),
interval: z
- .enum(intervals)
+ .enum(DATE_RANGE_INTERVAL_PRESETS)
.optional()
.describe(
"The interval to retrieve analytics for. If undefined, defaults to 24h.",
@@ -117,12 +116,12 @@ export const analyticsQuerySchema = z
})
.optional()
.describe(
- "The start date and time when to retrieve analytics from. Takes precedence over `interval`.",
+ "The start date and time when to retrieve analytics from. If set, takes precedence over `interval`.",
),
end: parseDateSchema
.optional()
.describe(
- "The end date and time when to retrieve analytics from. If not provided, defaults to the current date. Takes precedence over `interval`.",
+ "The end date and time when to retrieve analytics from. If not provided, defaults to the current date. If set along with `start`, takes precedence over `interval`.",
),
timezone: z
.string()
@@ -300,12 +299,6 @@ export const eventsQuerySchema = analyticsQuerySchema
.describe(
"The type of event to retrieve analytics for. Defaults to 'clicks'.",
),
- interval: z
- .enum(eventIntervals)
- .default("24h")
- .describe(
- "The interval to retrieve events for. Takes precedence over start and end. If undefined, defaults to 24h.",
- ),
page: z.coerce.number().default(1),
limit: z.coerce.number().default(PAGINATION_LIMIT),
sortOrder,
diff --git a/apps/web/lib/zod/schemas/commissions.ts b/apps/web/lib/zod/schemas/commissions.ts
index 68855b90f5..450711f5cc 100644
--- a/apps/web/lib/zod/schemas/commissions.ts
+++ b/apps/web/lib/zod/schemas/commissions.ts
@@ -1,4 +1,4 @@
-import { intervals } from "@/lib/analytics/constants";
+import { DATE_RANGE_INTERVAL_PRESETS } from "@/lib/analytics/constants";
import { CommissionStatus } from "@dub/prisma/client";
import { z } from "zod";
import { CustomerSchema } from "./customers";
@@ -35,7 +35,7 @@ export const getCommissionsQuerySchema = z
status: z.nativeEnum(CommissionStatus).optional(),
sortBy: z.enum(["createdAt", "amount"]).default("createdAt"),
sortOrder: z.enum(["asc", "desc"]).default("desc"),
- interval: z.enum(intervals).default("all"),
+ interval: z.enum(DATE_RANGE_INTERVAL_PRESETS).default("all"),
start: parseDateSchema.optional(),
end: parseDateSchema.optional(),
})
diff --git a/apps/web/lib/zod/schemas/partner-profile.ts b/apps/web/lib/zod/schemas/partner-profile.ts
index f073bc1766..7743202422 100644
--- a/apps/web/lib/zod/schemas/partner-profile.ts
+++ b/apps/web/lib/zod/schemas/partner-profile.ts
@@ -1,6 +1,6 @@
import {
+ DATE_RANGE_INTERVAL_PRESETS,
DUB_PARTNERS_ANALYTICS_INTERVAL,
- intervals,
} from "@/lib/analytics/constants";
import { z } from "zod";
import {
@@ -39,7 +39,9 @@ export const getPartnerEarningsQuerySchema = getCommissionsQuerySchema
})
.merge(
z.object({
- interval: z.enum(intervals).default(DUB_PARTNERS_ANALYTICS_INTERVAL),
+ interval: z
+ .enum(DATE_RANGE_INTERVAL_PRESETS)
+ .default(DUB_PARTNERS_ANALYTICS_INTERVAL),
type: z.enum(["click", "lead", "sale"]).optional(),
linkId: z.string().optional(),
sortBy: z.enum(["createdAt", "amount", "earnings"]).default("createdAt"),
@@ -52,7 +54,9 @@ export const getPartnerEarningsCountQuerySchema = getCommissionsCountQuerySchema
})
.merge(
z.object({
- interval: z.enum(intervals).default(DUB_PARTNERS_ANALYTICS_INTERVAL),
+ interval: z
+ .enum(DATE_RANGE_INTERVAL_PRESETS)
+ .default(DUB_PARTNERS_ANALYTICS_INTERVAL),
type: z.enum(["click", "lead", "sale"]).optional(),
linkId: z.string().optional(),
groupBy: z.enum(["linkId", "customerId", "status", "type"]).optional(),
diff --git a/apps/web/lib/zod/schemas/programs.ts b/apps/web/lib/zod/schemas/programs.ts
index 23ffadb783..ccd4de4f9c 100644
--- a/apps/web/lib/zod/schemas/programs.ts
+++ b/apps/web/lib/zod/schemas/programs.ts
@@ -1,6 +1,6 @@
import {
+ DATE_RANGE_INTERVAL_PRESETS,
DUB_PARTNERS_ANALYTICS_INTERVAL,
- intervals,
} from "@/lib/analytics/constants";
import { DUB_MIN_PAYOUT_AMOUNT_CENTS } from "@/lib/partners/constants";
import { ProgramEnrollmentStatus, ProgramType } from "@dub/prisma/client";
@@ -97,7 +97,9 @@ export const ProgramInviteSchema = z.object({
});
export const getProgramMetricsQuerySchema = z.object({
- interval: z.enum(intervals).default(DUB_PARTNERS_ANALYTICS_INTERVAL),
+ interval: z
+ .enum(DATE_RANGE_INTERVAL_PRESETS)
+ .default(DUB_PARTNERS_ANALYTICS_INTERVAL),
start: parseDateSchema.optional(),
end: parseDateSchema.optional(),
});