-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from Step3-kakao-tech-campus/develop
[5주차] : 개발 사항 Merge(develop → master)
- Loading branch information
Showing
42 changed files
with
833 additions
and
42 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import axios from 'axios'; | ||
import Swal from 'sweetalert2'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
const navigate = useNavigate(); | ||
|
||
// 프론트에서 API를 활용하기 위한 기본 axios 인스턴스 | ||
const instance = axios.create({ | ||
baseURL: process.env.REACT_APP_API_URL, // production level 에서는 env에서 baseURL을 넣어주어야함(보안 관련) | ||
timeout: 1000, // 타임아웃이 없으면 무한정 wait가 걸려버릴 수 있음 | ||
headers: { | ||
'Content-Type': 'application/json', // 서버단에서 JSON 형태를 많이써서, 프론트단에서 쏴줄 때 이러한 형태로 많이 쓴다(헤더 기본 설정) | ||
}, | ||
}); | ||
|
||
// request - 요청 | ||
// 아래와 같이 설정해주면 axios 요청시 자동으로 header에 토큰을 넣어서 보내준다. | ||
// 백엔드에서 받아온 JWT Access Token을 request header에 담아서 보내주는 코드 | ||
instance.interceptors.request.use((config) => { | ||
const token = localStorage.getItem('accessToken'); | ||
if (token) { | ||
// eslint-disable-next-line no-param-reassign | ||
config.headers.Authorization = `${token}`; | ||
} | ||
return config; | ||
}); | ||
|
||
// response - 응답 | ||
// 백엔드로부터 오는 response를 중간에 처리해주는 미들웨어 역할 | ||
// 400번대 에러들에 대한 에러 핸들링 | ||
// 현재 Swal을 통해 보여주는 알림창의 내용 중 text에 해당하는 내용은 백엔드쪽에서 보내주는 내용에 따라 변경예정 | ||
instance.interceptors.response.use( | ||
(response) => { | ||
return response; | ||
}, | ||
(error) => { | ||
// 401 error : 인증되지 않음 - 로그인 화면으로 이동 | ||
// token은 백엔드에서 유효하지 않다면 401(Unauthorized) Http code를 보내주기에, 로그인하도록 처리 | ||
if (error.response.status === 401) { | ||
Swal.fire({ | ||
icon: 'error', | ||
title: '로그인을 진행해주세요!', | ||
text: error.response.data.error.message, | ||
confirmButtonText: '확인', | ||
}).then(() => { | ||
navigate('/login'); | ||
// window.location.href = '/login'; | ||
}); | ||
return Promise.reject(error); | ||
} | ||
|
||
// 404 error : 지정한 리소스를 찾을 수 없음 | ||
// 에러 메시지를 띄워주고 & 잘못된 경로로 이동 시 ErrorPage로 이동 | ||
if (error.response.status === 404) { | ||
Swal.fire({ | ||
icon: 'error', | ||
title: '아이쿠! 에러가 발생했네요😅', | ||
text: error.response.data.error.message, | ||
confirmButtonText: '확인', | ||
}).then(() => { | ||
navigate('/errorPage'); | ||
// window.location.href = '/errorPage'; | ||
}); | ||
return Promise.reject(error); | ||
} | ||
|
||
// 401, 404 외의 다른 error에 대한 처리 및 에러 메시지 확인 가능 | ||
Swal.fire({ | ||
icon: 'error', | ||
title: '내용을 다시 확인해 주세요!', | ||
text: error.response.data.error.message, | ||
confirmButtonText: '확인', | ||
}); | ||
// 성공인지 실패인지 여부에 따라 resolve, reject 처리 | ||
// response를 제대로 받아도 만약 특정 데이터가 없을때 에러로 처리하고 싶다면 reject 처리 | ||
return Promise.reject(error); | ||
}, | ||
); | ||
|
||
export default instance; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const Line = () => { | ||
return <hr className="h-0.5 w-[15rem] bg-gray-400 border-0" />; | ||
}; | ||
|
||
export default Line; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from 'react'; | ||
import { BsArrowLeft } from 'react-icons/bs'; | ||
import { MdHome } from 'react-icons/md'; | ||
import { Link, useNavigate } from 'react-router-dom'; | ||
|
||
const LoginNav = () => { | ||
const navigate = useNavigate(); | ||
const goPreviousPage = () => { | ||
navigate(-1); // 바로 이전 페이지로 이동 | ||
}; | ||
|
||
return ( | ||
<div> | ||
<div className="flex justify-between p-[25px] "> | ||
<BsArrowLeft className="cursor-pointer" onClick={goPreviousPage} size={25} /> | ||
<Link to="/"> | ||
<MdHome size={25} /> | ||
</Link> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default LoginNav; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { PiMinus } from 'react-icons/pi'; | ||
|
||
const MinusBtn = ({ className, onClick }) => { | ||
return <PiMinus onClick={onClick} className={`text-slate-400 cursor-pointer ${className}`} />; | ||
}; | ||
|
||
export default MinusBtn; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
import { BsArrowLeft } from 'react-icons/bs'; | ||
import { BiSolidUser } from 'react-icons/bi'; | ||
import { MdHome } from 'react-icons/md'; | ||
import { Link, useNavigate } from 'react-router-dom'; | ||
|
||
const OtherNav = ({ iconColor = '#000', bgColor = 'bg-[#FFF]' }) => { | ||
const navigate = useNavigate(); | ||
const goPreviousPage = () => { | ||
navigate(-1); // 바로 이전 페이지로 이동 | ||
}; | ||
|
||
return ( | ||
<div> | ||
<div className={`flex justify-between p-[25px] ${bgColor}`}> | ||
<BsArrowLeft className="cursor-pointer" onClick={goPreviousPage} size={25} color={iconColor} /> | ||
<div className="flex"> | ||
<Link className="mr-4" to="/"> | ||
<MdHome size={25} color={iconColor} /> | ||
</Link> | ||
<Link to="/mypage"> | ||
<BiSolidUser size={25} color={iconColor} /> | ||
</Link> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default OtherNav; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { BsPlusLg } from 'react-icons/bs'; | ||
|
||
const PlusBtn = ({ className, onClick }) => { | ||
return <BsPlusLg size={20} onClick={onClick} className={`text-slate-400 cursor-pointer ${className}`} />; | ||
}; | ||
|
||
export default PlusBtn; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const TextArea = ({ placeholder, id, ...inputProps }) => { | ||
return ( | ||
<textarea | ||
type="text" | ||
rows="3" | ||
id={id} | ||
className="w-[18rem] rounded-lg border-gray-300 border-2 px-5 py-2 text-sm block my-4" | ||
placeholder={placeholder} | ||
{...inputProps} | ||
/> | ||
); | ||
}; | ||
|
||
export default TextArea; |
Oops, something went wrong.