Skip to content

Commit

Permalink
fix: InputField 컴포넌트 통합
Browse files Browse the repository at this point in the history
  • Loading branch information
wjsdncl committed Jun 14, 2024
1 parent 84e8289 commit fee9a91
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 62 deletions.
19 changes: 17 additions & 2 deletions src/components/Sign/InputField.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React from 'react';
import EyeOpenIcon from '../../assets/images/icon/ic_eye_open.svg';
import EyeCloseIcon from '../../assets/images/icon/ic_eye_close.svg';

interface InputFieldProps {
id: string;
Expand All @@ -7,7 +9,9 @@ interface InputFieldProps {
value: string;
placeholder: string;
error: string;
showPassword?: boolean;
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
togglePasswordVisibility?: () => void;
}

const InputField: React.FC<InputFieldProps> = ({
Expand All @@ -17,24 +21,35 @@ const InputField: React.FC<InputFieldProps> = ({
value,
placeholder,
error,
showPassword = false,
onChange,
togglePasswordVisibility,
}) => {
return (
<div>
<div className={`${id}_label`}>
<label htmlFor={id}>{label}</label>
</div>
<div>
<div className={`${id}_content`}>
<input
id={id}
className={`${id}_input ${error ? 'error_line' : ''}`}
type={type}
type={showPassword ? 'text' : type}
value={value}
name={id}
placeholder={placeholder}
onChange={onChange}
required
/>
{type === 'password' && togglePasswordVisibility && (
<button type='button' className='psw_chk_btn' onClick={togglePasswordVisibility}>
<img
className='psw_chk_img'
src={showPassword ? EyeOpenIcon : EyeCloseIcon}
alt='toggle password visibility'
/>
</button>
)}
{error && <span className={`error_msg ${id}_error_msg`}>{error}</span>}
</div>
</div>
Expand Down
55 changes: 0 additions & 55 deletions src/components/Sign/PasswordInputField.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions src/pages/SignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import './Sign.css';
import LogoImage from '../assets/images/title/title_img.svg';
import { validateEmail, validatePassword, errorMessages } from '../Utils/Validator';
import InputField from '../components/Sign/InputField';
import PasswordInputField from '../components/Sign/PasswordInputField';
import SocialSignIn from '../components/Sign/SocialSignIn';
import { PostSignIn } from '../api/Validator.api';
import { useNavigate } from 'react-router';
Expand Down Expand Up @@ -134,9 +133,10 @@ const SignIn: React.FC = () => {
error={errors.user_email}
onChange={handleInputChange}
/>
<PasswordInputField
<InputField
id='user_psw'
label='비밀번호'
type='password'
value={password}
placeholder='비밀번호를 입력해주세요'
error={errors.user_psw}
Expand Down
7 changes: 4 additions & 3 deletions src/pages/SignUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
validatePasswordMatch,
} from '../Utils/Validator';
import InputField from '../components/Sign/InputField';
import PasswordInputField from '../components/Sign/PasswordInputField';
import SocialSignIn from '../components/Sign/SocialSignIn';
import { PostSignUp } from '../api/Validator.api';
import { useNavigate } from 'react-router';
Expand Down Expand Up @@ -164,19 +163,21 @@ const SignUp: React.FC = () => {
error={errors.user_nickname}
onChange={handleInputChange}
/>
<PasswordInputField
<InputField
id='user_psw'
label='비밀번호'
type='password'
value={password}
placeholder='비밀번호를 입력해주세요'
error={errors.user_psw}
showPassword={showPassword}
onChange={handleInputChange}
togglePasswordVisibility={togglePasswordVisibilityHandler}
/>
<PasswordInputField
<InputField
id='user_psw_chk'
label='비밀번호 확인'
type='password'
value={passwordCheck}
placeholder='비밀번호를 다시 한 번 입력해주세요'
error={errors.user_psw_chk}
Expand Down

0 comments on commit fee9a91

Please sign in to comment.