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

[4주차 기본/심화/생각 과제] 🍁 로그인/회원가입 #4

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
37d9593
Feat: inital setting
namdaeun Nov 14, 2023
85aa43f
Docs: add MyPage
namdaeun Nov 14, 2023
99fe6b4
Feat: add Router.jsx
namdaeun Nov 14, 2023
bd50156
Feat: 회원가입 API 연결 + 스타일 파일 생성
namdaeun Nov 15, 2023
866615a
Feat: 비밀번호 확인 & 회원가입 버튼 활성화하는 함수 생성
namdaeun Nov 16, 2023
b3cd281
Feat: 아이디 중복 확인
namdaeun Nov 16, 2023
cc2d4f3
Feat: useEffect 조건 수정
namdaeun Nov 16, 2023
e8b5a50
Feat: 회원가입 버튼 누르면 로그인 페이지로 이동
namdaeun Nov 16, 2023
b51a3ed
Design: 회원가입 스타일 적용
namdaeun Nov 16, 2023
6955067
Design: 전체 UI 스타일 적용
namdaeun Nov 16, 2023
4d73a2e
Feat: 입력하고 있는 도중에는 중복 확인 버튼 검정색
namdaeun Nov 16, 2023
8244f43
Feat: 회원가입 버튼 누르면 Signup으로 이동
namdaeun Nov 16, 2023
4fd831a
Feat: 로그인 버튼 누르면 정보 가져오고 mypage로 이동
namdaeun Nov 16, 2023
f6aa91b
Feat: 로그인 버튼 누르면 Login으로 이동
namdaeun Nov 16, 2023
e5f379f
Feat: 로그인 데이터 가져와서 화면에 띄우기
namdaeun Nov 16, 2023
0274977
Feat: 생각과제
namdaeun Nov 16, 2023
4c5e50a
Remove: Header 파일 제거
namdaeun Nov 17, 2023
d48d0a3
Feat: toast
namdaeun Nov 17, 2023
c7cae17
Feat: Toast 재구현
namdaeun Nov 17, 2023
b5c07f8
Docs: 빈 칸 제거
namdaeun Nov 17, 2023
f653d21
Feat: toast 아이디 위치에 토스트 문구 띄우도록 html 코드 추가
namdaeun Nov 17, 2023
2b0b510
Docs: Router만 불러오기
namdaeun Nov 17, 2023
a7a690a
Feat: 프로필 사진 띄우기
namdaeun Nov 17, 2023
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
13 changes: 13 additions & 0 deletions Week4/LoginAndSignup/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>로그인 & 회원가입</title>
</head>
<body>
<div id="root"></div>
<div id="toast"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
Empty file.
15 changes: 15 additions & 0 deletions Week4/LoginAndSignup/src/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Router from './components/Router';
import './App.css'
import { GlobalStyle } from './style/GlobalStyle';

function App() {

return (
<>
<GlobalStyle />
<Router />
</>
)
}

export default App
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions Week4/LoginAndSignup/src/components/Router.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { BrowserRouter, Routes, Route } from 'react-router-dom';
import SignUp from '../pages/SignUp/SignUp';
import Login from '../pages/Login/Login';
import MyPage from '../pages/MyPage/MyPage';

const Router = () => {
return (
<BrowserRouter>
<Routes>
<Route path='/signup' element={<SignUp />} />
<Route path='/login' element={<Login />} />
<Route path='/mypage/:userId' element={<MyPage />} />
</Routes>
</BrowserRouter>
);
};

export default Router;
32 changes: 32 additions & 0 deletions Week4/LoginAndSignup/src/components/Toast.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useEffect } from 'react';
import { createPortal } from 'react-dom';
import styled from 'styled-components';

const Toast = ({ error, setError, errMessage }) => {
useEffect(() => {
setTimeout(() => {
setError(false);
}, 2000);
}, [error]);

return createPortal(
<ToastWrapper>
<ToastMessage>{errMessage}</ToastMessage>
</ToastWrapper>, document.getElementById("toast")
);
};

