forked from hackforla/VRMS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
import '../sass/DashboardUsers.scss'; | ||
// import '../sass/EventsContainer-media-queries.scss'; | ||
|
||
const DashboardUsers = (props) => { | ||
// const [isLoading, setIsLoading] = useState(false); | ||
const [users, setUsers] = useState([]); | ||
// const [isError, setIsError] = useState(false); | ||
|
||
async function fetchData() { | ||
try { | ||
const res = await fetch("/api/users"); | ||
const resJson = await res.json(); | ||
|
||
setUsers(resJson); | ||
} catch(error) { | ||
alert(error); | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
fetchData(); | ||
|
||
}, []); | ||
|
||
return ( | ||
<div className="flexcenter-container"> | ||
<div className="events-list"> | ||
<ul> | ||
{users.map((user, index) => { | ||
return ( | ||
<li key={index}> | ||
<div key={index} className="event"> | ||
<div className="user-name"> | ||
<h5>{user.name.firstName} {user.name.lastName}</h5> | ||
</div> | ||
<div className="user-roles"> | ||
<p>Current Role: {user.currentRole}</p> | ||
<p>Desired Role: {user.desiredRole}</p> | ||
</div> | ||
</div> | ||
</li> | ||
) | ||
})} | ||
</ul> | ||
</div> | ||
</div> | ||
) | ||
}; | ||
|
||
export default DashboardUsers; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import React, { useState, useEffect, createContext } from 'react'; | ||
|
||
export const authContext = createContext(); | ||
|
||
export function ProvideAuth({ children }) { | ||
const auth = useProvideAuth(); | ||
|
||
return <authContext.Provider value={auth}> | ||
{ children } | ||
</authContext.Provider> | ||
}; | ||
|
||
function useProvideAuth() { | ||
const [isAdmin, setIsAdmin] = useState(null); | ||
const [user, setUser] = useState(null); | ||
// const [userId, setUserId] = useState(null); | ||
|
||
// const isAdmin = async (userId) => { | ||
// console.log('isAdmin tentatively ran'); | ||
|
||
// try { | ||
// fetch('/api/[email protected]') | ||
// .then(response => response.json()) | ||
// .then(resJson => { | ||
// if (resJson.toString() === '5e1d2df6316d2f00172ef09e') { | ||
// console.log('It happened to be true'); | ||
// setUserId(resJson); | ||
// setUser(true); | ||
// } else { | ||
// console.log('It was definitely false what were you thinking'); | ||
// setUser(false); | ||
// } | ||
// }) | ||
// .catch(err => { | ||
// console.log(err); | ||
// }) | ||
|
||
const login = async (email) => { | ||
try { | ||
const response = await fetch(`/api/users?email=${email}`); | ||
const userId = await response.json(); | ||
|
||
const userResponse = await fetch(`/api/users/${userId}`); | ||
const user = await userResponse.json(); | ||
|
||
if(user.accessLevel === 'admin') { | ||
console.log('Hey... that worked...'); | ||
setUser(user); | ||
setIsAdmin(true); | ||
return true; | ||
} else { | ||
console.log('Nope not gonna work'); | ||
setIsAdmin(false); | ||
return false; | ||
} | ||
} catch(error) { | ||
console.log(error); | ||
} | ||
} | ||
|
||
|
||
// } catch(error) { | ||
// console.log(error); | ||
// } | ||
// } | ||
|
||
// const signin = (isLoggedIn) => { | ||
// if(isLoggedIn) { | ||
// return setUser(isLoggedIn); | ||
// } | ||
|
||
// } | ||
|
||
useEffect(() => { | ||
console.log(user); | ||
|
||
// const isTrue = () => { | ||
// console.log(userId === '5e1d2df6316d2f00172ef09e'); | ||
// return userId === '5e1d2df6316d2f00172ef09e' ? setUser(true) : setUser(false); | ||
// } | ||
// // login/subscribe | ||
// // user === true; | ||
// // // login/unsubscribe | ||
// return () => isTrue; | ||
// return () => {isAdmin()} | ||
}, []); | ||
|
||
return { user, isAdmin, login }; | ||
}; | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React, { useContext } from 'react'; | ||
|
||
import { authContext } from '../context/authContext'; | ||
|
||
const useAuth = () => { | ||
return useContext(authContext); | ||
}; | ||
|
||
export default useAuth; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.adminlogin-container { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
z-index: 1; | ||
padding-top: 6vh; | ||
} | ||
|
||
.adminlogin-headers { | ||
margin: 36px 0px; | ||
} | ||
|
||
.adminlogin-warning { | ||
width: 300px; | ||
color: red; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.user-roles { | ||
p { | ||
margin: 0px; | ||
} | ||
} |