diff --git a/pages/profile.tsx b/pages/profile.tsx index 15c1b93..cee0546 100644 --- a/pages/profile.tsx +++ b/pages/profile.tsx @@ -6,6 +6,7 @@ import prisma from '../lib/prisma' import Image from "next/image"; import Router from "next/router"; import { ProfileProps } from "../types/profile"; +import { Resolver, SubmitHandler, useForm } from "react-hook-form"; export const getServerSideProps: GetServerSideProps = async ({ req, res }) => { @@ -49,8 +50,19 @@ interface ResponseData { message: string } +type FormValues = { + bio: string; +}; + + + + + const Profil = (props: any) => { + const { register, handleSubmit, formState: { errors } } = useForm({ resolver }); + + const [bio, setBio] = useState(props.isUserProfile[0].bio || ""); const [response, setResponse] = useState(); const { data: session } = useSession(); @@ -60,15 +72,13 @@ const Profil = (props: any) => { }, []) + const onSubmit: SubmitHandler = async (data) => { - - const submitData = async (e: React.SyntheticEvent) => { - e.preventDefault(); - console.log('input value', e.target[0].value); - setBio(e.target[0].value) + console.log('input value', data.bio); + setBio(data.bio) try { - const body = { bioValue: e.target[0].value }; + const body = { bioValue: data.bio }; await fetch(`/api/profile`, { method: "PUT", headers: { "Content-Type": "application/json" }, @@ -87,7 +97,6 @@ const Profil = (props: any) => { } }; - if (!session) { return ( @@ -97,20 +106,18 @@ const Profil = (props: any) => { ); } - - return (

Mon compte

-
+

Ma bio : {bio}