MCPcopy
hub / github.com/Peppermint-Lab/peppermint / PortalLayout

Function PortalLayout

apps/client/layouts/portalLayout.tsx:22–411  ·  view source on GitHub ↗
({ children }: any)

Source from the content-addressed store, hash-verified

20}
21
22export default function PortalLayout({ children }: any) {
23 const location = useRouter();
24
25 const { loading, user, fetchUserProfile } = useUser();
26 const locale = user ? user.language : "en";
27
28 const { t, lang } = useTranslation("peppermint");
29
30 const [sidebarOpen, setSidebarOpen] = useState(false);
31
32 if (!user) {
33 location.push("/auth/login");
34 }
35
36 if (location.pathname.includes("/admin") && user.isAdmin === false) {
37 location.push("/");
38 alert("You do not have the correct perms for that action.");
39 }
40
41 const navigation = [
42 {
43 name: t("create_ticket"),
44 href: `/${locale}/portal/new`,
45 icon: PlusIcon,
46 current: location.pathname === "/new" ? true : false,
47 initial: "c",
48 },
49 {
50 name: t("sl_dashboard"),
51 href: `/${locale}/portal`,
52 icon: HomeIcon,
53 current: location.pathname === "/" ? true : false,
54 initial: "h",
55 },
56 ];
57
58 async function logout() {
59 const res = await fetch(`/api/v1/auth/user/${user.id}/logout`, {
60 method: "GET",
61 headers: {
62 "Content-Type": "application/json",
63 Authorization: `Bearer ${getCookie("session")}`,
64 },
65 }).then((res) => res.json());
66
67 if (res.success) {
68 deleteCookie("session");
69 location.reload();
70 }
71 }
72
73 function handleKeyPress(event: any) {
74 const pathname = location.pathname;
75 console.log(pathname);
76 if (
77 document.activeElement!.tagName !== "INPUT" &&
78 document.activeElement!.tagName !== "TEXTAREA" &&
79 !document.activeElement!.className.includes("ProseMirror") &&

Callers

nothing calls this directly

Calls 3

useUserFunction · 0.90
classNamesFunction · 0.70
logoutFunction · 0.70

Tested by

no test coverage detected