fix: keep payment user cards in payments
This commit is contained in:
@@ -42,16 +42,34 @@ export function createUsersStore({ api, onToast, at }) {
|
||||
});
|
||||
|
||||
let _activeRef = "stats"; // fallback if active isn't tracked
|
||||
let _pathContext = null;
|
||||
|
||||
function setActive(active) {
|
||||
_activeRef = active;
|
||||
}
|
||||
|
||||
function _setPathContext(context) {
|
||||
if (context === "payments") {
|
||||
_pathContext = "payments";
|
||||
return;
|
||||
}
|
||||
if (_activeRef === "users") {
|
||||
_pathContext = "users";
|
||||
return;
|
||||
}
|
||||
_pathContext = null;
|
||||
}
|
||||
|
||||
function _pushUserPath(userId) {
|
||||
if (typeof window === "undefined") return;
|
||||
if (window.location.protocol === "file:") return;
|
||||
if (_activeRef !== "users") return;
|
||||
const target = userId ? `/admin/users/${userId}` : `/admin/users`;
|
||||
let target = "";
|
||||
if (_activeRef === "users") {
|
||||
target = userId ? `/admin/users/${userId}` : `/admin/users`;
|
||||
} else if (_activeRef === "payments" && _pathContext === "payments") {
|
||||
target = userId ? `/admin/payments/users/${userId}` : `/admin/payments`;
|
||||
}
|
||||
if (!target) return;
|
||||
if (window.location.pathname === target) return;
|
||||
window.history.pushState(null, "", `${target}${window.location.search}${window.location.hash}`);
|
||||
}
|
||||
@@ -94,6 +112,7 @@ export function createUsersStore({ api, onToast, at }) {
|
||||
const userId =
|
||||
typeof userOrId === "object" && userOrId !== null ? userOrId.user_id : Number(userOrId);
|
||||
if (!userId) return;
|
||||
_setPathContext(opts.pathContext);
|
||||
|
||||
state.update((s) => ({
|
||||
...s,
|
||||
@@ -136,6 +155,7 @@ export function createUsersStore({ api, onToast, at }) {
|
||||
onToast(res?.error || "load_failed");
|
||||
state.update((s) => ({ ...s, openedUser: null }));
|
||||
if (!opts.skipPush) _pushUserPath(null);
|
||||
_pathContext = null;
|
||||
}
|
||||
} finally {
|
||||
state.update((s) => ({ ...s, userDetailLoading: false }));
|
||||
@@ -162,6 +182,7 @@ export function createUsersStore({ api, onToast, at }) {
|
||||
};
|
||||
});
|
||||
if (wasOpen && !opts.skipPush) _pushUserPath(null);
|
||||
_pathContext = null;
|
||||
}
|
||||
|
||||
async function loadUserLogs(page) {
|
||||
|
||||
@@ -62,6 +62,14 @@ export function adminPaymentIdFromPath(pathname) {
|
||||
return m ? Number(m[1]) : null;
|
||||
}
|
||||
|
||||
export function adminPaymentsUserIdFromPath(pathname) {
|
||||
const normalized = String(pathname || "")
|
||||
.toLowerCase()
|
||||
.replace(/\/+$/, "");
|
||||
const m = normalized.match(/^\/admin\/payments\/users\/(-?\d+)$/);
|
||||
return m ? Number(m[1]) : null;
|
||||
}
|
||||
|
||||
export function supportTicketIdFromPath(pathname) {
|
||||
const normalized = String(pathname || "")
|
||||
.toLowerCase()
|
||||
@@ -89,8 +97,12 @@ export function syncSectionPath(section, replace = false, adminSection = null, a
|
||||
const supportTicketId =
|
||||
adm === "support" ? adminSupportTicketIdFromPath(window.location.pathname) : null;
|
||||
const paymentId = adm === "payments" ? adminPaymentIdFromPath(window.location.pathname) : null;
|
||||
const paymentUserId =
|
||||
adm === "payments" ? adminPaymentsUserIdFromPath(window.location.pathname) : null;
|
||||
if (adm === "users" && uid) targetPath = `/admin/users/${uid}`;
|
||||
else if (adm === "support" && supportTicketId) targetPath = `/admin/support/${supportTicketId}`;
|
||||
else if (adm === "payments" && paymentUserId)
|
||||
targetPath = `/admin/payments/users/${paymentUserId}`;
|
||||
else if (adm === "payments" && paymentId) targetPath = `/admin/payments/${paymentId}`;
|
||||
else targetPath = `/admin/${adm}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user