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.

fix(jobs): order status lists by JOB_STATUSES and default Add Job to Draft by value, not list position

Khuram Niaz48fcc5ebed08
diff --git a/__tests__/AddJob.spec.tsx b/__tests__/AddJob.spec.tsx
index 6acab54..2425483 100644
--- a/__tests__/AddJob.spec.tsx
+++ b/__tests__/AddJob.spec.tsx
@@ -574,3 +574,40 @@ describe("AddJob Component - Error Handling", () => {
});
}, 10000);
});
+
+describe("AddJob Component - Status Order", () => {
+ const user = userEvent.setup({ skipHover: true });
+ window.HTMLElement.prototype.scrollIntoView = vi.fn();
+ window.HTMLElement.prototype.hasPointerCapture = vi.fn();
+
+ // A fresh install's migrations insert these before signup seeds the rest,
+ // so an unordered status list starts with them.
+ const freshInstallStatuses = [
+ { id: "offer-accepted-id", label: "Offer Accepted", value: "offer-accepted" },
+ { id: "offer-declined-id", label: "Offer Declined", value: "offer-declined" },
+ ...JOB_STATUSES,
+ ];
+
+ it("defaults to Draft and toggles to Applied whatever order statuses arrive in", async () => {
+ render(
+ <AddJob
+ jobStatuses={freshInstallStatuses}
+ companies={[]}
+ jobTitles={[]}
+ locations={[]}
+ jobSources={JOB_SOURCES}
+ tags={[]}
+ editJob={null}
+ resetEditJob={vi.fn()}
+ />,
+ );
+ await user.click(screen.getByTestId("add-job-btn"));
+
+ const status = screen.getByLabelText("Status");
+ expect(status).toHaveTextContent("Draft");
+ await user.click(screen.getByRole("switch"));
+ expect(status).toHaveTextContent("Applied");
+ await user.click(screen.getByRole("switch"));
+ expect(status).toHaveTextContent("Draft");
+ });
+});
diff --git a/__tests__/job.actions.spec.ts b/__tests__/job.actions.spec.ts
index 4617fa0..80bf347 100644
--- a/__tests__/job.actions.spec.ts
+++ b/__tests__/job.actions.spec.ts
@@ -153,6 +153,23 @@ describe("jobActions", () => {
await expect(getStatusList()).resolves.toStrictEqual(mockErrorResponse);
});
+
+ it("returns statuses in JOB_STATUSES order, unknown values last", async () => {
+ (prisma.jobStatus.findMany as any).mockResolvedValue([
+ { id: "1", label: "Offer Accepted", value: "offer-accepted" },
+ { id: "2", label: "Legacy", value: "legacy" },
+ { id: "3", label: "Draft", value: "draft" },
+ { id: "4", label: "New", value: "new" },
+ ]);
+
+ const result = await getStatusList();
+ expect(result.map((s: any) => s.value)).toEqual([
+ "new",
+ "draft",
+ "offer-accepted",
+ "legacy",
+ ]);
+ });
});
describe("getJobSourceList", () => {
it("should return job source list on successful query", async () => {
diff --git a/src/actions/job/references.ts b/src/actions/job/references.ts
index 93a8113..af6cff2 100644
--- a/src/actions/job/references.ts
+++ b/src/actions/job/references.ts
@@ -2,14 +2,22 @@
import prisma from "@/lib/db";
import { handleError } from "@/lib/utils";
import { canonicalizeEntityValue } from "@/lib/jobs/canonicalize";
+import { JOB_STATUSES } from "@/lib/constants";
import { requireUser } from "../shared";
// JobStatus is global reference data with no createdBy column, so unlike every
-// other list here it is not scoped to the current user.
+// other list here it is not scoped to the current user. Sorted in JS because
+// rows are in insertion order, and migrations insert some before signup.
+const STATUS_ORDER = new Map<string, number>(
+ JOB_STATUSES.map((s, i) => [s.value, i]),
+);
+
export const getStatusList = async (): Promise<any | undefined> => {
try {
const statuses = await prisma.jobStatus.findMany();
- return statuses;
+ const rank = (value: string) =>
+ STATUS_ORDER.get(value) ?? JOB_STATUSES.length;
+ return statuses.sort((a, b) => rank(a.value) - rank(b.value));
} catch (error) {
const msg = "Failed to fetch status list. ";
return handleError(error, msg);
diff --git a/src/components/myjobs/AddJob.tsx b/src/components/myjobs/AddJob.tsx
index a6f5704..9f6a0bc 100644
--- a/src/components/myjobs/AddJob.tsx
+++ b/src/components/myjobs/AddJob.tsx
@@ -115,11 +115,14 @@ export function AddJob({
APP_CONSTANTS.LAST_JOB_SOURCE_STORAGE_KEY,
null,
);
+ // By value, not position: the list's order is not guaranteed.
+ const draftStatusId = jobStatuses.find((s) => s.value === "draft")?.id;
+ const appliedStatusId = jobStatuses.find((s) => s.value === "applied")?.id;
const newJobDefaultValues = {
type: Object.keys(JOB_TYPES)[0],
workplaceType: "ONSITE",
dueDate: addDays(new Date(), 3),
- status: jobStatuses[0]?.id,
+ status: draftStatusId,
salaryRange: "",
jobUrl: "",
jobDescription: "N/A",
@@ -239,12 +242,13 @@ export function AddJob({
const jobAppliedChange = (applied: boolean) => {
if (applied) {
- form.getValues("status") === jobStatuses[0]?.id &&
- setValue("status", jobStatuses[1]?.id);
+ appliedStatusId &&
+ form.getValues("status") === draftStatusId &&
+ setValue("status", appliedStatusId);
setValue("dateApplied", new Date());
} else {
resetField("dateApplied");
- setValue("status", jobStatuses[0]?.id);
+ draftStatusId && setValue("status", draftStatusId);
}
};