Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

Add top activities card

Khuram Niazb4f957542b37
diff --git a/src/actions/dashboard.actions.ts b/src/actions/dashboard.actions.ts
index 834af4e..f5fa173 100644
--- a/src/actions/dashboard.actions.ts
+++ b/src/actions/dashboard.actions.ts
@@ -217,6 +217,82 @@ export const getJobsActivityForPeriod = async (): Promise<any | undefined> => {
}
};
+export interface TopActivityType {
+ label: string;
+ hours: number;
+}
+
+export const getTopActivityTypesByDuration = async (
+ daysAgo: number,
+): Promise<TopActivityType[]> => {
+ const user = await getCurrentUser();
+
+ if (!user) {
+ throw new Error("Not authenticated");
+ }
+
+ try {
+ const now = new Date();
+ const today = new Date(
+ now.getFullYear(),
+ now.getMonth(),
+ now.getDate(),
+ 23,
+ 59,
+ 59,
+ 999,
+ );
+ const startDate = new Date(
+ now.getFullYear(),
+ now.getMonth(),
+ now.getDate() - daysAgo + 1,
+ 0,
+ 0,
+ 0,
+ 0,
+ );
+
+ const activities = await prisma.activity.findMany({
+ where: {
+ userId: user.id,
+ endTime: {
+ gte: startDate,
+ lte: today,
+ },
+ },
+ select: {
+ duration: true,
+ activityType: {
+ select: {
+ label: true,
+ },
+ },
+ },
+ });
+
+ const groupedByType = activities.reduce(
+ (acc: Record<string, number>, activity) => {
+ const label = activity.activityType?.label || "Unknown";
+ const durationInHours = (activity.duration || 0) / 60;
+ acc[label] = (acc[label] || 0) + durationInHours;
+ return acc;
+ },
+ {},
+ );
+
+ const sorted = Object.entries(groupedByType)
+ .map(([label, hours]) => ({ label, hours: Math.round(hours * 10) / 10 }))
+ .sort((a, b) => b.hours - a.hours)
+ .slice(0, 3);
+
+ return sorted;
+ } catch (error) {
+ const msg = "Failed to fetch top activity types";
+ console.error(msg, error);
+ throw new Error(msg);
+ }
+};
+
export const getActivityCalendarData = async (): Promise<any | undefined> => {
try {
const user = await getCurrentUser();
diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx
index 42ff1be..0361fec 100644
--- a/src/app/dashboard/page.tsx
+++ b/src/app/dashboard/page.tsx
@@ -4,11 +4,13 @@ import {
getJobsActivityForPeriod,
getJobsAppliedForPeriod,
getRecentJobs,
+ getTopActivityTypesByDuration,
} from "@/actions/dashboard.actions";
import ActivityCalendar from "@/components/dashboard/ActivityCalendar";
import JobsApplied from "@/components/dashboard/JobsAppliedCard";
import NumberCardToggle from "@/components/dashboard/NumberCardToggle";
import RecentJobsCard from "@/components/dashboard/RecentJobsCard";
+import TopActivitiesCard from "@/components/dashboard/TopActivitiesCard";
import WeeklyBarChartToggle from "@/components/dashboard/WeeklyBarChartToggle";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
@@ -26,6 +28,8 @@ export default async function Dashboard() {
weeklyData,
activitiesData,
activityCalendarData,
+ topActivities7Days,
+ topActivities30Days,
] = await Promise.all([
getJobsAppliedForPeriod(7),
getJobsAppliedForPeriod(30),
@@ -33,6 +37,8 @@ export default async function Dashboard() {
getJobsActivityForPeriod(),
getActivityDataForPeriod(),
getActivityCalendarData(),
+ getTopActivityTypesByDuration(7),
+ getTopActivityTypesByDuration(30),
]);
const activityCalendarDataKeys = Object.keys(activityCalendarData);
const activitiesDataKeys = (data: string[]) =>
@@ -62,6 +68,12 @@ export default async function Dashboard() {
},
]}
/>
+ <TopActivitiesCard
+ data={[
+ { label: "Last 7 days", activities: topActivities7Days },
+ { label: "Last 30 days", activities: topActivities30Days },
+ ]}
+ />
</div>
<WeeklyBarChartToggle
charts={[
diff --git a/src/components/dashboard/TopActivitiesCard.tsx b/src/components/dashboard/TopActivitiesCard.tsx
new file mode 100644
index 0000000..257d2d2
--- /dev/null
+++ b/src/components/dashboard/TopActivitiesCard.tsx
@@ -0,0 +1,67 @@
+"use client";
+
+import { useState } from "react";
+import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
+import { cn } from "@/lib/utils";
+import { TopActivityType } from "@/actions/dashboard.actions";
+
+interface TopActivitiesCardProps {
+ data: {
+ label: string;
+ activities: TopActivityType[];
+ }[];
+}
+
+export default function TopActivitiesCard({ data }: TopActivitiesCardProps) {
+ const [activeIndex, setActiveIndex] = useState(0);
+ const current = data[activeIndex];
+
+ return (
+ <Card>
+ <CardHeader className="pb-2">
+ <div className="flex items-center justify-between">
+ <CardTitle className="text-sm font-medium">Top Activities</CardTitle>
+ <div className="flex rounded-md border text-xs">
+ {data.map((item, index) => (
+ <button
+ key={item.label}
+ onClick={() => setActiveIndex(index)}
+ className={cn(
+ "px-2 py-1 transition-colors",
+ index === 0 && "rounded-l-md",
+ index === data.length - 1 && "rounded-r-md",
+ activeIndex === index
+ ? "bg-primary text-primary-foreground"
+ : "hover:bg-muted",
+ )}
+ >
+ {item.label.replace("Last ", "")}
+ </button>
+ ))}
+ </div>
+ </div>
+ </CardHeader>
+ <CardContent>
+ {current.activities.length === 0 ? (
+ <p className="text-sm text-muted-foreground">No activities recorded</p>
+ ) : (
+ <div className="space-y-3">
+ {current.activities.map((activity, index) => (
+ <div key={activity.label} className="flex items-center gap-3">
+ <span className="text-lg font-semibold text-muted-foreground w-5">
+ {index + 1}
+ </span>
+ <div className="flex-1 min-w-0">
+ <p className="text-sm font-medium truncate">{activity.label}</p>
+ </div>
+ <span className="text-sm font-semibold tabular-nums">
+ {activity.hours}h
+ </span>
+ </div>
+ ))}
+ </div>
+ )}
+ </CardContent>
+ </Card>
+ );
+}