Skip to content
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

[#62] react-hook-form 설치 및 유효성 검사 로직 #89

Merged
merged 25 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7aa87cb
chore: react-hook-form 설치
dabin-Hailey Jan 20, 2024
a1af004
feat: 로그인 input에 대한 유효성 옵션 설정
dabin-Hailey Jan 21, 2024
429bbeb
Merge branch 'dev' of https://github.com/CoolPeace-yanolza/frontend i…
dabin-Hailey Jan 21, 2024
aa8709b
feat: LoginForm에 react-hook-form 적용
Jan 21, 2024
cc4116f
feat: AuthInputNormal에 react-hook-form 적용
dabin-Hailey Jan 21, 2024
7f00671
modify: 조건에 따라 check.svg 달라지는 로직 간단화
dabin-Hailey Jan 21, 2024
8156ab5
feat: AuthInputPassword에 react-hook-form 적용
dabin-Hailey Jan 21, 2024
9430b22
modify: 조건에 따라 check.svg 달라지는 로직 간단화
dabin-Hailey Jan 21, 2024
b8c2e49
feat: SignUpForm에 react-hook-form 적용
dabin-Hailey Jan 21, 2024
9589602
feat: SignUpForm의 이메일input을 AuthInputNormal로 변경
dabin-Hailey Jan 21, 2024
ba5dd59
feat: 회원가입 input에 대한 유효성 옵션 설정
dabin-Hailey Jan 22, 2024
7b44cc9
rename: utils > login.ts -> auth.ts로 파일명 변경
dabin-Hailey Jan 22, 2024
11e81ef
modify: filedOptions -> getInputOptions로 함수명 변경
dabin-Hailey Jan 22, 2024
b327ab8
modify: getInputOptions로 import 방식 변경
dabin-Hailey Jan 22, 2024
1040e01
feat: 회원가입 비밀번호&비밀번호 확인 input 유효성 검사 로직 구현
dabin-Hailey Jan 22, 2024
6238f62
feat: 회원가입 이름 input 유효성 검사 로직 구현
dabin-Hailey Jan 22, 2024
6d4a4f0
feat: 회원가입 이메일 input 유효성 검사 로직 구현
dabin-Hailey Jan 22, 2024
f0db448
feat: 회원가입 폼 입력상태에 따라 회원가입(submit)버튼 disabled 처리
dabin-Hailey Jan 22, 2024
c8662f4
Merge branch 'dev' of https://github.com/CoolPeace-yanolza/frontend i…
dabin-Hailey Jan 22, 2024
8865656
feat: 로그인 폼 유효성 검사 로직 구현
dabin-Hailey Jan 22, 2024
94a13e0
Merge branch 'dev' of https://github.com/CoolPeace-yanolza/frontend i…
dabin-Hailey Jan 23, 2024
f9b75dd
move: components > common> Auth 폴더 위치 components > Auth로 변경
dabin-Hailey Jan 23, 2024
c3026c5
feat: react-hook-form으로 로그인 제출 로직 구현
dabin-Hailey Jan 23, 2024
75cb062
feat: 로그인 API 에러 처리 구현
dabin-Hailey Jan 23, 2024
bab6b4f
Merge branch 'dev' of https://github.com/CoolPeace-yanolza/frontend i…
dabin-Hailey Jan 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"react-datepicker": "^4.25.0",
"react-dom": "^18.2.0",
"react-error-boundary": "^4.0.12",
"react-hook-form": "^7.49.3",
"react-loading-skeleton": "^3.3.1",
"react-paginate": "^8.2.0",
"react-router-dom": "^6.21.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@ import styled from '@emotion/styled';

import { AuthButton, AuthButtonStyleProps } from '@/types/auth';

const AuthButton = ({ size, variant, text, buttonFunc }: AuthButton) => {
const AuthButton = ({
size,
variant,
text,
disabled,
buttonFunc
}: AuthButton) => {
return (
<SubmitButton
$size={size}
$variant={variant}
onClick={buttonFunc}
disabled={disabled}
>
{text}
</SubmitButton>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,70 +1,76 @@
import { ChangeEvent, useState } from 'react';
import styled from '@emotion/styled';
import { useFormContext } from 'react-hook-form';

import { AuthInputNormal } from '@/types/auth';
import { AuthInputNormal, AuthInputStyleProps } from '@/types/auth';
import closeIcon from '@assets/icons/ic-login-close.svg';
import checkInvalid from '@assets/icons/ic-signup-check-invalid.svg';
import checkValid from '@assets/icons/ic-signup-check-valid.svg';
import { getInputOptions } from '@utils/index';

const AuthInputNormal = ({
type,
id,
placeholder,
usedFor,
isInvalid
isError
}: AuthInputNormal) => {
const [text, setText] = useState<string>('');
const { register, watch, resetField, getFieldState, formState } =
useFormContext();
const inputValue = watch(id);
const handleReset = () => resetField(id);

const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
setText(event.target.value);
};

const handleReset = (event: React.MouseEvent<HTMLButtonElement>) => {
event.preventDefault();
setText('');
};

// TODO : react-hook-form 적용 후 유효성 검사 로직 예정
const isInputTouched = getFieldState(id, formState).isTouched;
const isValid = isInputTouched ? !isError : false;

return (
<Container>
<Container
$usedFor={usedFor}
$type={type}
>
<Input
type={type}
id={id}
placeholder={placeholder}
value={text}
onChange={handleChange}
$usedFor={usedFor}
$type={type}
{...register(id, getInputOptions(id))}
/>
<Buttons>
{usedFor === 'login' && text.length > 0 && (
<Button onClick={handleReset}>
{usedFor === 'login' && !!inputValue && (
<Button
type="button"
onClick={handleReset}
>
<Icon
src={closeIcon}
alt="지우기 버튼"
/>
</Button>
)}
{usedFor === 'signup' &&
(isInvalid ? <Icon src={checkInvalid} /> : <Icon src={checkValid} />)}
{usedFor === 'signup' && type !== 'email' && (
<Icon src={isValid ? checkValid : checkInvalid} />
)}
</Buttons>
</Container>
);
};

export default AuthInputNormal;

const Container = styled.div`
const Container = styled.div<AuthInputStyleProps>`
position: relative;

width: 524px;
width: ${props =>
props.$usedFor === 'signup' && props.$type === 'email' ? '358px' : '524px'};
height: 79px;

display: flex;
align-items: center;
`;

const Input = styled.input`
width: 524px;
const Input = styled.input<AuthInputStyleProps>`
width: ${props =>
props.$usedFor === 'signup' && props.$type === 'email' ? '358px' : '524px'};
height: 79px;

border-radius: 16px;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
import { ChangeEvent, useState } from 'react';
import { useState } from 'react';
import styled from '@emotion/styled';
import { useFormContext } from 'react-hook-form';

import { AuthInput } from '@/types/auth';
import eyeOn from '@assets/icons/ic-login-eye-on.svg';
import eyeOff from '@assets/icons/ic-login-eye-off.svg';
import closeIcon from '@assets/icons/ic-login-close.svg';
import checkInvalid from '@assets/icons/ic-signup-check-invalid.svg';
import checkValid from '@assets/icons/ic-signup-check-valid.svg';
import { getInputOptions } from '@utils/index';

const AuthInputPassword = ({
id,
placeholder,
usedFor,
isInvalid
isError
}: AuthInput) => {
const [text, setText] = useState<string>('');
const [showPW, setShowPW] = useState(false);
const { register, watch, resetField, getFieldState, formState } =
useFormContext();

const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
setText(event.target.value);
};
const inputValue = watch(id);
const handleReset = () => resetField(id);

const handleReset = (event: React.MouseEvent<HTMLButtonElement>) => {
event.preventDefault();
setText('');
};
const passwordValue = watch('user_password');
const isInputTouched = getFieldState(id, formState).isTouched;
const isValid = isInputTouched ? !isError : false;

const [showPW, setShowPW] = useState(false);

const handleShowPW = (event: React.MouseEvent<HTMLButtonElement>) => {
event.preventDefault();
Expand All @@ -37,28 +39,28 @@ const AuthInputPassword = ({
type={showPW ? 'text' : 'password'}
id={id}
placeholder={placeholder}
value={text}
onChange={handleChange}
{...register(id, getInputOptions(id, passwordValue))}
/>
<Buttons>
{text.length > 0 && (
{!!inputValue && (
<Button onClick={handleShowPW}>
<Icon
src={showPW ? eyeOn : eyeOff}
alt={showPW ? '비밀번호 보기 버튼' : '비밀번호 숨김 버튼'}
/>
</Button>
)}
{usedFor === 'login' && text.length > 0 && (
{usedFor === 'login' && !!inputValue && (
<Button onClick={handleReset}>
<Icon
src={closeIcon}
alt="지우기 버튼"
/>
</Button>
)}
{usedFor === 'signup' &&
(isInvalid ? <Icon src={checkInvalid} /> : <Icon src={checkValid} />)}
{usedFor === 'signup' && (
<Icon src={isValid ? checkValid : checkInvalid} />
)}
</Buttons>
</Container>
);
Expand Down
File renamed without changes.
Loading