| 14 | import { useUser } from "../store/session"; |
| 15 | |
| 16 | export default function ShadLayout({ children }: any) { |
| 17 | const location = useRouter(); |
| 18 | |
| 19 | const { loading, user, fetchUserProfile } = useUser(); |
| 20 | |
| 21 | |
| 22 | const { t, lang } = useTranslation("peppermint"); |
| 23 | |
| 24 | if (!user) { |
| 25 | location.push("/auth/login"); |
| 26 | } |
| 27 | |
| 28 | if (location.pathname.includes("/admin") && user.isAdmin === false) { |
| 29 | location.push("/"); |
| 30 | alert("You do not have the correct perms for that action."); |
| 31 | } |
| 32 | |
| 33 | if (user && user.external_user) { |
| 34 | location.push("/portal"); |
| 35 | } |
| 36 | |
| 37 | return ( |
| 38 | !loading && |
| 39 | user && ( |
| 40 | <div className="min-h-screen overflow-hidden"> |
| 41 | <SidebarProvider> |
| 42 | <AppSidebar /> |
| 43 | <div className="w-full"> |
| 44 | <div className="sticky top-0 z-10 flex h-14 shrink-0 items-center gap-x-4 border-b bg-background px-4 sm:gap-x-6"> |
| 45 | <div className="flex flex-1 gap-x-4 self-stretch lg:gap-x-6 items-center"> |
| 46 | <SidebarTrigger title="[" /> |
| 47 | <div className="sm:flex hidden w-full justify-start items-center space-x-6"> |
| 48 | {user.isAdmin && ( |
| 49 | <Link href="https://github.com/Peppermint-Lab/peppermint/releases"> |
| 50 | <span className="inline-flex items-center rounded-md bg-green-700/10 px-3 py-2 text-xs font-medium text-green-600 ring-1 ring-inset ring-green-500/20"> |
| 51 | Version {process.env.NEXT_PUBLIC_CLIENT_VERSION} |
| 52 | </span> |
| 53 | </Link> |
| 54 | )} |
| 55 | </div> |
| 56 | |
| 57 | <div className="flex w-full sticky right-0 justify-end items-center gap-x-2 lg:gap-x-2 "> |
| 58 | <Button |
| 59 | variant="outline" |
| 60 | className="relative rounded-md p-2 text-gray-400 hover:text-gray-500 hover:cursor-pointer focus:outline-none" |
| 61 | > |
| 62 | <Link href="/notifications"> |
| 63 | <Bell className="h-4 w-4 text-foreground" /> |
| 64 | {user.notifcations.filter( |
| 65 | (notification) => !notification.read |
| 66 | ).length > 0 && ( |
| 67 | <svg |
| 68 | className="h-2.5 w-2.5 absolute bottom-6 left-6 animate-pulse fill-green-500" |
| 69 | viewBox="0 0 6 6" |
| 70 | aria-hidden="true" |
| 71 | > |
| 72 | <circle cx={3} cy={3} r={3} /> |
| 73 | </svg> |