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 recent activites card

Khuram Niaz6ba2380bcdf5
diff --git a/src/actions/dashboard.actions.ts b/src/actions/dashboard.actions.ts
index f5fa173..8056015 100644
--- a/src/actions/dashboard.actions.ts
+++ b/src/actions/dashboard.actions.ts
@@ -293,6 +293,34 @@ export const getTopActivityTypesByDuration = async (
}
};
+export const getRecentActivities = async () => {
+ try {
+ const user = await getCurrentUser();
+
+ if (!user) {
+ throw new Error("Not authenticated");
+ }
+ const list = await prisma.activity.findMany({
+ where: {
+ userId: user.id,
+ endTime: { not: null },
+ },
+ include: {
+ activityType: true,
+ },
+ orderBy: {
+ endTime: "desc",
+ },
+ take: 6,
+ });
+ return list;
+ } catch (error) {
+ const msg = "Failed to fetch recent activities.";
+ 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 a71a355..805772f 100644
--- a/src/app/dashboard/page.tsx
+++ b/src/app/dashboard/page.tsx
@@ -3,13 +3,14 @@ import {
getActivityDataForPeriod,
getJobsActivityForPeriod,
getJobsAppliedForPeriod,
+ getRecentActivities,
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 RecentCardToggle from "@/components/dashboard/RecentCardToggle";
import TopActivitiesCard from "@/components/dashboard/TopActivitiesCard";
import WeeklyBarChartToggle from "@/components/dashboard/WeeklyBarChartToggle";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
@@ -25,6 +26,7 @@ export default async function Dashboard() {
{ count: jobsAppliedLast7Days, trend: trendFor7Days },
{ count: jobsAppliedLast30Days, trend: trendFor30Days },
recentJobs,
+ recentActivities,
weeklyData,
activitiesData,
activityCalendarData,
@@ -34,6 +36,7 @@ export default async function Dashboard() {
getJobsAppliedForPeriod(7),
getJobsAppliedForPeriod(30),
getRecentJobs(),
+ getRecentActivities(),
getJobsActivityForPeriod(),
getActivityDataForPeriod(),
getActivityCalendarData(),
@@ -94,7 +97,7 @@ export default async function Dashboard() {
/>
</div>
<div>
- <RecentJobsCard jobs={recentJobs} />
+ <RecentCardToggle jobs={recentJobs} activities={recentActivities} />
</div>
<div className="w-full col-span-3">
<Tabs defaultValue={activityCalendarDataKeys.at(-1)}>
diff --git a/src/components/dashboard/RecentCardToggle.tsx b/src/components/dashboard/RecentCardToggle.tsx
new file mode 100644
index 0000000..e1e858b
--- /dev/null
+++ b/src/components/dashboard/RecentCardToggle.tsx
@@ -0,0 +1,114 @@
+"use client";
+
+import { useState } from "react";
+import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
+import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
+import { cn } from "@/lib/utils";
+import { JobResponse } from "@/models/job.model";
+import { format } from "date-fns";
+import Link from "next/link";
+
+type RecentActivity = {
+ id: string;
+ activityName: string;
+ duration: number | null;
+ endTime: Date | null;
+ activityType: { label: string } | null;
+};
+
+interface RecentCardToggleProps {
+ jobs: JobResponse[];
+ activities: RecentActivity[];
+}
+
+function formatDuration(totalMinutes: number) {
+ const hours = Math.floor(totalMinutes / 60);
+ const minutes = totalMinutes % 60;
+ return totalMinutes === 0 ? "0min" : `${hours}h ${minutes}min`;
+}
+
+const tabs = ["Jobs", "Activities"] as const;
+
+export default function RecentCardToggle({
+ jobs,
+ activities,
+}: RecentCardToggleProps) {
+ const [activeIndex, setActiveIndex] = useState(0);
+
+ return (
+ <Card className="mb-2">
+ <CardHeader>
+ <div className="flex items-center justify-between">
+ <CardTitle className="text-green-600">
+ Recent {tabs[activeIndex]}
+ </CardTitle>
+ <div className="flex rounded-md border text-xs">
+ {tabs.map((tab, index) => (
+ <button
+ key={tab}
+ onClick={() => setActiveIndex(index)}
+ className={cn(
+ "px-2 py-1 transition-colors",
+ index === 0 && "rounded-l-md",
+ index === tabs.length - 1 && "rounded-r-md",
+ activeIndex === index
+ ? "bg-primary text-primary-foreground"
+ : "hover:bg-muted",
+ )}
+ >
+ {tab}
+ </button>
+ ))}
+ </div>
+ </div>
+ </CardHeader>
+ <CardContent className="grid gap-6">
+ {activeIndex === 0
+ ? jobs.map((job) => (
+ <div key={job.id} className="flex items-center gap-4">
+ <Avatar className="hidden h-8 w-8 sm:flex">
+ <AvatarImage
+ src={job.Company?.logoUrl || "/images/jobsync-logo.svg"}
+ alt="Avatar"
+ />
+ <AvatarFallback>JS</AvatarFallback>
+ </Avatar>
+ <Link href={`/dashboard/myjobs/${job?.id}`}>
+ <div className="grid gap-1">
+ <p className="text-sm font-medium leading-none">
+ {job.JobTitle?.label}
+ </p>
+ <p className="text-sm text-muted-foreground">
+ {job.Company?.label}
+ </p>
+ </div>
+ </Link>
+ <div className="ml-auto text-sm font-medium">
+ {format(job?.appliedDate, "PP")}
+ </div>
+ </div>
+ ))
+ : activities.map((activity) => (
+ <div key={activity.id} className="flex items-center gap-4">
+ <div className="grid gap-1 min-w-0 flex-1">
+ <p className="text-sm font-medium leading-none truncate">
+ {activity.activityName}
+ </p>
+ <p className="text-sm text-muted-foreground">
+ {activity.activityType?.label || "Unknown"}
+ </p>
+ </div>
+ <div className="ml-auto text-right shrink-0">
+ <p className="text-sm font-medium">
+ {formatDuration(activity.duration ?? 0)}
+ </p>
+ <p className="text-xs text-muted-foreground">
+ {activity.endTime ? format(activity.endTime, "PP") : ""}
+ </p>
+ </div>
+ </div>
+ ))}
+ </CardContent>
+ </Card>
+ );
+}