fix(i18n): localize admin recovery states
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import React, { useState } from "react";
|
||||
|
||||
import {
|
||||
Box,
|
||||
@@ -17,6 +17,8 @@ import {
|
||||
import { api } from "../api";
|
||||
import { useToast } from "../toast";
|
||||
import { useI18n } from "../i18n/I18nProvider";
|
||||
import { useViewResource } from "../hooks/useViewResource";
|
||||
import ViewStateNotice from "../components/ViewStateNotice";
|
||||
|
||||
type AuditItem = {
|
||||
id: number;
|
||||
@@ -39,36 +41,26 @@ function canUndo(type: string) {
|
||||
|
||||
export default function AdminAuditPage() {
|
||||
const { toast } = useToast();
|
||||
const { t } = useI18n();
|
||||
const [items, setItems] = useState<AuditItem[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const { language, t } = useI18n();
|
||||
const [busyId, setBusyId] = useState<number | null>(null);
|
||||
|
||||
const load = useCallback(async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const auditResource = useViewResource(
|
||||
async () => {
|
||||
const r = await api.get<AuditItem[]>("/admin/audit?take=200");
|
||||
setItems(r.data ?? []);
|
||||
} catch {
|
||||
setItems([]);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
void load();
|
||||
}, [load]);
|
||||
return r.data ?? [];
|
||||
},
|
||||
{ initialData: [], errorMessage: t("adminAuditLoadFailed"), deps: [t] },
|
||||
);
|
||||
|
||||
const undo = async (e: AuditItem) => {
|
||||
if (!canUndo(e.type)) return;
|
||||
setBusyId(e.id);
|
||||
try {
|
||||
const res = await api.post<{ ok: boolean; message: string }>(`/admin/audit/${e.id}/undo`, {});
|
||||
toast(res.data?.message || "Undone.", "success");
|
||||
await load();
|
||||
toast(res.data?.message || t("adminAuditUndone"), "success");
|
||||
await auditResource.reload();
|
||||
} catch (err: any) {
|
||||
const msg = err?.response?.data?.message || err?.response?.data || err?.message || "Undo failed.";
|
||||
const msg = err?.response?.data?.message || err?.response?.data || err?.message || t("adminAuditUndoFailed");
|
||||
toast(String(msg), "error");
|
||||
} finally {
|
||||
setBusyId(null);
|
||||
@@ -80,16 +72,16 @@ export default function AdminAuditPage() {
|
||||
try {
|
||||
await api.post(`/jobapplications/${e.jobApplicationId}/restore`, {});
|
||||
toast(t("adminAuditRestored"), "success");
|
||||
await load();
|
||||
await auditResource.reload();
|
||||
} catch (err: any) {
|
||||
const msg = err?.response?.data || err?.message || "Restore failed.";
|
||||
const msg = err?.response?.data || err?.message || t("adminAuditRestoreFailed");
|
||||
toast(String(msg), "error");
|
||||
} finally {
|
||||
setBusyId(null);
|
||||
}
|
||||
};
|
||||
|
||||
const rows = useMemo(() => items, [items]);
|
||||
const rows = auditResource.data;
|
||||
|
||||
return (
|
||||
<Paper sx={{ mt: 0, p: 2 }}>
|
||||
@@ -100,7 +92,15 @@ export default function AdminAuditPage() {
|
||||
{t("adminAuditSubtitle")}
|
||||
</Typography>
|
||||
|
||||
<TableContainer sx={{ borderRadius: 2, border: "none", boxShadow: "0px 1px 2px 0px rgba(15,23,42,0.04), 0px 8px 24px -12px rgba(15,23,42,0.12)" }}>
|
||||
<ViewStateNotice
|
||||
loading={auditResource.loading}
|
||||
error={auditResource.error}
|
||||
title={t("adminAuditLoadFailed")}
|
||||
description={t("adminAuditLoadFailedBody")}
|
||||
onRetry={auditResource.reload}
|
||||
/>
|
||||
|
||||
{!auditResource.error ? <TableContainer sx={{ borderRadius: 2, border: "none", boxShadow: "0px 1px 2px 0px rgba(15,23,42,0.04), 0px 8px 24px -12px rgba(15,23,42,0.12)" }}>
|
||||
<Table size="small">
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
@@ -113,7 +113,7 @@ export default function AdminAuditPage() {
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{loading ? (
|
||||
{auditResource.loading ? (
|
||||
<TableRow>
|
||||
<TableCell colSpan={6}>
|
||||
<Typography sx={{ color: "text.secondary" }}>{t("loading")}</Typography>
|
||||
@@ -127,7 +127,7 @@ export default function AdminAuditPage() {
|
||||
</TableRow>
|
||||
) : (
|
||||
rows.map((e) => {
|
||||
const jobLabel = e.jobTitle || `Job #${e.jobApplicationId}`;
|
||||
const jobLabel = e.jobTitle || t("adminAuditJobFallback", { id: e.jobApplicationId });
|
||||
const ownerLabel = e.ownerEmail || e.ownerUserName || e.ownerUserId || "-";
|
||||
const details = e.oldValue || e.newValue ? `${e.oldValue ?? ""} -> ${e.newValue ?? ""}` : "";
|
||||
const disabled = busyId === e.id;
|
||||
@@ -135,7 +135,7 @@ export default function AdminAuditPage() {
|
||||
|
||||
return (
|
||||
<TableRow key={e.id} hover>
|
||||
<TableCell>{e.at ? new Date(e.at).toLocaleString() : ""}</TableCell>
|
||||
<TableCell>{e.at ? new Date(e.at).toLocaleString(language === "nb" ? "nb-NO" : "en-GB") : ""}</TableCell>
|
||||
<TableCell>
|
||||
<Chip label={e.type} size="small" variant="outlined" />
|
||||
</TableCell>
|
||||
@@ -161,12 +161,12 @@ export default function AdminAuditPage() {
|
||||
<Box sx={{ display: "flex", gap: 1, flexWrap: "wrap" }}>
|
||||
{canUndo(e.type) ? (
|
||||
<Button size="small" variant="outlined" disabled={disabled} onClick={() => void undo(e)}>
|
||||
Undo
|
||||
{t("adminAuditUndo")}
|
||||
</Button>
|
||||
) : null}
|
||||
{showRestore ? (
|
||||
<Button size="small" variant="contained" disabled={disabled} onClick={() => void restore(e)}>
|
||||
Restore
|
||||
{t("adminAuditRestore")}
|
||||
</Button>
|
||||
) : null}
|
||||
</Box>
|
||||
@@ -177,7 +177,7 @@ export default function AdminAuditPage() {
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableContainer>
|
||||
</TableContainer> : null}
|
||||
</Paper>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -250,11 +250,11 @@ export default function CareerProfilePage() {
|
||||
setLoadError(null);
|
||||
} catch (error: any) {
|
||||
setMe(null);
|
||||
setLoadError(String(error?.response?.data || error?.message || "Unable to load profile right now."));
|
||||
setLoadError(String(error?.response?.data || error?.message || t("profileLoadFailed")));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
}, [t]);
|
||||
|
||||
useEffect(() => {
|
||||
void loadProfile();
|
||||
@@ -292,14 +292,14 @@ export default function CareerProfilePage() {
|
||||
const status = cvRunStatus(run);
|
||||
const prior = previous[run.id];
|
||||
if (activeRunLabels.has(prior) && status === "pending_review") {
|
||||
toast(`CV ${run.trigger} is ready to review.`, "info");
|
||||
toast(t("profileCvRunReady", { trigger: run.trigger }), "info");
|
||||
}
|
||||
if (activeRunLabels.has(prior) && status === "failed") {
|
||||
toast(run.errorMessage || `CV ${run.trigger} failed.`, "error");
|
||||
toast(run.errorMessage || t("profileCvRunFailed", { trigger: run.trigger }), "error");
|
||||
}
|
||||
previous[run.id] = status;
|
||||
}
|
||||
}, [extractionRuns, toast]);
|
||||
}, [extractionRuns, t, toast]);
|
||||
|
||||
// Field-review lookup passed to the extracted sections. They stay decoupled from the full profile
|
||||
// shape; the parent still owns structuredCv and the metadata source.
|
||||
|
||||
@@ -108,11 +108,11 @@ export default function ProfilePage() {
|
||||
setLoadError(null);
|
||||
} catch (error: any) {
|
||||
setMe(null);
|
||||
setLoadError(String(error?.response?.data || error?.message || "Unable to load profile right now."));
|
||||
setLoadError(String(error?.response?.data || error?.message || t("profileLoadFailed")));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
}, [t]);
|
||||
|
||||
useEffect(() => {
|
||||
void loadProfile();
|
||||
|
||||
Reference in New Issue
Block a user