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

[#7] OAuth 회원가입, 로그인 UI 및 동작 #33

Merged
merged 7 commits into from
Aug 16, 2021
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
1 change: 1 addition & 0 deletions client/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SERVER_URL=
3 changes: 3 additions & 0 deletions client/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
module.exports = {
testEnvironment: 'jsdom',
moduleNameMapper: {
'.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2|svg)$': 'jest-transform-stub',
},
};
13 changes: 13 additions & 0 deletions client/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 client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"fork-ts-checker-webpack-plugin": "^6.3.2",
"html-webpack-plugin": "^5.3.2",
"jest": "^27.0.6",
"jest-transform-stub": "^2.0.0",
"prettier": "^2.3.2",
"typescript": "^4.3.5",
"webpack": "^5.50.0",
Expand Down
17 changes: 17 additions & 0 deletions client/src/components/login/Login.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import { render } from '@testing-library/react';
import Login from './Login';

describe('Login 컴포넌트', () => {
test('facebook 버튼 UI', () => {
const login = render(<Login />);

login.getByText('페이스북으로 로그인');
});

test('google 버튼 UI', () => {
const login = render(<Login />);

login.getByText('구글로 로그인');
});
});
69 changes: 69 additions & 0 deletions client/src/components/login/Login.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import React, { useCallback, useMemo } from 'react';
import styled from 'styled-components';
import OAuthButton from './OAuthButton';
import FACEBOOK from './facebook.svg';
import GOOGLE from './google.svg';

enum OAuthType {
Facebook,
Google,
}

const Header = styled.h1`
font-size: 24px;
font-weight: normal;
`;

const LoginContainer = styled.div`
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
`;

const OAuthButtonWrapper = styled.div`
margin-top: 20px;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
gap: 10px;
`;

const Login = (): JSX.Element => {
const handleOAuthButtonClick = useCallback((redirectURL: string) => {
return () => (location.href = redirectURL);
}, []);

const BUTTON_PROPS = useMemo(
Copy link
Collaborator

Choose a reason for hiding this comment

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

enum으로 처리되어서 이미 충분히 깔끔하지만 스타일 관련된 부분하고 아이콘은 컴포넌트 밖으로 빼도 되지 않을까 싶은데.. 잘 모르겠네요 ㅎㅎ

Copy link
Member Author

Choose a reason for hiding this comment

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

아 처음엔 밖으로 뺏는데 또 onClick 때문에 결국 밖에 하나 안에 하나 만들어야 되더라구요 ㅠㅜ 그래서 이렇게 한번 해봤는데 저도 헷갈려서 다른 분들은 어떤게 나을까요? 👀

Copy link
Collaborator

Choose a reason for hiding this comment

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

이 부분은 진짜 선택의 문제 같은 느낌이네요 .. 스타일 코드는 따로 다 빼놓고, handleOAuthButtonClick이 url을 받아서 작동하게 하면 될 것 같긴한데.. 잘모르겠습니다 진짜 .. ㅋㅋㅋ

() => ({
[OAuthType.Facebook]: {
backgroundColor: '#4267b2',
fontColor: '#ffffff',
icon: FACEBOOK,
content: '페이스북으로 로그인',
onClick: handleOAuthButtonClick(`${process.env.SERVER_URL}/auth/facebook-login`),
},
[OAuthType.Google]: {
backgroundColor: '#EA4335',
fontColor: '#ffffff',
icon: GOOGLE,
content: '구글로 로그인',
onClick: handleOAuthButtonClick(`${process.env.SERVER_URL}/auth/google-login`),
},
}),
[handleOAuthButtonClick]
);

return (
<LoginContainer>
<Header>회원 로그인</Header>
<OAuthButtonWrapper>
<OAuthButton {...BUTTON_PROPS[OAuthType.Facebook]} />
<OAuthButton {...BUTTON_PROPS[OAuthType.Google]} />
</OAuthButtonWrapper>
</LoginContainer>
);
};

export default Login;
55 changes: 55 additions & 0 deletions client/src/components/login/OAuthButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React, { MouseEventHandler } from 'react';
import styled from 'styled-components';

type ContainerProps = {
backgroundColor: string;
fontColor: string;
};

const OAuthButtonContainer = styled.button<ContainerProps>`
background-color: ${(props) => props.backgroundColor};
color: ${(props) => props.fontColor};
display: flex;
align-items: center;
justify-content: center;
gap: 15px;
height: 50px;
width: 300px;
padding: 15px;
border: none;
cursor: pointer;
`;

const OAuthIcon = styled.img`
max-width: 18px;
max-height: 100%;
`;

const OAuthButtonContent = styled.span`
font-size: 16px;
`;

type Props = {
backgroundColor: string;
fontColor: string;
icon: string;
content: string;
onClick: MouseEventHandler;
};

const OAuthButton = ({
icon,
fontColor,
backgroundColor,
content,
onClick,
}: Props): JSX.Element => {
return (
<OAuthButtonContainer fontColor={fontColor} backgroundColor={backgroundColor} onClick={onClick}>
<OAuthIcon src={icon} />
<OAuthButtonContent>{content}</OAuthButtonContent>
</OAuthButtonContainer>
);
};

export default OAuthButton;
43 changes: 43 additions & 0 deletions client/src/components/login/facebook.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions client/src/components/login/google.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions client/src/components/login/kakao.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion client/webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ module.exports = merge(common, {
mode: 'DEV',
},
}),
new EnvironmentPlugin([]),
new EnvironmentPlugin(['SERVER_URL']),
],
});