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.
TypeScript ai-agentai-resume-analyzerapplication-trackerapplication-tracking-systematscareerjob-applicationjob-automationjob-huntingjob-searchjob-seeker-toolsjob-trackerjob-trackingjobsearchjobseekersmcpollamaresumeresume-reviewself-hosted
Add search feature to myjobs
Khuram Niazcc4b69c13114
diff --git a/__tests__/JobsContainer.spec.tsx b/__tests__/JobsContainer.spec.tsxnew file mode 100644index 0000000..03ea4e9--- /dev/null+++ b/__tests__/JobsContainer.spec.tsx@@ -0,0 +1,647 @@+import JobsContainer from "@/components/myjobs/JobsContainer";+import "@testing-library/jest-dom";+import { screen, render, waitFor, act } from "@testing-library/react";+import userEvent from "@testing-library/user-event";+import {+ getJobsList,+ getJobDetails,+ deleteJobById,+ updateJobStatus,+} from "@/actions/job.actions";+import { useRouter, usePathname, useSearchParams } from "next/navigation";++jest.mock("next-auth", () => {+ const mockAuth = jest.fn();+ const mockSignIn = jest.fn();+ const mockSignOut = jest.fn();+ const mockHandlers = { GET: jest.fn(), POST: jest.fn() };++ return {+ __esModule: true,+ default: jest.fn(() => ({+ auth: mockAuth,+ handlers: mockHandlers,+ signIn: mockSignIn,+ signOut: mockSignOut,+ })),+ auth: mockAuth,+ signIn: mockSignIn,+ signOut: mockSignOut,+ handlers: mockHandlers,+ };+});++jest.mock("next-auth/providers/credentials", () => ({+ __esModule: true,+ default: jest.fn(() => ({+ id: "credentials",+ name: "Credentials",+ type: "credentials",+ })),+}));++jest.mock("@/actions/job.actions", () => ({+ getJobsList: jest.fn(),+ getJobDetails: jest.fn(),+ deleteJobById: jest.fn(),+ updateJobStatus: jest.fn(),+}));++jest.mock("next/navigation", () => ({+ useRouter: jest.fn(),+ usePathname: jest.fn(),+ useSearchParams: jest.fn(),+}));++global.ResizeObserver = jest.fn().mockImplementation(() => ({+ observe: jest.fn(),+ unobserve: jest.fn(),+ disconnect: jest.fn(),+}));++document.createRange = () => {+ const range = new Range();++ range.getBoundingClientRect = jest.fn().mockReturnValue({+ bottom: 0,+ height: 0,+ left: 0,+ right: 0,+ top: 0,+ width: 0,+ });++ range.getClientRects = () => {+ return {+ item: () => null,+ length: 0,+ [Symbol.iterator]: jest.fn(),+ };+ };++ return range;+};++describe("JobsContainer Search Functionality", () => {+ const mockRouter = {+ push: jest.fn(),+ back: jest.fn(),+ forward: jest.fn(),+ refresh: jest.fn(),+ replace: jest.fn(),+ prefetch: jest.fn(),+ };++ const mockSearchParams = new URLSearchParams();++ const mockStatuses = [+ { id: "1", label: "Applied", value: "applied" },+ { id: "2", label: "Interview", value: "interview" },+ { id: "3", label: "Draft", value: "draft" },+ { id: "4", label: "Rejected", value: "rejected" },+ ];++ const mockCompanies = [+ { id: "1", label: "Amazon", value: "amazon", createdBy: "user-1" },+ { id: "2", label: "Google", value: "google", createdBy: "user-1" },+ ];++ const mockTitles = [+ {+ id: "1",+ label: "Full Stack Developer",+ value: "full stack developer",+ createdBy: "user-1",+ },+ {+ id: "2",+ label: "Frontend Developer",+ value: "frontend developer",+ createdBy: "user-1",+ },+ ];++ const mockLocations = [+ { id: "1", label: "Remote", value: "remote", createdBy: "user-1" },+ { id: "2", label: "San Francisco", value: "san francisco", createdBy: "user-1" },+ ];++ const mockSources = [+ { id: "1", label: "Indeed", value: "indeed" },+ { id: "2", label: "LinkedIn", value: "linkedin" },+ ];++ const mockJobs = [+ {+ id: "1",+ userId: "user-1",+ JobTitle: { id: "1", label: "Full Stack Developer", value: "full stack developer", createdBy: "user-1" },+ Company: { id: "1", label: "Amazon", value: "amazon", createdBy: "user-1", logoUrl: "" },+ Location: { id: "1", label: "Remote", value: "remote", createdBy: "user-1" },+ Status: { id: "1", label: "Applied", value: "applied" },+ JobSource: { id: "1", label: "Indeed", value: "indeed" },+ jobType: "FT",+ appliedDate: new Date("2024-06-19"),+ dueDate: new Date("2024-06-22"),+ },+ {+ id: "2",+ userId: "user-1",+ JobTitle: { id: "2", label: "Frontend Developer", value: "frontend developer", createdBy: "user-1" },+ Company: { id: "2", label: "Google", value: "google", createdBy: "user-1", logoUrl: "" },+ Location: { id: "2", label: "San Francisco", value: "san francisco", createdBy: "user-1" },+ Status: { id: "2", label: "Interview", value: "interview" },+ JobSource: { id: "2", label: "LinkedIn", value: "linkedin" },+ jobType: "FT",+ appliedDate: new Date("2024-06-20"),+ dueDate: new Date("2024-06-25"),+ },+ ];++ const user = userEvent.setup({ delay: null });+ window.HTMLElement.prototype.scrollIntoView = jest.fn();+ window.HTMLElement.prototype.hasPointerCapture = jest.fn();++ beforeEach(() => {+ jest.clearAllMocks();+ jest.useFakeTimers();+ (useRouter as jest.Mock).mockReturnValue(mockRouter);+ (usePathname as jest.Mock).mockReturnValue("/dashboard/myjobs");+ (useSearchParams as jest.Mock).mockReturnValue(mockSearchParams);+ });++ afterEach(() => {+ jest.useRealTimers();+ });++ const renderComponent = () => {+ return render(+ <JobsContainer+ statuses={mockStatuses}+ companies={mockCompanies}+ titles={mockTitles}+ locations={mockLocations}+ sources={mockSources}+ />+ );+ };++ describe("Search Input", () => {+ it("should render search input with placeholder", async () => {+ (getJobsList as jest.Mock).mockResolvedValue({+ success: true,+ data: mockJobs,+ total: 2,+ });++ renderComponent();++ await waitFor(() => {+ expect(screen.getByPlaceholderText("Search jobs...")).toBeInTheDocument();+ });+ });++ it("should update search input value when typing", async () => {+ (getJobsList as jest.Mock).mockResolvedValue({+ success: true,+ data: mockJobs,+ total: 2,+ });++ renderComponent();++ await waitFor(() => {+ expect(screen.getByPlaceholderText("Search jobs...")).toBeInTheDocument();+ });++ const searchInput = screen.getByPlaceholderText("Search jobs...");++ await act(async () => {+ await user.type(searchInput, "Amazon");+ });++ expect(searchInput).toHaveValue("Amazon");+ });++ it("should debounce search input for 300ms", async () => {+ (getJobsList as jest.Mock).mockResolvedValue({+ success: true,+ data: mockJobs,+ total: 2,+ });++ renderComponent();++ await waitFor(() => {+ expect(getJobsList).toHaveBeenCalledTimes(1);+ });++ const searchInput = screen.getByPlaceholderText("Search jobs...");++ await act(async () => {+ await user.type(searchInput, "A");+ });++ // Should not have called getJobsList yet (debounce not elapsed)+ expect(getJobsList).toHaveBeenCalledTimes(1);++ // Advance timer by 300ms to trigger debounce+ await act(async () => {+ jest.advanceTimersByTime(300);+ });++ // Now search should have been triggered+ await waitFor(() => {+ expect(getJobsList).toHaveBeenCalledTimes(2);+ });+ });++ it("should call getJobsList with search term after debounce", async () => {+ (getJobsList as jest.Mock).mockResolvedValue({+ success: true,+ data: mockJobs,+ total: 2,+ });++ renderComponent();++ await waitFor(() => {+ expect(getJobsList).toHaveBeenCalledTimes(1);+ });++ const searchInput = screen.getByPlaceholderText("Search jobs...");++ await act(async () => {+ await user.type(searchInput, "Amazon");+ });++ await act(async () => {+ jest.advanceTimersByTime(300);+ });++ await waitFor(() => {+ expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, "Amazon");+ });+ });++ it("should not trigger search on initial mount with empty search", async () => {+ (getJobsList as jest.Mock).mockResolvedValue({+ success: true,+ data: mockJobs,+ total: 2,+ });++ renderComponent();++ await waitFor(() => {+ expect(getJobsList).toHaveBeenCalledTimes(1);+ });++ // Initial call should not have search parameter+ expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, undefined);+ });++ it("should trigger search when clearing search term after searching", async () => {+ (getJobsList as jest.Mock).mockResolvedValue({+ success: true,+ data: mockJobs,+ total: 2,+ });++ renderComponent();++ await waitFor(() => {+ expect(getJobsList).toHaveBeenCalledTimes(1);+ });++ const searchInput = screen.getByPlaceholderText("Search jobs...");++ // Type to trigger search+ await act(async () => {+ await user.type(searchInput, "Test");+ });++ await act(async () => {+ jest.advanceTimersByTime(300);+ });++ await waitFor(() => {+ expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, "Test");+ });++ // Clear the search input+ await act(async () => {+ await user.clear(searchInput);+ });++ await act(async () => {+ jest.advanceTimersByTime(300);+ });++ // Should call with undefined when cleared after having searched+ await waitFor(() => {+ expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, undefined);+ });+ });+ });++ describe("Search with Filters", () => {+ it("should combine search with status filter", async () => {+ (getJobsList as jest.Mock).mockResolvedValue({+ success: true,+ data: mockJobs,+ total: 2,+ });++ renderComponent();++ await waitFor(() => {+ expect(screen.getByPlaceholderText("Search jobs...")).toBeInTheDocument();+ });++ // Type in search+ const searchInput = screen.getByPlaceholderText("Search jobs...");+ await act(async () => {+ await user.type(searchInput, "Developer");+ });++ await act(async () => {+ jest.advanceTimersByTime(300);+ });++ await waitFor(() => {+ expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, "Developer");+ });++ // Now change filter+ const filterTrigger = screen.getByRole("combobox");+ await act(async () => {+ await user.click(filterTrigger);+ });++ const appliedOption = screen.getByRole("option", { name: "Applied" });+ await act(async () => {+ await user.click(appliedOption);+ });++ await waitFor(() => {+ expect(getJobsList).toHaveBeenCalledWith(1, 25, "applied", "Developer");+ });+ });++ it("should preserve search when changing filter", async () => {+ (getJobsList as jest.Mock).mockResolvedValue({+ success: true,+ data: mockJobs,+ total: 2,+ });++ renderComponent();++ await waitFor(() => {+ expect(getJobsList).toHaveBeenCalledTimes(1);+ });++ // Type in search+ const searchInput = screen.getByPlaceholderText("Search jobs...");+ await act(async () => {+ await user.type(searchInput, "Amazon");+ });++ await act(async () => {+ jest.advanceTimersByTime(300);+ });++ await waitFor(() => {+ expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, "Amazon");+ });++ // Change filter+ const filterTrigger = screen.getByRole("combobox");+ await act(async () => {+ await user.click(filterTrigger);+ });++ const interviewOption = screen.getByRole("option", { name: "Interview" });+ await act(async () => {+ await user.click(interviewOption);+ });++ // Search term should still be present+ await waitFor(() => {+ expect(getJobsList).toHaveBeenCalledWith(1, 25, "interview", "Amazon");+ });+ });++ it("should clear filter but preserve search when selecting None filter", async () => {+ (getJobsList as jest.Mock).mockResolvedValue({+ success: true,+ data: mockJobs,+ total: 2,+ });++ renderComponent();++ await waitFor(() => {+ expect(getJobsList).toHaveBeenCalledTimes(1);+ });++ // First type in search+ const searchInput = screen.getByPlaceholderText("Search jobs...");+ await act(async () => {+ await user.type(searchInput, "Developer");+ });++ await act(async () => {+ jest.advanceTimersByTime(300);+ });++ // Set a filter+ const filterTrigger = screen.getByRole("combobox");+ await act(async () => {+ await user.click(filterTrigger);+ });++ const appliedOption = screen.getByRole("option", { name: "Applied" });+ await act(async () => {+ await user.click(appliedOption);+ });++ await waitFor(() => {+ expect(getJobsList).toHaveBeenCalledWith(1, 25, "applied", "Developer");+ });++ // Now clear filter by selecting None+ await act(async () => {+ await user.click(filterTrigger);+ });++ const noneOption = screen.getByRole("option", { name: "None" });+ await act(async () => {+ await user.click(noneOption);+ });++ // Filter should be cleared but search preserved+ await waitFor(() => {+ expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, "Developer");+ });+ });+ });++ describe("Search Results Display", () => {+ it("should display filtered jobs after search", async () => {+ const amazonJob = [mockJobs[0]];++ (getJobsList as jest.Mock)+ .mockResolvedValueOnce({+ success: true,+ data: mockJobs,+ total: 2,+ })+ .mockResolvedValueOnce({+ success: true,+ data: amazonJob,+ total: 1,+ });++ renderComponent();++ await waitFor(() => {+ expect(screen.getByText("Amazon")).toBeInTheDocument();+ expect(screen.getByText("Google")).toBeInTheDocument();+ });++ const searchInput = screen.getByPlaceholderText("Search jobs...");+ await act(async () => {+ await user.type(searchInput, "Amazon");+ });++ await act(async () => {+ jest.advanceTimersByTime(300);+ });++ await waitFor(() => {+ expect(screen.getByText("Amazon")).toBeInTheDocument();+ });+ });++ it("should show loading state during search", async () => {+ let resolvePromise: (value: any) => void;+ const searchPromise = new Promise((resolve) => {+ resolvePromise = resolve;+ });++ (getJobsList as jest.Mock)+ .mockResolvedValueOnce({+ success: true,+ data: mockJobs,+ total: 2,+ })+ .mockReturnValueOnce(searchPromise);++ renderComponent();++ await waitFor(() => {+ expect(screen.getByText("Amazon")).toBeInTheDocument();+ });++ const searchInput = screen.getByPlaceholderText("Search jobs...");+ await act(async () => {+ await user.type(searchInput, "test");+ });++ await act(async () => {+ jest.advanceTimersByTime(300);+ });++ // Should show loading indicator+ await waitFor(() => {+ expect(screen.getByTestId("loader")).toBeInTheDocument();+ });++ // Resolve the search+ await act(async () => {+ resolvePromise!({+ success: true,+ data: [],+ total: 0,+ });+ });+ });+ });++ describe("Load More with Search", () => {+ it("should preserve search term when loading more", async () => {+ (getJobsList as jest.Mock).mockResolvedValue({+ success: true,+ data: mockJobs,+ total: 50,+ });++ renderComponent();++ await waitFor(() => {+ expect(screen.getByText("Load More")).toBeInTheDocument();+ });++ // Type search+ const searchInput = screen.getByPlaceholderText("Search jobs...");+ await act(async () => {+ await user.type(searchInput, "Developer");+ });++ await act(async () => {+ jest.advanceTimersByTime(300);+ });++ await waitFor(() => {+ expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, "Developer");+ });++ // Click load more+ const loadMoreButton = screen.getByText("Load More");+ await act(async () => {+ await user.click(loadMoreButton);+ });++ // Should include search term in load more call+ await waitFor(() => {+ expect(getJobsList).toHaveBeenCalledWith(2, 25, undefined, "Developer");+ });+ });+ });++ describe("Error Handling", () => {+ it("should handle search error gracefully", async () => {+ (getJobsList as jest.Mock)+ .mockResolvedValueOnce({+ success: true,+ data: mockJobs,+ total: 2,+ })+ .mockResolvedValueOnce({+ success: false,+ message: "Search failed",+ });++ renderComponent();++ await waitFor(() => {+ expect(screen.getByText("Amazon")).toBeInTheDocument();+ });++ const searchInput = screen.getByPlaceholderText("Search jobs...");+ await act(async () => {+ await user.type(searchInput, "test");+ });++ await act(async () => {+ jest.advanceTimersByTime(300);+ });++ await waitFor(() => {+ expect(getJobsList).toHaveBeenCalledWith(1, 25, undefined, "test");+ });+ });+ });+});diff --git a/__tests__/job.actions.spec.ts b/__tests__/job.actions.spec.tsindex fdab6bf..8d0e542 100644--- a/__tests__/job.actions.spec.ts+++ b/__tests__/job.actions.spec.ts@@ -167,6 +167,168 @@ describe("jobActions", () => {message: "Not authenticated",});});++ describe("search functionality", () => {+ it("should build OR clause when search parameter is provided", async () => {+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);+ const { data, total } = await getMockJobsList(1, 10);+ (prisma.job.findMany as jest.Mock).mockResolvedValue(data);+ (prisma.job.count as jest.Mock).mockResolvedValue(total);++ await getJobsList(1, 10, undefined, "Amazon");++ expect(prisma.job.findMany).toHaveBeenCalledWith(+ expect.objectContaining({+ where: expect.objectContaining({+ userId: mockUser.id,+ OR: [+ { JobTitle: { label: { contains: "Amazon" } } },+ { Company: { label: { contains: "Amazon" } } },+ { Location: { label: { contains: "Amazon" } } },+ { description: { contains: "Amazon" } },+ ],+ }),+ })+ );+ expect(prisma.job.count).toHaveBeenCalledWith(+ expect.objectContaining({+ where: expect.objectContaining({+ OR: [+ { JobTitle: { label: { contains: "Amazon" } } },+ { Company: { label: { contains: "Amazon" } } },+ { Location: { label: { contains: "Amazon" } } },+ { description: { contains: "Amazon" } },+ ],+ }),+ })+ );+ });++ it("should search across job title", 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, "Developer");++ const findManyCall = (prisma.job.findMany as jest.Mock).mock.calls[0][0];+ expect(findManyCall.where.OR).toContainEqual({+ JobTitle: { label: { contains: "Developer" } },+ });+ });++ it("should search across company name", 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, "Google");++ const findManyCall = (prisma.job.findMany as jest.Mock).mock.calls[0][0];+ expect(findManyCall.where.OR).toContainEqual({+ Company: { label: { contains: "Google" } },+ });+ });++ it("should search across location", 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, "Remote");++ const findManyCall = (prisma.job.findMany as jest.Mock).mock.calls[0][0];+ expect(findManyCall.where.OR).toContainEqual({+ Location: { label: { contains: "Remote" } },+ });+ });++ it("should search across description", 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({+ description: { contains: "React" },+ });+ });++ it("should combine search with 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, "applied", "Developer");++ const findManyCall = (prisma.job.findMany as jest.Mock).mock.calls[0][0];+ expect(findManyCall.where).toMatchObject({+ userId: mockUser.id,+ Status: { value: "applied" },+ OR: expect.any(Array),+ });+ });++ it("should not include OR clause when search 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, undefined, undefined);++ const findManyCall = (prisma.job.findMany as jest.Mock).mock.calls[0][0];+ expect(findManyCall.where.OR).toBeUndefined();+ });++ it("should not include OR clause when search is empty string", 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, "");++ const findManyCall = (prisma.job.findMany as jest.Mock).mock.calls[0][0];+ expect(findManyCall.where.OR).toBeUndefined();+ });++ it("should return filtered results with correct pagination", async () => {+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);+ const mockFilteredData = [+ {+ id: "1",+ JobTitle: { label: "Full Stack Developer" },+ Company: { label: "Amazon" },+ },+ ];+ (prisma.job.findMany as jest.Mock).mockResolvedValue(mockFilteredData);+ (prisma.job.count as jest.Mock).mockResolvedValue(1);++ const result = await getJobsList(1, 10, undefined, "Amazon");++ expect(result).toEqual({+ success: true,+ data: mockFilteredData,+ total: 1,+ });+ });++ it("should combine job type filter with search", 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, "PT", "Developer");++ const findManyCall = (prisma.job.findMany as jest.Mock).mock.calls[0][0];+ expect(findManyCall.where).toMatchObject({+ userId: mockUser.id,+ jobType: "PT",+ OR: expect.any(Array),+ });+ });+ });});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.tsindex e9d3795..86683c9 100644--- a/src/actions/job.actions.ts+++ b/src/actions/job.actions.ts@@ -31,7 +31,8 @@ export const getJobSourceList = async (): Promise<any | undefined> => {export const getJobsList = async (page: number = 1,limit: number = APP_CONSTANTS.RECORDS_PER_PAGE,- filter?: string+ filter?: string,+ search?: string): Promise<any | undefined> => {try {const user = await getCurrentUser();@@ -52,12 +53,24 @@ export const getJobsList = async (},}: {};++ const whereClause: any = {+ userId: user.id,+ ...filterBy,+ };++ if (search) {+ whereClause.OR = [+ { JobTitle: { label: { contains: search } } },+ { Company: { label: { contains: search } } },+ { Location: { label: { contains: search } } },+ { description: { contains: search } },+ ];+ }+const [data, total] = await Promise.all([prisma.job.findMany({- where: {- userId: user.id,- ...filterBy,- },+ where: whereClause,skip,take: limit,select: {@@ -79,10 +92,7 @@ export const getJobsList = async (},}),prisma.job.count({- where: {- userId: user.id,- ...filterBy,- },+ where: whereClause,}),]);return { success: true, data, total };diff --git a/src/components/myjobs/JobsContainer.tsx b/src/components/myjobs/JobsContainer.tsxindex 3e0ca32..9074eaa 100644--- a/src/components/myjobs/JobsContainer.tsx+++ b/src/components/myjobs/JobsContainer.tsx@@ -1,5 +1,5 @@"use client";-import { useCallback, useEffect, useState } from "react";+import { useCallback, useEffect, useRef, useState } from "react";import {Card,CardContent,@@ -8,7 +8,8 @@ import {CardTitle,} from "../ui/card";import { Button } from "../ui/button";-import { File, ListFilter } from "lucide-react";+import { Input } from "../ui/input";+import { File, ListFilter, Search } from "lucide-react";import {deleteJobById,getJobDetails,@@ -74,21 +75,24 @@ function JobsContainer({const [page, setPage] = useState(1);const [totalJobs, setTotalJobs] = useState(0);const [filterKey, setFilterKey] = useState<string>();+ const [searchTerm, setSearchTerm] = useState("");const [editJob, setEditJob] = useState(null);const [loading, setLoading] = useState(false);const [recordsPerPage, setRecordsPerPage] = useState<number>(APP_CONSTANTS.RECORDS_PER_PAGE,);+ const hasSearched = useRef(false);const jobsPerPage = recordsPerPage;const loadJobs = useCallback(- async (page: number, filter?: string) => {+ async (page: number, filter?: string, search?: string) => {setLoading(true);const { success, data, total, message } = await getJobsList(page,jobsPerPage,- filter+ filter,+ search);if (success && data) {setJobs((prev) => (page === 1 ? data : [...prev, ...data]));@@ -109,11 +113,11 @@ function JobsContainer({);const reloadJobs = useCallback(async () => {- await loadJobs(1);- if (filterKey !== "none") {- setFilterKey("none");+ await loadJobs(1, undefined, searchTerm || undefined);+ if (filterKey) {+ setFilterKey(undefined);}- }, [loadJobs, filterKey]);+ }, [loadJobs, filterKey, searchTerm]);const onDeleteJob = async (jobId: string) => {const { res, success, message } = await deleteJobById(jobId);@@ -169,14 +173,29 @@ function JobsContainer({useEffect(() => {(async () => await loadJobs(1))();- }, [loadJobs, recordsPerPage]);+ }, [loadJobs]);++ useEffect(() => {+ if (searchTerm !== "") {+ hasSearched.current = true;+ }+ // Skip only on initial mount when search is empty+ if (searchTerm === "" && !hasSearched.current) return;++ const timer = setTimeout(() => {+ loadJobs(1, filterKey, searchTerm || undefined);+ }, 300);+ return () => clearTimeout(timer);+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [searchTerm]);const onFilterChange = (filterBy: string) => {if (filterBy === "none") {- reloadJobs();+ setFilterKey(undefined);+ loadJobs(1, undefined, searchTerm || undefined);} else {setFilterKey(filterBy);- loadJobs(1, filterBy);+ loadJobs(1, filterBy, searchTerm || undefined);}};@@ -220,6 +239,16 @@ function JobsContainer({<CardTitle>My Jobs</CardTitle><div className="flex items-center"><div className="ml-auto flex items-center gap-2">+ <div className="relative">+ <Search className="absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground" />+ <Input+ type="search"+ placeholder="Search jobs..."+ className="pl-8 h-8 w-[150px] lg:w-[200px]"+ value={searchTerm}+ onChange={(e) => setSearchTerm(e.target.value)}+ />+ </div><Select value={filterKey} onValueChange={onFilterChange}><SelectTrigger className="w-[120px] h-8"><ListFilter className="h-3.5 w-3.5" />@@ -293,7 +322,7 @@ function JobsContainer({<Buttonsize="sm"variant="outline"- onClick={() => loadJobs(page + 1, filterKey)}+ onClick={() => loadJobs(page + 1, filterKey, searchTerm || undefined)}disabled={loading}className="btn btn-primary">