refactor: support prefixed webapp routes
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import { writable } from "svelte/store";
|
||||
import { withRoutePrefix } from "../../webapp/routes.js";
|
||||
|
||||
export function createPaymentsStore({
|
||||
api,
|
||||
onToast = () => {},
|
||||
at = (key, _params, fallback) => fallback || key,
|
||||
routePrefix = "",
|
||||
}) {
|
||||
const state = writable({
|
||||
payments: [],
|
||||
@@ -25,7 +27,10 @@ export function createPaymentsStore({
|
||||
function pushPaymentPath(paymentId) {
|
||||
if (typeof window === "undefined" || window.location.protocol === "file:") return;
|
||||
if (active !== "payments") return;
|
||||
const target = paymentId ? `/admin/payments/${paymentId}` : "/admin/payments";
|
||||
const target = withRoutePrefix(
|
||||
paymentId ? `/admin/payments/${paymentId}` : "/admin/payments",
|
||||
routePrefix
|
||||
);
|
||||
if (window.location.pathname === target) return;
|
||||
window.history.pushState(null, "", `${target}${window.location.search}${window.location.hash}`);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { writable } from "svelte/store";
|
||||
import { withRoutePrefix } from "../../webapp/routes.js";
|
||||
|
||||
export function createAdminSupportStore({ api, onToast, at }) {
|
||||
export function createAdminSupportStore({ api, onToast, at, routePrefix = "" }) {
|
||||
const OPEN_TICKET_POLL_MS = 3_000;
|
||||
const STATS_POLL_MS = 30_000;
|
||||
const HIDDEN_POLL_MS = 300_000;
|
||||
@@ -58,7 +59,10 @@ export function createAdminSupportStore({ api, onToast, at }) {
|
||||
function pushTicketPath(ticketId) {
|
||||
if (typeof window === "undefined" || window.location.protocol === "file:") return;
|
||||
if (active !== "support") return;
|
||||
const target = ticketId ? `/admin/support/${ticketId}` : "/admin/support";
|
||||
const target = withRoutePrefix(
|
||||
ticketId ? `/admin/support/${ticketId}` : "/admin/support",
|
||||
routePrefix
|
||||
);
|
||||
if (window.location.pathname !== target) {
|
||||
window.history.pushState(
|
||||
null,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { writable } from "svelte/store";
|
||||
import { withRoutePrefix } from "../../webapp/routes.js";
|
||||
|
||||
export function createUsersStore({ api, onToast, at }) {
|
||||
export function createUsersStore({ api, onToast, at, routePrefix = "" }) {
|
||||
const USERS_PAGE_SIZE = 25;
|
||||
const USER_LOGS_PAGE_SIZE = 20;
|
||||
|
||||
@@ -70,6 +71,7 @@ export function createUsersStore({ api, onToast, at }) {
|
||||
target = userId ? `/admin/payments/users/${userId}` : `/admin/payments`;
|
||||
}
|
||||
if (!target) return;
|
||||
target = withRoutePrefix(target, routePrefix);
|
||||
if (window.location.pathname === target) return;
|
||||
window.history.pushState(null, "", `${target}${window.location.search}${window.location.hash}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user