export default Toast;

const ToastWrapper = styled.div`
background-color: var(--color-bg);
position: fixed;
bottom: 11rem;
right: 25rem;
padding: 0.6rem;
border-radius: 1rem;
`;

const ToastMessage = styled.div`
color: black;
`;
Empty file.
10 changes: 10 additions & 0 deletions Week4/LoginAndSignup/src/main.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.jsx'
import './index.css'

ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode>
<App />
</React.StrictMode>,
)
78 changes: 78 additions & 0 deletions Week4/LoginAndSignup/src/pages/Login/Login.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { useState } from 'react';
import * as S from './style';
import axios from "axios";
import Toast from '../../components/Toast';
import { useNavigate } from 'react-router-dom';

const Login = () => {
const [username, setUsername] = useState("");
const [password, setPassword] = useState("");
const [error, setError] = useState(false);
const [errMessage, setErrMessage] = useState("");
const navigate = useNavigate();
const saveUsername = (event) => {
setUsername(event.target.value);
};

const savePassword = (event) => {
setPassword(event.target.value);
};

const moveSignupPage = () => {
navigate(`/signup`);
};

const getData = async () => {
try {
const res = await axios.post(`${import.meta.env.VITE_BASE_URL}/api/v1/members/sign-in`, {
username: username,
password: password,
})
console.log("✨성공🤩✨");
console.log(`아이디 : ${res.data.username}`);
console.log(`비번 : ${res.data.password}`);
navigate(`/mypage/${res.data.id}`);
} catch (err) {
setError(true);
setErrMessage(err.response.data.message);
}
};

return (
<>
<S.Container>
<S.InputContainer>
<S.PageTitle>Login</S.PageTitle>
<S.Field className='id-field'>ID</S.Field>
<input
type="text"
size="25"
placeholder="아이디를 입력해주세요"
value={username}
onChange={saveUsername} />
<S.Field className='pw-field'>PASSWORD</S.Field>
<input
type="text"
size="25"
placeholder="비밀번호를 입력해주세요"
value={password}
onChange={savePassword} />
</S.InputContainer>
<S.ButtonContainer>
<S.Button type="button" onClick={getData}>로그인</S.Button>
<S.SignUpBtn type="button" onClick={moveSignupPage}>회원가입</S.SignUpBtn>
</S.ButtonContainer>
</S.Container>
{error ?
<Toast
error={error}
setError={setError}
errMessage={errMessage}
></Toast>
: null
}
</>
);
};

export default Login;
77 changes: 77 additions & 0 deletions Week4/LoginAndSignup/src/pages/Login/style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import styled from 'styled-components';

export const Container = styled.div`
width: 23rem;
height: 25rem;
background-color: var(--color-bg);
border-radius: 1rem;
display: inline-block;
flex-direction: column;
box-shadow: 12px 15px 63px -1px rgba(0,0,0,0.81);
-webkit-box-shadow: 12px 15px 63px -1px rgba(0,0,0,0.81);
-moz-box-shadow: 12px 15px 63px -1px rgba(0,0,0,0.81);
`;
Comment on lines +4 to +13
Copy link
Member

Choose a reason for hiding this comment

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

p4) shadow까지 넣어주고 세심하게 신경쓴게 보인다!! good~!


export const PageTitle = styled.h3`
text-align: center;
font-size: 1.5rem;
font-weight: bold;
padding: 2rem;
margin-bottom: 1rem;
color: var(--color-accent);
`;

export const InputContainer = styled.div`
line-height: 40px;
`;

export const ButtonContainer = styled.div`
display: block;
margin-left: 4rem;
margin-top: 3rem;
`;

export const Field = styled.div`
display: inline;
margin-right: 1.5rem;
margin-left: 2rem;
&.id-field {
margin-right: 6rem;
}
&.pwd-field {
margin-right: 3.5rem;
}
`;

