wcz-layout
Version:
105 lines (104 loc) • 2.78 kB
JavaScript
import { t as clientEnv } from "./env-Bm6rrgwT.mjs";
import { r as getUser } from "./user-BQiWoQk1.mjs";
import { permissions } from "virtual:wcz-layout";
import { redirect } from "@tanstack/react-router";
//#region src/lib/utils.ts
const WISTRON_PRIMARY_COLOR = "#00506E";
const WISTRON_SECONDARY_COLOR = "#64DC00";
var Platform = class {
static get isAndroid() {
return /android/i.test(this.userAgent);
}
static get isIOS() {
return /iPad|iPhone|iPod/.test(this.userAgent);
}
static get isWindows() {
return /windows/i.test(this.userAgent);
}
static get isMacOS() {
return /Macintosh|MacIntel|MacPPC|Mac68K/.test(this.userAgent);
}
static get userAgent() {
return typeof navigator === "undefined" ? "" : navigator.userAgent;
}
};
const rootRouteHead = (options) => ({
meta: [
{ charSet: "utf-8" },
{
name: "viewport",
content: "width=device-width, initial-scale=1"
},
{ title: clientEnv.VITE_APP_TITLE },
{
name: "og:type",
content: "website"
},
{
name: "og:title",
content: clientEnv.VITE_APP_TITLE
},
{
name: "og:image",
content: "/favicon-32x32.png"
}
],
links: [
{
rel: "apple-touch-icon",
sizes: "180x180",
href: "/apple-touch-icon.png"
},
{
rel: "icon",
type: "image/png",
sizes: "32x32",
href: "/favicon-32x32.png"
},
{
rel: "icon",
type: "image/png",
sizes: "16x16",
href: "/favicon-16x16.png"
},
{
rel: "manifest",
href: options?.manifest || "/manifest.json"
},
{
rel: "icon",
href: "/favicon.ico"
}
]
});
const requirePermission = (permissionKey) => {
return async ({ location }) => {
const user = await getUser();
if (!user) throw redirect({
href: `/auth/login?returnTo=${encodeURIComponent(location.href)}`,
reloadDocument: true
});
if (!hasPermission(user, permissionKey)) throw new Error("You do not have permission to access this page.");
return { user };
};
};
const getFieldStatus = (field) => {
const { meta } = field.state;
return {
isTouched: meta.isTouched,
hasError: !!meta.errors.length,
helperText: meta.errors[0]?.message
};
};
const buildUser = (payload) => ({
name: payload.name?.split("/")[0],
email: payload.preferred_username?.toLowerCase(),
department: payload.department?.toUpperCase() || "",
employeeId: payload.employeeId?.toUpperCase() || "",
companyName: payload.companyName || "",
groups: payload.groups ?? []
});
const hasPermission = (user, key) => user ? permissions[key].some((group) => user.groups.includes(group)) : false;
//#endregion
export { getFieldStatus as a, rootRouteHead as c, buildUser as i, WISTRON_PRIMARY_COLOR as n, hasPermission as o, WISTRON_SECONDARY_COLOR as r, requirePermission as s, Platform as t };
//# sourceMappingURL=utils-DpcYsXTK.mjs.map