2021-03-26 15:51:19 +00:00
|
|
|
import Link from 'next/link';
|
2021-04-27 14:19:12 +00:00
|
|
|
import {useContext, useEffect, useState} from "react";
|
2021-03-30 12:25:09 +00:00
|
|
|
import { useRouter } from "next/router";
|
2021-03-24 15:03:04 +00:00
|
|
|
import { signOut, useSession } from 'next-auth/client';
|
2021-04-21 10:10:27 +00:00
|
|
|
import { MenuIcon, XIcon } from '@heroicons/react/outline';
|
2021-05-07 17:05:33 +00:00
|
|
|
import {collectPageParameters, telemetryEventTypes, useTelemetry} from "../lib/telemetry";
|
2021-03-24 15:03:04 +00:00
|
|
|
|
|
|
|
export default function Shell(props) {
|
2021-03-30 12:25:09 +00:00
|
|
|
const router = useRouter();
|
2021-03-24 15:03:04 +00:00
|
|
|
const [ session, loading ] = useSession();
|
|
|
|
const [ profileDropdownExpanded, setProfileDropdownExpanded ] = useState(false);
|
2021-04-16 16:36:27 +00:00
|
|
|
const [ mobileMenuExpanded, setMobileMenuExpanded ] = useState(false);
|
2021-04-27 14:19:12 +00:00
|
|
|
let telemetry = useTelemetry();
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
telemetry.withJitsu((jitsu) => {
|
2021-05-07 17:05:33 +00:00
|
|
|
return jitsu.track(telemetryEventTypes.pageView, collectPageParameters(router.pathname))
|
2021-04-27 14:19:12 +00:00
|
|
|
});
|
|
|
|
}, [telemetry])
|
2021-03-24 15:03:04 +00:00
|
|
|
|
|
|
|
const toggleProfileDropdown = () => {
|
|
|
|
setProfileDropdownExpanded(!profileDropdownExpanded);
|
|
|
|
}
|
|
|
|
|
2021-04-16 16:36:27 +00:00
|
|
|
const toggleMobileMenu = () => {
|
|
|
|
setMobileMenuExpanded(!mobileMenuExpanded);
|
|
|
|
}
|
|
|
|
|
2021-04-20 12:59:25 +00:00
|
|
|
const logoutHandler = () => {
|
2021-05-07 16:01:29 +00:00
|
|
|
signOut({ redirect: false }).then( () => router.push('/auth/logout') );
|
2021-04-20 12:59:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-07 16:01:29 +00:00
|
|
|
if ( ! loading && ! session ) {
|
|
|
|
router.replace('/auth/login');
|
|
|
|
}
|
|
|
|
|
|
|
|
return session && (
|
2021-03-24 15:03:04 +00:00
|
|
|
<div>
|
2021-05-11 13:11:17 +00:00
|
|
|
<div className="bg-gradient-to-b from-blue-600 via-blue-600 to-blue-300 pb-32">
|
|
|
|
<nav className="bg-blue-600">
|
2021-03-24 15:03:04 +00:00
|
|
|
<div className="max-w-7xl mx-auto sm:px-6 lg:px-8">
|
2021-05-11 13:11:17 +00:00
|
|
|
<div className="border-b border-blue-500">
|
2021-03-24 15:03:04 +00:00
|
|
|
<div className="flex items-center justify-between h-16 px-4 sm:px-0">
|
|
|
|
<div className="flex items-center">
|
|
|
|
<div className="flex-shrink-0">
|
2021-04-07 15:03:02 +00:00
|
|
|
<img className="h-6" src="/calendso-white.svg" alt="Calendso" />
|
2021-03-24 15:03:04 +00:00
|
|
|
</div>
|
|
|
|
<div className="hidden md:block">
|
|
|
|
<div className="ml-10 flex items-baseline space-x-4">
|
2021-03-26 15:51:19 +00:00
|
|
|
<Link href="/">
|
2021-05-11 13:11:17 +00:00
|
|
|
<a className={router.pathname == "/" ? "bg-blue-500 transition-colors duration-300 ease-in-out text-white px-3 py-2 rounded-md text-sm font-medium" : "text-white hover:bg-blue-500 transition-colors duration-300 ease-in-out hover:text-white px-3 py-2 rounded-md text-sm font-medium"}>Dashboard</a>
|
2021-03-26 15:51:19 +00:00
|
|
|
</Link>
|
2021-04-08 14:20:38 +00:00
|
|
|
{/* <Link href="/">
|
2021-05-11 13:11:17 +00:00
|
|
|
<a className={router.pathname.startsWith("/bookings") ? "bg-blue-500 transition-colors duration-300 ease-in-out text-white px-3 py-2 rounded-md text-sm font-medium" : "text-white hover:bg-blue-500 transition-colors duration-300 ease-in-out hover:text-white px-3 py-2 rounded-md text-sm font-medium"}>Bookings</a>
|
2021-04-08 14:20:38 +00:00
|
|
|
</Link> */}
|
|
|
|
<Link href="/availability">
|
2021-05-11 13:11:17 +00:00
|
|
|
<a className={router.pathname.startsWith("/availability") ? "bg-blue-500 transition-colors duration-300 ease-in-out text-white px-3 py-2 rounded-md text-sm font-medium" : "text-white hover:bg-blue-500 transition-colors duration-300 ease-in-out hover:text-white px-3 py-2 rounded-md text-sm font-medium"}>Availability</a>
|
2021-03-26 15:51:19 +00:00
|
|
|
</Link>
|
|
|
|
<Link href="/integrations">
|
2021-05-11 13:11:17 +00:00
|
|
|
<a className={router.pathname.startsWith("/integrations") ? "bg-blue-500 transition-colors duration-300 ease-in-out text-white px-3 py-2 rounded-md text-sm font-medium" : "text-white hover:bg-blue-500 transition-colors duration-300 ease-in-out hover:text-white px-3 py-2 rounded-md text-sm font-medium"}>Integrations</a>
|
2021-03-26 15:51:19 +00:00
|
|
|
</Link>
|
2021-05-07 15:04:56 +00:00
|
|
|
<Link href="/settings/profile">
|
2021-05-11 13:11:17 +00:00
|
|
|
<a className={router.pathname.startsWith("/settings") ? "bg-blue-500 transition-colors duration-300 ease-in-out text-white px-3 py-2 rounded-md text-sm font-medium" : "text-white hover:bg-blue-500 transition-colors duration-300 ease-in-out hover:text-white px-3 py-2 rounded-md text-sm font-medium"}>Settings</a>
|
2021-03-26 15:51:19 +00:00
|
|
|
</Link>
|
2021-03-24 15:03:04 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="hidden md:block">
|
|
|
|
<div className="ml-4 flex items-center md:ml-6">
|
|
|
|
<div className="ml-3 relative">
|
|
|
|
<div>
|
|
|
|
<button onClick={toggleProfileDropdown} type="button" className="max-w-xs bg-gray-800 rounded-full flex items-center text-sm focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-800 focus:ring-white" id="user-menu" aria-expanded="false" aria-haspopup="true">
|
|
|
|
<span className="sr-only">Open user menu</span>
|
2021-05-11 13:11:17 +00:00
|
|
|
<img className="h-8 w-8 rounded-full" src={session.user.image ? session.user.image : "https://eu.ui-avatars.com/api/?background=fff&color=039be5&name=" + encodeURIComponent(session.user.name || "")} alt="" />
|
2021-03-24 15:03:04 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
{
|
|
|
|
profileDropdownExpanded && (
|
2021-05-11 09:21:05 +00:00
|
|
|
<div className="origin-top-right absolute right-0 mt-2 w-48 rounded-md shadow-lg py-1 bg-white ring-1 ring-black ring-opacity-5 focus:outline-none z-50" role="menu" aria-orientation="vertical" aria-labelledby="user-menu">
|
2021-05-05 20:01:56 +00:00
|
|
|
<Link href={"/" + session.user.username}><a target="_blank" className="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" role="menuitem">Your Public Page</a></Link>
|
2021-04-09 15:49:02 +00:00
|
|
|
<Link href="/settings/profile"><a className="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" role="menuitem">Your Profile</a></Link>
|
|
|
|
<Link href="/settings/password"><a className="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" role="menuitem">Login & Security</a></Link>
|
2021-04-20 12:59:25 +00:00
|
|
|
<button onClick={logoutHandler} className="w-full text-left block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" role="menuitem">Sign out</button>
|
2021-03-24 15:03:04 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="-mr-2 flex md:hidden">
|
2021-05-17 17:50:30 +00:00
|
|
|
<button onClick={toggleMobileMenu} type="button" className=" inline-flex items-center justify-center p-2 rounded-md text-white focus:outline-none" aria-controls="mobile-menu" aria-expanded="false">
|
2021-03-24 15:03:04 +00:00
|
|
|
<span className="sr-only">Open main menu</span>
|
2021-04-21 10:10:27 +00:00
|
|
|
{ !mobileMenuExpanded && <MenuIcon className="block h-6 w-6" /> }
|
|
|
|
{ mobileMenuExpanded && <XIcon className="block h-6 w-6" /> }
|
2021-03-24 15:03:04 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2021-05-26 19:47:06 +00:00
|
|
|
{ mobileMenuExpanded && <div className="border-b border-blue-500 md:hidden bg-blue-600" id="mobile-menu">
|
2021-03-24 15:03:04 +00:00
|
|
|
<div className="px-2 py-3 space-y-1 sm:px-3">
|
2021-04-16 16:36:27 +00:00
|
|
|
<Link href="/">
|
2021-05-26 19:47:06 +00:00
|
|
|
<a className={router.pathname == "/" ? "bg-blue-500 text-white block px-3 py-2 rounded-md text-base font-medium" : "text-gray-100 hover:bg-gray-700 hover:text-white block px-3 py-2 rounded-md text-base font-medium"}>Dashboard</a>
|
2021-04-16 16:36:27 +00:00
|
|
|
</Link>
|
|
|
|
<Link href="/availability">
|
2021-05-26 19:47:06 +00:00
|
|
|
<a className={router.pathname.startsWith("/availability") ? "bg-blue-500 text-white block px-3 py-2 rounded-md text-base font-medium" : "text-gray-100 hover:bg-gray-700 hover:text-white block px-3 py-2 rounded-md text-base font-medium"}>Availability</a>
|
2021-04-16 16:36:27 +00:00
|
|
|
</Link>
|
|
|
|
<Link href="/integrations">
|
2021-05-26 19:47:06 +00:00
|
|
|
<a className={router.pathname.startsWith("/integrations") ? "bg-blue-500 text-white block px-3 py-2 rounded-md text-base font-medium" : "text-gray-100 hover:bg-gray-700 hover:text-white block px-3 py-2 rounded-md text-base font-medium"}>Integrations</a>
|
2021-04-16 16:36:27 +00:00
|
|
|
</Link>
|
2021-03-24 15:03:04 +00:00
|
|
|
</div>
|
2021-05-26 19:47:06 +00:00
|
|
|
<div className="pt-4 pb-3 border-t border-blue-500">
|
2021-03-24 15:03:04 +00:00
|
|
|
<div className="flex items-center px-5">
|
|
|
|
<div className="flex-shrink-0">
|
|
|
|
<img className="h-10 w-10 rounded-full" src={"https://eu.ui-avatars.com/api/?background=039be5&color=fff&name=" + encodeURIComponent(session.user.name || session.user.username)} alt="" />
|
|
|
|
</div>
|
|
|
|
<div className="ml-3">
|
|
|
|
<div className="text-base font-medium leading-none text-white">{session.user.name || session.user.username}</div>
|
2021-05-26 19:47:06 +00:00
|
|
|
<div className="text-sm font-medium leading-none text-gray-200">{session.user.email}</div>
|
2021-03-24 15:03:04 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="mt-3 px-2 space-y-1">
|
2021-04-16 16:36:27 +00:00
|
|
|
<Link href="/settings/profile">
|
2021-05-26 19:47:06 +00:00
|
|
|
<a className="block px-3 py-2 rounded-md text-base font-medium text-gray-100 hover:text-white hover:bg-gray-700">Your Profile</a>
|
2021-04-16 16:36:27 +00:00
|
|
|
</Link>
|
|
|
|
<Link href="/settings">
|
2021-05-26 19:47:06 +00:00
|
|
|
<a className={router.pathname.startsWith("/settings") ? "bg-blue-500 text-white block px-3 py-2 rounded-md text-base font-medium" : "text-gray-100 hover:bg-gray-700 hover:text-white block px-3 py-2 rounded-md text-base font-medium"}>Settings</a>
|
2021-04-16 16:36:27 +00:00
|
|
|
</Link>
|
2021-05-26 19:47:06 +00:00
|
|
|
<button onClick={logoutHandler} className="block w-full text-left px-3 py-2 rounded-md text-base font-medium text-gray-100 hover:text-white hover:bg-gray-700">Sign out</button>
|
2021-03-24 15:03:04 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-04-16 16:36:27 +00:00
|
|
|
}
|
2021-03-24 15:03:04 +00:00
|
|
|
</nav>
|
|
|
|
<header className="py-10">
|
|
|
|
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
|
|
|
<h1 className="text-3xl font-bold text-white">
|
|
|
|
{props.heading}
|
|
|
|
</h1>
|
|
|
|
</div>
|
|
|
|
</header>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<main className="-mt-32">
|
|
|
|
<div className="max-w-7xl mx-auto pb-12 px-4 sm:px-6 lg:px-8">
|
|
|
|
{props.children}
|
|
|
|
</div>
|
|
|
|
</main>
|
|
|
|
</div>
|
|
|
|
);
|
2021-05-07 16:01:29 +00:00
|
|
|
}
|