fix(admin): ignore stale user modal loads
This commit is contained in:
@@ -54,6 +54,7 @@ export function createUsersStore({ api, onToast, at, routePrefix = "" }) {
|
|||||||
|
|
||||||
let _activeRef = "stats"; // fallback if active isn't tracked
|
let _activeRef = "stats"; // fallback if active isn't tracked
|
||||||
let _pathContext = null;
|
let _pathContext = null;
|
||||||
|
let _openUserRequestId = 0;
|
||||||
|
|
||||||
function setActive(active) {
|
function setActive(active) {
|
||||||
_activeRef = active;
|
_activeRef = active;
|
||||||
@@ -124,6 +125,7 @@ export function createUsersStore({ api, onToast, at, routePrefix = "" }) {
|
|||||||
const userId =
|
const userId =
|
||||||
typeof userOrId === "object" && userOrId !== null ? userOrId.user_id : Number(userOrId);
|
typeof userOrId === "object" && userOrId !== null ? userOrId.user_id : Number(userOrId);
|
||||||
if (!userId) return;
|
if (!userId) return;
|
||||||
|
const requestId = ++_openUserRequestId;
|
||||||
_setPathContext(opts.pathContext);
|
_setPathContext(opts.pathContext);
|
||||||
|
|
||||||
state.update((s) => ({
|
state.update((s) => ({
|
||||||
@@ -161,7 +163,15 @@ export function createUsersStore({ api, onToast, at, routePrefix = "" }) {
|
|||||||
const hasHwidLimit =
|
const hasHwidLimit =
|
||||||
sub?.hwid_device_limit !== null && sub?.hwid_device_limit !== undefined;
|
sub?.hwid_device_limit !== null && sub?.hwid_device_limit !== undefined;
|
||||||
const hwidLimit = hasHwidLimit ? Number(sub?.hwid_device_limit) : null;
|
const hwidLimit = hasHwidLimit ? Number(sub?.hwid_device_limit) : null;
|
||||||
state.update((s) => ({
|
state.update((s) => {
|
||||||
|
if (
|
||||||
|
requestId !== _openUserRequestId ||
|
||||||
|
!s.openedUser ||
|
||||||
|
s.openedUser.user_id !== userId
|
||||||
|
) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
return {
|
||||||
...s,
|
...s,
|
||||||
openedUserDetail: res,
|
openedUserDetail: res,
|
||||||
openedUser: res.user ? { ...res.user, ...s.openedUser, ...res.user } : s.openedUser,
|
openedUser: res.user ? { ...res.user, ...s.openedUser, ...res.user } : s.openedUser,
|
||||||
@@ -174,26 +184,51 @@ export function createUsersStore({ api, onToast, at, routePrefix = "" }) {
|
|||||||
hwidDeviceLimitDraft: hasHwidLimit && hwidLimit > 0 ? String(hwidLimit) : "",
|
hwidDeviceLimitDraft: hasHwidLimit && hwidLimit > 0 ? String(hwidLimit) : "",
|
||||||
grantTrafficGbDraft: "",
|
grantTrafficGbDraft: "",
|
||||||
grantTrafficKindDraft: "regular",
|
grantTrafficKindDraft: "regular",
|
||||||
}));
|
};
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
onToast(res?.error || "load_failed");
|
let shouldClearPath = false;
|
||||||
state.update((s) => ({ ...s, openedUser: null }));
|
let shouldShowError = false;
|
||||||
if (!opts.skipPush) _pushUserPath(null);
|
state.update((s) => {
|
||||||
|
if (
|
||||||
|
requestId !== _openUserRequestId ||
|
||||||
|
!s.openedUser ||
|
||||||
|
s.openedUser.user_id !== userId
|
||||||
|
) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
shouldShowError = true;
|
||||||
|
shouldClearPath = true;
|
||||||
_pathContext = null;
|
_pathContext = null;
|
||||||
|
return { ...s, openedUser: null };
|
||||||
|
});
|
||||||
|
if (shouldShowError) onToast(res?.error || "load_failed");
|
||||||
|
if (shouldClearPath && !opts.skipPush) _pushUserPath(null);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
state.update((s) => ({ ...s, userDetailLoading: false }));
|
state.update((s) => {
|
||||||
|
if (
|
||||||
|
requestId !== _openUserRequestId ||
|
||||||
|
!s.openedUser ||
|
||||||
|
s.openedUser.user_id !== userId
|
||||||
|
) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
return { ...s, userDetailLoading: false };
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeUser(opts = {}) {
|
function closeUser(opts = {}) {
|
||||||
let wasOpen = false;
|
let wasOpen = false;
|
||||||
|
_openUserRequestId += 1;
|
||||||
state.update((s) => {
|
state.update((s) => {
|
||||||
wasOpen = Boolean(s.openedUser);
|
wasOpen = Boolean(s.openedUser);
|
||||||
return {
|
return {
|
||||||
...s,
|
...s,
|
||||||
openedUser: null,
|
openedUser: null,
|
||||||
openedUserDetail: null,
|
openedUserDetail: null,
|
||||||
|
userDetailLoading: false,
|
||||||
userDeleteOpen: false,
|
userDeleteOpen: false,
|
||||||
userBanConfirmOpen: false,
|
userBanConfirmOpen: false,
|
||||||
userMessageConfirmOpen: false,
|
userMessageConfirmOpen: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user