fix(i18n): preserve attachment dialogs across language changes
This commit is contained in:
@@ -88,6 +88,8 @@ export default function Attachments({ jobId }: { jobId: number }) {
|
||||
const labelId = useId();
|
||||
const { toast } = useToast();
|
||||
const { language, t } = useI18n();
|
||||
const currentT = useRef(t);
|
||||
currentT.current = t;
|
||||
const { confirmAction, promptForValue } = useDialogActions();
|
||||
const [items, setItems] = useState<AttachmentItem[]>([]);
|
||||
const [loadError, setLoadError] = useState<string | null>(null);
|
||||
@@ -105,11 +107,11 @@ export default function Attachments({ jobId }: { jobId: number }) {
|
||||
setItems(res.data);
|
||||
setLoadError(null);
|
||||
} catch (error) {
|
||||
setLoadError(getApiErrorMessage(error, t("attachmentsLoadFailed")));
|
||||
setLoadError(getApiErrorMessage(error, currentT.current("attachmentsLoadFailed")));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [jobId, t]);
|
||||
}, [jobId]);
|
||||
|
||||
useEffect(() => {
|
||||
void load();
|
||||
@@ -146,7 +148,7 @@ export default function Attachments({ jobId }: { jobId: number }) {
|
||||
);
|
||||
|
||||
const rename = async (a: AttachmentItem) => {
|
||||
const next = await promptForValue(t("attachmentsRenamePrompt"), a.fileName, { title: t("attachmentsRenameTitle"), confirmLabel: t("attachmentsRename") });
|
||||
const next = await promptForValue({ key: "attachmentsRenamePrompt" }, a.fileName, { title: { key: "attachmentsRenameTitle" }, confirmLabel: { key: "attachmentsRename" } });
|
||||
if (!next || next.trim() === a.fileName) return;
|
||||
try {
|
||||
await api.patch(`/attachments/${a.id}`, { fileName: next.trim() });
|
||||
@@ -168,7 +170,7 @@ export default function Attachments({ jobId }: { jobId: number }) {
|
||||
};
|
||||
|
||||
const remove = async (a: AttachmentItem) => {
|
||||
if (!(await confirmAction(t("attachmentsDeleteConfirm", { name: a.fileName }), { title: t("attachmentsDeleteTitle"), confirmLabel: t("attachmentsDelete"), destructive: true }))) return;
|
||||
if (!(await confirmAction({ key: "attachmentsDeleteConfirm", params: { name: a.fileName } }, { title: { key: "attachmentsDeleteTitle" }, confirmLabel: { key: "attachmentsDelete" }, destructive: true }))) return;
|
||||
try {
|
||||
await api.delete(`/attachments/${a.id}`);
|
||||
toast(t("attachmentsDeleted"), "success");
|
||||
|
||||
Reference in New Issue
Block a user