mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-28 15:56:39 +00:00
♻️ set default start time to 7 days ago
This commit is contained in:
@@ -10,14 +10,7 @@ import HttpCode from "@server/types/HttpCode";
|
|||||||
import { fromError } from "zod-validation-error";
|
import { fromError } from "zod-validation-error";
|
||||||
import response from "@server/lib/response";
|
import response from "@server/lib/response";
|
||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
|
import { getSevenDaysAgo } from "@app/lib/getSevenDaysAgo";
|
||||||
function getSevenDaysAgo() {
|
|
||||||
const today = new Date();
|
|
||||||
today.setHours(0, 0, 0, 0); // Set to midnight
|
|
||||||
const sevenDaysAgo = new Date(today);
|
|
||||||
sevenDaysAgo.setDate(today.getDate() - 7);
|
|
||||||
return sevenDaysAgo.toISOString();
|
|
||||||
}
|
|
||||||
|
|
||||||
const queryAccessAuditLogsQuery = z.object({
|
const queryAccessAuditLogsQuery = z.object({
|
||||||
// iso string just validate its a parseable date
|
// iso string just validate its a parseable date
|
||||||
@@ -28,7 +21,7 @@ const queryAccessAuditLogsQuery = z.object({
|
|||||||
})
|
})
|
||||||
.transform((val) => Math.floor(new Date(val).getTime() / 1000))
|
.transform((val) => Math.floor(new Date(val).getTime() / 1000))
|
||||||
.optional()
|
.optional()
|
||||||
.prefault(getSevenDaysAgo),
|
.prefault(() => getSevenDaysAgo().toISOString()),
|
||||||
timeEnd: z
|
timeEnd: z
|
||||||
.string()
|
.string()
|
||||||
.refine((val) => !isNaN(Date.parse(val)), {
|
.refine((val) => !isNaN(Date.parse(val)), {
|
||||||
|
|||||||
@@ -21,14 +21,13 @@ import { useSubscriptionStatusContext } from "@app/hooks/useSubscriptionStatusCo
|
|||||||
import { useLicenseStatusContext } from "@app/hooks/useLicenseStatusContext";
|
import { useLicenseStatusContext } from "@app/hooks/useLicenseStatusContext";
|
||||||
import { build } from "@server/build";
|
import { build } from "@server/build";
|
||||||
import { Alert, AlertDescription } from "@app/components/ui/alert";
|
import { Alert, AlertDescription } from "@app/components/ui/alert";
|
||||||
|
import { getSevenDaysAgo } from "@app/lib/getSevenDaysAgo";
|
||||||
|
|
||||||
export default function GeneralPage() {
|
export default function GeneralPage() {
|
||||||
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
const api = createApiClient(useEnvContext());
|
const api = createApiClient(useEnvContext());
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
const { env } = useEnvContext();
|
|
||||||
const { orgId } = useParams();
|
const { orgId } = useParams();
|
||||||
const subscription = useSubscriptionStatusContext();
|
const subscription = useSubscriptionStatusContext();
|
||||||
const { isUnlocked } = useLicenseStatusContext();
|
const { isUnlocked } = useLicenseStatusContext();
|
||||||
@@ -91,11 +90,11 @@ export default function GeneralPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const yesterday = new Date(now.getTime() - 24 * 60 * 60 * 1000);
|
const lastWeek = getSevenDaysAgo();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
startDate: {
|
startDate: {
|
||||||
date: yesterday
|
date: lastWeek
|
||||||
},
|
},
|
||||||
endDate: {
|
endDate: {
|
||||||
date: now
|
date: now
|
||||||
|
|||||||
@@ -1,32 +1,30 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { Button } from "@app/components/ui/button";
|
import { ColumnFilter } from "@app/components/ColumnFilter";
|
||||||
import { toast } from "@app/hooks/useToast";
|
import { DateTimeValue } from "@app/components/DateTimePicker";
|
||||||
import { useState, useRef, useEffect } from "react";
|
|
||||||
import { createApiClient } from "@app/lib/api";
|
|
||||||
import { useEnvContext } from "@app/hooks/useEnvContext";
|
|
||||||
import { useParams, useRouter, useSearchParams } from "next/navigation";
|
|
||||||
import { useTranslations } from "next-intl";
|
|
||||||
import {
|
import {
|
||||||
getStoredPageSize,
|
getStoredPageSize,
|
||||||
LogDataTable,
|
LogDataTable,
|
||||||
setStoredPageSize
|
setStoredPageSize
|
||||||
} from "@app/components/LogDataTable";
|
} from "@app/components/LogDataTable";
|
||||||
import { ColumnDef } from "@tanstack/react-table";
|
|
||||||
import { DateTimeValue } from "@app/components/DateTimePicker";
|
|
||||||
import { Key, User } from "lucide-react";
|
|
||||||
import { ColumnFilter } from "@app/components/ColumnFilter";
|
|
||||||
import SettingsSectionTitle from "@app/components/SettingsSectionTitle";
|
import SettingsSectionTitle from "@app/components/SettingsSectionTitle";
|
||||||
import { useSubscriptionStatusContext } from "@app/hooks/useSubscriptionStatusContext";
|
|
||||||
import { useLicenseStatusContext } from "@app/hooks/useLicenseStatusContext";
|
|
||||||
import { build } from "@server/build";
|
|
||||||
import { Alert, AlertDescription } from "@app/components/ui/alert";
|
import { Alert, AlertDescription } from "@app/components/ui/alert";
|
||||||
|
import { useEnvContext } from "@app/hooks/useEnvContext";
|
||||||
|
import { useLicenseStatusContext } from "@app/hooks/useLicenseStatusContext";
|
||||||
|
import { useSubscriptionStatusContext } from "@app/hooks/useSubscriptionStatusContext";
|
||||||
|
import { toast } from "@app/hooks/useToast";
|
||||||
|
import { createApiClient } from "@app/lib/api";
|
||||||
|
import { getSevenDaysAgo } from "@app/lib/getSevenDaysAgo";
|
||||||
|
import { build } from "@server/build";
|
||||||
|
import { ColumnDef } from "@tanstack/react-table";
|
||||||
|
import { Key, User } from "lucide-react";
|
||||||
|
import { useTranslations } from "next-intl";
|
||||||
|
import { useParams, useRouter, useSearchParams } from "next/navigation";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
export default function GeneralPage() {
|
export default function GeneralPage() {
|
||||||
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const api = createApiClient(useEnvContext());
|
const api = createApiClient(useEnvContext());
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
const { env } = useEnvContext();
|
|
||||||
const { orgId } = useParams();
|
const { orgId } = useParams();
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
const subscription = useSubscriptionStatusContext();
|
const subscription = useSubscriptionStatusContext();
|
||||||
@@ -79,11 +77,11 @@ export default function GeneralPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const yesterday = new Date(now.getTime() - 24 * 60 * 60 * 1000);
|
const lastWeek = getSevenDaysAgo();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
startDate: {
|
startDate: {
|
||||||
date: yesterday
|
date: lastWeek
|
||||||
},
|
},
|
||||||
endDate: {
|
endDate: {
|
||||||
date: now
|
date: now
|
||||||
|
|||||||
@@ -1,24 +1,28 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { Button } from "@app/components/ui/button";
|
|
||||||
import { toast } from "@app/hooks/useToast";
|
|
||||||
import { useState, useRef, useEffect } from "react";
|
|
||||||
import { createApiClient } from "@app/lib/api";
|
|
||||||
import { useEnvContext } from "@app/hooks/useEnvContext";
|
|
||||||
import { useParams, useRouter, useSearchParams } from "next/navigation";
|
|
||||||
import { useTranslations } from "next-intl";
|
|
||||||
import { getStoredPageSize, LogDataTable, setStoredPageSize } from "@app/components/LogDataTable";
|
|
||||||
import { ColumnDef } from "@tanstack/react-table";
|
|
||||||
import { DateTimeValue } from "@app/components/DateTimePicker";
|
|
||||||
import { Key, RouteOff, User, Lock, Unlock, ArrowUpRight } from "lucide-react";
|
|
||||||
import Link from "next/link";
|
|
||||||
import { ColumnFilter } from "@app/components/ColumnFilter";
|
import { ColumnFilter } from "@app/components/ColumnFilter";
|
||||||
|
import { DateTimeValue } from "@app/components/DateTimePicker";
|
||||||
|
import {
|
||||||
|
getStoredPageSize,
|
||||||
|
LogDataTable,
|
||||||
|
setStoredPageSize
|
||||||
|
} from "@app/components/LogDataTable";
|
||||||
import SettingsSectionTitle from "@app/components/SettingsSectionTitle";
|
import SettingsSectionTitle from "@app/components/SettingsSectionTitle";
|
||||||
|
import { Button } from "@app/components/ui/button";
|
||||||
|
import { useEnvContext } from "@app/hooks/useEnvContext";
|
||||||
|
import { toast } from "@app/hooks/useToast";
|
||||||
|
import { createApiClient } from "@app/lib/api";
|
||||||
|
import { getSevenDaysAgo } from "@app/lib/getSevenDaysAgo";
|
||||||
|
import { ColumnDef } from "@tanstack/react-table";
|
||||||
|
import { ArrowUpRight, Key, Lock, Unlock, User } from "lucide-react";
|
||||||
|
import { useTranslations } from "next-intl";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { useParams, useRouter, useSearchParams } from "next/navigation";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
export default function GeneralPage() {
|
export default function GeneralPage() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const api = createApiClient(useEnvContext());
|
const api = createApiClient(useEnvContext());
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
const { env } = useEnvContext();
|
|
||||||
const { orgId } = useParams();
|
const { orgId } = useParams();
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
|
|
||||||
@@ -91,11 +95,11 @@ export default function GeneralPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const yesterday = new Date(now.getTime() - 24 * 60 * 60 * 1000);
|
const lastWeek = getSevenDaysAgo();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
startDate: {
|
startDate: {
|
||||||
date: yesterday
|
date: lastWeek
|
||||||
},
|
},
|
||||||
endDate: {
|
endDate: {
|
||||||
date: now
|
date: now
|
||||||
@@ -757,8 +761,8 @@ export default function GeneralPage() {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<SettingsSectionTitle
|
<SettingsSectionTitle
|
||||||
title={t('requestLogs')}
|
title={t("requestLogs")}
|
||||||
description={t('requestLogsDescription')}
|
description={t("requestLogsDescription")}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<LogDataTable
|
<LogDataTable
|
||||||
|
|||||||
@@ -47,19 +47,12 @@ import {
|
|||||||
TooltipProvider,
|
TooltipProvider,
|
||||||
TooltipTrigger
|
TooltipTrigger
|
||||||
} from "./ui/tooltip";
|
} from "./ui/tooltip";
|
||||||
|
import { getSevenDaysAgo } from "@app/lib/getSevenDaysAgo";
|
||||||
|
|
||||||
export type AnalyticsContentProps = {
|
export type AnalyticsContentProps = {
|
||||||
orgId: string;
|
orgId: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
function getSevenDaysAgo() {
|
|
||||||
const today = new Date();
|
|
||||||
today.setHours(0, 0, 0, 0); // Set to midnight
|
|
||||||
const sevenDaysAgo = new Date(today);
|
|
||||||
sevenDaysAgo.setDate(today.getDate() - 7);
|
|
||||||
return sevenDaysAgo;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function LogAnalyticsData(props: AnalyticsContentProps) {
|
export function LogAnalyticsData(props: AnalyticsContentProps) {
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
const path = usePathname();
|
const path = usePathname();
|
||||||
|
|||||||
7
src/lib/getSevenDaysAgo.ts
Normal file
7
src/lib/getSevenDaysAgo.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
export function getSevenDaysAgo() {
|
||||||
|
const today = new Date();
|
||||||
|
today.setHours(0, 0, 0, 0); // Set to midnight
|
||||||
|
const sevenDaysAgo = new Date(today);
|
||||||
|
sevenDaysAgo.setDate(today.getDate() - 7);
|
||||||
|
return sevenDaysAgo;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user