From 47739caa54d38413de2c19ef098acf8182b8314e Mon Sep 17 00:00:00 2001 From: bytesparallel Date: Sun, 19 Dec 2021 18:39:03 -0600 Subject: [PATCH] saving prototype code for change profile info code --- src/components/profile/Profile.js | 36 ++------------ src/components/profile/ProfileForm.js | 60 ++++++++++++++++++++++++ src/components/profile/ProfileFormv2.txt | 32 +++++++++++++ 3 files changed, 96 insertions(+), 32 deletions(-) create mode 100644 src/components/profile/ProfileForm.js create mode 100644 src/components/profile/ProfileFormv2.txt diff --git a/src/components/profile/Profile.js b/src/components/profile/Profile.js index ae35fd7..0e4551d 100644 --- a/src/components/profile/Profile.js +++ b/src/components/profile/Profile.js @@ -1,12 +1,14 @@ import { React } from "react" import { useState, useEffect } from "react"; +import { useHistory } from "react-router-dom"; import { ProfileForm } from "./ProfileForm"; export const Profile = () => { const [Users, fetchUsers] = useState([]) const [currentuser, setcurrentuser] = useState(localStorage.getItem("graphicsbaytracker_customer")) const [currentUsertrackedcards, setcurrentUsertrackedcards] = useState([]) - const [formactive, setformstate] = useState(false) + const history = useHistory() + useEffect( () => { @@ -32,37 +34,7 @@ const showprofileinfo = () => { return (

{founduser?.name}
{founduser?.email}

) } -const toggleForm = () => { - setformstate(true) - formactive === true ? : -} - - useEffect(() => { - Users.filter( - ({ - id, - name, - email - }) => { - if (Users.id === parseInt(currentuser)) - return ( - - ) - } - ) - } - ) const removetrackedcard = (gpudataobj) => { @@ -84,7 +56,7 @@ const toggleForm = () => {

My Tracked Cards

{showprofileinfo()}

- diff --git a/src/components/profile/ProfileForm.js b/src/components/profile/ProfileForm.js new file mode 100644 index 0000000..e13629b --- /dev/null +++ b/src/components/profile/ProfileForm.js @@ -0,0 +1,60 @@ +import { useEffect, useState } from "react" +import { useHistory } from "react-router-dom" + + +export const ProfileForm = () => { + const[usertoedit, setediteduser ] = useState(localStorage.getItem("graphicsbaytracker_customer")) + const [userpool, setuserpool] = useState([]) + const [ founduser, setfounduser] = useState({}) + const history = useHistory() + + + const editprofileinfocall = (editedprofileinfo) => { + fetch('https://localhost:8088/users', { + method: 'PUT', + body: JSON.stringify({ + id: founduser.id, + name: editedprofileinfo.name, + email: editedprofileinfo.email, + + }), + headers: { + "Content-type": "application/json; charset=UTF-8" + } + }).then(response => { + return response.json() + }).then(json => { + console.log(json) + this.setState({ + user:json + }); + }).then(() => history.push("profile/Profile")) + + } + useEffect( + () => { + const desireduser = userpool.find((userobj) => userobj.id === parseInt(usertoedit)) + return setfounduser(desireduser) + } + ) + useEffect( + () => { + fetch("http://localhost:8088/users") + .then(res => res.json()) + .then(setuserpool) + }, []) + return ( + <> +

Edit Profile Data

+ +
+
+
+ + editprofileinfocall(editedprofileinfo)}/> + + + + ) +} + diff --git a/src/components/profile/ProfileFormv2.txt b/src/components/profile/ProfileFormv2.txt new file mode 100644 index 0000000..ccb88d4 --- /dev/null +++ b/src/components/profile/ProfileFormv2.txt @@ -0,0 +1,32 @@ +const [formactive, setformstate] = useState(false) +const toggleForm = () => { + setformstate(true) + formactive === true ? : +} + + + useEffect(() => { + Users.filter( + ({ + id, + name, + email + }) => { + if (Users.id === parseInt(currentuser)) + return ( + + ) + } + ) + } + ) \ No newline at end of file