Archived
added prettier and formatted code
This commit is contained in:
+10
-17
@@ -1,22 +1,15 @@
|
||||
import React, {useState, useEffect} from "react";
|
||||
import { useHistory,useParams } from "react-router-dom";
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { useHistory, useParams } from "react-router-dom";
|
||||
import { getSmug_UserById, putSmug_User } from "./ProfileManager";
|
||||
|
||||
|
||||
export const EditProfile = () => {
|
||||
const { id } = useParams()
|
||||
const history = useHistory()
|
||||
const [ usertoedit, setusertoedit] = useState({})
|
||||
const { id } = useParams();
|
||||
const history = useHistory();
|
||||
const [usertoedit, setusertoedit] = useState({});
|
||||
|
||||
useEffect(
|
||||
() => {
|
||||
getSmug_UserById().then(data => setusertoedit(data))
|
||||
},[]
|
||||
)
|
||||
useEffect(() => {
|
||||
getSmug_UserById().then((data) => setusertoedit(data));
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<form>
|
||||
|
||||
</form>
|
||||
)
|
||||
}
|
||||
return <form></form>;
|
||||
};
|
||||
|
||||
+28
-22
@@ -1,28 +1,34 @@
|
||||
import React, {useState, useEffect} from "react";
|
||||
import { useHistory,useParams } from "react-router-dom";
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { useHistory, useParams } from "react-router-dom";
|
||||
import { getSmug_UserById } from "./ProfileManager";
|
||||
|
||||
export const Profile = () => {
|
||||
const [currentuser, setcurrentuser] = useState(localStorage.getItem("smug_user_id"))
|
||||
const [smug_user, setsmuguser] = useState({})
|
||||
const [currentuser, setcurrentuser] = useState(
|
||||
localStorage.getItem("smug_user_id"),
|
||||
);
|
||||
const [smug_user, setsmuguser] = useState({});
|
||||
|
||||
useEffect(
|
||||
() => {
|
||||
getSmug_UserById(currentuser).then(data => setsmuguser(data))
|
||||
},[]
|
||||
)
|
||||
// How to filter a user by their uid? Not quite sure
|
||||
return (
|
||||
useEffect(() => {
|
||||
getSmug_UserById(currentuser).then((data) => setsmuguser(data));
|
||||
}, []);
|
||||
// How to filter a user by their uid? Not quite sure
|
||||
return (
|
||||
<>
|
||||
<h2>My Profile</h2>
|
||||
<div>
|
||||
<p> Username: {smug_user.user.username}</p>
|
||||
<p> Email: {smug_user.user.email}</p>
|
||||
<p> Name: {smug_user.user.first_name} {smug_user.user.last_name}</p>
|
||||
<p>{smug_user.business_owner ? "Current user is business owner" : "Current user is a standard user"}</p>
|
||||
<p> User is staff? {smug_user.user.is_staff ? "Yes" : "No"}</p>
|
||||
|
||||
</div>
|
||||
<h2>My Profile</h2>
|
||||
<div>
|
||||
<p> Username: {smug_user.user.username}</p>
|
||||
<p> Email: {smug_user.user.email}</p>
|
||||
<p>
|
||||
{" "}
|
||||
Name: {smug_user.user.first_name} {smug_user.user.last_name}
|
||||
</p>
|
||||
<p>
|
||||
{smug_user.business_owner
|
||||
? "Current user is business owner"
|
||||
: "Current user is a standard user"}
|
||||
</p>
|
||||
<p> User is staff? {smug_user.user.is_staff ? "Yes" : "No"}</p>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,22 +1,18 @@
|
||||
export const getSmug_UserById = (id) => {
|
||||
return fetch(`http://localhost:8000/smug_users/${id}`, {
|
||||
headers:{
|
||||
"Authorization": `Token ${localStorage.getItem("sf_token")}`
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
}
|
||||
return fetch(`http://localhost:8000/smug_users/${id}`, {
|
||||
headers: {
|
||||
Authorization: `Token ${localStorage.getItem("sf_token")}`,
|
||||
},
|
||||
}).then((response) => response.json());
|
||||
};
|
||||
|
||||
export const putSmug_User = (editedProfile) => {
|
||||
return fetch(`http://localhost:8000/games/${editedProfile.id}`, {
|
||||
method: "PUT",
|
||||
body: JSON.stringify(
|
||||
editedProfile
|
||||
),
|
||||
headers:{
|
||||
"Authorization": `Token ${localStorage.getItem("sf_token")}`,
|
||||
"Content-Type": "Application/json"
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
return fetch(`http://localhost:8000/games/${editedProfile.id}`, {
|
||||
method: "PUT",
|
||||
body: JSON.stringify(editedProfile),
|
||||
headers: {
|
||||
Authorization: `Token ${localStorage.getItem("sf_token")}`,
|
||||
"Content-Type": "Application/json",
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user