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

[강성구] Sprint11 #309

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions .prettierrc.json
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
}
326 changes: 285 additions & 41 deletions package-lock.json

Large diffs are not rendered by default.

19 changes: 12 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@tanstack/react-query": "^5.52.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.52.2",
"react-router-dom": "^6.23.1",
"react-scripts": "5.0.1",
"styled-components": "^6.1.11",
"web-vitals": "^2.1.4"
},
"devDependencies": {
"@tanstack/eslint-plugin-query": "^5.52.0",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"@types/jest": "^29.5.12",
"@types/node": "^20.14.9",
"@types/react-dom": "^18.3.0",
"@types/react-router-dom": "^5.3.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.23.1",
"react-scripts": "5.0.1",
"styled-components": "^6.1.11",
"typescript": "^4.9.5",
"web-vitals": "^2.1.4"
"typescript": "^4.9.5"
},
"scripts": {
"start": "react-scripts start",
Expand Down
70 changes: 40 additions & 30 deletions src/components/auth/OAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,59 @@ import googleIcon from '../../core/assets/icons/sns/google/google.svg';
import styled from 'styled-components';

const OAuthLoginContainer = styled.div`
display: flex;
background-color: #e6f2ff;
border-radius: 0.8rem;
padding: 0.8rem 3.2rem ;
justify-content: space-between;
align-items: center;
display: flex;
background-color: #e6f2ff;
border-radius: 0.8rem;
padding: 0.8rem 3.2rem;
justify-content: space-between;
align-items: center;
`;

const OAuthIcons = styled.div`
display: flex;
align-items: center;
gap: 1.6rem;
display: flex;
align-items: center;
gap: 1.6rem;
`;

const OAuthIcon = styled.img`
cursor: pointer;
width: 4.4rem;
height: 4.4rem;
cursor: pointer;
width: 4.4rem;
height: 4.4rem;
`;

const ToggleSign = styled.div`
text-align: center;
text-align: center;
margin-bottom: 10rem;
`;

interface OAuthProps {
isLogin: boolean;
isLogin: boolean;
}

const OAuth = ({isLogin}:OAuthProps) => {
return (
<>
<OAuthLoginContainer>
<p>간편 로그인하기</p>
<OAuthIcons>
<a href="https://www.google.com/"><OAuthIcon src={googleIcon} alt="구글 아이콘"/></a>
<a href="https://www.kakaocorp.com/page/"><OAuthIcon src={kakaoIcon} alt="카카오 아이콘"/></a>
</OAuthIcons>
</OAuthLoginContainer>
<ToggleSign>
<p>{isLogin ? '판다마켓이 처음이신가요?' : '이미 회원이신가요?'} <Link to={isLogin?'/signUp':'/signIn'}>{isLogin?'회원가입':'로그인'}</Link></p>
</ToggleSign>
</>
);
}
const OAuth = ({ isLogin }: OAuthProps) => {
return (
<>
<OAuthLoginContainer>
<p>간편 로그인하기</p>
<OAuthIcons>
<a href="https://www.google.com/">
<OAuthIcon src={googleIcon} alt="구글 아이콘" />
</a>
<a href="https://www.kakaocorp.com/page/">
<OAuthIcon src={kakaoIcon} alt="카카오 아이콘" />
</a>
</OAuthIcons>
</OAuthLoginContainer>
<ToggleSign>
<p>
{isLogin ? '판다마켓이 처음이신가요?' : '이미 회원이신가요?'}{' '}
<Link to={isLogin ? '/signUp' : '/login'}>
{isLogin ? '회원가입' : '로그인'}
</Link>
Comment on lines +53 to +56
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이걸 컴포넌트로 만들어서 isLoginprops로 받으면 깔끔하겠네요 !

</p>
</ToggleSign>
</>
);
};

export default OAuth;
118 changes: 87 additions & 31 deletions src/components/auth/signIn/SignInForm.tsx
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;
Loading
Loading