fix(interviews): distinguish linked CV loading failure and empty state

This commit is contained in:
cesnimda
2026-11-17 18:49:46 +01:00
parent 06d92b3827
commit bf9b6d5e84
2 changed files with 71 additions and 5 deletions
@@ -216,6 +216,9 @@ function InterviewAiAssistant({ jobId, onAccepted }: { jobId: number; onAccepted
const { canUseAi } = useAccountPlan();
const { language: uiLanguage, t } = useI18n();
const [cv, setCv] = useState<ApplicationCv | null>(null);
const [cvLoading, setCvLoading] = useState(true);
const [cvError, setCvError] = useState<{ cause: unknown } | null>(null);
const [cvReadAttempt, setCvReadAttempt] = useState(0);
const [focus, setFocus] = useState<(typeof INTERVIEW_AI_FOCUS)[number]["key"]>("full");
const [language, setLanguage] = useState<"en" | "nb-NO">(() => uiLanguage === "nb" ? "nb-NO" : "en");
const [instructions, setInstructions] = useState("");
@@ -225,11 +228,13 @@ function InterviewAiAssistant({ jobId, onAccepted }: { jobId: number; onAccepted
useEffect(() => {
let active = true;
setCv(null); setCvLoading(true); setCvError(null);
applicationAssetsApi.cv(jobId)
.then((result) => { if (active) setCv(result); })
.catch(() => { if (active) setCv(null); });
.catch((cause) => { if (active) setCvError({ cause }); })
.finally(() => { if (active) setCvLoading(false); });
return () => { active = false; };
}, [jobId]);
}, [jobId, cvReadAttempt]);
const selected = INTERVIEW_AI_FOCUS.find((item) => item.key === focus) ?? INTERVIEW_AI_FOCUS[0];
const generate = async () => {
@@ -274,15 +279,16 @@ function InterviewAiAssistant({ jobId, onAccepted }: { jobId: number; onAccepted
}
};
const hasCv = !!cv?.attachedVariantId;
const hasCv = !cvLoading && !cvError && !!cv?.attachedVariantId;
return (
<Shell title={t("interviewAiTitle")} subtitle={t("interviewAiSubtitle")} loading={false} error={null}>
<Stack spacing={2}>
{hasCv ? (
<ViewStateNotice title={t("assetsLoadFailed")} loading={cvLoading} error={cvError ? { kind: "error", message: getApiErrorMessage(cvError.cause, t("assetsLoadFailed")), retryable: true } : null} onRetry={() => setCvReadAttempt(attempt => attempt + 1)} compact />
{!cvLoading && !cvError && (hasCv ? (
<Alert severity="success" variant="outlined">{t("interviewAiUsing")} <strong>{cv?.attachedVariantName}</strong></Alert>
) : (
<Alert severity="info">{t("interviewAiSelectCv")}</Alert>
)}
))}
<Stack direction={{ xs: "column", sm: "row" }} spacing={1.5}>
<TextField select size="small" label={t("interviewAiFocus")} value={focus} onChange={(event) => setFocus(event.target.value as typeof focus)} sx={{ minWidth: 220 }}>
{INTERVIEW_AI_FOCUS.map((item) => <MenuItem key={item.key} value={item.key}>{t(item.labelKey)}</MenuItem>)}