refactor(admin-permissions, reports): normalize admin account kind and improve currency fallback logic
Some checks failed
lotteryadmin CI / build (push) Has been cancelled
Some checks failed
lotteryadmin CI / build (push) Has been cancelled
Refactored the admin account kind resolution to utilize a normalization function for better consistency across the application. Updated the currency fallback logic in the reports console to prioritize enabled and bettable currencies, enhancing the accuracy of currency display.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { normalizeAdminAccountKind } from "@/lib/admin-account-kind";
|
||||
import {
|
||||
adminHasAnyPermission,
|
||||
adminHasAnyPermissionCode,
|
||||
@@ -10,8 +11,9 @@ export function resolveAdminAccountKind(profile: AdminProfile | null | undefined
|
||||
if (!profile) {
|
||||
return null;
|
||||
}
|
||||
if (profile.account_kind) {
|
||||
return profile.account_kind === "site_operator" ? "site_admin" : profile.account_kind;
|
||||
const normalized = normalizeAdminAccountKind(profile.account_kind);
|
||||
if (normalized) {
|
||||
return normalized;
|
||||
}
|
||||
if (profile.is_super_admin) {
|
||||
return "super_admin";
|
||||
|
||||
24
src/lib/admin-account-kind.ts
Normal file
24
src/lib/admin-account-kind.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import type { AdminAccountKind } from "@/types/api/admin-auth";
|
||||
|
||||
/** 旧版 localStorage 可能仍存 `site_operator`,归一为 `site_admin`。 */
|
||||
export function normalizeAdminAccountKind(
|
||||
kind: string | undefined | null,
|
||||
): AdminAccountKind | undefined {
|
||||
if (!kind) {
|
||||
return undefined;
|
||||
}
|
||||
if (kind === "site_operator") {
|
||||
return "site_admin";
|
||||
}
|
||||
if (
|
||||
kind === "super_admin"
|
||||
|| kind === "site_admin"
|
||||
|| kind === "site_finance"
|
||||
|| kind === "site_cs"
|
||||
|| kind === "agent_operator"
|
||||
|| kind === "platform_account"
|
||||
) {
|
||||
return kind;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
@@ -238,7 +238,7 @@ function resolveDisplayCurrency(apiCode?: string | null): string {
|
||||
if (trimmed) {
|
||||
return trimmed;
|
||||
}
|
||||
const fallback = getCachedAdminCurrencies().find((row) => row.is_default)?.code;
|
||||
const fallback = getCachedAdminCurrencies().find((row) => row.is_enabled && row.is_bettable)?.code;
|
||||
return fallback?.trim() || "NPR";
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { normalizeAdminAccountKind } from "@/lib/admin-account-kind";
|
||||
import type { AdminProfile } from "@/types/api/admin-auth";
|
||||
import type { AdminNavItem } from "@/modules/_config/admin-nav";
|
||||
|
||||
@@ -35,16 +36,9 @@ export function readProfile(): AdminProfile | null {
|
||||
);
|
||||
})
|
||||
: [];
|
||||
const accountKind =
|
||||
v.account_kind === "super_admin"
|
||||
|| v.account_kind === "site_admin"
|
||||
|| v.account_kind === "site_finance"
|
||||
|| v.account_kind === "site_cs"
|
||||
|| v.account_kind === "site_operator"
|
||||
|| v.account_kind === "agent_operator"
|
||||
|| v.account_kind === "platform_account"
|
||||
? (v.account_kind === "site_operator" ? "site_admin" : v.account_kind)
|
||||
: undefined;
|
||||
const accountKind = normalizeAdminAccountKind(
|
||||
typeof v.account_kind === "string" ? v.account_kind : undefined,
|
||||
);
|
||||
return {
|
||||
id: v.id,
|
||||
username: v.username,
|
||||
|
||||
Reference in New Issue
Block a user