mirror of
https://github.com/kjanat/livedash-node.git
synced 2026-01-16 13:52:16 +01:00
Update dashboard metrics and session handling
- Refactor DashboardContent to improve trend calculations for user metrics and session time. - Modify SessionViewPage to ensure loading state is set before fetching session data. - Adjust SessionsPage to clean up display of session start time and remove unnecessary comments. - Enhance DonutChart to handle various data point types and improve percentage calculations. - Update GeographicMap to utilize @rapideditor/country-coder for country coordinates. - Improve safeParseDate function in csvFetcher for better date handling and error logging. - Refactor sessionMetrics to clarify variable names and improve session duration calculations. - Update next.config.js for better configuration clarity. - Bump package version to 0.2.0 and update dependencies in package.json and package-lock.json. - Clean up API handler for dashboard sessions to improve readability and maintainability. - Adjust tsconfig.json for better module resolution and strict type checking.
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { useSession } from "next-auth/react";
|
||||
import { Company } from "../../lib/types";
|
||||
import { Company } from "../../../lib/types";
|
||||
|
||||
export default function CompanySettingsPage() {
|
||||
const { data: session, status } = useSession();
|
||||
|
||||
@ -276,15 +276,15 @@ function DashboardContent() {
|
||||
trend={{
|
||||
value: metrics.usersTrend ?? 0,
|
||||
label:
|
||||
metrics.usersTrend > 0
|
||||
(metrics.usersTrend ?? 0) > 0
|
||||
? `${metrics.usersTrend}% increase`
|
||||
: `${Math.abs(metrics.usersTrend || 0)}% decrease`,
|
||||
isPositive: metrics.usersTrend >= 0,
|
||||
: `${Math.abs(metrics.usersTrend ?? 0)}% decrease`,
|
||||
isPositive: (metrics.usersTrend ?? 0) >= 0,
|
||||
}}
|
||||
/>
|
||||
<MetricCard
|
||||
title="Avg. Session Time"
|
||||
value={`${Math.round(metrics.avgSessionTime || 0)}m`}
|
||||
value={`${Math.round(metrics.avgSessionTimeTrend || 0)}m`}
|
||||
icon={
|
||||
<svg
|
||||
className="h-5 w-5"
|
||||
@ -302,12 +302,12 @@ function DashboardContent() {
|
||||
</svg>
|
||||
}
|
||||
trend={{
|
||||
value: metrics.sessionTimeTrend ?? 0,
|
||||
value: metrics.avgSessionTimeTrend ?? 0,
|
||||
label:
|
||||
metrics.sessionTimeTrend > 0
|
||||
? `${metrics.sessionTimeTrend}% increase`
|
||||
: `${Math.abs(metrics.sessionTimeTrend || 0)}% decrease`,
|
||||
isPositive: metrics.sessionTimeTrend >= 0,
|
||||
(metrics.avgSessionTimeTrend ?? 0) > 0
|
||||
? `${metrics.avgSessionTimeTrend}% increase`
|
||||
: `${Math.abs(metrics.avgSessionTimeTrend ?? 0)}% decrease`,
|
||||
isPositive: (metrics.avgSessionTimeTrend ?? 0) >= 0,
|
||||
}}
|
||||
/>
|
||||
<MetricCard
|
||||
|
||||
@ -25,7 +25,7 @@ export default function SessionViewPage() {
|
||||
|
||||
if (status === "authenticated" && id) {
|
||||
const fetchSession = async () => {
|
||||
if (!session) setLoading(true);
|
||||
setLoading(true); // Always set loading before fetch
|
||||
setError(null);
|
||||
try {
|
||||
const response = await fetch(`/api/dashboard/session/${id}`);
|
||||
@ -52,7 +52,7 @@ export default function SessionViewPage() {
|
||||
setError("Session ID is missing.");
|
||||
setLoading(false);
|
||||
}
|
||||
}, [id, status, router, session]);
|
||||
}, [id, status, router]); // session removed from dependencies
|
||||
|
||||
if (status === "loading") {
|
||||
return (
|
||||
|
||||
@ -283,12 +283,12 @@ export default function SessionsPage() {
|
||||
Session ID: {session.sessionId || session.id}
|
||||
</h2>
|
||||
<p className="text-sm text-gray-500 mb-1">
|
||||
Start Time (Local):{" "}
|
||||
Start Time{/* (Local) */}:{" "}
|
||||
{new Date(session.startTime).toLocaleString()}
|
||||
</p>
|
||||
<p className="text-xs text-gray-400 mb-1">
|
||||
{/* <p className="text-xs text-gray-400 mb-1">
|
||||
Start Time (Raw API): {session.startTime.toString()}
|
||||
</p>
|
||||
</p> */}
|
||||
{session.category && (
|
||||
<p className="text-sm text-gray-700">
|
||||
Category:{" "}
|
||||
|
||||
Reference in New Issue
Block a user