Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

async fix

Richie McIlroy89d1e9ffa1ff
diff --git a/apps/web/app/(org)/dashboard/admin/AdminDashboardClient.tsx b/apps/web/app/(org)/dashboard/admin/AdminDashboardClient.tsx
index c1d956b01..6e5303dce 100644
--- a/apps/web/app/(org)/dashboard/admin/AdminDashboardClient.tsx
+++ b/apps/web/app/(org)/dashboard/admin/AdminDashboardClient.tsx
@@ -1,11 +1,8 @@
"use client";
import { useState, useEffect } from "react";
-import {
- DateRange,
- getUsersCreatedInRange,
- getPaidUsersStatsInRange,
-} from "./actions";
+import { getUsersCreatedInRange, getPaidUsersStatsInRange } from "./actions";
+import { DateRange } from "./dateRangeUtils";
import UserLookup from "./UserLookup";
type Stats = {
diff --git a/apps/web/app/(org)/dashboard/admin/actions.ts b/apps/web/app/(org)/dashboard/admin/actions.ts
index 00f19fa2b..c9890ec7e 100644
--- a/apps/web/app/(org)/dashboard/admin/actions.ts
+++ b/apps/web/app/(org)/dashboard/admin/actions.ts
@@ -5,47 +5,7 @@ import { getCurrentUser } from "@cap/database/auth/session";
import { users, videos } from "@cap/database/schema";
import { eq, gte, and, sql, isNotNull, or, lte } from "drizzle-orm";
import { stripe } from "@cap/utils";
-
-export type DateRange = "today" | "yesterday" | "last7days" | "thisMonth" | "allTime";
-
-export function getDateRangeFilter(range: DateRange): { start: Date; end: Date } {
- const now = new Date();
- const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
-
- switch (range) {
- case "today":
- return {
- start: today,
- end: new Date(today.getTime() + 24 * 60 * 60 * 1000)
- };
- case "yesterday":
- const yesterday = new Date(today);
- yesterday.setDate(yesterday.getDate() - 1);
- return {
- start: yesterday,
- end: today
- };
- case "last7days":
- const last7Days = new Date(today);
- last7Days.setDate(last7Days.getDate() - 7);
- return {
- start: last7Days,
- end: new Date(today.getTime() + 24 * 60 * 60 * 1000)
- };
- case "thisMonth":
- const monthStart = new Date(now.getFullYear(), now.getMonth(), 1);
- const monthEnd = new Date(now.getFullYear(), now.getMonth() + 1, 1);
- return {
- start: monthStart,
- end: monthEnd
- };
- case "allTime":
- return {
- start: new Date(0),
- end: new Date()
- };
- }
-}
+import { DateRange, getDateRangeFilter } from "./dateRangeUtils";
export async function lookupUserById(data: FormData) {
const currentUser = await getCurrentUser();
diff --git a/apps/web/app/(org)/dashboard/admin/dateRangeUtils.ts b/apps/web/app/(org)/dashboard/admin/dateRangeUtils.ts
new file mode 100644
index 000000000..a9cba2ac0
--- /dev/null
+++ b/apps/web/app/(org)/dashboard/admin/dateRangeUtils.ts
@@ -0,0 +1,40 @@
+export type DateRange = "today" | "yesterday" | "last7days" | "thisMonth" | "allTime";
+
+export function getDateRangeFilter(range: DateRange): { start: Date; end: Date } {
+ const now = new Date();
+ const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
+
+ switch (range) {
+ case "today":
+ return {
+ start: today,
+ end: new Date(today.getTime() + 24 * 60 * 60 * 1000)
+ };
+ case "yesterday":
+ const yesterday = new Date(today);
+ yesterday.setDate(yesterday.getDate() - 1);
+ return {
+ start: yesterday,
+ end: today
+ };
+ case "last7days":
+ const last7Days = new Date(today);
+ last7Days.setDate(last7Days.getDate() - 7);
+ return {
+ start: last7Days,
+ end: new Date(today.getTime() + 24 * 60 * 60 * 1000)
+ };
+ case "thisMonth":
+ const monthStart = new Date(now.getFullYear(), now.getMonth(), 1);
+ const monthEnd = new Date(now.getFullYear(), now.getMonth() + 1, 1);
+ return {
+ start: monthStart,
+ end: monthEnd
+ };
+ case "allTime":
+ return {
+ start: new Date(0),
+ end: new Date()
+ };
+ }
+}
\ No newline at end of file