stackpress
Version:
Incept is a content management framework.
35 lines (34 loc) • 4.09 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useEffect } from 'react';
import { useLanguage } from 'r22n';
import NotifyContainer from '../notify/NotifyContainer';
import { unload } from '../notify/hooks';
import { useTheme } from '../theme/hooks';
import { useConfig, useSession, useRequest } from '../server/hooks';
import LayoutHead from './components/LayoutHead';
import LayoutLeft from './components/LayoutLeft';
import LayoutMain from './components/LayoutMain';
import LayoutMenu from './components/LayoutMenu';
import LayoutRight from './components/LayoutRight';
import LayoutProvider from './LayoutProvider';
import { useToggle } from './hooks';
export function AdminUserMenu() {
const session = useSession();
const { changeLanguage } = useLanguage();
return (_jsxs("section", { className: "flex flex-col px-h-100-0", children: [_jsxs("header", { children: [session.data.id ? (_jsxs("div", { className: "px-px-10 px-py-14 theme-tx1 flex items-center", children: [_jsx("i", { className: "px-fs-26 inline-block px-mr-10 fas fa-user-circle" }), _jsx("span", { children: session.data.name })] })) : null, _jsxs("nav", { className: "theme-bg-bg3 px-px-10 px-py-12", children: [_jsx("a", { className: "theme-info theme-bg-bg0 px-fs-10 inline-block px-p-5", onClick: () => changeLanguage('en_US'), children: "EN" }), _jsx("a", { className: "theme-info theme-bg-bg0 px-fs-10 inline-block px-p-5 px-ml-5", onClick: () => changeLanguage('th_TH'), children: "TH" })] })] }), _jsx("main", { className: "flex-grow bg-t-0", children: session.data.id ? (_jsxs("div", { className: "px-h-100-0", children: [session.data.roles && session.data.roles.includes('ADMIN') && (_jsxs("nav", { className: "theme-bc-bd0 flex items-center px-px-10 px-py-14 border-b", children: [_jsx("i", { className: "inline-block px-mr-10 fas fa-gauge" }), _jsx("a", { className: "theme-info", href: "/admin/profile/search", children: "Admin" })] })), _jsxs("nav", { className: "theme-bc-bd0 flex items-center px-px-10 px-py-14 border-b", children: [_jsx("i", { className: "inline-block px-mr-10 fas fa-power-off" }), _jsx("a", { className: "theme-info", href: "/auth/signout", children: "Sign Out" })] })] })) : (_jsxs("div", { className: "h-full", children: [_jsxs("nav", { className: "theme-bc-bd0 flex items-center px-px-10 px-py-14 border-b", children: [_jsx("i", { className: "inline-block px-mr-10 fas fa-lock" }), _jsx("a", { className: "theme-info", href: "/auth/signin", children: "Sign In" })] }), _jsxs("nav", { className: "theme-bc-bd0 flex items-center px-px-10 px-py-14 border-b", children: [_jsx("i", { className: "inline-block px-mr-10 fas fa-trophy" }), _jsx("a", { className: "theme-info", href: "/auth/signup", children: "Sign Up" })] })] })) })] }));
}
export function AdminApp({ children }) {
const config = useConfig();
const request = useRequest();
const [left, toggleLeft] = useToggle();
const [right, toggleRight] = useToggle();
const { theme, toggle: toggleTheme } = useTheme();
const menu = config.path('admin.menu', []);
const pathname = request.url.pathname;
return (_jsxs("div", { className: `${theme} relative overflow-hidden px-w-100-0 px-h-100-0 theme-bg-bg0 theme-tx1`, children: [_jsx(LayoutHead, { open: left, theme: theme, toggleLeft: toggleLeft, toggleRight: toggleRight, toggleTheme: toggleTheme }), _jsx(LayoutLeft, { brand: config.path('brand.name', 'Stackpress'), base: config.path('admin.base', '/admin'), logo: config.path('brand.icon', 'icon.png'), open: left, toggle: toggleLeft, children: _jsx(LayoutMenu, { path: pathname, menu: menu }) }), _jsx(LayoutRight, { open: right, children: _jsx(AdminUserMenu, {}) }), _jsx(LayoutMain, { open: left, children: children })] }));
}
export default function LayoutAdmin(props) {
const { data, session, request, response, children } = props;
useEffect(unload, []);
return (_jsxs(LayoutProvider, { data: data, session: session, request: request, response: response, children: [_jsx(AdminApp, { children: children }), _jsx(NotifyContainer, {})] }));
}