Guest User

Untitled

a guest
Jul 23rd, 2024
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // layout.tsx
  2. import {
  3.   HiArrowSmRight,
  4.   HiChartPie,
  5.   HiInbox,
  6.   HiShoppingBag,
  7.   HiTable,
  8.   HiUser,
  9.   HiViewBoards,
  10. } from "react-icons/hi";
  11.  
  12.  
  13. export const metadata: Metadata = {
  14.   title: "Create T3 Turbo",
  15.   description: "Simple monorepo with shared backend for web & mobile apps",
  16. };
  17.  
  18. const menuGroups: MenuGroup[] = [
  19.   {
  20.     label: "Dashboard",
  21.     icon: <HiViewBoards />,
  22.     route: "/platform/dashboard",
  23.     items: [],
  24.   },
  25.   {
  26.     label: "Subscriptions",
  27.     icon: <HiShoppingBag />,
  28.     items: [
  29.       { label: "Plans", route: "/platform/subscriptions/plans" },
  30.       { label: "Products", route: "/platform/subscriptions/products" },
  31.       { label: "Transactions", route: "/platform/subscriptions/transactions" },
  32.     ],
  33.   },
  34.   {
  35.     label: "Reports",
  36.     icon: <HiChartPie />,
  37.     items: [
  38.       { label: "Overview", route: "/platform/reports" },
  39.       { label: "Analytics", route: "/platform/reports/analytics" },
  40.       { label: "Sales", route: "/platform/reports/sales" },
  41.     ],
  42.   },
  43. ];
  44. export default function PlatformLayout({ children }: { children: any }) {
  45.   const currSession = session();
  46.   console.log("layout session", currSession);
  47.   if (!currSession) {
  48.     redirect("/auth");
  49.   }
  50.   // You can await this here if you don't want to show Suspense fallback below
  51.   // void api.post.all.prefetch();
  52.   return (
  53.     <HydrateClient>
  54.       <Suspense fallback={<LoadingPage />}>
  55.         <DefaultLayout
  56.           sideMenuItems={menuGroups}
  57.           notifications={[]}
  58.           user={{
  59.             userAvatar: "https://ui-avatars.com/api/?format=png",
  60.             fullname: "John Doe",
  61.             profileLink: "/platform/user/me",
  62.             settingsLink: "/platform/user/settings",
  63.             logoutLink: "/platform/user/logout",
  64.           }}
  65.         >
  66.           <div className="flex flex-col rounded-md bg-gray-100">
  67.             <div className="rounded-t-md bg-gray-200 p-4 font-bold">
  68.               Current Session
  69.             </div>
  70.             <pre className="whitespace-pre-wrap break-all px-4 py-6">
  71.               {JSON.stringify(currSession, null, 2)}
  72.             </pre>
  73.           </div>
  74.           {children}
  75.         </DefaultLayout>
  76.       </Suspense>
  77.     </HydrateClient>
  78.   );
  79. }
  80.  
  81. // types.ts
  82. import type { ComponentProps, FC } from "react";
  83. import type { IconType } from "react-icons";
  84.  
  85. export interface SidebarProps {
  86.   items: MenuGroup[];
  87.   sidebarOpen: boolean;
  88.   setSidebarOpen: (arg: boolean) => void;
  89. }
  90. export interface MenuGroup {
  91.   label: string;
  92.   icon: any;
  93.   route?: string;
  94.   items: MenuGroupItem[];
  95. }
  96. export interface MenuGroupItem {
  97.   icon?: any;
  98.   label: string;
  99.   route: string;
  100.   children?: MenuGroupItem[];
  101. }
  102. // sidemenu.tsx
  103.  
  104. export const SidebarArea = ({
  105.   sidebarOpen,
  106.   setSidebarOpen,
  107.   items,
  108. }: SidebarProps) => {
  109.   const renderSideItemNoCollapsed = (item: MenuGroup) => (
  110.     <Sidebar.Item href={item.route} icon={item.icon}>
  111.       {item.label}
  112.     </Sidebar.Item>
  113.   );
  114.   const renderSideItemWithChildren = (item: MenuGroup, rootIndex: number) => (
  115.     <Sidebar.Collapse icon={item.icon} label={item.label}>
  116.       {item.items.map((t, index) => (
  117.         <Sidebar.Item key={`${rootIndex}_${index}`} href={t.route}>{t.label}</Sidebar.Item>
  118.       ))}
  119.     </Sidebar.Collapse>
  120.   );
  121.   return (
  122.     <ClickOutside onClick={() => setSidebarOpen(false)}>
  123.       <aside
  124.         className={`z-9999 w-72.5 border-stroke dark:border-stroke-dark dark:bg-gray-dark absolute left-0 top-0 flex h-screen flex-col overflow-y-hidden border-r bg-white lg:static lg:translate-x-0 ${sidebarOpen
  125.           ? "translate-x-0 duration-300 ease-linear"
  126.           : "-translate-x-full"
  127.           }`}
  128.       >
  129.         {/* <!-- SIDEBAR HEADER --> */}
  130.         <div className="py-5.5 lg:py-6.5 flex items-center justify-between gap-2 px-6 xl:py-10">
  131.           <Link href="/">
  132.             <Image
  133.               width={176}
  134.               height={32}
  135.               src={"/images/logo/logo-dark.svg"}
  136.               alt="Logo"
  137.               priority
  138.               className="dark:hidden"
  139.               style={{ width: "auto", height: "auto" }}
  140.             />
  141.             <Image
  142.               width={176}
  143.               height={32}
  144.               src={"/images/logo/logo.svg"}
  145.               alt="Logo"
  146.               priority
  147.               className="hidden dark:block"
  148.               style={{ width: "auto", height: "auto" }}
  149.             />
  150.           </Link>
  151.  
  152.           <button
  153.             onClick={() => setSidebarOpen(!sidebarOpen)}
  154.             className="block lg:hidden"
  155.             title="Toggle Sidebar"
  156.           >
  157.             <svg
  158.               className="fill-current"
  159.               width="20"
  160.               height="18"
  161.               viewBox="0 0 20 18"
  162.               fill="none"
  163.               xmlns="http://www.w3.org/2000/svg"
  164.             >
  165.               <path
  166.                 d="M19 8.175H2.98748L9.36248 1.6875C9.69998 1.35 9.69998 0.825 9.36248 0.4875C9.02498 0.15 8.49998 0.15 8.16248 0.4875L0.399976 8.3625C0.0624756 8.7 0.0624756 9.225 0.399976 9.5625L8.16248 17.4375C8.31248 17.5875 8.53748 17.7 8.76248 17.7C8.98748 17.7 9.17498 17.625 9.36248 17.475C9.69998 17.1375 9.69998 16.6125 9.36248 16.275L3.02498 9.8625H19C19.45 9.8625 19.825 9.4875 19.825 9.0375C19.825 8.55 19.45 8.175 19 8.175Z"
  167.                 fill=""
  168.               />
  169.             </svg>
  170.           </button>
  171.         </div>
  172.         {/* <!-- SIDEBAR HEADER --> */}
  173.  
  174.         <Sidebar aria-label="Sabo Backoffice">
  175.           <Sidebar.Logo href="#" img="/logo.svg" imgAlt="Sabo Backoffice">
  176.             Sabo Backoffice
  177.           </Sidebar.Logo>
  178.           <Sidebar.Items key={'root'}>
  179.             {items.map((group, groupIndex) => (
  180.               <Sidebar.ItemGroup>
  181.                 {group.items.length === 0 && renderSideItemNoCollapsed(group)}
  182.                 {group.items.length > 0 && renderSideItemWithChildren(group, groupIndex)}
  183.               </Sidebar.ItemGroup>
  184.             ))}
  185.           </Sidebar.Items>
  186.         </Sidebar>
  187.       </aside>
  188.     </ClickOutside>
  189.   );
  190. };
  191. // error
  192.  
  193. │ Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: <svg />. Did you accidentally export a JSX literal instead of a component?
  194. │     at eval (webpack-internal:///(ssr)/../../node_modules/flowbite-react/dist/esm/components/Sidebar/SidebarItem.mjs:41:96)
  195. │     at ul
  196. │     at SidebarItemGroup (webpack-internal:///(ssr)/../../node_modules/flowbite-react/dist/esm/components/Sidebar/SidebarItemGroup.mjs:15:29)
  197. │     at div
  198. │     at SidebarItems (webpack-internal:///(ssr)/../../node_modules/flowbite-react/dist/esm/components/Sidebar/SidebarItems.mjs:13:25)
  199. │     at div
  200. │     at nav
  201. │     at SidebarComponent (webpack-internal:///(ssr)/../../node_modules/flowbite-react/dist/esm/components/Sidebar/Sidebar.mjs:27:29)
  202. │     at aside
  203. │     at div
  204. │     at ClickOutside (webpack-internal:///(ssr)/../../packages/ui/src/Common/Events/ClickOutside.tsx:10:25)
  205. │     at SidebarArea (webpack-internal:///(ssr)/../../packages/ui/src/Backoffice/Sidebar/index.tsx:20:24)
  206. │     at div
  207. │     at DefaultLayout (webpack-internal:///(ssr)/../../packages/ui/src/Backoffice/Layouts/DefaultLaout.tsx:12:26)
  208. │     at Lazy
  209. │     at Suspense
  210. │     at HydrationBoundary (webpack-internal:///(ssr)/../../node_modules/@tanstack/react-query/build/modern/HydrationBoundary.js:12:28)
  211. │     at Lazy
  212. │     at InnerLayoutRouter (webpack-internal:///(ssr)/../../node_modules/next/dist/esm/client/components/layout-router.js:249:11)
  213. │     at RedirectErrorBoundary (webpack-internal:///(ssr)/../../node_modules/next/dist/esm/client/components/redirect-boundary.js:63:9)
  214. │     at RedirectBoundary (webpack-internal:///(ssr)/../../node_modules/next/dist/esm/client/components/redirect-boundary.js:71:11)
  215. │     at NotFoundErrorBoundary (webpack-internal:///(ssr)/../../node_modules/next/dist/esm/client/components/not-found-boundary.js:76:9)
  216. │     at NotFoundBoundary (webpack-internal:///(ssr)/../../node_modules/next/dist/esm/client/components/not-found-boundary.js:84:11)
  217. │     at LoadingBoundary (webpack-internal:///(ssr)/../../node_modules/next/dist/esm/client/components/layout-router.js:354:11)
  218. │     at ErrorBoundary (webpack-internal:///(ssr)/../../node_modules/next/dist/esm/client/components/error-boundary.js:151:11)
  219. │     at InnerScrollAndFocusHandler (webpack-internal:///(ssr)/../../node_modules/next/dist/esm/client/components/layout-router.js:160:9)
  220. │     at ScrollAndFocusHandler (webpack-internal:///(ssr)/../../node_modules/next/dist/esm/client/components/layout-router.js:235:11)
  221. │     at RenderFromTemplateContext (webpack-internal:///(ssr)/../../node_modules/next/dist/esm/client/components/render-from-template-context.js:13:71)
  222. │     at Lazy
  223. │     at OuterLayoutRouter (webpack-internal:///(ssr)/../../node_modules/next/dist/esm/client/components/layout-router.js:377:11)
  224. │     at Lazy
  225. │     at TRPCProvider (webpack-internal:///(ssr)/../../node_modules/@trpc/react-query/dist/shared/hooks/createHooksInternal.mjs:43:17)
  226. │     at QueryClientProvider (webpack-internal:///(ssr)/../../node_modules/@tanstack/react-query/build/modern/QueryClientProvider.js:23:30)
  227. │     at TRPCReactProvider (webpack-internal:///(ssr)/./src/trpc/react.tsx:39:92)
  228. │     at Lazy
  229. │     at DefaultPropsProvider (webpack-internal:///(ssr)/../../node_modules/@mui/system/esm/DefaultPropsProvider/DefaultPropsProvider.js:17:33)
  230. │     at RtlProvider (webpack-internal:///(ssr)/../../node_modules/@mui/system/esm/RtlProvider/index.js:22:7)
  231. │     at ThemeProvider (webpack-internal:///(ssr)/../../node_modules/@mui/private-theming/ThemeProvider/ThemeProvider.js:45:5)
  232. │     at ThemeProvider (webpack-internal:///(ssr)/../../node_modules/@mui/system/esm/ThemeProvider/ThemeProvider.js:61:13)
  233. │     at ThemeProvider (webpack-internal:///(ssr)/../../node_modules/@mui/material/styles/ThemeProvider.js:25:18)
  234. │     at Lazy
  235. │     at AppRouterCacheProvider (webpack-internal:///(ssr)/../../node_modules/@mui/material-nextjs/v13-appRouter/appRouterV13.js:24:13)
Advertisement
Add Comment
Please, Sign In to add comment