diff --git a/src/App.js b/src/App.js index 9fa91b9..c510d32 100644 --- a/src/App.js +++ b/src/App.js @@ -10,6 +10,8 @@ import Resources from "../src/views/resources/resources"; import ForgotPassword from "./views/Auth/ForgotPassword"; import ResetPassword from "./views/Auth/ResetPassword"; import Admin from "./views/admin/joint"; +import AdminLogin from "./views/admin/LoginForm" +import AdminSignup from "./views/admin/SignUpForm" import { ProtectedRoute, GuestRoute } from './components/routes'; @@ -20,6 +22,16 @@ function App() { + + +
+
+ +
+
{children}
+
+
+
+ + ); +} + +export default AuthPage; diff --git a/src/views/admin/LoginForm.jsx b/src/views/admin/LoginForm.jsx new file mode 100644 index 0000000..33c313a --- /dev/null +++ b/src/views/admin/LoginForm.jsx @@ -0,0 +1,100 @@ +import React, { useState } from "react"; +import Auth from "./AuthPage"; +import {signin} from "../Auth/AuthService"; +import { useHistory } from "react-router-dom"; +import { useUserContext } from "../../context/AuthContext" + +const LoginForm = () => { + const initialState = { + email: "", + password: "" + } + const [state, setState] = useState(initialState); + const { setToken, setUser } = useUserContext() + const [errorMsg, setErrorMsg] = useState(" ") + const [loading, setLoading] = useState(false) + const history = useHistory(); + + const [showPassword, setShowPassword] = useState(false) + + const togglePassword = () => { + setShowPassword(!showPassword) + } + + const handleChange = (e) => { + const { name, value } = e.target; + console.log(state) + setState({ ...state, [name]: value }); + }; + + const handleSubmit = (event) => { + setLoading(true) + event.preventDefault() + signin(state).then((response) => { + if(response.data){ + const {data} = response?.data + if (data.message){ + setToken(data.token) + setUser(data.user) + history.push(`/dashboard`); + } + setLoading(false) + } + else{ + setErrorMsg("Could not Sign User In, Check Credentials") + setLoading(false) + } + }); + }; + + return ( + +
+
+

Log In

+

Enter your assigned SCA email address to gain access to the platform.

+
+
+
{errorMsg}
+ + + {/*
+ + +
*/} + + +
+

+ Don't have access? + + Request Access + +

+
+ +
+
+ ); +}; + +export default LoginForm; diff --git a/src/views/admin/SignUpForm.jsx b/src/views/admin/SignUpForm.jsx new file mode 100644 index 0000000..5a91189 --- /dev/null +++ b/src/views/admin/SignUpForm.jsx @@ -0,0 +1,111 @@ +import React, { useState } from "react"; +import Auth from "./AuthPage"; +import {signup} from "../Auth/AuthService"; +import { useHistory } from "react-router-dom"; + +import { useUserContext } from "../../context/AuthContext"; + +const SignUpForm = () => { + const initialState = { + email: "", + } + + const [state, setState] = useState(initialState); + const { setToken, setUser } = useUserContext() + const [errorMsg, setErrorMsg] = useState('') + const history = useHistory(); + const [loading, setLoading] = useState(false) + + const [showPassword, setShowPassword] = useState(false) + + const togglePassword = () => { + setShowPassword(!showPassword) + } + + const handleChange = (e) => { + const { name, value } = e.target; + setState({ ...state, [name]: value }); + }; + + + const handleSubmit = (event) => { + event.preventDefault() + setLoading(true) + signup(state).then((response) => { + if(response.data){ + const { data } = response.data + if (data.message) { + setToken(data.token) + setUser(data.user) + history.push(`/dashboard`); + } + setLoading(false) + } + else{ + console.log(response) + setErrorMsg("Could not Create Account, Check Credentials") + setLoading(false) + } + }) + .catch((error) => { + console.log(error); + setLoading(false) + setErrorMsg(error) + }) + }; + return ( + +
+
+

Request Access

+

Enter your assigned SCA email address and why you’ll like to gain access to the platform.

+
+
{errorMsg}
+
+ + + {/*
+ + +
*/} + + + + + +
+

+ Already have an account ? + + Login + +

+
+ +
+
+ ); +}; + +export default SignUpForm;