-
Notifications
You must be signed in to change notification settings - Fork 56
부산대FE_ 안형찬_1단계 - 로그인 기능 구현하기 #103
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
Open
hyeongchanan
wants to merge
5
commits into
next-step:hyeongchanan
Choose a base branch
from
hyeongchanan:upstream/hyeongchan0
base: hyeongchanan
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3b78d11
1단계 내용 가져오기
hyeongchanan fa70f76
로그인 페이지 구현
hyeongchanan 9a8d10c
Merge branch 'hyeongchanan' into upstream/hyeongchan0
hyeongchanan 512a2eb
1단계 피드백 반영
hyeongchanan 2f5b5c7
Merge branch 'upstream/hyeongchan0' of https://github.com/hyeongchana…
hyeongchanan 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 hidden or 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,29 @@ | ||
| import { useState } from 'react'; | ||
|
|
||
| type ValidatorFn = (value: string) => string | null; | ||
|
|
||
| function useInput(validator: ValidatorFn, initialValue ='') { | ||
| const [value, setValue] = useState(initialValue); | ||
| const [error, setError] = useState<string | null>(null); | ||
| const [touched, setTouched] = useState(false); | ||
|
|
||
| const onChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
| setValue(e.target.value); | ||
| if (touched) { | ||
| const errorMsg = validator(e.target.value); | ||
| setError(errorMsg); | ||
| } | ||
| }; | ||
|
|
||
| const onBlur = () => { | ||
| setTouched(true); | ||
| const errorMsg = validator(value); | ||
| setError(errorMsg); | ||
| }; | ||
|
|
||
| const isValid = !error && touched; | ||
|
|
||
| return { value, onChange, onBlur, error, isValid }; | ||
| } | ||
|
|
||
| export default useInput; | ||
This file contains hidden or 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,85 @@ | ||
|
|
||
| import theme from '@/styles/theme'; | ||
| import styled from '@emotion/styled'; | ||
|
|
||
| export const MyDiv = styled.div` | ||
| max-width: 720px; | ||
| width: 100%; | ||
| min-height: 100vh; | ||
| height: 100%; | ||
| background-color: rgb(255, 255, 255); | ||
| padding-top: 2.75rem; | ||
| `; | ||
|
|
||
| export const LoginMain = styled.main` | ||
| width: 100%; | ||
| height: calc(-2.75rem + 100vh); | ||
| display: flex; | ||
| flex-direction: column; | ||
| align-items: center; | ||
| justify-content: center; | ||
| `; | ||
|
|
||
| export const KakaoLogo = styled.img` | ||
| width: 5.5rem; | ||
| color: rgb(42, 48, 56); | ||
| `; | ||
| export const LoginSection = styled.section` | ||
| width: 100%; | ||
| max-width: 26.25rem; | ||
| padding: 16px; | ||
| `; | ||
|
|
||
| export const InputSection = styled.input<{ hasError?: boolean }>` | ||
| width: 100%; | ||
| box-sizing: border-box; | ||
| color: rgb(42, 48, 56); | ||
| transition: border-color 200ms; | ||
| border-style: solid; | ||
| min-height: 2.75rem; | ||
| font-size: 1rem; | ||
| font-weight: 400; | ||
| line-height: 1.375rem; | ||
| padding: 8px 0px; | ||
| border-width: 0px 0px 1px; | ||
| border-color: ${({ hasError }) => (hasError ? 'red' : 'rgb(220, 222, 227)')}; | ||
| &:focus { | ||
| outline: none; | ||
| border-color: ${({ hasError }) => hasError ? 'red' : 'rgb(42, 48, 56)'}; | ||
| } | ||
|
|
||
| `; | ||
|
|
||
| export const LoginButton = styled.button<{ notVaild?: boolean }>` | ||
| width: 100%; | ||
| height: 2.75rem; | ||
| font-size: 0.875rem; | ||
| font-weight: 400; | ||
| line-height: 1.1875rem; | ||
| color: rgb(42, 48, 56); | ||
| background-color: ${theme.colors.kakaoYellow}; | ||
| border-radius: 4px; | ||
| border: none; | ||
| cursor: ${({notVaild}) => (notVaild? 'not-allowed' :'pointer' ) }; | ||
| opacity: ${({notVaild}) => (notVaild? '0.5' :'1' ) }; | ||
| transition: background-color 200ms; | ||
| `; | ||
|
|
||
| export const EmptyDiv16h= styled.div` | ||
| width: 100%; | ||
| height: 16px; | ||
| background-color: transparent; | ||
| `; | ||
|
|
||
| export const EmptyDiv48h = styled.div` | ||
| width: 100%; | ||
| height: 48px; | ||
| background-color: transparent; | ||
| `; | ||
|
|
||
| export const ErrorMessage = styled.div` | ||
| color: red; | ||
| font-size: 0.75rem; | ||
| margin-top: 4px; | ||
| `; | ||
|
|
This file contains hidden or 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 hidden or 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,12 @@ | ||
| export const validateEmail = (value: string): string | null => { | ||
| if (!value) return 'ID를 입력해주세요.'; | ||
| const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | ||
| if (!emailRegex.test(value)) return 'ID는 이메일 형식으로 입력해주세요.'; | ||
| return null; | ||
| }; | ||
|
|
||
| export const validatePassword = (value: string): string | null => { | ||
| if (!value) return 'PW를 입력해주세요.'; | ||
| if (value.length < 8) return 'PW는 최소 8글자 이상이어야 합니다.'; | ||
| return null; | ||
| }; |
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.
touched는 어떤 경우에 사용이 되는건가요?
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.
처음 입력할때 입력을 완료하기 전에는 오류 메세지가 나지 않도록 하기위해 만들었습니다.
id 랑 pw를 입력하다가 다른곳을 클릭해 포커스가 나가면, 그때부터 touched 가 true가 되고 오류가 있으면 오류 메세지가 출력됩니다.