import { useUser } from "@auth0/nextjs-auth0/client"; import Link from "next/link"; import { useEffect, useState } from "react"; import { ProfileCard } from "../../components/ProfileCard/ProfileCard"; import { SEO } from "../../components/SEO"; const PageMe = () => { const { user, error, isLoading } = useUser(); type personsSchema = { Id: string; Name: string; Desc?: string; Img?: string; IsAdmin?: boolean; DevBadge?: boolean; AssignedUser?: string; }; type badgeSchema = { Id: string; // ID Name: string; // badge name Desc: string; // badge description (short) Expl?: string; // badge explanation (long) Img?: string; // direct url to an image Date?: string; // datetime w/ timezone (eg: "2022-02-25T10:23:54Z") }; const [personsData, setPersonsData] = useState(null); const [badgesData, setBadgesData] = useState(null); useEffect(() => { if (!user) return; fetch("https://gractwo.pl/api/v1/persons-of-note") .then((res) => { return res.json(); }) .then((data) => { setPersonsData( data.filter((el: personsSchema) => { return el.AssignedUser === user.sub?.replace("oauth2|discord|", ""); })[0] ); }); fetch( `https://gractwo.pl/api/v1/badges/${user.sub?.replace( "oauth2|discord|", "" )}` ) .then((res) => { return res.json(); }) .then((data) => { setBadgesData(data); }); }, [user]); return ( <> {isLoading && (

Ładujemy dane dla Ciebie...

Sit tight.

)} {!isLoading && error && (

Wystąpił błąd.

Tyle wiemy:

{error.name}

{error.message}

)} {!isLoading && !error && user && (
{/* */}
)} {!isLoading && !user && (

/ja

Musisz być zalogowany aby skorzystać z funkcjonalności tej strony.

)} ); }; export default PageMe;