"use client" import { Note, Input, Textarea, Button, useToasts } from "@geist-ui/core/dist" import { User } from "@lib/server/prisma" import { useState } from "react" const Profile = ({ user }: { user: User }) => { // TODO: make this displayName, requires fetching user from DB as session doesnt have it const [name, setName] = useState(user.name || "") const [bio, setBio] = useState() const { setToast } = useToasts() const handleNameChange = (e: React.ChangeEvent) => { setName(e.target.value) } const handleBioChange = (e: React.ChangeEvent) => { setBio(e.target.value) } const onSubmit = async (e: React.FormEvent) => { e.preventDefault() if (!name && !bio) { setToast({ text: "Please fill out at least one field", type: "error" }) return } const data = { displayName: name, bio } const res = await fetch(`/api/user/${user.id}`, { method: "PUT", headers: { "Content-Type": "application/json", }, body: JSON.stringify(data) }) if (res.status === 200) { setToast({ text: "Profile updated", type: "success" }) } else { setToast({ text: "Something went wrong updating your profile", type: "error" }) } } return ( <> This information will be publicly available on your profile