✅ add - bootstrap

feature/page-admin
Eric 4 years ago
parent 38159b90c1
commit fd4dc77603

@ -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<FormValues>({ resolver });
const [bio, setBio] = useState(props.isUserProfile[0].bio || "");
const [response, setResponse] = useState<ResponseData | undefined>();
const { data: session } = useSession();
@ -60,15 +72,13 @@ const Profil = (props: any) => {
}, [])
const onSubmit: SubmitHandler<FormValues> = 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 (
<Layout>
@ -97,20 +106,18 @@ const Profil = (props: any) => {
);
}
return (
<Layout>
<div className="page">
<h1>Mon compte</h1>
<main>
<form onSubmit={submitData}>
<form onSubmit={handleSubmit(onSubmit)}>
<p>Ma bio : {bio}</p>
<input
autoFocus
placeholder="Ma bio..."
type="text"
defaultValue={bio}
{...register("bio")}
/>
<input type="submit" value="Save changes" />
</form>

Loading…
Cancel
Save