Переглянути джерело

allow admin to setup the items that can use onpack zip file of expiry

fix負數倉
PC-20260115JRSN\Administrator 2 тижднів тому
джерело
коміт
4680f3d2d8
1 змінених файлів з 3 додано та 24 видалено
  1. +3
    -24
      src/components/BagPrint/BagPrintSearch.tsx

+ 3
- 24
src/components/BagPrint/BagPrintSearch.tsx Переглянути файл

@@ -55,6 +55,7 @@ import {
import dayjs from "dayjs";
import { useSession } from "next-auth/react";
import { SessionWithTokens } from "@/config/authConfig";
import { AUTH, hasAbility } from "@/authorities";
import { NEXT_PUBLIC_API_URL } from "@/config/api";
import { clientAuthFetch } from "@/app/utils/clientAuthFetch";

@@ -77,28 +78,6 @@ const REFRESH_MS = 60 * 1000;
const PRINTER_CHECK_MS = 60 * 1000;
const PRINTER_RETRY_MS = 30 * 1000;
const SETTINGS_KEY = "bagPrint_settings";
const ONPACK_ADMIN_USERNAME = "2fi";

/** Login username from backend JWT `sub` (UserDetails.username). */
function loginUsernameFromSession(session: SessionWithTokens | null | undefined): string {
const token = session?.accessToken?.trim();
if (token) {
try {
const parts = token.split(".");
if (parts.length >= 2) {
const b64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
const padded = b64 + "=".repeat((4 - (b64.length % 4)) % 4);
const payload = JSON.parse(atob(padded)) as { sub?: unknown };
if (typeof payload.sub === "string" && payload.sub.trim()) {
return payload.sub.trim();
}
}
} catch {
// fall through to display name
}
}
return (session?.user?.name ?? "").trim();
}

const DEFAULT_SETTINGS = {
dabag_ip: "",
@@ -221,8 +200,8 @@ function sortExpiryRows(

const BagPrintSearch: React.FC = () => {
const { data: session } = useSession() as { data: SessionWithTokens | null };
const canSeeOnPackAdmin =
loginUsernameFromSession(session).toLowerCase() === ONPACK_ADMIN_USERNAME;
const abilities = session?.abilities ?? session?.user?.abilities ?? [];
const canSeeOnPackAdmin = hasAbility(abilities, AUTH.ADMIN);
const [planDate, setPlanDate] = useState(() => dayjs().format("YYYY-MM-DD"));
const [jobOrders, setJobOrders] = useState<JobOrderListItem[]>([]);
const [loading, setLoading] = useState(true);


Завантаження…
Відмінити
Зберегти