"use client" import Button from "@components/button" import Input from "@components/input" import Note from "@components/note" import { useToasts } from "@components/toasts" import { useSession } from "next-auth/react" import { useEffect, useState } from "react" import styles from "./profile.module.css" const Profile = () => { const { data: session } = useSession() const [name, setName] = useState(session?.user.name || "") const [submitting, setSubmitting] = useState(false) const { setToast } = useToasts() useEffect(() => { if (!name) { setName(session?.user.name || "") } }, [name, session]) const handleNameChange = (e: React.ChangeEvent) => { setName(e.target.value) } const onSubmit = async (e: React.FormEvent) => { e.preventDefault() if (!name) { setToast({ message: "Please fill out at least one field", type: "error" }) return } setSubmitting(true) const data = { displayName: name } const res = await fetch(`/api/user/${session?.user.id}`, { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify(data) }) setSubmitting(false) if (res.status === 200) { setToast({ message: "Profile updated", type: "success" }) } else { setToast({ message: "Something went wrong updating your profile", type: "error" }) } } /* if we have their email, they signed in with OAuth */ // const imageViaOauth = Boolean(session?.user.email) // const TooltipComponent = ({ children }: { children: React.ReactNode }) => // imageViaOauth ? ( // // {children} // // ) : ( // <>{children} // ) return ( <> Your display name is publicly available on your profile.
{/*
{user.image ? ( ) : ( )}
*/}
) } export default Profile