index.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import type { NextPage } from "next";
  2. import Link from "next/link";
  3. import { FC } from "react";
  4. import Layout from "../components/Layout";
  5. import {
  6. useAuth,
  7. UserContextAuthenticatedInterface,
  8. } from "../context/UserContext";
  9. const AuthenticatedView: FC<
  10. Pick<UserContextAuthenticatedInterface, "user" | "logout">
  11. > = ({ user, logout }) => (
  12. <div>
  13. <h1 className="text-2xl font-bold mb-4 text-center">Welcome back!</h1>
  14. <div className="rounded w-full mx-auto border p-4 flex flex-col gap-4 xs:max-w-md xs:gap-6 xs:py-6">
  15. <header className="flex flex-col items-center text-center gap-2 xs:flex-row xs:gap-4 xs:text-left">
  16. <div className="h-12 w-12 bg-gray-300 rounded-full flex justify-center items-center">
  17. <img
  18. src="/favicon.svg"
  19. width={25}
  20. height={30}
  21. alt="profile picture"
  22. />
  23. </div>
  24. <div>
  25. <h2 className="font-bold">{user.name}</h2>
  26. <p className="text-sm">{user.email}</p>
  27. <p>
  28. <span className="bg-green-200 font-semibold font-mono rounded text-xs inline-block px-1 leading-5">
  29. {user.team}
  30. </span>
  31. </p>
  32. </div>
  33. </header>
  34. <div className="flex flex-col gap-2 xs:flex-row">
  35. <Link href="/settings">
  36. <a className="default-button">Edit profile</a>
  37. </Link>
  38. <button
  39. type="button"
  40. onClick={() => logout()}
  41. className="outline-button"
  42. >
  43. Logout
  44. </button>
  45. </div>
  46. </div>
  47. </div>
  48. );
  49. const Home: NextPage = () => {
  50. const { user, logout } = useAuth();
  51. return (
  52. <Layout>
  53. <div className="">
  54. {user ? (
  55. <AuthenticatedView user={user} logout={logout} />
  56. ) : (
  57. <div>
  58. <h1 className="text-2xl font-bold mb-4 text-center">Welcome!</h1>
  59. <p className="text-center">Please, sign up or log in to continue</p>
  60. </div>
  61. )}
  62. </div>
  63. </Layout>
  64. );
  65. };
  66. export default Home;