-
Notifications
You must be signed in to change notification settings - Fork 35
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
[강성구] Sprint11 #309
Merged
wlgns2223
merged 3 commits into
codeit-bootcamp-frontend:React-강성구
from
L1m3Kun:React-강성구
Aug 26, 2024
The head ref may contain hidden characters: "React-\uAC15\uC131\uAD6C"
Merged
[강성구] Sprint11 #309
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"printWidth": 80, | ||
"trailingComma": "all", | ||
"tabWidth": 2, | ||
"semi": true, | ||
"singleQuote": true, | ||
"bracketSpacing": true, | ||
"arrowParens": "always", | ||
"useTabs": false | ||
} |
Large diffs are not rendered by default.
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
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,41 +1,97 @@ | ||
import { useEffect } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { useState } from 'react'; | ||
import { FieldValues, useForm } from 'react-hook-form'; | ||
|
||
import useSignIn from 'lib/hooks/auth/useSignIn'; | ||
import localStorageTools from 'lib/localStorage/localStorageTools'; | ||
import usePasswordVisibility from 'lib/hooks/usePasswordVisibility'; | ||
import { StorageNameOfUserInfo } from 'core/config/context/AuthContext'; | ||
|
||
import BtnLarge from 'core/buttons/BtnLarge'; | ||
|
||
import { Container, ErrorMessage, Form, Icon, Input, InputWrapper, Label } from '../styles'; | ||
import * as S from '../styles'; | ||
|
||
const SignInForm = () => { | ||
const {ref,icon, handlePasswordVisibility} = usePasswordVisibility(); | ||
const navigate = useNavigate(); | ||
const [isValid, setIsValid] = useState<boolean>(false); | ||
const emailErrorMessage = ''; | ||
const passwordErrorMessage = ''; | ||
|
||
const handleSubmit = (e:React.MouseEvent<HTMLFormElement, MouseEvent>) => { | ||
e.preventDefault(); | ||
navigate('/items'); | ||
const { getInfo } = localStorageTools(); | ||
const navigator = useNavigate(); | ||
|
||
const { | ||
register, | ||
handleSubmit, | ||
formState: { errors, isValid }, | ||
setError, | ||
} = useForm({ mode: 'onBlur' }); | ||
|
||
const signInMutate = useSignIn({ setError }); | ||
|
||
const { isVisible, icon, handlePasswordVisibility } = usePasswordVisibility(); | ||
|
||
const onSubmit = (newValues: FieldValues) => { | ||
const { email, password } = newValues; | ||
signInMutate.mutateAsync({ | ||
email, | ||
password, | ||
}); | ||
}; | ||
|
||
useEffect(() => { | ||
const userInfo = getInfo(StorageNameOfUserInfo); | ||
if (userInfo?.accessToken) { | ||
navigator('/'); | ||
} | ||
|
||
return ( | ||
<Form onSubmit={handleSubmit}> | ||
<Container> | ||
<Label htmlFor="email">이메일</Label> | ||
<Input type="email" id="email" name="email" placeholder="이메일을 입력해주세요"/> | ||
<ErrorMessage>{emailErrorMessage}</ErrorMessage> | ||
</Container> | ||
<Container> | ||
<Label htmlFor="password">비밀번호</Label> | ||
<InputWrapper> | ||
<Input ref={ref} type='password' id="password" name="password" placeholder="비밀번호를 입력해주세요"/> | ||
<Icon src={icon} onClick={handlePasswordVisibility}/> | ||
</InputWrapper> | ||
<ErrorMessage>{passwordErrorMessage}</ErrorMessage> | ||
</Container> | ||
<BtnLarge bgColor={'var(--gray-400)'} color={'var(--font-button)'} disabled={!isValid}>로그인</BtnLarge> | ||
</Form> | ||
); | ||
} | ||
}, []); | ||
|
||
return ( | ||
<S.Form onSubmit={handleSubmit(onSubmit)}> | ||
<S.Container> | ||
<S.Label htmlFor="email">이메일</S.Label> | ||
<S.Input | ||
{...register('email', { | ||
required: '이메일을 입력해주세요.', | ||
pattern: { | ||
value: | ||
/^[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*\.[a-zA-Z]{2,3}$/i, | ||
message: '잘못된 형식입니다.', | ||
}, | ||
})} | ||
type="email" | ||
$isValid={isValid} | ||
placeholder="이메일을 입력해주세요" | ||
/> | ||
<S.ErrorMessage | ||
$isValid={errors.email === undefined} | ||
>{`${errors.email?.message}`}</S.ErrorMessage> | ||
</S.Container> | ||
<S.Container> | ||
<S.Label htmlFor="password">비밀번호</S.Label> | ||
<S.InputWrapper> | ||
<S.Input | ||
{...register('password', { | ||
required: '비밀번호를 입력해주세요.', | ||
minLength: { | ||
value: 8, | ||
message: '8자 이상 입력해주세요.', | ||
}, | ||
})} | ||
type={isVisible ? 'text' : 'password'} | ||
$isValid={false} | ||
placeholder="비밀번호를 입력해주세요" | ||
/> | ||
<S.Icon src={icon} onClick={handlePasswordVisibility} /> | ||
</S.InputWrapper> | ||
<S.ErrorMessage | ||
$isValid={errors.password === undefined} | ||
>{`${errors.password?.message}`}</S.ErrorMessage> | ||
</S.Container> | ||
<BtnLarge | ||
bgColor={isValid ? 'var(--main-color)' : 'var(--gray-400)'} | ||
color={'var(--font-button)'} | ||
disabled={!isValid} | ||
> | ||
로그인 | ||
</BtnLarge> | ||
</S.Form> | ||
); | ||
}; | ||
|
||
export default SignInForm; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
이걸 컴포넌트로 만들어서
isLogin
을props
로 받으면 깔끔하겠네요 !