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: implement last-used location and source persistence in AddJob component

Khuram Niazc18a8ff8eb32
diff --git a/__tests__/AddJob.spec.tsx b/__tests__/AddJob.spec.tsx
index 39a4692..c0a5052 100644
--- a/__tests__/AddJob.spec.tsx
+++ b/__tests__/AddJob.spec.tsx
@@ -9,6 +9,7 @@ import { format } from "date-fns";
import { addJob, updateJob } from "@/actions/job.actions";
import { toastActionResult } from "@/lib/toast";
import type { JobResponse } from "@/models/job.model";
+import { APP_CONSTANTS } from "@/lib/constants";
vi.mock("@/utils/user.utils", () => ({
getCurrentUser: vi.fn(),
}));
@@ -268,6 +269,105 @@ describe("AddJob Component", () => {
}, 10000);
});
+describe("AddJob Component - Last Used Location/Source", () => {
+ const mockJobStatuses = JOB_STATUSES;
+ const mockJobSources = JOB_SOURCES;
+ const mockResetEditJob = vi.fn();
+ const user = userEvent.setup({ skipHover: true });
+
+ const renderAddJob = 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}
+ />,
+ );
+ const addJobButton = screen.getByTestId("add-job-btn");
+ await user.click(addJobButton);
+ };
+
+ beforeEach(() => {
+ vi.clearAllMocks();
+ localStorage.clear();
+ });
+
+ it("pre-fills location and source from a valid last-used id in localStorage", async () => {
+ localStorage.setItem(
+ APP_CONSTANTS.LAST_JOB_LOCATION_STORAGE_KEY,
+ JSON.stringify("1yy"),
+ );
+ localStorage.setItem(
+ APP_CONSTANTS.LAST_JOB_SOURCE_STORAGE_KEY,
+ JSON.stringify("1359dac4-a397-4461-b747-382706dcbe79"),
+ );
+ await renderAddJob();
+
+ expect(screen.getByLabelText("Job Location")).toHaveTextContent("Remote");
+ expect(screen.getByLabelText("Job Source")).toHaveTextContent("Indeed");
+ });
+
+ it("ignores a last-used id that no longer exists, e.g. the entity was deleted", async () => {
+ localStorage.setItem(
+ APP_CONSTANTS.LAST_JOB_LOCATION_STORAGE_KEY,
+ JSON.stringify("deleted-location-id"),
+ );
+ localStorage.setItem(
+ APP_CONSTANTS.LAST_JOB_SOURCE_STORAGE_KEY,
+ JSON.stringify("deleted-source-id"),
+ );
+ await renderAddJob();
+
+ expect(screen.getByLabelText("Job Location")).toHaveTextContent(
+ "Select location",
+ );
+ expect(screen.getByLabelText("Job Source")).toHaveTextContent(
+ "Select source",
+ );
+ });
+
+ it("saves the selected location and source to localStorage after a successful save", async () => {
+ await renderAddJob();
+
+ await user.click(screen.getByRole("combobox", { name: /job title/i }));
+ await user.click(
+ screen.getByRole("option", { name: "Full Stack Developer" }),
+ );
+
+ await user.click(screen.getByRole("combobox", { name: /company/i }));
+ await user.click(screen.getByRole("option", { name: "Amazon" }));
+
+ await user.click(
+ screen.getByRole("combobox", { name: /job location/i }),
+ );
+ await user.click(screen.getByRole("option", { name: "Remote" }));
+
+ await user.click(
+ screen.getByRole("combobox", { name: /job source/i }),
+ );
+ await user.click(screen.getByRole("option", { name: "Indeed" }));
+
+ await user.click(screen.getByTestId("save-job-btn"));
+
+ await waitFor(() => {
+ expect(localStorage.getItem(APP_CONSTANTS.LAST_JOB_LOCATION_STORAGE_KEY)).toBe(
+ JSON.stringify("1yy"),
+ );
+ expect(localStorage.getItem(APP_CONSTANTS.LAST_JOB_SOURCE_STORAGE_KEY)).toBe(
+ JSON.stringify("1359dac4-a397-4461-b747-382706dcbe79"),
+ );
+ });
+ }, 10000);
+});
+
describe("AddJob Component - Edit Mode", () => {
const mockJobStatuses = JOB_STATUSES;
const mockJobSources = JOB_SOURCES;
diff --git a/__tests__/AgentChatClosePaths.spec.tsx b/__tests__/AgentChatClosePaths.spec.tsx
index f53a70d..2efd547 100644
--- a/__tests__/AgentChatClosePaths.spec.tsx
+++ b/__tests__/AgentChatClosePaths.spec.tsx
@@ -136,6 +136,6 @@ describe("agent chat close paths", () => {
expect(screen.queryByLabelText("Approval pending")).not.toBeInTheDocument();
expect(
screen.getByRole("button", { name: /open assistant/i }).textContent,
- ).toBe("AI Agent");
+ ).toBe("Chat AI");
});
});
diff --git a/src/components/AgentChatTrigger.tsx b/src/components/AgentChatTrigger.tsx
index f526b75..5162419 100644
--- a/src/components/AgentChatTrigger.tsx
+++ b/src/components/AgentChatTrigger.tsx
@@ -15,7 +15,7 @@ export function AgentChatTrigger() {
onClick={() => (isOpen ? close() : open())}
>
<MessageSquare className="h-4 w-4" />
- AI Agent
+ Chat AI
{/* Deliberately no streaming state: nothing generates while the panel
is closed, so there is no background activity to advertise. */}
{approvalPending && (
diff --git a/src/components/myjobs/AddJob.tsx b/src/components/myjobs/AddJob.tsx
index ddf7ad3..cde4183 100644
--- a/src/components/myjobs/AddJob.tsx
+++ b/src/components/myjobs/AddJob.tsx
@@ -53,6 +53,10 @@ import { getResumeList } from "@/actions/profile.actions";
import { getCoverLetterList } from "@/actions/coverLetter.actions";
import { TagInput } from "./TagInput";
import { APP_CONSTANTS } from "@/lib/constants";
+import {
+ getFromLocalStorage,
+ saveToLocalStorage,
+} from "@/utils/localstorage.utils";
type AddJobProps = {
jobStatuses: JobStatus[];
@@ -100,6 +104,17 @@ export function AddJob({
router.replace(newPath);
}
}, [dialogOpen, router, searchParams]);
+ // Pre-fill with the last-used location/source, but only if that entity
+ // still exists (handles deletion and cross-user localStorage collisions,
+ // since `locations`/`jobSources` are already scoped to the current user).
+ const lastLocationId = getFromLocalStorage(
+ APP_CONSTANTS.LAST_JOB_LOCATION_STORAGE_KEY,
+ null,
+ );
+ const lastSourceId = getFromLocalStorage(
+ APP_CONSTANTS.LAST_JOB_SOURCE_STORAGE_KEY,
+ null,
+ );
const newJobDefaultValues = {
type: Object.keys(JOB_TYPES)[0],
workplaceType: "ONSITE",
@@ -108,6 +123,8 @@ export function AddJob({
salaryRange: "1",
jobUrl: "",
jobDescription: "N/A",
+ location: locations.find((l) => l.id === lastLocationId)?.id,
+ source: jobSources.find((s) => s.id === lastSourceId)?.id,
};
const form = useForm<z.infer<typeof AddJobFormSchema>>({
@@ -193,6 +210,14 @@ export function AddJob({
toastActionResult(result, {
success: `Job has been ${editJob ? "updated" : "created"} successfully`,
onSuccess: () => {
+ saveToLocalStorage(
+ APP_CONSTANTS.LAST_JOB_LOCATION_STORAGE_KEY,
+ data.location,
+ );
+ saveToLocalStorage(
+ APP_CONSTANTS.LAST_JOB_SOURCE_STORAGE_KEY,
+ data.source,
+ );
reset();
setDialogOpen(false);
redirect(redirectPath ?? "/dashboard/myjobs");
diff --git a/src/lib/constants.ts b/src/lib/constants.ts
index e9501ce..6718eed 100644
--- a/src/lib/constants.ts
+++ b/src/lib/constants.ts
@@ -30,6 +30,8 @@ export const APP_CONSTANTS = {
SIDEBAR_STORAGE_KEY: "sidebar-expanded",
DASHBOARD_WEEKLY_CHART_STORAGE_KEY: "dashboard-weekly-chart-tab",
DASHBOARD_RECENT_CARD_STORAGE_KEY: "dashboard-recent-card-tab",
+ LAST_JOB_LOCATION_STORAGE_KEY: "last-job-location",
+ LAST_JOB_SOURCE_STORAGE_KEY: "last-job-source",
SIDEBAR_DOM_ID: "app-sidebar",
// Paired so the rail width and its matching content offset can't drift.
SIDEBAR_WIDTH: {