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: Add new job directly from dashboard

Khuram Niaz8c2dc79c9608
diff --git a/__tests__/AddExperience.spec.tsx b/__tests__/AddExperience.spec.tsx
index d64ed15..46a66a5 100644
--- a/__tests__/AddExperience.spec.tsx
+++ b/__tests__/AddExperience.spec.tsx
@@ -747,9 +747,8 @@ describe("AddExperience Component", () => {
const saveButton = screen.getByRole("button", { name: /save/i });
await user.click(saveButton);
- const loader = screen
- .getByText(/save/i)
- .parentElement?.querySelector(".spinner");
+ const saveBtn = screen.getByRole("button", { name: /save/i });
+ const loader = saveBtn.querySelector(".spinner");
expect(loader).toBeInTheDocument();
await waitFor(() => {
diff --git a/__tests__/AddJob.spec.tsx b/__tests__/AddJob.spec.tsx
index b103d2b..2a3daa5 100644
--- a/__tests__/AddJob.spec.tsx
+++ b/__tests__/AddJob.spec.tsx
@@ -17,6 +17,8 @@ vi.mock("@/actions/job.actions", () => ({
vi.mock("next/navigation", () => ({
redirect: vi.fn(),
+ useRouter: vi.fn(() => ({ replace: vi.fn() })),
+ useSearchParams: vi.fn(() => new URLSearchParams()),
}));
global.ResizeObserver = class ResizeObserver {
@@ -104,6 +106,28 @@ describe("AddJob Component", () => {
it("should open the dialog when clicked on add job button with title 'Edit Job'", async () => {
// TODO: To be tested with job container and jobs table component
});
+
+ it("should open the dialog immediately when initialOpen is true", async () => {
+ const mockCompanies = (await getMockList(1, 10, "companies")).data;
+ const mockJobTitles = (await getMockList(1, 10, "jobTitles")).data;
+ const mockLocations = (await getMockList(1, 10, "locations")).data;
+ render(
+ <AddJob
+ jobStatuses={mockJobStatuses}
+ companies={mockCompanies}
+ jobTitles={mockJobTitles}
+ locations={mockLocations}
+ jobSources={mockJobSources}
+ tags={[]}
+ editJob={null}
+ resetEditJob={mockResetEditJob}
+ initialOpen={true}
+ />,
+ );
+ const dialogTitle = screen.getAllByTestId("add-job-dialog-title")[0];
+ expect(dialogTitle).toBeInTheDocument();
+ expect(dialogTitle).toHaveTextContent("Add Job");
+ });
it("should show relevant react-hook-form errors", async () => {
const saveBtn = screen.getByTestId("save-job-btn");
await user.click(saveBtn);
diff --git a/__tests__/JobsAppliedCard.spec.tsx b/__tests__/JobsAppliedCard.spec.tsx
new file mode 100644
index 0000000..6a5fbbd
--- /dev/null
+++ b/__tests__/JobsAppliedCard.spec.tsx
@@ -0,0 +1,35 @@
+import JobsAppliedCard from "@/components/dashboard/JobsAppliedCard";
+import { render, screen } from "@testing-library/react";
+import userEvent from "@testing-library/user-event";
+import { useRouter } from "next/navigation";
+
+vi.mock("next/navigation", () => ({
+ useRouter: vi.fn(),
+}));
+
+describe("JobsAppliedCard", () => {
+ const mockPush = vi.fn();
+
+ beforeEach(() => {
+ vi.clearAllMocks();
+ (useRouter as any).mockReturnValue({ push: mockPush });
+ });
+
+ it("should navigate to myjobs with add-job=true when New Job button is clicked", async () => {
+ const user = userEvent.setup();
+ render(<JobsAppliedCard />);
+
+ await user.click(screen.getByRole("button", { name: /new job/i }));
+
+ expect(mockPush).toHaveBeenCalledWith("/dashboard/myjobs?add-job=true");
+ });
+
+ it("should navigate to tasks page when New Task button is clicked", async () => {
+ const user = userEvent.setup();
+ render(<JobsAppliedCard />);
+
+ await user.click(screen.getByRole("button", { name: /new task/i }));
+
+ expect(mockPush).toHaveBeenCalledWith("/dashboard/tasks");
+ });
+});
diff --git a/__tests__/JobsContainer.spec.tsx b/__tests__/JobsContainer.spec.tsx
index 5cf114d..67ffe42 100644
--- a/__tests__/JobsContainer.spec.tsx
+++ b/__tests__/JobsContainer.spec.tsx
@@ -980,4 +980,45 @@ describe("JobsContainer Search Functionality", () => {
expect(mockRouter.push).toHaveBeenCalledWith("/dashboard/myjobs");
});
});
+
+ describe("add-job query param", () => {
+ it("should open the Add Job dialog when add-job=true is in the URL", async () => {
+ (getJobsList as any).mockResolvedValue({
+ success: true,
+ data: [],
+ total: 0,
+ });
+ const params = new URLSearchParams("add-job=true");
+ (useSearchParams as any).mockReturnValue(params);
+
+ render(
+ <JobsContainer
+ statuses={mockStatuses}
+ companies={mockCompanies}
+ titles={mockTitles}
+ locations={mockLocations}
+ sources={mockSources}
+ tags={[]}
+ />,
+ );
+
+ await waitFor(() => {
+ expect(screen.getByTestId("add-job-dialog-title")).toBeInTheDocument();
+ });
+ });
+
+ it("should not open the Add Job dialog when add-job param is absent", async () => {
+ (getJobsList as any).mockResolvedValue({
+ success: true,
+ data: [],
+ total: 0,
+ });
+
+ renderComponent();
+
+ await waitFor(() => {
+ expect(screen.queryByTestId("add-job-dialog-title")).not.toBeInTheDocument();
+ });
+ });
+ });
});
diff --git a/src/components/dashboard/JobsAppliedCard.tsx b/src/components/dashboard/JobsAppliedCard.tsx
index 7414356..dabb94f 100644
--- a/src/components/dashboard/JobsAppliedCard.tsx
+++ b/src/components/dashboard/JobsAppliedCard.tsx
@@ -23,7 +23,7 @@ export default function JobsAppliedCard() {
<CardFooter className="flex flex-col gap-2 items-start">
<Button
variant="outline"
- onClick={() => router.push("/dashboard/myjobs")}
+ onClick={() => router.push("/dashboard/myjobs?add-job=true")}
>
<PlusCircle className="h-3.5 w-3.5 mr-1" />
<span className="sm:not-sr-only sm:whitespace-nowrap">New Job</span>
diff --git a/src/components/myjobs/AddJob.tsx b/src/components/myjobs/AddJob.tsx
index c0ce05e..2e353d5 100644
--- a/src/components/myjobs/AddJob.tsx
+++ b/src/components/myjobs/AddJob.tsx
@@ -42,7 +42,7 @@ import { SALARY_RANGES } from "@/lib/data/salaryRangeData";
import TiptapEditor from "../TiptapEditor";
import { Input } from "../ui/input";
import { Switch } from "../ui/switch";
-import { redirect } from "next/navigation";
+import { redirect, useRouter, useSearchParams } from "next/navigation";
import { Combobox } from "../ComboBox";
import { NotesCollapsibleSection } from "./NotesCollapsibleSection";
import { CoverLetter, Resume } from "@/models/profile.model";
@@ -60,6 +60,7 @@ type AddJobProps = {
tags: Tag[];
editJob?: JobResponse | null;
resetEditJob: () => void;
+ initialOpen?: boolean;
};
export function AddJob({
@@ -71,13 +72,25 @@ export function AddJob({
tags,
editJob,
resetEditJob,
+ initialOpen,
}: AddJobProps) {
- const [dialogOpen, setDialogOpen] = useState(false);
+ const router = useRouter();
+ const searchParams = useSearchParams();
+ const [dialogOpen, setDialogOpen] = useState(initialOpen ?? false);
const [resumeDialogOpen, setResumeDialogOpen] = useState(false);
const [resumes, setResumes] = useState<Resume[]>([]);
const [coverLetters, setCoverLetters] = useState<CoverLetter[]>([]);
const [availableTags, setAvailableTags] = useState<Tag[]>(tags);
const [isPending, startTransition] = useTransition();
+
+ useEffect(() => {
+ if (!dialogOpen && searchParams.get("add-job") === "true") {
+ const params = new URLSearchParams(searchParams.toString());
+ params.delete("add-job");
+ const newPath = params.toString() ? `?${params.toString()}` : window.location.pathname;
+ router.replace(newPath);
+ }
+ }, [dialogOpen, router, searchParams]);
const form = useForm<z.infer<typeof AddJobFormSchema>>({
resolver: zodResolver(AddJobFormSchema) as any,
defaultValues: {
diff --git a/src/components/myjobs/JobsContainer.tsx b/src/components/myjobs/JobsContainer.tsx
index c3f0971..736902b 100644
--- a/src/components/myjobs/JobsContainer.tsx
+++ b/src/components/myjobs/JobsContainer.tsx
@@ -441,6 +441,7 @@ function JobsContainer({
tags={tags}
editJob={editJob}
resetEditJob={resetEditJob}
+ initialOpen={queryParams.get("add-job") === "true"}
/>
</div>
</CardHeader>
diff --git a/src/components/profile/AddExperience.tsx b/src/components/profile/AddExperience.tsx
index a2fc872..0fb0f81 100644
--- a/src/components/profile/AddExperience.tsx
+++ b/src/components/profile/AddExperience.tsx
@@ -84,21 +84,16 @@ function AddExperience({
if (experienceToEdit) {
const experience: WorkExperience =
experienceToEdit.workExperiences?.at(0)!;
- reset(
- {
- id: experience?.id,
- title: experience?.jobTitle.id,
- company: experience?.Company.id,
- location: experience?.location.id,
- startDate: experience?.startDate,
- endDate: experience?.endDate,
- jobDescription: experience?.description,
- currentJob: !!!experience?.endDate,
- },
- {
- keepDefaultValues: true,
- },
- );
+ reset({
+ id: experience?.id,
+ title: experience?.jobTitle.id,
+ company: experience?.Company.id,
+ location: experience?.location.id,
+ startDate: experience?.startDate,
+ endDate: experience?.endDate,
+ jobDescription: experience?.description,
+ currentJob: !!!experience?.endDate,
+ });
} else {
reset(
{