-
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
60 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,11 @@ | ||
export function authenticate(email, password) { | ||
return new Promise((resolve, reject) => { | ||
setTimeout(() => { | ||
resolve({ | ||
name: "New name", | ||
dateOfBirth: "01/01/1991", | ||
email: "[email protected]" | ||
}); | ||
}, 2500); | ||
}); | ||
} |
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 |
---|---|---|
@@ -1,20 +1,21 @@ | ||
import React, { useState, useContext } from "react"; | ||
import LoadingContext from "./loadingContext"; | ||
import { authenticate } from "./auth"; | ||
import UserDetailsContext from "./userDetailsContext"; | ||
|
||
const Login = () => { | ||
const { showLoading, hideLoading } = useContext(LoadingContext); | ||
// const { showLoading, hideLoading } = useContext(LoadingContext); | ||
const { setUserDetails } = useContext(UserDetailsContext); | ||
|
||
const [email] = useState("[email protected]"); | ||
const [password] = useState("password"); | ||
|
||
const authenticateUser = () => { | ||
showLoading(); | ||
// authenticateUser(email, password).then(userDetails => { | ||
// const { | ||
// name, | ||
// dateOfBirth, | ||
// email, | ||
// secretQuestion, | ||
// secretAnswer | ||
// } = userDetails; | ||
// hideLoading; | ||
// }); | ||
// showLoading(); | ||
authenticateUser(email, password).then(userDetails => { | ||
const { name, dateOfBirth, email } = userDetails; | ||
// hideLoading; | ||
}); | ||
}; | ||
return <button onClick={authenticateUser}>Login</button>; | ||
}; | ||
|
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,30 @@ | ||
import React, { useState, useContext } from "react"; | ||
import merge from "lodash.merge"; | ||
|
||
import UserDetailsContext from "./userDetailsContext"; | ||
|
||
const UserDetailsProvider = ({ children }) => { | ||
const setUserDetails = ({ name, dateOfBirth, email }) => { | ||
updateUserDetails(prevState => { | ||
const newState = { ...prevState }; | ||
return merge(newState, { | ||
name, | ||
dateOfBirth, | ||
}); | ||
}); | ||
}; | ||
const userState = { | ||
name: "", | ||
dateOfBirth: "", | ||
email: "" | ||
}; | ||
const [userDetails, updateUserDetails] = useState(userState); | ||
return ( | ||
<UserDetailsContext.Provider value={userDetails}> | ||
{children} | ||
</UserDetailsContext.Provider> | ||
); | ||
}; | ||
|
||
export default UserDetailsProvider; |