fix(i18n): preserve pending admin confirmations and users reads
This commit is contained in:
@@ -127,7 +127,7 @@ export default function AdminUsersPage() {
|
||||
const currentTranslation = useRef(t);
|
||||
useEffect(() => { currentTranslation.current=t; }, [t]);
|
||||
useEffect(() => { const lifetime=owner.current; lifetime.mounted=true; lifetime.generation+=1; return () => { lifetime.mounted=false; lifetime.generation+=1; }; }, []);
|
||||
const userResource=useViewResource(async () => (await api.get<UserDto[]>("/users")).data ?? [], { initialData: [], errorMessage: t("adminUsersLoadFailed") });
|
||||
const userResource=useViewResource(async () => (await api.get<UserDto[]>("/users")).data ?? [], { initialData: [], errorMessage: "" });
|
||||
const users=userResource.data;
|
||||
const loading=userResource.loading || userResource.refreshing;
|
||||
const load=userResource.reload;
|
||||
@@ -179,11 +179,11 @@ export default function AdminUsersPage() {
|
||||
const name = u.userName || u.email || u.id;
|
||||
const confirmed = await confirmAction(
|
||||
u.isCurrentUser
|
||||
? t("adminUsersSelfDemoteWarning")
|
||||
: t("adminUsersDemoteWarning", { name }),
|
||||
? { key: "adminUsersSelfDemoteWarning" }
|
||||
: { key: "adminUsersDemoteWarning", params: { name } },
|
||||
{
|
||||
title: u.isCurrentUser ? t("adminUsersSelfDemoteTitle") : t("adminUsersDemoteTitle"),
|
||||
confirmLabel: t("adminUsersRemoveAdmin"),
|
||||
title: { key: u.isCurrentUser ? "adminUsersSelfDemoteTitle" : "adminUsersDemoteTitle" },
|
||||
confirmLabel: { key: "adminUsersRemoveAdmin" },
|
||||
destructive: true,
|
||||
},
|
||||
);
|
||||
@@ -201,7 +201,7 @@ export default function AdminUsersPage() {
|
||||
if (active()) toast(getApiErrorMessage(e, currentTranslation.current("adminUsersRolesUpdateFailed")), "error");
|
||||
}
|
||||
finally { finishAction(active); }
|
||||
}, [beginAction, confirmAction, finishAction, load, t, toast]);
|
||||
}, [beginAction, confirmAction, finishAction, load, toast]);
|
||||
|
||||
const sendReset = useCallback(async (u: UserDto) => {
|
||||
const active=beginAction(); if (!active) return;
|
||||
@@ -218,10 +218,10 @@ export default function AdminUsersPage() {
|
||||
const active=beginAction(); if (!active) return;
|
||||
try {
|
||||
const name = u.userName || u.email || u.id;
|
||||
const message = u.isCurrentUser
|
||||
? t("adminUsersDeleteSelfWarning")
|
||||
: t("adminUsersDeleteConfirmNamed", { name });
|
||||
if (!(await confirmAction(message, { title: t("adminUsersDeleteConfirmTitle"), confirmLabel: t("adminUsersDelete"), destructive: true })) || !active()) return;
|
||||
if (!(await confirmAction(u.isCurrentUser
|
||||
? { key: "adminUsersDeleteSelfWarning" }
|
||||
: { key: "adminUsersDeleteConfirmNamed", params: { name } },
|
||||
{ title: { key: "adminUsersDeleteConfirmTitle" }, confirmLabel: { key: "adminUsersDelete" }, destructive: true })) || !active()) return;
|
||||
const response=await api.delete(`/users/${u.id}`, { headers: { "X-Confirm-Account-Deletion": u.email || u.userName || "" } });
|
||||
if (!active()) return;
|
||||
toast(currentTranslation.current(response.status===202 ? "adminUsersDeletionQueued" : "adminUsersDeleted"), "info");
|
||||
@@ -230,7 +230,7 @@ export default function AdminUsersPage() {
|
||||
if (active()) toast(getApiErrorMessage(e, currentTranslation.current("adminUsersDeleteFailed")), "error");
|
||||
}
|
||||
finally { finishAction(active); }
|
||||
}, [beginAction, confirmAction, finishAction, load, t, toast]);
|
||||
}, [beginAction, confirmAction, finishAction, load, toast]);
|
||||
|
||||
const columns = useMemo<GridColDef[]>(() => [
|
||||
{
|
||||
@@ -301,7 +301,7 @@ export default function AdminUsersPage() {
|
||||
</Box>
|
||||
</PageSection>
|
||||
|
||||
<ViewStateNotice loading={userResource.loading} error={userResource.error} title={t("adminUsersLoadFailed")} onRetry={async () => { body.current?.focus(); await load(); }} />
|
||||
<ViewStateNotice loading={userResource.loading} error={userResource.error ? { ...userResource.error, message: userResource.error.message || t("adminUsersLoadFailed") } : null} title={t("adminUsersLoadFailed")} onRetry={async () => { body.current?.focus(); await load(); }} />
|
||||
|
||||
{!userResource.error ? isMobile ? (
|
||||
<Stack spacing={1.5}>
|
||||
|
||||
Reference in New Issue
Block a user