-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/admin login 1 #5
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React, { useState, useEffect } from 'react' | ||
import RoundedAvatar from './RoundedAvatar' | ||
import BackArrowImg from '../assets/back-arrow.svg' | ||
import ShowPasswordImg from '../assets/show-password.svg' | ||
|
||
function PasswordAvatar({ user, onBack }) { | ||
const [password, setPassword] = useState('') | ||
const [showPassword, setShowPassword] = useState(false) | ||
|
||
function authenticateUser(event) { | ||
event.preventDefault() | ||
} | ||
|
||
function onPasswordChange(event) { | ||
setPassword(event.target.value) | ||
} | ||
|
||
return ( | ||
<div className='password-avatar-container'> | ||
<button type='button' className='default-btn back-arrow-btn' onClick={onBack}> | ||
<img src={BackArrowImg} alt='back arrow'/> | ||
</button> | ||
<div> | ||
<RoundedAvatar user={user} /> | ||
<form className='password-form' onSubmit={authenticateUser}> | ||
<div className='sign-in-container'> | ||
<div className='password-textbox-container'> | ||
<input className='textbox password-textbox' type={(showPassword) ? 'password' : 'text'} name='password' onChange={onPasswordChange} required/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JFYI: when you have quite a few props (or just attributes) on the component, you could split it into multiple lines to improve readability (especially for PR's viewers, but also for developers in the code): <input
className='textbox password-textbox'
type={(showPassword) ? 'password' : 'text'}
name='password'
onChange={onPasswordChange}
required
/> |
||
<button type='button' className={`default-btn show-password-btn ${(showPassword) ? 'visible' : ''}`} onMouseDown={() => setShowPassword(!showPassword)}> | ||
<img src={ShowPasswordImg} alt='show password'/> | ||
</button> | ||
</div> | ||
<button type='button' className='btn'>Sign In</button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default PasswordAvatar | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Btw, when you use default exports, do you get auto completes in your VSCode? |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,14 @@ import JackImg from '../assets/users/[email protected]' | |
export const ADMIN_USER = 'admin' | ||
export const REGULAR_USER = 'regular' | ||
|
||
export function createUser({id, name, age, role}) { | ||
export function createUser({id, name, age, role, coins}) { | ||
return { | ||
id, | ||
name, | ||
age, | ||
role, | ||
image: getUserImage(name) | ||
image: getUserImage(name), | ||
coins | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,13 @@ import { createUser, ADMIN_USER } from '../domain/User' | |
import RoundedAvatar from '../components/RoundedAvatar' | ||
import LoadingAnimation from '../components/LoadingAnimation' | ||
import firebase from 'firebase' | ||
import PasswordAvatar from '../components/PasswordAvatar'; | ||
|
||
function LoginPage({ logUserIn }) { | ||
const history = useHistory() | ||
const [users, setUsers] = useState([]) | ||
const [isLoading, setIsLoading] = useState(true) | ||
const [adminUser, setAdminUser] = useState(null) | ||
|
||
useEffect(() => { | ||
function fetchUsers() { | ||
|
@@ -29,10 +31,14 @@ function LoginPage({ logUserIn }) { | |
|
||
function onAvatarImgClick(user) { | ||
if (user.role === ADMIN_USER) { | ||
history.push('/secure-login') | ||
setAdminUser(user) | ||
} else { | ||
history.replace('/') | ||
logUser(user) | ||
} | ||
} | ||
|
||
function logUser(user) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest using Log by itself is the same log as in |
||
history.replace('/') | ||
logUserIn(user) | ||
} | ||
|
||
|
@@ -42,10 +48,14 @@ function LoginPage({ logUserIn }) { | |
{isLoading ? ( | ||
<LoadingAnimation /> | ||
): ( | ||
<div className='users-container'> | ||
{users && users.map((user) => | ||
(<RoundedAvatar key={user.id} user={user} onImgClick={() => onAvatarImgClick(user)}/>))} | ||
</div> | ||
(adminUser) ? ( | ||
<PasswordAvatar user={adminUser} onBack={() => setAdminUser(null)}/> | ||
) : ( | ||
<div className='users-container'> | ||
{users && users.map((user) => | ||
(<RoundedAvatar key={user.id} user={user} onImgClick={() => onAvatarImgClick(user)}/>))} | ||
</div> | ||
) | ||
)} | ||
</div> | ||
<div className='login-side-img'></div> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now these imports give you paths to the image, not components, so I would recommend using the lower case (otherwise it's a little bit confusing).
Alternatively, you can use SVGO's feature, supported by the CRA, to import SVGs as real react components: