From f4b5bca6f08bfa391a6dad369b0b58208f86a4bd Mon Sep 17 00:00:00 2001 From: abdellah hariti Date: Wed, 28 Aug 2024 14:34:56 +0100 Subject: [PATCH] feat: header logged in state (#11124) * feat: add header logged in state * fix merge conflict * use img instead of next/image * fixe conflicts --- src/components/header.tsx | 65 ++++++++++++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/src/components/header.tsx b/src/components/header.tsx index a8084b735aab5..4ce79d8a5d507 100644 --- a/src/components/header.tsx +++ b/src/components/header.tsx @@ -1,5 +1,9 @@ +'use client'; + +import {Fragment, useEffect, useState} from 'react'; import {HamburgerMenuIcon} from '@radix-ui/react-icons'; import Image from 'next/image'; +import Link from 'next/link'; import SentryLogoSVG from 'sentry-docs/logos/sentry-logo-dark.svg'; @@ -18,7 +22,48 @@ type Props = { noSearch?: boolean; }; +type User = { + avatarUrl: string; + email: string; + id: string; + isActive: boolean; + name: string; + username: string; +}; + +function Avatar({user}: {user: User}) { + return ( + +
+ {/* eslint-disable-next-line @next/next/no-img-element */} + {user.name} +
+ {user.name} + {user.username} +
+
+ + ); +} + export function Header({pathname, searchPlatforms, noSearch}: Props) { + // this should work on production (given the request is not blocked by ad blockers), + // but it doesn't on dev or previews because of CORS + // I implemeted a workaround in the form of an api route while building this + const [user, setUser] = useState(null); + useEffect(() => { + fetch('https://sentry.io/api/0/users/me/', {credentials: 'include'}) + .then(r => r.json()) + .then(setUser) + // eslint-disable-next-line no-console + .catch(console.error); + }, []); return (
{/* define a header-height variable for consumption by other components */} @@ -64,13 +109,19 @@ export function Header({pathname, searchPlatforms, noSearch}: Props) {
Changelog Sandbox - Sign In - - Get Started - + {user ? ( + + ) : ( + + Sign In + + Get Started + + + )}