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.

feat(dashboard): add daily goals calendar above the recent card

Khuram Niazcab3dea2669c
diff --git a/__tests__/DailyGoalsCalendar.spec.tsx b/__tests__/DailyGoalsCalendar.spec.tsx
new file mode 100644
index 0000000..f9c3a8c
--- /dev/null
+++ b/__tests__/DailyGoalsCalendar.spec.tsx
@@ -0,0 +1,112 @@
+import { act, render, screen, waitFor } from "@testing-library/react";
+import userEvent from "@testing-library/user-event";
+import DailyGoalsCalendar from "@/components/dashboard/DailyGoalsCalendar";
+import { getDailyGoalValues } from "@/actions/dailyGoals.actions";
+import { toastError } from "@/lib/toast";
+
+vi.mock("@/actions/dailyGoals.actions", () => ({
+ getDailyGoalValues: vi.fn(),
+}));
+
+vi.mock("@/lib/toast", () => ({
+ toastError: vi.fn(),
+}));
+
+const deferred = <T,>() => {
+ let resolve!: (v: T) => void;
+ const promise = new Promise<T>((r) => (resolve = r));
+ return { promise, resolve };
+};
+
+describe("DailyGoalsCalendar", () => {
+ const user = userEvent.setup();
+ const today = "2026-10-05";
+
+ const renderCalendar = () =>
+ render(
+ <DailyGoalsCalendar
+ today={today}
+ initialValues={{ "2026-10-01": { jobs: 3, hours: 2.5 } }}
+ />,
+ );
+
+ const root = () => screen.getByRole("status").closest(".daily-goals-calendar")!;
+
+ it("shows the current month from the initial values without fetching", () => {
+ renderCalendar();
+ expect(screen.getByRole("status")).toHaveTextContent("Oct 2026");
+ expect(
+ screen.getByText(/October 1: Jobs applied 3 of 5, Activity 2\.5 of 4 h/),
+ ).toBeInTheDocument();
+ expect(getDailyGoalValues).not.toHaveBeenCalled();
+ });
+
+ it("shows a legend naming both rings and their targets", () => {
+ renderCalendar();
+ expect(screen.getByText("Jobs applied")).toBeInTheDocument();
+ expect(screen.getByText("Activity")).toBeInTheDocument();
+ expect(screen.getByText("4 h")).toBeInTheDocument();
+ });
+
+ it("cannot navigate into future months", () => {
+ renderCalendar();
+ expect(screen.getByRole("button", { name: "Next month" })).toHaveAttribute(
+ "aria-disabled",
+ "true",
+ );
+ });
+
+ it("fetches a month on first visit and caches it", async () => {
+ (getDailyGoalValues as any).mockResolvedValue({
+ success: true,
+ data: { "2026-09-10": { jobs: 5, hours: 4 } },
+ });
+ renderCalendar();
+
+ await user.click(screen.getByRole("button", { name: "Previous month" }));
+ expect(getDailyGoalValues).toHaveBeenCalledWith("2026-09");
+ expect(
+ await screen.findByText(/September 10: Jobs applied 5 of 5, Activity 4 of 4 h\. All goals met\./),
+ ).toBeInTheDocument();
+ expect(root()).not.toHaveAttribute("aria-busy");
+
+ await user.click(screen.getByRole("button", { name: "Next month" }));
+ await user.click(screen.getByRole("button", { name: "Previous month" }));
+ expect(getDailyGoalValues).toHaveBeenCalledTimes(1);
+ });
+
+ it("keeps the busy state for the month on screen", async () => {
+ const sep = deferred<any>();
+ const aug = deferred<any>();
+ (getDailyGoalValues as any)
+ .mockReturnValueOnce(sep.promise)
+ .mockReturnValueOnce(aug.promise);
+ renderCalendar();
+
+ await user.click(screen.getByRole("button", { name: "Previous month" }));
+ await user.click(screen.getByRole("button", { name: "Previous month" }));
+ expect(root()).toHaveAttribute("aria-busy", "true");
+
+ // September settles while August is on screen: the dim must stay
+ await act(async () => sep.resolve({ success: true, data: {} }));
+ expect(root()).toHaveAttribute("aria-busy", "true");
+
+ await act(async () => aug.resolve({ success: true, data: {} }));
+ expect(root()).not.toHaveAttribute("aria-busy");
+ });
+
+ it("toasts a failed month and retries on the next visit", async () => {
+ (getDailyGoalValues as any)
+ .mockResolvedValueOnce({ success: false, message: "Boom" })
+ .mockResolvedValueOnce({ success: true, data: {} });
+ renderCalendar();
+
+ await user.click(screen.getByRole("button", { name: "Previous month" }));
+ await waitFor(() => expect(toastError).toHaveBeenCalledWith("Boom"));
+ expect(root()).not.toHaveAttribute("aria-busy");
+
+ await user.click(screen.getByRole("button", { name: "Next month" }));
+ await user.click(screen.getByRole("button", { name: "Previous month" }));
+ expect(getDailyGoalValues).toHaveBeenCalledTimes(2);
+ });
+});
diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx
index 0697224..53eeea3 100644
--- a/src/app/dashboard/page.tsx
+++ b/src/app/dashboard/page.tsx
@@ -1,3 +1,4 @@
+import { format } from "date-fns";
import {
getActivityCalendarData,
getActivityDataForPeriod,
@@ -6,7 +7,9 @@ import {
getRecentActivities,
getRecentJobs,
} from "@/actions/dashboard.actions";
+import { getDailyGoalValues } from "@/actions/dailyGoals.actions";
import ActivityCalendar from "@/components/dashboard/ActivityCalendar";
+import DailyGoalsCalendar from "@/components/dashboard/DailyGoalsCalendar";
import JobsActivityCard from "@/components/dashboard/JobsActivityCard";
import JobsApplied from "@/components/dashboard/JobsAppliedCard";
import RecentCardToggle from "@/components/dashboard/RecentCardToggle";
@@ -19,6 +22,8 @@ export const metadata: Metadata = {
};
export default async function Dashboard() {
+ // Server-computed so server and browser agree on "today"
+ const today = format(new Date(), "yyyy-MM-dd");
const [
summary7Days,
summary30Days,
@@ -27,6 +32,7 @@ export default async function Dashboard() {
weeklyData,
activitiesData,
activityCalendarData,
+ dailyGoals,
] = await Promise.all([
getJobsActivitySummary(7),
getJobsActivitySummary(30),
@@ -35,6 +41,7 @@ export default async function Dashboard() {
getJobsActivityForPeriod(),
getActivityDataForPeriod(),
getActivityCalendarData(),
+ getDailyGoalValues(today.slice(0, 7)),
]);
const activityCalendarDataKeys = Object.keys(activityCalendarData);
return (
@@ -67,8 +74,14 @@ export default async function Dashboard() {
]}
/>
</div>
- <div className="@3xl/main:relative @3xl/main:self-stretch">
- <RecentCardToggle jobs={recentJobs} activities={recentActivities} />
+ <div className="flex flex-col gap-2 @3xl/main:self-stretch">
+ <DailyGoalsCalendar
+ today={today}
+ initialValues={dailyGoals.success ? dailyGoals.data : {}}
+ />
+ <div className="@3xl/main:relative @3xl/main:min-h-64 @3xl/main:flex-1">
+ <RecentCardToggle jobs={recentJobs} activities={recentActivities} />
+ </div>
</div>
<div className="w-full col-span-3">
<ActivityCalendar
diff --git a/src/components/dashboard/DailyGoalsCalendar.tsx b/src/components/dashboard/DailyGoalsCalendar.tsx
new file mode 100644
index 0000000..11e6da1
--- /dev/null
+++ b/src/components/dashboard/DailyGoalsCalendar.tsx
@@ -0,0 +1,71 @@
+"use client";
+
+import { useState } from "react";
+import { GcMonthCalendar, type GcGoal } from "react-goal-calendar";
+import { getDailyGoalValues } from "@/actions/dailyGoals.actions";
+import { Card } from "@/components/ui/card";
+import { DAILY_GOALS } from "@/lib/constants";
+import { GOAL_IDS, goalMonthRange, type GoalValues } from "@/lib/dailyGoals";
+import { toastError } from "@/lib/toast";
+import { cn } from "@/lib/utils";
+
+const GOALS: GcGoal[] = [
+ { id: GOAL_IDS.JOBS, label: "Jobs applied", target: DAILY_GOALS.JOBS_TARGET },
+ {
+ id: GOAL_IDS.HOURS,
+ label: "Activity",
+ target: DAILY_GOALS.HOURS_TARGET,
+ unit: "h",
+ },
+];
+
+interface DailyGoalsCalendarProps {
+ today: string;
+ initialValues: GoalValues;
+}
+
+export default function DailyGoalsCalendar({
+ today,
+ initialValues,
+}: DailyGoalsCalendarProps) {
+ const { minMonth, maxMonth } = goalMonthRange(today);
+ const [month, setMonth] = useState(maxMonth);
+ const [valuesByMonth, setValuesByMonth] = useState<
+ Record<string, GoalValues>
+ >({ [maxMonth]: initialValues });
+ const [loadingMonth, setLoadingMonth] = useState<string | null>(null);
+
+ const handleMonthChange = async (next: string) => {
+ setMonth(next);
+ if (valuesByMonth[next]) return;
+ setLoadingMonth(next);
+ const result = await getDailyGoalValues(next);
+ if (result.success) {
+ setValuesByMonth((prev) => ({ ...prev, [next]: result.data }));
+ } else {
+ toastError(result.message);
+ }
+ // A later navigation may already own the busy state
+ setLoadingMonth((current) => (current === next ? null : current));
+ };
+
+ const loading = loadingMonth === month;
+
+ return (
+ <Card
+ aria-busy={loading || undefined}
+ className={cn("daily-goals-calendar p-4", loading && "opacity-60")}
+ >
+ <GcMonthCalendar
+ goals={GOALS}
+ values={valuesByMonth[month]}
+ today={today}
+ month={month}
+ minMonth={minMonth}
+ maxMonth={maxMonth}
+ onMonthChange={handleMonthChange}
+ legend
+ />
+ </Card>
+ );
+}