-
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.
Merge pull request #4 from junction-asia-2023/feat/login
feat: Add default login
- Loading branch information
Showing
13 changed files
with
142 additions
and
16 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
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,36 @@ | ||
import { FunctionComponent } from 'react'; | ||
|
||
import useLogin from './hooks/useLogin'; | ||
|
||
const LoginContainer: FunctionComponent = () => { | ||
const { | ||
email, | ||
handleEmailChange, | ||
password, | ||
handlePasswordChange, | ||
error, | ||
handleSubmitClick, | ||
} = useLogin(); | ||
|
||
return ( | ||
<div> | ||
<div>Login</div> | ||
<input | ||
type="text" | ||
value={email} | ||
placeholder="Insert your email" | ||
onChange={handleEmailChange} | ||
/> | ||
<input | ||
type="password" | ||
value={password} | ||
placeholder="Insert your password" | ||
onChange={handlePasswordChange} | ||
/> | ||
{error && <span>Please check your email or password</span>} | ||
<button onClick={handleSubmitClick}>submit</button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default LoginContainer; |
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 @@ | ||
import { atomWithReset } from 'jotai/utils'; | ||
|
||
import { User } from './type'; | ||
|
||
export const userAtom = atomWithReset<User>({}); |
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,8 @@ | ||
import { DummyUser } from './type'; | ||
|
||
export const DUMMY_USER: DummyUser = { | ||
email: '[email protected]', | ||
companyNo: 'JS1234', | ||
password: 'just', | ||
department: 'dev1', | ||
}; |
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,45 @@ | ||
import { ChangeEventHandler, ReactEventHandler, useState } from 'react'; | ||
import { useAtom } from 'jotai'; | ||
|
||
import { setItem } from '../../shared/utils/storage'; | ||
import { DummyUser } from '../type'; | ||
import { DUMMY_USER } from '../constants'; | ||
import { userAtom } from '../atom'; | ||
|
||
const useLogin = () => { | ||
const [email, setEmail] = useState(''); | ||
const [password, setPassword] = useState(''); | ||
const [error, setError] = useState(false); | ||
const [, setUser] = useAtom(userAtom); | ||
|
||
const handleEmailChange: ChangeEventHandler<HTMLInputElement> = (e) => { | ||
setEmail(e.target.value); | ||
setError(false); | ||
}; | ||
const handlePasswordChange: ChangeEventHandler<HTMLInputElement> = (e) => { | ||
setPassword(e.target.value); | ||
setError(false); | ||
}; | ||
const handleSubmitClick: ReactEventHandler<HTMLButtonElement> = () => { | ||
if (DUMMY_USER.email !== email || DUMMY_USER.password !== password) { | ||
setError(true); | ||
return; | ||
} | ||
const curUser: DummyUser = { ...DUMMY_USER }; | ||
delete curUser.password; | ||
setUser({ ...curUser }); | ||
setItem('user', curUser); | ||
// TODO: Redirect Home; | ||
}; | ||
|
||
return { | ||
email, | ||
handleEmailChange, | ||
password, | ||
handlePasswordChange, | ||
error, | ||
handleSubmitClick, | ||
}; | ||
}; | ||
|
||
export default useLogin; |
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,6 @@ | ||
export type User = { | ||
email?: string; | ||
companyNo?: string; | ||
department?: string; | ||
}; | ||
export type DummyUser = User & { password?: string }; |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { FunctionComponent, PropsWithChildren } from 'react'; | ||
|
||
import './layout.scss'; | ||
import useLayout from './hooks/useLayout'; | ||
|
||
const LayoutContainer: FunctionComponent<PropsWithChildren> = ({ | ||
children, | ||
}) => { | ||
useLayout(); | ||
return <div className="layout-container">{children}</div>; | ||
}; | ||
|
||
export default LayoutContainer; |
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,18 @@ | ||
import { useAtom } from 'jotai'; | ||
import { useLayoutEffect } from 'react'; | ||
|
||
import { userAtom } from '../../../login/atom'; | ||
import { getItem } from '../../utils/storage'; | ||
|
||
const useLayout = () => { | ||
const [user] = useAtom(userAtom); | ||
|
||
useLayoutEffect(() => { | ||
const user = getItem('user'); | ||
if (!user) { | ||
// TODO: Redirect Login | ||
} | ||
}, []); | ||
}; | ||
|
||
export default useLayout; |
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,4 @@ | ||
.layout-container { | ||
min-width: 320px; | ||
max-width: 480px; | ||
} |
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 |
---|---|---|
|
@@ -8,8 +8,3 @@ body { | |
place-content: center; | ||
min-height: 100vh; | ||
} | ||
|
||
.layout-container { | ||
min-width: 320px; | ||
max-width: 480px; | ||
} |