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: Clickable number of jobs for job titles

Khuram Niazb19b7e8772ca
diff --git a/__tests__/JobsContainer.spec.tsx b/__tests__/JobsContainer.spec.tsx
index 5adbf80..efc57ec 100644
--- a/__tests__/JobsContainer.spec.tsx
+++ b/__tests__/JobsContainer.spec.tsx
@@ -322,7 +322,7 @@ describe("JobsContainer Search Functionality", () => {
});
await waitFor(() => {
- expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, "Amazon", undefined, undefined);
+ expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, "Amazon", undefined, undefined, undefined);
});
});
@@ -340,7 +340,7 @@ describe("JobsContainer Search Functionality", () => {
});
// Initial call should not have search parameter
- expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, undefined, undefined, undefined);
+ expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, undefined, undefined, undefined, undefined);
});
it("should trigger search when clearing search term after searching", async () => {
@@ -368,7 +368,7 @@ describe("JobsContainer Search Functionality", () => {
});
await waitFor(() => {
- expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, "Test", undefined, undefined);
+ expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, "Test", undefined, undefined, undefined);
});
// Clear the search input
@@ -382,7 +382,7 @@ describe("JobsContainer Search Functionality", () => {
// Should call with undefined when cleared after having searched
await waitFor(() => {
- expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, undefined, undefined, undefined);
+ expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, undefined, undefined, undefined, undefined);
});
});
});
@@ -414,7 +414,7 @@ describe("JobsContainer Search Functionality", () => {
});
await waitFor(() => {
- expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, "Developer", undefined, undefined);
+ expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, "Developer", undefined, undefined, undefined);
});
// Now change filter
@@ -429,7 +429,7 @@ describe("JobsContainer Search Functionality", () => {
});
await waitFor(() => {
- expect(getJobsList).toHaveBeenCalledWith(1, 25, "applied", "Developer", undefined, undefined);
+ expect(getJobsList).toHaveBeenCalledWith(1, 25, "applied", "Developer", undefined, undefined, undefined);
});
});
@@ -457,7 +457,7 @@ describe("JobsContainer Search Functionality", () => {
});
await waitFor(() => {
- expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, "Amazon", undefined, undefined);
+ expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, "Amazon", undefined, undefined, undefined);
});
// Change filter
@@ -473,7 +473,7 @@ describe("JobsContainer Search Functionality", () => {
// Search term should still be present
await waitFor(() => {
- expect(getJobsList).toHaveBeenCalledWith(1, 25, "interview", "Amazon", undefined, undefined);
+ expect(getJobsList).toHaveBeenCalledWith(1, 25, "interview", "Amazon", undefined, undefined, undefined);
});
});
@@ -512,7 +512,7 @@ describe("JobsContainer Search Functionality", () => {
});
await waitFor(() => {
- expect(getJobsList).toHaveBeenCalledWith(1, 25, "applied", "Developer", undefined, undefined);
+ expect(getJobsList).toHaveBeenCalledWith(1, 25, "applied", "Developer", undefined, undefined, undefined);
});
// Now clear filter by selecting None
@@ -527,7 +527,7 @@ describe("JobsContainer Search Functionality", () => {
// Filter should be cleared but search preserved
await waitFor(() => {
- expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, "Developer", undefined, undefined);
+ expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, "Developer", undefined, undefined, undefined);
});
});
});
@@ -639,7 +639,7 @@ describe("JobsContainer Search Functionality", () => {
});
await waitFor(() => {
- expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, "Developer", undefined, undefined);
+ expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, "Developer", undefined, undefined, undefined);
});
// Click load more
@@ -650,7 +650,7 @@ describe("JobsContainer Search Functionality", () => {
// Should include search term in load more call
await waitFor(() => {
- expect(getJobsList).toHaveBeenCalledWith(2, 25, undefined, "Developer", undefined, undefined);
+ expect(getJobsList).toHaveBeenCalledWith(2, 25, undefined, "Developer", undefined, undefined, undefined);
});
});
});
@@ -684,7 +684,7 @@ describe("JobsContainer Search Functionality", () => {
});
await waitFor(() => {
- expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, "test", undefined, undefined);
+ expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, "test", undefined, undefined, undefined);
});
});
});
@@ -702,7 +702,7 @@ describe("JobsContainer Search Functionality", () => {
renderComponent();
await waitFor(() => {
- expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, undefined, "google", true);
+ expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, undefined, "google", true, undefined);
});
});
@@ -776,7 +776,7 @@ describe("JobsContainer Search Functionality", () => {
renderComponent();
await waitFor(() => {
- expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, undefined, "google", true);
+ expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, undefined, "google", true, undefined);
});
const filterTrigger = screen.getByRole("combobox");
@@ -790,8 +790,65 @@ describe("JobsContainer Search Functionality", () => {
});
await waitFor(() => {
- expect(getJobsList).toHaveBeenCalledWith(1, 25, "applied", undefined, "google", true);
+ expect(getJobsList).toHaveBeenCalledWith(1, 25, "applied", undefined, "google", true, undefined);
});
});
});
+
+ describe("Title Filter from URL", () => {
+ it("should pass title filter to getJobsList when URL has title param", async () => {
+ const titleSearchParams = new URLSearchParams("title=full+stack+developer&applied=true");
+ (useSearchParams as jest.Mock).mockReturnValue(titleSearchParams);
+ (getJobsList as jest.Mock).mockResolvedValue({
+ success: true,
+ data: mockJobs,
+ total: 2,
+ });
+
+ renderComponent();
+
+ await waitFor(() => {
+ expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, undefined, undefined, true, "full stack developer");
+ });
+ });
+
+ it("should show title badge when title param is present", async () => {
+ const titleSearchParams = new URLSearchParams("title=full+stack+developer&applied=true");
+ (useSearchParams as jest.Mock).mockReturnValue(titleSearchParams);
+ (getJobsList as jest.Mock).mockResolvedValue({
+ success: true,
+ data: mockJobs,
+ total: 2,
+ });
+
+ renderComponent();
+
+ await waitFor(() => {
+ expect(screen.getByText("Full Stack Developer")).toBeInTheDocument();
+ });
+ });
+
+ it("should clear title filter when badge is clicked", async () => {
+ const titleSearchParams = new URLSearchParams("title=full+stack+developer&applied=true");
+ (useSearchParams as jest.Mock).mockReturnValue(titleSearchParams);
+ (getJobsList as jest.Mock).mockResolvedValue({
+ success: true,
+ data: mockJobs,
+ total: 2,
+ });
+
+ renderComponent();
+
+ await waitFor(() => {
+ expect(screen.getByText("Full Stack Developer")).toBeInTheDocument();
+ });
+
+ const badge = screen.getByText("Full Stack Developer").closest("button")!;
+ await act(async () => {
+ await user.click(badge);
+ });
+
+ expect(mockRouter.push).toHaveBeenCalledWith("/dashboard/myjobs");
+ });
+ });
});
diff --git a/__tests__/job.actions.spec.ts b/__tests__/job.actions.spec.ts
index 70282ed..3bf5a88 100644
--- a/__tests__/job.actions.spec.ts
+++ b/__tests__/job.actions.spec.ts
@@ -436,6 +436,79 @@ describe("jobActions", () => {
expect(findManyCall.where.applied).toBeUndefined();
});
});
+
+ describe("title filter", () => {
+ it("should filter by title value when titleValue is provided", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.job.findMany as jest.Mock).mockResolvedValue([]);
+ (prisma.job.count as jest.Mock).mockResolvedValue(0);
+
+ await getJobsList(1, 10, undefined, undefined, undefined, undefined, "full stack developer");
+
+ const findManyCall = (prisma.job.findMany as jest.Mock).mock
+ .calls[0][0];
+ expect(findManyCall.where).toMatchObject({
+ userId: mockUser.id,
+ JobTitle: { value: "full stack developer" },
+ });
+ });
+
+ it("should combine title filter with applied filter", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.job.findMany as jest.Mock).mockResolvedValue([]);
+ (prisma.job.count as jest.Mock).mockResolvedValue(0);
+
+ await getJobsList(1, 10, undefined, undefined, undefined, true, "full stack developer");
+
+ const findManyCall = (prisma.job.findMany as jest.Mock).mock
+ .calls[0][0];
+ expect(findManyCall.where).toMatchObject({
+ userId: mockUser.id,
+ JobTitle: { value: "full stack developer" },
+ applied: true,
+ });
+ });
+
+ it("should exclude JobTitle from search OR when titleValue is set", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.job.findMany as jest.Mock).mockResolvedValue([]);
+ (prisma.job.count as jest.Mock).mockResolvedValue(0);
+
+ await getJobsList(1, 10, undefined, "React", undefined, undefined, "full stack developer");
+
+ const findManyCall = (prisma.job.findMany as jest.Mock).mock
+ .calls[0][0];
+ expect(findManyCall.where.OR).not.toContainEqual(
+ { JobTitle: { label: { contains: "React" } } },
+ );
+ });
+
+ it("should include JobTitle in search OR when titleValue is not set", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.job.findMany as jest.Mock).mockResolvedValue([]);
+ (prisma.job.count as jest.Mock).mockResolvedValue(0);
+
+ await getJobsList(1, 10, undefined, "React");
+
+ const findManyCall = (prisma.job.findMany as jest.Mock).mock
+ .calls[0][0];
+ expect(findManyCall.where.OR).toContainEqual(
+ { JobTitle: { label: { contains: "React" } } },
+ );
+ });
+
+ it("should not add JobTitle when titleValue is undefined", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.job.findMany as jest.Mock).mockResolvedValue([]);
+ (prisma.job.count as jest.Mock).mockResolvedValue(0);
+
+ await getJobsList(1, 10);
+
+ const findManyCall = (prisma.job.findMany as jest.Mock).mock
+ .calls[0][0];
+ expect(findManyCall.where.JobTitle).toBeUndefined();
+ });
+ });
});
describe("getJobDetails", () => {
it("should throw error when jobId is not provided", async () => {
diff --git a/src/actions/job.actions.ts b/src/actions/job.actions.ts
index bf18011..87d5b5e 100644
--- a/src/actions/job.actions.ts
+++ b/src/actions/job.actions.ts
@@ -43,6 +43,7 @@ export const getJobsList = async (
search?: string,
companyValue?: string,
appliedOnly?: boolean,
+ titleValue?: string,
): Promise<any | undefined> => {
try {
const user = await getCurrentUser();
@@ -73,14 +74,19 @@ export const getJobsList = async (
whereClause.Company = { value: companyValue };
}
+ if (titleValue) {
+ whereClause.JobTitle = { value: titleValue };
+ }
+
if (appliedOnly) {
whereClause.applied = true;
}
if (search) {
- const searchConditions: Record<string, any>[] = [
- { JobTitle: { label: { contains: search } } },
- ];
+ const searchConditions: Record<string, any>[] = [];
+ if (!titleValue) {
+ searchConditions.push({ JobTitle: { label: { contains: search } } });
+ }
if (!companyValue) {
searchConditions.push({ Company: { label: { contains: search } } });
}
diff --git a/src/components/admin/JobTitlesTable.tsx b/src/components/admin/JobTitlesTable.tsx
index ae92444..61fc8f2 100644
--- a/src/components/admin/JobTitlesTable.tsx
+++ b/src/components/admin/JobTitlesTable.tsx
@@ -19,6 +19,7 @@ import {
} from "../ui/table";
import { JobTitle } from "@/models/job.model";
import { MoreHorizontal, Trash } from "lucide-react";
+import Link from "next/link";
import { AlertDialog } from "@/models/alertDialog.model";
import { DeleteAlertDialog } from "../DeleteAlertDialog";
import { deleteJobTitleById } from "@/actions/jobtitle.actions";
@@ -94,7 +95,16 @@ function JobTitlesTable({ jobTitles, reloadJobTitles }: JobTitlesTableProps) {
{title.value}
</TableCell>
<TableCell className="font-medium">
- {title._count?.jobs}
+ {title._count?.jobs ? (
+ <Link
+ href={`/dashboard/myjobs?title=${encodeURIComponent(title.value)}&applied=true`}
+ className="text-primary underline-offset-4 hover:underline"
+ >
+ {title._count.jobs}
+ </Link>
+ ) : (
+ title._count?.jobs ?? 0
+ )}
</TableCell>
<TableCell>
<DropdownMenu>
diff --git a/src/components/myjobs/JobsContainer.tsx b/src/components/myjobs/JobsContainer.tsx
index e5562b1..03a18d3 100644
--- a/src/components/myjobs/JobsContainer.tsx
+++ b/src/components/myjobs/JobsContainer.tsx
@@ -78,6 +78,9 @@ function JobsContainer({
const [companyFilter, setCompanyFilter] = useState<string | null>(
queryParams.get("company"),
);
+ const [titleFilter, setTitleFilter] = useState<string | null>(
+ queryParams.get("title"),
+ );
const [appliedFilter, setAppliedFilter] = useState(
queryParams.get("applied") === "true",
);
@@ -99,16 +102,28 @@ function JobsContainer({
? companies.find((c) => c.value === companyFilter)?.label
: null;
+ const titleLabel = titleFilter
+ ? titles.find((t) => t.value === titleFilter)?.label
+ : null;
+
const clearCompanyFilter = () => {
setCompanyFilter(null);
setAppliedFilter(false);
router.push(pathname);
};
+ const clearTitleFilter = () => {
+ setTitleFilter(null);
+ setAppliedFilter(false);
+ router.push(pathname);
+ };
+
useEffect(() => {
const cp = queryParams.get("company");
+ const tp = queryParams.get("title");
const ap = queryParams.get("applied") === "true";
setCompanyFilter(cp);
+ setTitleFilter(tp);
setAppliedFilter(ap);
}, [queryParams]);
@@ -124,6 +139,7 @@ function JobsContainer({
search,
companyFilter || undefined,
appliedFilter || undefined,
+ titleFilter || undefined,
);
if (success && data) {
setJobs((prev) => (page === 1 ? data : [...prev, ...data]));
@@ -140,7 +156,7 @@ function JobsContainer({
return;
}
},
- [jobsPerPage, companyFilter, appliedFilter],
+ [jobsPerPage, companyFilter, appliedFilter, titleFilter],
);
const reloadJobs = useCallback(async () => {
@@ -283,6 +299,15 @@ function JobsContainer({
<X className="h-3.5 w-3.5" />
</button>
)}
+ {titleLabel && (
+ <button
+ onClick={clearTitleFilter}
+ className="inline-flex items-center gap-1 rounded-md bg-primary/10 px-2.5 py-1 text-sm font-medium text-primary hover:bg-primary/20 transition-colors"
+ >
+ {titleLabel}
+ <X className="h-3.5 w-3.5" />
+ </button>
+ )}
<div className="relative flex-1 min-w-[140px] sm:flex-none">
<Search className="absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground" />
<Input