export const Button = styled.button`
display: block;
width: 70%;
margin: 1rem;
padding: 0.4rem;
border-radius: 0.5rem;
font-weight: bold;
border: solid;
background-color: var(--color-button-bg);
color: var(--color-accent);
&:hover {
background-color: var(--color-accent);
color: var(--color-button-bg);
font-weight: bold;
}
`;

export const SignUpBtn = styled.button`
display: block;
width: 70%;
margin: 1rem;
padding: 0.4rem;
border-radius: 0.5rem;
font-weight: bold;
border: solid;
text-align: center;
&:hover {
background-color: #000000;
color: #FF1493;
font-weight: bold;
}
`;
48 changes: 48 additions & 0 deletions Week4/LoginAndSignup/src/pages/MyPage/MyPage.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { useNavigate, useParams } from 'react-router-dom';
import axios from "axios";
import * as S from './style';
import { useState } from 'react';
import profileImg from "../../assets/profile/profile.png";

const MyPage = () => {
const { userId } = useParams();
const navigate = useNavigate();
const [username, setUsername] = useState("");
const [nickname, setNickname] = useState("");

const moveLoginPage = () => {
navigate(`/login`);
};

const getLoginData = async () => {
try {
axios.get(`${import.meta.env.VITE_BASE_URL}/api/v1/members/${userId}`, {
userId: userId,
}).then((response) => {
setUsername(response.data.username);
setNickname(response.data.nickname);
console.log("✨🔥성공🔥✨");

Comment on lines +21 to +25
Copy link
Member

Choose a reason for hiding this comment

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

p4) then을 사용한 이유가 궁금해! try 에서는 성공하면 바로 변수에 담아서 set함수 사용가능하지 않나??

Copy link
Contributor Author

@namdaeun namdaeun Dec 21, 2023

Choose a reason for hiding this comment

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

get이 성공한 경우에만 set하도록 저렇게 적었어요!..흠 then을 사용하지 않으면 get에 성공한 값을 어떻게 불러올 수 있나요,,??

})
} catch (err) {
console.log(err);
}
};
getLoginData();

return (
<S.Container>
<S.PageTitle>MY PAGE</S.PageTitle>
<S.Profile src={profileImg} />
<S.TextArea>
ID : {username}
</S.TextArea>
<S.TextArea>
닉네임 : {nickname}
</S.TextArea>
<S.Button type="button" onClick={moveLoginPage}>로그아웃</S.Button>
</S.Container>
);
};

export default MyPage;
50 changes: 50 additions & 0 deletions Week4/LoginAndSignup/src/pages/MyPage/style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import styled from 'styled-components';

export const Container = styled.div`
width: 23rem;
height: 20rem;
line-height: 40px;
background-color: var(--color-bg);
border-radius: 1rem;
display: inline-block;
flex-direction: column;
-webkit-box-shadow: 0px 0px 17px 1px rgba(93,93,93,0.72);
box-shadow: 0px 0px 17px 1px rgba(93,93,93,0.72);
`;

export const PageTitle = styled.h3`
text-align: center;
font-size: 1.5rem;
padding: 2rem;
font-weight: bold;
padding-bottom: 0;
`;

export const TextArea = styled.div`
text-align: center;
background-color: var(--color-light-pink);
font-size: 1rem;
font-weight: bold;
padding: 0.2rem;
`;

export const Profile = styled.img`
width: 4rem;
height: auto;
margin-left: 9.5rem;
`;

export const Button = styled.button`
display: block;
width: 70%;
margin-left: 3.5rem;
margin-top: 1.5rem;
padding: 0.4rem;
border-radius: 0.5rem;
border: solid;
&:hover {
background-color: var(--color-button-bg);
color: var(--color-light-pink);
font-weight: bold;
}
`;
Loading