fix(wallet): fetch pricing by concrete role key
This commit is contained in:
parent
aa8696bf9f
commit
d3f3850e1d
2 changed files with 51 additions and 2 deletions
|
|
@ -52,12 +52,37 @@ export default function DashboardLayout(props: ParentProps) {
|
||||||
if (target) navigate(target);
|
if (target) navigate(target);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const roleKey = createMemo(() => {
|
||||||
|
if (typeof window === "undefined") return "DEVELOPER";
|
||||||
|
const fromUrl = new URLSearchParams(window.location.search).get("role");
|
||||||
|
if (fromUrl && fromUrl.trim()) return fromUrl.trim().toUpperCase();
|
||||||
|
try {
|
||||||
|
const raw =
|
||||||
|
localStorage.getItem("nxtgauge_signup_profile_v1") ||
|
||||||
|
localStorage.getItem("nxtgauge_auth_user") ||
|
||||||
|
localStorage.getItem("nxtgauge_user") ||
|
||||||
|
sessionStorage.getItem("nxtgauge_signup_profile_v1") ||
|
||||||
|
sessionStorage.getItem("nxtgauge_auth_user") ||
|
||||||
|
sessionStorage.getItem("nxtgauge_user");
|
||||||
|
if (!raw) return "DEVELOPER";
|
||||||
|
const parsed = JSON.parse(raw);
|
||||||
|
const candidate = String(
|
||||||
|
parsed?.selectedProfessionalRole || parsed?.active_role || parsed?.roleKey || parsed?.role || ""
|
||||||
|
)
|
||||||
|
.trim()
|
||||||
|
.toUpperCase();
|
||||||
|
return candidate && candidate !== "PROFESSIONAL" ? candidate : "DEVELOPER";
|
||||||
|
} catch {
|
||||||
|
return "DEVELOPER";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DashboardShell
|
<DashboardShell
|
||||||
sidebarItems={SIDEBAR_ITEMS}
|
sidebarItems={SIDEBAR_ITEMS}
|
||||||
activeSidebar={activeSidebar()}
|
activeSidebar={activeSidebar()}
|
||||||
onSidebarSelect={handleSidebarSelect}
|
onSidebarSelect={handleSidebarSelect}
|
||||||
roleKey="PROFESSIONAL"
|
roleKey={roleKey()}
|
||||||
userName={readUserName()}
|
userName={readUserName()}
|
||||||
>
|
>
|
||||||
{props.children}
|
{props.children}
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,32 @@ export default function BuyTracecoinsPage() {
|
||||||
const [error, setError] = createSignal("");
|
const [error, setError] = createSignal("");
|
||||||
const [success, setSuccess] = createSignal(false);
|
const [success, setSuccess] = createSignal(false);
|
||||||
|
|
||||||
|
const resolveRoleKey = () => {
|
||||||
|
if (typeof window === "undefined") return "DEVELOPER";
|
||||||
|
const fromUrl = new URLSearchParams(window.location.search).get("role");
|
||||||
|
if (fromUrl && fromUrl.trim()) return fromUrl.trim().toUpperCase();
|
||||||
|
const keys = ["nxtgauge_signup_profile_v1", "nxtgauge_auth_user", "nxtgauge_user"];
|
||||||
|
for (const key of keys) {
|
||||||
|
try {
|
||||||
|
const raw = window.localStorage.getItem(key) || window.sessionStorage.getItem(key);
|
||||||
|
if (!raw) continue;
|
||||||
|
const parsed = JSON.parse(raw);
|
||||||
|
const candidate = String(
|
||||||
|
parsed?.selectedProfessionalRole || parsed?.active_role || parsed?.roleKey || parsed?.role || ""
|
||||||
|
)
|
||||||
|
.trim()
|
||||||
|
.toUpperCase();
|
||||||
|
if (candidate && candidate !== "PROFESSIONAL") return candidate;
|
||||||
|
} catch {
|
||||||
|
// ignore malformed storage payloads
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "DEVELOPER";
|
||||||
|
};
|
||||||
|
|
||||||
const [packages] = createResource(async () => {
|
const [packages] = createResource(async () => {
|
||||||
const res = await api.get("/pricing/packages?roleKey=PROFESSIONAL");
|
const roleKey = resolveRoleKey();
|
||||||
|
const res = await api.get(`/pricing/packages?role=${encodeURIComponent(roleKey)}&roleKey=${encodeURIComponent(roleKey)}`);
|
||||||
return res.data?.packages || [];
|
return res.data?.packages || [];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue