From 2f30b5c802f578dbb4148f7cf2f0a04f5ea8731e Mon Sep 17 00:00:00 2001 From: bytesparallel Date: Tue, 21 Dec 2021 13:48:33 -0600 Subject: [PATCH] saving MVP for review --- src/components/profile/ProfileForm.js | 34 ++++++++++++++++++++------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/components/profile/ProfileForm.js b/src/components/profile/ProfileForm.js index e6af57d..5605af0 100644 --- a/src/components/profile/ProfileForm.js +++ b/src/components/profile/ProfileForm.js @@ -7,12 +7,12 @@ export const ProfileForm = () => { const [userpool, setuserpool] = useState([]) const [ founduser, setfounduser] = useState({}) const [ editedusername, seteditedusername ] = useState("") - const [ editeduseremail, setediteduseremail ] = useState("") + const [editeduseremail, setediteduseremail] = useState("") const history = useHistory() const editprofileinfocall = () => { - fetch(`https://localhost:8088/users/${founduser.id}`, { + fetch(`http://localhost:8088/users/${founduser.id}`, { method: 'PUT', body: JSON.stringify({ name: editedusername, @@ -24,14 +24,30 @@ export const ProfileForm = () => { } }).then(response => { return response.json() - }).then(json => { - console.log(json) - this.setState({ - user:json - }); + // }).then(json => { + // console.log(json) + // this.setState({ + // user:json + // }); }).then(() => history.push("profile/Profile")) } + + // PUT request using fetch inside useEffect React hook + // const editprofileinfocall = () => { + // const requestOptions = { + // method: 'PUT', + // // headers: { 'Content-Type': 'application/json' }, + // // body: JSON.stringify({ name: 'React Hooks PUT Request Example', email:'This string' }) + // }; + // fetch(`http://localhost:8088/`, requestOptions) + // .then(response => response.json()) + // .then(data => this.setState({ postId: data.id })); + + + // empty dependency array means this effect will only run once (like componentDidMount in classes) + // }; + useEffect( () => { const desireduser = userpool.find((userobj) => userobj.id === parseInt(usertoedit)) @@ -48,9 +64,9 @@ export const ProfileForm = () => {

Edit Profile Data


- {seteditedusername(e.target.editedusername)}}/>
+ {seteditedusername(e.target.value)}}/>

- { setediteduseremail(e.target.editeduseremail)}}/> + { setediteduseremail(e.target.value)}}/>