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 resume section validation and messaging for default resume actions

Khuram Niaz89202b02f086
diff --git a/__tests__/defaultResume.actions.spec.ts b/__tests__/defaultResume.actions.spec.ts
index b69f034..5d60f39 100644
--- a/__tests__/defaultResume.actions.spec.ts
+++ b/__tests__/defaultResume.actions.spec.ts
@@ -83,7 +83,9 @@ describe("Default Resume Actions", () => {
describe("setDefaultResume", () => {
it("sets the pointer to a resume the user owns", async () => {
(getCurrentUser as any).mockResolvedValue(mockUser);
- (prisma.resume.findFirst as any).mockResolvedValue({ id: "resume-1" });
+ (prisma.resume.findFirst as any).mockResolvedValue({
+ _count: { ResumeSections: 2 },
+ });
(prisma.user.update as any).mockResolvedValue({});
const result = await setDefaultResume("resume-1");
@@ -91,7 +93,7 @@ describe("Default Resume Actions", () => {
expect(result).toEqual({ success: true });
expect(prisma.resume.findFirst).toHaveBeenCalledWith({
where: { id: "resume-1", profile: { userId: mockUser.id } },
- select: { id: true },
+ select: { _count: { select: { ResumeSections: true } } },
});
expect(prisma.user.update).toHaveBeenCalledWith({
where: { id: mockUser.id },
@@ -99,6 +101,21 @@ describe("Default Resume Actions", () => {
});
});
+ it("rejects a resume below the minimum section count and leaves the pointer unchanged", async () => {
+ (getCurrentUser as any).mockResolvedValue(mockUser);
+ (prisma.resume.findFirst as any).mockResolvedValue({
+ _count: { ResumeSections: 1 },
+ });
+
+ const result = await setDefaultResume("sparse-resume");
+
+ expect(result).toEqual({
+ success: false,
+ message: "Add at least 2 sections before setting this resume as default.",
+ });
+ expect(prisma.user.update).not.toHaveBeenCalled();
+ });
+
it("rejects a resume the user does not own and leaves the pointer unchanged", async () => {
(getCurrentUser as any).mockResolvedValue(mockUser);
(prisma.resume.findFirst as any).mockResolvedValue(null);
diff --git a/__tests__/resumeSections.spec.ts b/__tests__/resumeSections.spec.ts
new file mode 100644
index 0000000..34d4705
--- /dev/null
+++ b/__tests__/resumeSections.spec.ts
@@ -0,0 +1,56 @@
+import {
+ buildInsufficientSectionsMessage,
+ hasMinResumeSections,
+} from "@/lib/resumeSections";
+import { APP_CONSTANTS } from "@/lib/constants";
+
+describe("hasMinResumeSections", () => {
+ it("returns false below the minimum", () => {
+ expect(hasMinResumeSections(0)).toBe(false);
+ expect(
+ hasMinResumeSections(APP_CONSTANTS.MIN_RESUME_SECTIONS_FOR_SELECTION - 1),
+ ).toBe(false);
+ });
+
+ it("returns true at or above the minimum", () => {
+ expect(
+ hasMinResumeSections(APP_CONSTANTS.MIN_RESUME_SECTIONS_FOR_SELECTION),
+ ).toBe(true);
+ expect(
+ hasMinResumeSections(APP_CONSTANTS.MIN_RESUME_SECTIONS_FOR_SELECTION + 1),
+ ).toBe(true);
+ });
+
+ it("treats null/undefined as zero sections", () => {
+ expect(hasMinResumeSections(null)).toBe(false);
+ expect(hasMinResumeSections(undefined)).toBe(false);
+ });
+});
+
+describe("buildInsufficientSectionsMessage", () => {
+ it("includes the minimum count and the action", () => {
+ const message = buildInsufficientSectionsMessage(
+ "setting this resume as default",
+ );
+
+ expect(message).toContain(
+ String(APP_CONSTANTS.MIN_RESUME_SECTIONS_FOR_SELECTION),
+ );
+ expect(message).toContain("setting this resume as default");
+ });
+
+ it("appends the hint in parentheses when provided", () => {
+ const message = buildInsufficientSectionsMessage(
+ "running a review",
+ "e.g. Summary and Experience",
+ );
+
+ expect(message).toContain("(e.g. Summary and Experience)");
+ });
+
+ it("omits the parentheses when no hint is provided", () => {
+ const message = buildInsufficientSectionsMessage("running a review");
+
+ expect(message).not.toContain("(");
+ });
+});
diff --git a/__tests__/resumeSections.utils.spec.ts b/__tests__/resumeSections.utils.spec.ts
new file mode 100644
index 0000000..efc3500
--- /dev/null
+++ b/__tests__/resumeSections.utils.spec.ts
@@ -0,0 +1,37 @@
+import { warnInsufficientResumeSections } from "@/utils/resumeSections.utils";
+import { buildInsufficientSectionsMessage } from "@/lib/resumeSections";
+
+const mockToast = vi.fn();
+vi.mock("@/components/ui/use-toast", () => ({
+ toast: (...args: any[]) => mockToast(...args),
+}));
+
+describe("warnInsufficientResumeSections", () => {
+ it("shows a destructive toast with the built message", () => {
+ warnInsufficientResumeSections("setting this resume as default");
+
+ expect(mockToast).toHaveBeenCalledWith({
+ variant: "destructive",
+ title: "Not enough content",
+ description: buildInsufficientSectionsMessage(
+ "setting this resume as default",
+ ),
+ });
+ });
+
+ it("forwards the hint through to the built message", () => {
+ warnInsufficientResumeSections(
+ "running a review",
+ "e.g. Summary and Experience",
+ );
+
+ expect(mockToast).toHaveBeenCalledWith({
+ variant: "destructive",
+ title: "Not enough content",
+ description: buildInsufficientSectionsMessage(
+ "running a review",
+ "e.g. Summary and Experience",
+ ),
+ });
+ });
+});
diff --git a/src/actions/profile.actions.ts b/src/actions/profile.actions.ts
index 2cc50b0..4cc1203 100644
--- a/src/actions/profile.actions.ts
+++ b/src/actions/profile.actions.ts
@@ -14,6 +14,10 @@ import {
} from "@/models/skills.schema";
import { getCurrentUser } from "@/utils/user.utils";
import { APP_CONSTANTS } from "@/lib/constants";
+import {
+ buildInsufficientSectionsMessage,
+ hasMinResumeSections,
+} from "@/lib/resumeSections";
import { revalidatePath } from "next/cache";
import { z } from "zod";
import path from "path";
@@ -146,11 +150,19 @@ export const setDefaultResume = async (
// Verify ownership before pointing the user at this resume.
const owned = await prisma.resume.findFirst({
where: { id: resumeId, profile: { userId: user.id } },
- select: { id: true },
+ select: { _count: { select: { ResumeSections: true } } },
});
if (!owned) {
throw new Error("Resume not found");
}
+ if (!hasMinResumeSections(owned._count.ResumeSections)) {
+ return {
+ success: false,
+ message: buildInsufficientSectionsMessage(
+ "setting this resume as default",
+ ),
+ };
+ }
await prisma.user.update({
where: { id: user.id },
diff --git a/src/components/profile/AiJobMatchSection.tsx b/src/components/profile/AiJobMatchSection.tsx
index 11754a9..f817fe1 100644
--- a/src/components/profile/AiJobMatchSection.tsx
+++ b/src/components/profile/AiJobMatchSection.tsx
@@ -286,6 +286,12 @@ export const AiJobMatchSection = ({
{/* Scrollable content */}
<div className="flex-1 overflow-y-auto px-6 pt-4 pb-6" onScroll={handleSheetScroll}>
+ {selectedModel.provider === "ollama" &&
+ ollamaConnected === false &&
+ connectionError && (
+ <p className="text-xs text-red-600">{connectionError}</p>
+ )}
+
{!isLoading && !selectedResumeId && (
<div className={`flex flex-col items-center gap-2${!hasContent ? " pt-12" : " py-2"}`}>
<Select
@@ -313,12 +319,6 @@ export const AiJobMatchSection = ({
</SelectGroup>
</SelectContent>
</Select>
-
- {selectedModel.provider === "ollama" &&
- ollamaConnected === false &&
- connectionError && (
- <p className="text-xs text-destructive">{connectionError}</p>
- )}
</div>
)}
diff --git a/src/components/profile/AiResumeReviewSection.tsx b/src/components/profile/AiResumeReviewSection.tsx
index 7902b73..ada0a5c 100644
--- a/src/components/profile/AiResumeReviewSection.tsx
+++ b/src/components/profile/AiResumeReviewSection.tsx
@@ -26,6 +26,10 @@ import { checkOllamaConnection } from "@/utils/ai.utils";
import { getUserSettings } from "@/actions/userSettings.actions";
import { useSlowResponseWarning } from "@/hooks/useSlowResponseWarning";
import { SlowResponseWarning } from "../common/SlowResponseWarning";
+import {
+ hasMinResumeSections,
+ warnInsufficientResumeSections,
+} from "@/utils/resumeSections.utils";
interface AiSectionProps {
resume: Resume;
@@ -79,7 +83,8 @@ const AiResumeReviewSection = ({ resume }: AiSectionProps) => {
const [result, setResult] = useState<ResumeReviewResult | undefined>();
const [isLoading, setIsLoading] = useState(false);
const abortRef = useRef<AbortController | null>(null);
- const { scrollAnchorRef, handleSheetScroll, resetScroll } = useSheetAutoScroll(isLoading, result);
+ const { scrollAnchorRef, handleSheetScroll, resetScroll } =
+ useSheetAutoScroll(isLoading, result);
const { width, handleMouseDown } = useResizablePanel("ai-panel-width");
const stop = useCallback(() => {
@@ -89,13 +94,11 @@ const AiResumeReviewSection = ({ resume }: AiSectionProps) => {
}, []);
const getResumeReview = async () => {
- if (!resume || (resume.ResumeSections?.length ?? 0) < 2) {
- toast({
- variant: "destructive",
- title: "Not enough content",
- description:
- "Add at least 2 sections (e.g. Summary and Experience) before running a review.",
- });
+ if (!resume || !hasMinResumeSections(resume.ResumeSections?.length)) {
+ warnInsufficientResumeSections(
+ "running a review",
+ "e.g. Summary and Experience",
+ );
return;
}
@@ -192,7 +195,9 @@ const AiResumeReviewSection = ({ resume }: AiSectionProps) => {
<SheetTitle className="text-[11px] font-bold tracking-[0.15em] uppercase text-foreground leading-none shrink-0 m-0">
AI REVIEW
</SheetTitle>
- <span className="text-muted-foreground/30 text-xs select-none">···</span>
+ <span className="text-muted-foreground/30 text-xs select-none">
+ ···
+ </span>
<div className="flex items-center gap-1.5 min-w-0">
{statusIcon}
<span className="text-xs text-muted-foreground font-mono truncate">
@@ -212,32 +217,39 @@ const AiResumeReviewSection = ({ resume }: AiSectionProps) => {
</SheetClose>
</div>
- <div className="flex-1 overflow-y-auto px-6 pt-4 pb-6" onScroll={handleSheetScroll}>
- {!isLoading && <div className={`flex justify-center items-center${!hasContent ? " min-h-[calc(100dvh-9rem)]" : " py-2"}`}>
- <Button
- size="sm"
- variant="outline"
- className="h-8 gap-1 cursor-pointer"
- onClick={getResumeReview}
- disabled={
- isLoading ||
- (selectedModel.provider === "ollama" &&
- ollamaConnected === false)
- }
- >
- <Sparkles className="h-3.5 w-3.5" />
- <span className="sr-only sm:not-sr-only sm:whitespace-nowrap">
- Generate AI Review
- </span>
- </Button>
- </div>}
-
+ <div
+ className="flex-1 overflow-y-auto px-6 pt-4 pb-6"
+ onScroll={handleSheetScroll}
+ >
{selectedModel.provider === "ollama" &&
ollamaConnected === false &&
connectionError && (
- <p className="text-xs text-destructive mt-2">{connectionError}</p>
+ <p className="text-xs text-red-600">{connectionError}</p>
)}
+ {!isLoading && (
+ <div
+ className={`flex justify-center items-center${!hasContent ? " min-h-[calc(100dvh-9rem)]" : " py-2"}`}
+ >
+ <Button
+ size="sm"
+ variant="outline"
+ className="h-8 gap-1 cursor-pointer"
+ onClick={getResumeReview}
+ disabled={
+ isLoading ||
+ (selectedModel.provider === "ollama" &&
+ ollamaConnected === false)
+ }
+ >
+ <Sparkles className="h-3.5 w-3.5" />
+ <span className="sr-only sm:not-sr-only sm:whitespace-nowrap">
+ Generate AI Review
+ </span>
+ </Button>
+ </div>
+ )}
+
{isLoading && !hasContent ? (
<div className="flex items-center flex-col mt-4">
<Loading />
diff --git a/src/components/profile/ProfileContainer.tsx b/src/components/profile/ProfileContainer.tsx
index 097bd82..6287d6f 100644
--- a/src/components/profile/ProfileContainer.tsx
+++ b/src/components/profile/ProfileContainer.tsx
@@ -113,6 +113,7 @@ const ProfileContainer = () => {
jobCount: r._count?.Job ?? 0,
FileId: r.FileId,
isDefault: r.id === defaultResumeId,
+ sectionCount: r._count?.ResumeSections ?? 0,
}));
const coverLetterDocs: ProfileDocument[] = coverLetters.map((cl) => ({
id: cl.id!,
diff --git a/src/components/profile/ResumeContainer.tsx b/src/components/profile/ResumeContainer.tsx
index 8d0e44e..b48f5d1 100644
--- a/src/components/profile/ResumeContainer.tsx
+++ b/src/components/profile/ResumeContainer.tsx
@@ -36,6 +36,7 @@ import {
import { Button } from "../ui/button";
import { Badge } from "../ui/badge";
import {
+ ArrowLeft,
MoreVertical,
FileDown,
Sparkles,
@@ -58,9 +59,14 @@ import {
import { ResumeImportData } from "@/models/resumeImport.schema";
import { AiModel, defaultModel } from "@/models/ai.model";
import { getUserSettings } from "@/actions/userSettings.actions";
+import { checkOllamaConnection } from "@/utils/ai.utils";
import { streamResumeImport } from "@/utils/resumeImportStream.utils";
import { extractSkillCategories } from "@/utils/skillImport.utils";
import type { DeepPartial } from "ai";
+import {
+ hasMinResumeSections,
+ warnInsufficientResumeSections,
+} from "@/utils/resumeSections.utils";
type PendingCard = {
id: string;
@@ -342,6 +348,7 @@ function ResumeContainer({
defaultResumeId?: string | null;
}) {
const router = useRouter();
+ const goBack = () => router.back();
const isDefault = !!resume?.id && resume.id === defaultResumeId;
const [setDefaultConfirmOpen, setSetDefaultConfirmOpen] = useState(false);
const resumeSectionRef = useRef<AddResumeSectionRef>(null);
@@ -365,6 +372,10 @@ function ResumeContainer({
// AI availability for "Structure with AI" button
const [aiModel, setAiModel] = useState<AiModel>(defaultModel);
const [aiReady, setAiReady] = useState(false);
+ const [ollamaConnected, setOllamaConnected] = useState<boolean | null>(
+ null,
+ );
+ const [connectionError, setConnectionError] = useState<string>("");
// Plain boolean (not useTransition): streaming fires rapid state updates that
// must not run as interruptible transition renders.
const [isStructuring, setIsStructuring] = useState(false);
@@ -494,6 +505,18 @@ function ResumeContainer({
};
setAiModel(model);
setAiReady(true);
+ if (model.provider === "ollama") {
+ setOllamaConnected(null);
+ setConnectionError("");
+ checkOllamaConnection(model.provider).then((result) => {
+ setOllamaConnected(result.isConnected);
+ if (!result.isConnected) {
+ setConnectionError(
+ result.error || "Ollama is not reachable.",
+ );
+ }
+ });
+ }
}
});
}
@@ -741,6 +764,11 @@ function ResumeContainer({
return (
<>
+ <div className="flex justify-between">
+ <Button title="Go Back" size="sm" variant="outline" onClick={goBack}>
+ <ArrowLeft />
+ </Button>
+ </div>
<Card>
<CardHeader className="flex-col gap-2 sm:flex-row sm:justify-between sm:items-center lg:grid lg:grid-cols-3 lg:items-center">
<div className="flex items-center gap-2">
@@ -798,7 +826,15 @@ function ResumeContainer({
{!isDefault && (
<DropdownMenuItem
className="cursor-pointer"
- onClick={() => setSetDefaultConfirmOpen(true)}
+ onClick={() => {
+ if (!hasMinResumeSections(ResumeSections?.length)) {
+ warnInsufficientResumeSections(
+ "setting this resume as default",
+ );
+ return;
+ }
+ setSetDefaultConfirmOpen(true);
+ }}
>
<Star className="h-4 w-4 mr-2" />
Set as default
@@ -881,13 +917,25 @@ function ResumeContainer({
{showStructureWithAI && (
<Card className="border-dashed">
<CardHeader className="flex-row items-center justify-between">
- <p className="text-sm text-muted-foreground">
- A file is attached. Structure it into sections using AI.
- </p>
+ <div>
+ <p className="text-sm text-muted-foreground">
+ A file is attached. Structure it into sections using AI.
+ </p>
+ {aiModel.provider === "ollama" &&
+ ollamaConnected === false &&
+ connectionError && (
+ <p className="text-xs text-red-600 mt-1">
+ {connectionError}
+ </p>
+ )}
+ </div>
<Button
size="sm"
variant="outline"
- disabled={isStructuring}
+ disabled={
+ isStructuring ||
+ (aiModel.provider === "ollama" && ollamaConnected === false)
+ }
onClick={handleStructureWithAI}
>
{isStructuring ? (
diff --git a/src/components/profile/ResumeTable.tsx b/src/components/profile/ResumeTable.tsx
index fcda457..5d6818a 100644
--- a/src/components/profile/ResumeTable.tsx
+++ b/src/components/profile/ResumeTable.tsx
@@ -32,6 +32,10 @@ import { deleteResumeById, setDefaultResume } from "@/actions/profile.actions";
import { deleteCoverLetterById } from "@/actions/coverLetter.actions";
import { DeleteAlertDialog } from "../DeleteAlertDialog";
import { Badge } from "../ui/badge";
+import {
+ hasMinResumeSections,
+ warnInsufficientResumeSections,
+} from "@/utils/resumeSections.utils";
type DocumentTableProps = {
documents: ProfileDocument[];
@@ -90,6 +94,10 @@ function DocumentTable({
const onSetDefault = (doc: ProfileDocument) => {
if (!doc.id) return;
+ if (!hasMinResumeSections(doc.sectionCount)) {
+ warnInsufficientResumeSections("setting this resume as default");
+ return;
+ }
// Confirm whenever a different resume already holds the default. Decided by
// defaultResumeId (not the loaded-docs lookup) so it fires even when the
// current default lives on a not-yet-loaded page.
diff --git a/src/components/settings/AiSettings.tsx b/src/components/settings/AiSettings.tsx
index 4ae6253..576cf23 100644
--- a/src/components/settings/AiSettings.tsx
+++ b/src/components/settings/AiSettings.tsx
@@ -1,5 +1,5 @@
"use client";
-import { useEffect, useState } from "react";
+import { useCallback, useEffect, useState } from "react";
import {
AiModel,
AiProvider,
@@ -23,7 +23,7 @@ import {
import { Label } from "../ui/label";
import { Button } from "../ui/button";
import { toast } from "../ui/use-toast";
-import { XCircle, Loader2 } from "lucide-react";
+import { XCircle, Loader2, RefreshCw } from "lucide-react";
import { checkOllamaConnection } from "@/utils/ai.utils";
import { getUserSettings, updateAiSettings } from "@/actions/userSettings.actions";
@@ -84,81 +84,92 @@ function AiSettings() {
}
};
- useEffect(() => {
- if (!isInitialized) return;
- const entry = PROVIDER_REGISTRY[selectedModel.provider];
- if (!entry) return;
+ const fetchModelsForProvider = useCallback(
+ (provider: AiProvider) => {
+ const entry = PROVIDER_REGISTRY[provider];
+ if (!entry) return () => {};
- if (!entry.modelsEndpoint) {
- const fallbackModels = getFallbackModels(selectedModel.provider);
- setFetchedModels(fallbackModels);
- setSelectedModel((prev) =>
- prev.model && !fallbackModels.includes(prev.model)
- ? { ...prev, model: undefined }
- : prev,
- );
- return;
- }
+ if (!entry.modelsEndpoint) {
+ const fallbackModels = getFallbackModels(provider);
+ setFetchedModels(fallbackModels);
+ setSelectedModel((prev) =>
+ prev.model && !fallbackModels.includes(prev.model)
+ ? { ...prev, model: undefined }
+ : prev,
+ );
+ return () => {};
+ }
- const fallback = getFallbackModels(selectedModel.provider);
- let cancelled = false;
- setIsLoadingModels(true);
- setFetchError("");
- setConnectionError("");
+ const fallback = getFallbackModels(provider);
+ let cancelled = false;
+ setIsLoadingModels(true);
+ setFetchError("");
+ setConnectionError("");
- (async () => {
- try {
- if (entry.category === "local") {
- const connResult = await checkOllamaConnection(selectedModel.provider as AiProvider);
- if (!connResult.isConnected) {
+ (async () => {
+ try {
+ if (entry.category === "local") {
+ const connResult = await checkOllamaConnection(provider);
+ if (!connResult.isConnected) {
+ if (!cancelled) {
+ setFetchedModels(fallback);
+ setConnectionError(connResult.error || "Ollama is not reachable.");
+ }
+ return;
+ }
+ }
+ const response = await fetch(`/api/ai/${entry.modelsEndpoint}`);
+ if (!response.ok) {
+ const errorData = await response.json().catch(() => null);
+ const errorMsg = errorData?.error
+ || (entry.category === "local"
+ ? `Failed to fetch ${entry.displayName} models. Make sure ${entry.displayName} is running.`
+ : `Failed to fetch ${entry.displayName} models. Please check your API key in API Keys settings.`);
if (!cancelled) {
+ setFetchError(errorMsg);
setFetchedModels(fallback);
- setConnectionError(connResult.error || "Ollama is not reachable.");
}
return;
}
- }
- const response = await fetch(`/api/ai/${entry.modelsEndpoint}`);
- if (!response.ok) {
- const errorData = await response.json().catch(() => null);
- const errorMsg = errorData?.error
- || (entry.category === "local"
- ? `Failed to fetch ${entry.displayName} models. Make sure ${entry.displayName} is running.`
- : `Failed to fetch ${entry.displayName} models. Please check your API key in API Keys settings.`);
+ const data = await response.json();
+ const models = entry.parseModelsResponse?.(data) ?? [];
+ const finalModels = models.length > 0 ? models : fallback;
+ if (!cancelled) {
+ setFetchedModels(finalModels);
+ setSelectedModel((prev) =>
+ prev.model && !finalModels.includes(prev.model)
+ ? { ...prev, model: undefined }
+ : prev,
+ );
+ }
+ } catch (error) {
+ console.error(`Error fetching ${entry.displayName} models:`, error);
if (!cancelled) {
- setFetchError(errorMsg);
setFetchedModels(fallback);
+ setFetchError(
+ entry.category === "local"
+ ? `Failed to fetch ${entry.displayName} models. Make sure ${entry.displayName} is running.`
+ : `Failed to fetch ${entry.displayName} models. Please check your API key in API Keys settings.`,
+ );
}
- return;
+ } finally {
+ if (!cancelled) setIsLoadingModels(false);
}
- const data = await response.json();
- const models = entry.parseModelsResponse?.(data) ?? [];
- const finalModels = models.length > 0 ? models : fallback;
- if (!cancelled) {
- setFetchedModels(finalModels);
- setSelectedModel((prev) =>
- prev.model && !finalModels.includes(prev.model)
- ? { ...prev, model: undefined }
- : prev,
- );
- }
- } catch (error) {
- console.error(`Error fetching ${entry.displayName} models:`, error);
- if (!cancelled) {
- setFetchedModels(fallback);
- setFetchError(
- entry.category === "local"
- ? `Failed to fetch ${entry.displayName} models. Make sure ${entry.displayName} is running.`
- : `Failed to fetch ${entry.displayName} models. Please check your API key in API Keys settings.`,
- );
- }
- } finally {
- if (!cancelled) setIsLoadingModels(false);
- }
- })();
+ })();
- return () => { cancelled = true; };
- }, [selectedModel.provider, isInitialized]);
+ return () => { cancelled = true; };
+ },
+ [],
+ );
+
+ useEffect(() => {
+ if (!isInitialized) return;
+ return fetchModelsForProvider(selectedModel.provider);
+ }, [selectedModel.provider, isInitialized, fetchModelsForProvider]);
+
+ const retryConnection = () => {
+ fetchModelsForProvider(selectedModel.provider);
+ };
const saveModelSettings = async () => {
if (!selectedModel.model) {
@@ -292,9 +303,21 @@ function AiSettings() {
</div>
)}
{connectionError && (
- <div className="flex items-center gap-1 text-red-600 text-sm mt-2">
- <XCircle className="h-4 w-4 flex-shrink-0" />
- <span>{connectionError}</span>
+ <div className="flex items-center gap-1 mt-2">
+ <Button
+ variant="outline"
+ size="sm"
+ className="h-6 flex-shrink-0 text-muted-foreground"
+ onClick={retryConnection}
+ disabled={isLoadingModels}
+ >
+ <RefreshCw className={`h-3.5 w-3.5 ${isLoadingModels ? "animate-spin" : ""}`} />
+ Retry
+ </Button>
+ <div className="flex items-center gap-1 text-red-600 text-sm">
+ <XCircle className="h-4 w-4 flex-shrink-0" />
+ <span>{connectionError}</span>
+ </div>
</div>
)}
</div>
diff --git a/src/lib/resumeSections.ts b/src/lib/resumeSections.ts
new file mode 100644
index 0000000..b91ae8d
--- /dev/null
+++ b/src/lib/resumeSections.ts
@@ -0,0 +1,16 @@
+import { APP_CONSTANTS } from "@/lib/constants";
+
+export const hasMinResumeSections = (
+ sectionCount: number | null | undefined,
+): boolean =>
+ (sectionCount ?? 0) >= APP_CONSTANTS.MIN_RESUME_SECTIONS_FOR_SELECTION;
+
+export const buildInsufficientSectionsMessage = (
+ action: string,
+ hint?: string,
+): string => {
+ const min = APP_CONSTANTS.MIN_RESUME_SECTIONS_FOR_SELECTION;
+ return `Add at least ${min} sections${
+ hint ? ` (${hint})` : ""
+ } before ${action}.`;
+};
diff --git a/src/models/profile.model.ts b/src/models/profile.model.ts
index ba4ec6d..d111647 100644
--- a/src/models/profile.model.ts
+++ b/src/models/profile.model.ts
@@ -12,6 +12,7 @@ export interface Resume {
File?: File;
_count?: {
Job?: number;
+ ResumeSections?: number;
};
}
@@ -147,4 +148,5 @@ export interface ProfileDocument {
FileId?: string;
content?: string;
isDefault?: boolean;
+ sectionCount?: number;
}
diff --git a/src/utils/resumeSections.utils.ts b/src/utils/resumeSections.utils.ts
new file mode 100644
index 0000000..0c552a6
--- /dev/null
+++ b/src/utils/resumeSections.utils.ts
@@ -0,0 +1,18 @@
+import { toast } from "@/components/ui/use-toast";
+import {
+ buildInsufficientSectionsMessage,
+ hasMinResumeSections,
+} from "@/lib/resumeSections";
+
+export { hasMinResumeSections };
+
+export const warnInsufficientResumeSections = (
+ action: string,
+ hint?: string,
+): void => {
+ toast({
+ variant: "destructive",
+ title: "Not enough content",
+ description: buildInsufficientSectionsMessage(action, hint),
+ });
+};