fix(interviews): retain follow-up drafts when switching language

This commit is contained in:
cesnimda
2026-11-17 15:48:39 +01:00
parent 3a88d1d291
commit d48091df89
2 changed files with 45 additions and 5 deletions
@@ -409,7 +409,7 @@ function PrepRow({ jobId, item, busy, onChanged, onError }: {
export function ApplicationFollowUp({ jobId }: { jobId: number }) {
const { t } = useI18n();
const [data, setData] = useState<FollowUp | null>(null);
const [error, setError] = useState<string | null>(null);
const [error, setError] = useState<{ cause: unknown; fallback: "interviewFollowUpLoadFailed" | "interviewFollowUpSaveFailed" } | null>(null);
const [loading, setLoading] = useState(true);
const [busy, setBusy] = useState(false);
const [date, setDate] = useState<string>("");
@@ -424,11 +424,11 @@ export function ApplicationFollowUp({ jobId }: { jobId: number }) {
setAction(result.nextAction ?? "");
setError(null);
} catch (err) {
setError(getApiErrorMessage(err, t("interviewFollowUpLoadFailed")));
setError({ cause: err, fallback: "interviewFollowUpLoadFailed" });
} finally {
setLoading(false);
}
}, [jobId, t]);
}, [jobId]);
useEffect(() => {
load();
@@ -441,7 +441,7 @@ export function ApplicationFollowUp({ jobId }: { jobId: number }) {
setData(result);
setError(null);
} catch (err) {
setError(getApiErrorMessage(err, t("interviewFollowUpSaveFailed")));
setError({ cause: err, fallback: "interviewFollowUpSaveFailed" });
} finally {
setBusy(false);
}
@@ -452,7 +452,7 @@ export function ApplicationFollowUp({ jobId }: { jobId: number }) {
title={t("interviewFollowUpTitle")}
subtitle={t("interviewFollowUpSubtitle")}
loading={loading}
error={error}
error={error ? getApiErrorMessage(error.cause, t(error.fallback)) : null}
>
<Stack spacing={2}>
{data && data.openFollowUpTasks > 0 && (
@@ -297,6 +297,46 @@ test("prep surfaces a load error", async () => {
// ---------- follow-up ----------
test.each(['en', 'nb'] as const)('follow-up language switch from %s preserves the unsaved date and next action without a read', async from => {
localStorage.setItem('uiLanguage', from);
const to = from === 'en' ? 'nb' : 'en';
mockedApi.get.mockReset(); routeGet();
mockedApi.put.mockReset().mockResolvedValue({ data: followUp } as any);
render(<ApplicationFollowUp jobId={7} />);
fireEvent.change(await screen.findByLabelText(translations[from].interviewFollowUpDate), { target: { value: '2026-12-01' } });
fireEvent.change(screen.getByLabelText(translations[from].workspaceNextAction), { target: { value: 'Discuss the offer Øresund' } });
await act(async () => window.dispatchEvent(new StorageEvent('storage', { key: 'uiLanguage', newValue: to })));
expect(screen.getByLabelText(translations[to].interviewFollowUpDate)).toHaveValue('2026-12-01');
expect(screen.getByLabelText(translations[to].workspaceNextAction)).toHaveValue('Discuss the offer Øresund');
expect(mockedApi.get).toHaveBeenCalledTimes(1);
expect(mockedApi.put).not.toHaveBeenCalled();
fireEvent.click(screen.getByRole('button', { name: translations[to].save }));
await waitFor(() => expect(mockedApi.put).toHaveBeenCalledTimes(1));
expect(mockedApi.put).toHaveBeenCalledWith('/jobapplications/7/follow-up', { followUpAt: '2026-12-01', nextAction: 'Discuss the offer Øresund' });
});
test.each((['en', 'nb'] as const).flatMap(from => (['read', 'save'] as const).map(operation => [from, operation] as const)))('follow-up %s %s error stays current without another read', async (from, operation) => {
localStorage.setItem('uiLanguage', from);
const to = from === 'en' ? 'nb' : 'en';
mockedApi.get.mockReset(); routeGet();
mockedApi.put.mockReset();
const key = operation === 'read' ? 'interviewFollowUpLoadFailed' : 'interviewFollowUpSaveFailed';
if (operation === 'read') mockedApi.get.mockRejectedValue(new Error('synthetic follow-up read failure'));
else mockedApi.put.mockRejectedValue(new Error('synthetic follow-up save failure'));
try {
render(<ApplicationFollowUp jobId={7} />);
if (operation === 'save') {
await screen.findByLabelText(translations[from].interviewFollowUpDate);
fireEvent.click(screen.getByRole('button', { name: translations[from].save }));
}
expect(await screen.findByText(translations[from][key])).toBeVisible();
await act(async () => window.dispatchEvent(new StorageEvent('storage', { key: 'uiLanguage', newValue: to })));
expect(await screen.findByText(translations[to][key])).toBeVisible();
expect(mockedApi.get).toHaveBeenCalledTimes(1);
expect(mockedApi.put).toHaveBeenCalledTimes(operation === 'save' ? 1 : 0);
} finally { mockedApi.put.mockReset(); }
});
test("follow-up loads the existing date and open checklist tasks", async () => {
routeGet();