generated from nyu-software-engineering/generic-mern-stack-project
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from agiledev-students-spring2024/homeBranch
- Added components folder where we add components
- Loading branch information
Showing
7 changed files
with
250 additions
and
18 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
Binary file not shown.
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
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,31 @@ | ||
import React from 'react' | ||
import { useNavigate } from 'react-router-dom' | ||
|
||
const Home = (props) => { | ||
const { loggedIn, email } = props | ||
const navigate = useNavigate() | ||
|
||
const onButtonClick = () => { | ||
// You'll update this function later | ||
} | ||
|
||
return ( | ||
<div className="mainContainer"> | ||
<div className={'titleContainer'}> | ||
<div>Welcome!</div> | ||
</div> | ||
<div>This is the home page.</div> | ||
<div className={'buttonContainer'}> | ||
<input | ||
className={'inputButton'} | ||
type="button" | ||
onClick={onButtonClick} | ||
value={loggedIn ? 'Log out' : 'Log in'} | ||
/> | ||
{loggedIn ? <div>Your email address is {email}</div> : <div />} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default Home |
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,74 @@ | ||
import React, { useState } from 'react' | ||
import { useNavigate } from 'react-router-dom' | ||
|
||
const Login = (props) => { | ||
const [email, setEmail] = useState('') | ||
const [password, setPassword] = useState('') | ||
const [emailError, setEmailError] = useState('') | ||
const [passwordError, setPasswordError] = useState('') | ||
|
||
const navigate = useNavigate() | ||
|
||
const onButtonClick = () => { | ||
// Set initial error values to empty | ||
setEmailError('') | ||
setPasswordError('') | ||
|
||
// Check if the user has entered both fields correctly | ||
if ('' === email) { | ||
setEmailError('Please enter your email') | ||
return | ||
} | ||
|
||
if (!/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(email)) { | ||
setEmailError('Please enter a valid email') | ||
return | ||
} | ||
|
||
if ('' === password) { | ||
setPasswordError('Please enter a password') | ||
return | ||
} | ||
|
||
if (password.length < 7) { | ||
setPasswordError('The password must be 8 characters or longer') | ||
return | ||
} | ||
|
||
// Authentication calls will be made here... | ||
} | ||
|
||
return ( | ||
<div className={'mainContainer'}> | ||
<div className={'titleContainer'}> | ||
<div>Login</div> | ||
</div> | ||
<br /> | ||
<div className={'inputContainer'}> | ||
<input | ||
value={email} | ||
placeholder="Enter your email here" | ||
onChange={(ev) => setEmail(ev.target.value)} | ||
className={'inputBox'} | ||
/> | ||
<label className="errorLabel">{emailError}</label> | ||
</div> | ||
<br /> | ||
<div className={'inputContainer'}> | ||
<input | ||
value={password} | ||
placeholder="Enter your password here" | ||
onChange={(ev) => setPassword(ev.target.value)} | ||
className={'inputBox'} | ||
/> | ||
<label className="errorLabel">{passwordError}</label> | ||
</div> | ||
<br /> | ||
<div className={'inputContainer'}> | ||
<input className={'inputButton'} type="button" onClick={onButtonClick} value={'Log in'} /> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default 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