✅ 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 Image from "next/image";
import Router from "next/router"; import Router from "next/router";
import { ProfileProps } from "../types/profile"; import { ProfileProps } from "../types/profile";
import { Resolver, SubmitHandler, useForm } from "react-hook-form";
export const getServerSideProps: GetServerSideProps = async ({ req, res }) => { export const getServerSideProps: GetServerSideProps = async ({ req, res }) => {
@ -49,8 +50,19 @@ interface ResponseData {
message: string message: string
} }
type FormValues = {
bio: string;
};
const Profil = (props: any) => { const Profil = (props: any) => {
const { register, handleSubmit, formState: { errors } } = useForm<FormValues>({ resolver });
const [bio, setBio] = useState(props.isUserProfile[0].bio || ""); const [bio, setBio] = useState(props.isUserProfile[0].bio || "");
const [response, setResponse] = useState<ResponseData | undefined>(); const [response, setResponse] = useState<ResponseData | undefined>();
const { data: session } = useSession(); const { data: session } = useSession();
@ -60,15 +72,13 @@ const Profil = (props: any) => {
}, []) }, [])
const onSubmit: SubmitHandler<FormValues> = async (data) => {
console.log('input value', data.bio);
const submitData = async (e: React.SyntheticEvent) => { setBio(data.bio)
e.preventDefault();
console.log('input value', e.target[0].value);
setBio(e.target[0].value)
try { try {
const body = { bioValue: e.target[0].value }; const body = { bioValue: data.bio };
await fetch(`/api/profile`, { await fetch(`/api/profile`, {
method: "PUT", method: "PUT",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
@ -87,7 +97,6 @@ const Profil = (props: any) => {
} }
}; };
if (!session) { if (!session) {
return ( return (
<Layout> <Layout>
@ -97,20 +106,18 @@ const Profil = (props: any) => {
); );
} }
return ( return (
<Layout> <Layout>
<div className="page"> <div className="page">
<h1>Mon compte</h1> <h1>Mon compte</h1>
<main> <main>
<form onSubmit={submitData}> <form onSubmit={handleSubmit(onSubmit)}>
<p>Ma bio : {bio}</p> <p>Ma bio : {bio}</p>
<input <input
autoFocus autoFocus
placeholder="Ma bio..." placeholder="Ma bio..."
type="text"
defaultValue={bio} defaultValue={bio}
{...register("bio")}
/> />
<input type="submit" value="Save changes" /> <input type="submit" value="Save changes" />
</form> </form>

Loading…
Cancel
Save