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(resume-export): add ResumeExportSettings model, canExportResume predicate, prepared-blob export path, and dev:webpack script

Khuram Niaz243130c763cd
diff --git a/__tests__/canExportResume.spec.ts b/__tests__/canExportResume.spec.ts
new file mode 100644
index 0000000..e6326f1
--- /dev/null
+++ b/__tests__/canExportResume.spec.ts
@@ -0,0 +1,96 @@
+import { describe, expect, it, vi } from "vitest";
+import type {
+ ContactInfo,
+ Resume,
+ ResumeSection,
+} from "@/models/profile.model";
+
+// The predicate lives beside the export hook, which pulls the router and the
+// toast layer at module scope. Neither is exercised here.
+vi.mock("next/navigation", () => ({
+ useRouter: () => ({ refresh: vi.fn() }),
+}));
+vi.mock("@/lib/toast", () => ({
+ toastError: vi.fn(),
+ toastSuccess: vi.fn(),
+}));
+
+import { canExportResume } from "@/components/profile/resume-container/useResumePdfExport";
+
+const base: Resume = { id: "r1", title: "My Resume" };
+
+describe("canExportResume", () => {
+ it("is false for a resume with no contact name and no sections", () => {
+ expect(canExportResume(base)).toBe(false);
+ });
+
+ it("is false when the contact name is only whitespace", () => {
+ expect(
+ canExportResume({
+ ...base,
+ ContactInfo: { firstName: " ", lastName: "\t" } as ContactInfo,
+ }),
+ ).toBe(false);
+ });
+
+ it("is true with only a first name", () => {
+ expect(
+ canExportResume({
+ ...base,
+ ContactInfo: { firstName: "Ada" } as ContactInfo,
+ }),
+ ).toBe(true);
+ });
+
+ it("is true with only a last name", () => {
+ expect(
+ canExportResume({
+ ...base,
+ ContactInfo: { lastName: "Lovelace" } as ContactInfo,
+ }),
+ ).toBe(true);
+ });
+
+ it("is true with a summary section and no contact name", () => {
+ expect(
+ canExportResume({
+ ...base,
+ ResumeSections: [
+ { summary: { content: "<p>Hi</p>" } } as ResumeSection,
+ ],
+ }),
+ ).toBe(true);
+ });
+
+ it("is true for each of the other content-bearing section shapes", () => {
+ const shapes = [
+ { workExperiences: [{}] },
+ { educations: [{}] },
+ { licenseOrCertifications: [{}] },
+ { skills: [{}] },
+ ];
+ for (const shape of shapes) {
+ expect(
+ canExportResume({
+ ...base,
+ ResumeSections: [shape as unknown as ResumeSection],
+ }),
+ ).toBe(true);
+ }
+ });
+
+ it("is false for sections that exist but hold nothing", () => {
+ expect(
+ canExportResume({
+ ...base,
+ ResumeSections: [
+ {
+ workExperiences: [],
+ educations: [],
+ skills: [],
+ } as unknown as ResumeSection,
+ ],
+ }),
+ ).toBe(false);
+ });
+});
diff --git a/package.json b/package.json
index 66eade8..65ba845 100644
--- a/package.json
+++ b/package.json
@@ -4,6 +4,7 @@
"private": true,
"scripts": {
"dev": "next dev --turbopack -p 3737",
+ "dev:webpack": "next dev -p 3737",
"build": "next build",
"start": "next start",
"lint": "eslint .",
diff --git a/src/components/profile/ExportPdfDialog.tsx b/src/components/profile/ExportPdfDialog.tsx
index 75bff95..7c70ed8 100644
--- a/src/components/profile/ExportPdfDialog.tsx
+++ b/src/components/profile/ExportPdfDialog.tsx
@@ -12,15 +12,20 @@ import {
} from "../ui/dialog";
import { Button } from "../ui/button";
import { cn } from "@/lib/utils";
-// Imported from ./types directly: the barrel re-exports generateResumePdfBlob,
-// which would pull @react-pdf/renderer into this eagerly-loaded chunk.
-import { RESUME_LAYOUT_LABELS, type ResumeLayout } from "./resume-pdf/types";
+import {
+ RESUME_LAYOUT_LABELS,
+ type ResumeExportSettings,
+ type ResumeLayout,
+} from "@/models/resumeExport.model";
type ExportPdfDialogProps = {
open: boolean;
onOpenChange: (open: boolean) => void;
isExporting: boolean;
- onExport: (layout: ResumeLayout) => void;
+ onExport: (
+ settings: ResumeExportSettings,
+ prepared?: { blob: Blob; filename: string } | null,
+ ) => void;
};
// Paper stays white in dark mode on purpose: the PDF page is white.
@@ -190,7 +195,7 @@ export function ExportPdfDialog({
disabled={isExporting}
onClick={() => {
onOpenChange(false);
- onExport(selected);
+ onExport({ template: selected });
}}
>
{isExporting ? (
diff --git a/src/components/profile/resume-container/useResumePdfExport.ts b/src/components/profile/resume-container/useResumePdfExport.ts
index e8908b0..3f5176b 100644
--- a/src/components/profile/resume-container/useResumePdfExport.ts
+++ b/src/components/profile/resume-container/useResumePdfExport.ts
@@ -3,7 +3,30 @@ import { useState } from "react";
import { useRouter } from "next/navigation";
import { toastError, toastSuccess } from "@/lib/toast";
import type { Resume } from "@/models/profile.model";
-import type { ResumeLayout } from "../resume-pdf";
+import {
+ defaultResumeExportSettings,
+ type ResumeExportSettings,
+} from "@/models/resumeExport.model";
+
+// The one rule for what counts as an exportable resume. The dialog reads it to
+// disable Export up front; the hook keeps it as its own safety net.
+export function canExportResume(resume: Resume): boolean {
+ const hasName = Boolean(
+ resume.ContactInfo?.firstName?.trim() ||
+ resume.ContactInfo?.lastName?.trim(),
+ );
+ const hasSections = Boolean(
+ resume.ResumeSections?.some(
+ (s) =>
+ s.summary?.content ||
+ s.workExperiences?.length ||
+ s.educations?.length ||
+ s.licenseOrCertifications?.length ||
+ s.skills?.length,
+ ),
+ );
+ return hasName || hasSections;
+}
// Owns PDF export: generating the blob, downloading it, and the follow-up
// prompt when the resume already has a file attached.
@@ -48,19 +71,11 @@ export function useResumePdfExport(resume: Resume) {
router.refresh();
};
- const handleExportPdf = async (layout: ResumeLayout) => {
- const hasName =
- resume.ContactInfo?.firstName?.trim() ||
- resume.ContactInfo?.lastName?.trim();
- const hasSections = resume.ResumeSections?.some(
- (s) =>
- s.summary?.content ||
- s.workExperiences?.length ||
- s.educations?.length ||
- s.licenseOrCertifications?.length ||
- s.skills?.length,
- );
- if (!hasName && !hasSections) {
+ const handleExportPdf = async (
+ settings: ResumeExportSettings = defaultResumeExportSettings,
+ prepared?: { blob: Blob; filename: string } | null,
+ ) => {
+ if (!canExportResume(resume)) {
toastError(
"Add your contact info and at least one section (Summary, Experience, or Education) before exporting.",
"Nothing to export",
@@ -70,8 +85,14 @@ export function useResumePdfExport(resume: Resume) {
setIsExporting(true);
try {
- const { generateResumePdfBlob } = await import("../resume-pdf");
- const { blob, filename } = await generateResumePdfBlob(resume, layout);
+ // The dialog hands back the blob already on screen; generating is the
+ // fallback for a failed preview or a caller with no preview at all.
+ let output = prepared;
+ if (!output) {
+ const { generateResumePdfBlob } = await import("../resume-pdf");
+ output = await generateResumePdfBlob(resume, settings);
+ }
+ const { blob, filename } = output;
if (!resume.FileId) {
triggerDownload(blob, filename);
diff --git a/src/components/profile/resume-pdf/generateResumePdf.tsx b/src/components/profile/resume-pdf/generateResumePdf.tsx
index 4ae913c..19ad7ef 100644
--- a/src/components/profile/resume-pdf/generateResumePdf.tsx
+++ b/src/components/profile/resume-pdf/generateResumePdf.tsx
@@ -1,7 +1,11 @@
import React from "react";
import { Resume, SectionType } from "@/models/profile.model";
import { htmlToPdfNodes } from "./html-to-pdf";
-import { ResumeLayout, RESUME_LAYOUT_LABELS } from "./types";
+import {
+ RESUME_LAYOUT_LABELS,
+ defaultResumeExportSettings,
+ type ResumeExportSettings,
+} from "./types";
import { simpleHtmlStyles } from "./styles/simple.styles";
import { professionalHtmlStyles } from "./styles/professional.styles";
@@ -23,8 +27,9 @@ export function sanitizeFilename(name: string): string {
export async function generateResumePdfBlob(
resume: Resume,
- layout: ResumeLayout = "simple",
+ settings: ResumeExportSettings = defaultResumeExportSettings,
): Promise<{ blob: Blob; filename: string }> {
+ const layout = settings.template;
const htmlStyles = layout === "professional" ? professionalHtmlStyles : simpleHtmlStyles;
// Parse HTML in the browser main thread before entering react-pdf's rendering context
diff --git a/src/components/profile/resume-pdf/index.ts b/src/components/profile/resume-pdf/index.ts
index 84ec05e..ec3f59c 100644
--- a/src/components/profile/resume-pdf/index.ts
+++ b/src/components/profile/resume-pdf/index.ts
@@ -1,4 +1,4 @@
export { downloadResumePdf, generateResumePdfBlob, sanitizeFilename } from "./generateResumePdf";
export { htmlToPdfNodes } from "./html-to-pdf";
-export type { ResumeLayout } from "./types";
-export { RESUME_LAYOUT_LABELS } from "./types";
+export type { ResumeExportSettings, ResumeLayout } from "./types";
+export { RESUME_LAYOUT_LABELS, defaultResumeExportSettings } from "./types";
diff --git a/src/components/profile/resume-pdf/types.ts b/src/components/profile/resume-pdf/types.ts
index 2480b56..ff7b1f5 100644
--- a/src/components/profile/resume-pdf/types.ts
+++ b/src/components/profile/resume-pdf/types.ts
@@ -1,11 +1,13 @@
import type { Style } from "@react-pdf/types";
-export type ResumeLayout = "simple" | "professional";
-
-export const RESUME_LAYOUT_LABELS: Record<ResumeLayout, string> = {
- simple: "Simple",
- professional: "Professional",
-};
+export type {
+ ResumeExportSettings,
+ ResumeLayout,
+} from "@/models/resumeExport.model";
+export {
+ RESUME_LAYOUT_LABELS,
+ defaultResumeExportSettings,
+} from "@/models/resumeExport.model";
export type HtmlStyleSet = {
bodyText: Style;
diff --git a/src/models/resumeExport.model.ts b/src/models/resumeExport.model.ts
new file mode 100644
index 0000000..18f3752
--- /dev/null
+++ b/src/models/resumeExport.model.ts
@@ -0,0 +1,15 @@
+export type ResumeLayout = "simple" | "professional";
+
+export const RESUME_LAYOUT_LABELS: Record<ResumeLayout, string> = {
+ simple: "Simple",
+ professional: "Professional",
+};
+
+// The preview cache key. Each future setting is one added field here.
+export interface ResumeExportSettings {
+ template: ResumeLayout;
+}
+
+export const defaultResumeExportSettings: ResumeExportSettings = {
+ template: "simple",
+};