Skip to content

Commit

Permalink
Merge pull request #187 from Step3-kakao-tech-campus/feat/#180
Browse files Browse the repository at this point in the history
page 디렉토리 구조 통일
  • Loading branch information
JeonDoGyun authored Nov 10, 2023
2 parents e2f9765 + d66979c commit fcd6f80
Show file tree
Hide file tree
Showing 105 changed files with 699 additions and 647 deletions.
14 changes: 6 additions & 8 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import ValidateCheckLayout from 'layouts/ValidateCheckLayout';
import EditProfilePage from 'pages/editProfile/EditProfilePage';
import GNB from 'layouts/GNB';
import NotFound from 'pages/notFound/NotFound';
import ErrorBoundary from 'commons/ErrorBoundary';

const queryClient = new QueryClient({
defaultOptions: {
Expand All @@ -31,6 +30,7 @@ const router = createBrowserRouter([
children: [
{
element: <ValidateCheckLayout />,

children: [
{
path: '/',
Expand Down Expand Up @@ -96,13 +96,11 @@ const router = createBrowserRouter([

function App() {
return (
<ErrorBoundary>
<QueryClientProvider client={queryClient}>
<RecoilRoot>
<RouterProvider router={router} />;
</RecoilRoot>
</QueryClientProvider>
</ErrorBoundary>
<QueryClientProvider client={queryClient}>
<RecoilRoot>
<RouterProvider router={router} />
</RecoilRoot>
</QueryClientProvider>
);
}

Expand Down
35 changes: 23 additions & 12 deletions src/commons/apis/useGetFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,38 @@ import { useState } from 'react';

const useGetFetch = (url: string) => {
const [data, setData] = useState<Promise<any>>();
const [error, setError] = useState<Promise<Error>>();
const [getStatusCode, setErrorStatusCode] = useState<number>();
const [getLoading, setLoading] = useState<boolean>(false);

const getData = async () => {
setLoading(true);
const response = await fetch(url);
try {
setLoading(true);
const response = await fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});

if (!response.ok) {
setErrorStatusCode(response.status);
return;
}
if (!response.ok) {
setErrorStatusCode(response.status);
return;
}

const jsonData = await response.json();
setData(jsonData);
setLoading(false);
const jsonData = await response.json();
setData(jsonData);

// eslint-disable-next-line consistent-return
return jsonData;
// eslint-disable-next-line consistent-return
return jsonData;
} catch (err) {
setError(err as Promise<Error>);
} finally {
setLoading(false);
}
};

return { data, getStatusCode, getLoading, getData };
return { data, error, getStatusCode, getLoading, getData };
};

export default useGetFetch;
8 changes: 4 additions & 4 deletions src/commons/apis/usePostFetch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useState } from 'react';

const usePostFetch = (url: string, options: object) => {
const [data, setData] = useState();
const [data, setData] = useState<Promise<any>>();
const [error, setError] = useState<Promise<Error>>();
const [postStatusCode, setStatusCode] = useState<number>();
const [postloading, setLoading] = useState<boolean>(false);

Expand All @@ -14,17 +15,16 @@ const usePostFetch = (url: string, options: object) => {
setStatusCode(response.status);
return;
}

const jsonData = await response.json();
setData(jsonData);
} catch (err) {
console.error('Error: ', err);
setError(err as Promise<Error>);
} finally {
setLoading(false);
}
};

return { data, postStatusCode, postloading, postData };
return { data, error, postStatusCode, postloading, postData };
};

export default usePostFetch;
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/commons/Input.tsx → src/commons/components/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InputGroupProps } from 'commons/InputGroup';
import { InputGroupProps } from 'commons/components/InputGroup';

const Input = ({
id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import Container from 'commons/Container';
import Input from 'commons/Input';
import Container from 'commons/components/Container';
import Input from 'commons/components/Input';

export interface InputGroupProps
extends React.HTMLAttributes<HTMLInputElement> {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useNavigate } from 'react-router-dom';
import { useState } from 'react';
import { getCookie, removeToken, setCookie } from './cookie/cookie';
import { getCookie, removeToken } from '../cookie/cookie';

// 로그인 되었을 때 상태를 보여주는 SelectBox 제작
const UserDropdownBox = () => {
Expand All @@ -25,7 +25,6 @@ const UserDropdownBox = () => {
break;
case '로그아웃':
removeToken();
setCookie('accountInfo', 'Not Login');
window.location.reload();
break;
default:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { getCookie, removeToken, setCookie } from './cookie/cookie';
import { getCookie, removeToken } from '../cookie/cookie';

const UserToggleBox = () => {
const token = getCookie('loginToken');
Expand All @@ -16,14 +16,13 @@ const UserToggleBox = () => {
const handleOptionClick = (option: string) => {
switch (option) {
case 'My 정보 변경':
navigate(`/shelter/${id}/edit`); // 아직 회원정보 수정 페이지 구현 안됨
navigate(`/shelter/${id}/edit`);
break;
case 'My 보호소 이동':
navigate(`/shelter/${id}/1`);
break;
case '로그아웃':
removeToken();
setCookie('userAccountInfo', 'Not Login');
window.location.reload();
break;
default:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import PageButton from 'pages/profileList/PageButton';
import PageButton from 'pages/profileList/components/PageButton';

export function getPaginationItems(
currentPage: number,
Expand Down
3 changes: 2 additions & 1 deletion src/commons/cookie/cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ export const removeCookie = (name: string) => {

export const removeToken = () => {
removeCookie('loginToken');
removeCookie('userAccountInfo');
removeCookie('accountInfo');
removeCookie('loginState');
};
7 changes: 7 additions & 0 deletions src/commons/modals/AutoplayGuideModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react';

const AutoplayGuideModal = () => {
return <div></div>;
};

export default 'AutoplayGuideModal';
70 changes: 37 additions & 33 deletions src/commons/modals/LoginGuideModal.tsx
Original file line number Diff line number Diff line change
@@ -1,48 +1,52 @@
import { setCookie } from 'commons/cookie/cookie';
import { removeCookie, setCookie } from 'commons/cookie/cookie';
import { useNavigate } from 'react-router-dom';
import { useRecoilState, useRecoilValue } from 'recoil';
import { useRecoilState } from 'recoil';
import { tokenCheckState } from 'recoil/shelterState';

const LoginGuideModal = () => {
const navigate = useNavigate();
const [isLogined, setIsLogined] = useRecoilState(tokenCheckState); // default : true
const [isLogined, setIsLogined] = useRecoilState(tokenCheckState);
// default : true (로그인이 되지 않았을 때 사용하기 위해)

if (isLogined) {
return null;
}

return (
<dialog
className="fixed z-50 flex justify-center w-full h-[20vh] opacity-80 hover:opacity-100 bottom-2 rounded-lg border-2 border-gray-300 text-black"
open={isLogined}
>
<div className="modal-content w-[600px] flex flex-col gap-4 justify-center">
<div className="font-bold text-center text-lg">
<div>로그인이 만료되었습니다.</div>
<div>다시 로그인 하시겠습니까?</div>
<>
<dialog
className="fixed z-50 flex justify-center w-full h-[20vh] opacity-100 hover:opacity-100 bottom-2 rounded-lg border-2 border-gray-300 text-black"
open={!isLogined}
>
<div className="modal-content w-[600px] flex flex-col gap-4 justify-center">
<div className="font-bold text-center text-lg">
<div>로그인 정보가 만료되었습니다.</div>
<div>다시 로그인 하시겠습니까?</div>
</div>
<div className="flex justify-evenly font-bold ">
<button
className="border-brand-color text-brand-color border-2 rounded-md px-4 py-1 transition duration-300 hover:bg-brand-color hover:text-white "
onClick={() => {
navigate('/login');
removeCookie('loginState');
setIsLogined(true);
}}
>
로그인 하기
</button>
<button
className="bg-brand-color text-white rounded-md px-4 py-1 transition duration-300 hover:bg-white hover:text-brand-color"
onClick={() => {
setCookie('loginState', 'Not Login');
setIsLogined(true);
}}
>
로그아웃 유지하기
</button>
</div>
</div>
<div className="flex justify-evenly font-bold ">
<button
className="border-brand-color text-brand-color border-2 rounded-md px-4 py-1 transition duration-300 hover:bg-brand-color hover:text-white "
onClick={() => {
navigate('/login');
setIsLogined(true);
}}
>
로그인 하기
</button>
<button
className="bg-brand-color text-white rounded-md px-4 py-1 transition duration-300 hover:bg-white hover:text-brand-color"
onClick={() => {
setCookie('userAccountInfo', 'Not Login', { maxAge: 60000 * 30 }); // 30분
setIsLogined(true);
}}
>
로그아웃 유지하기
</button>
</div>
</div>
</dialog>
</dialog>
</>
);
};

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/layouts/VGNB.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import LogoButton from 'commons/LogoButton';
import UserToggleBox from 'commons/UserToggleBox';
import LogoButton from 'commons/components/LogoButton';
import UserToggleBox from 'commons/components/UserToggleBox';
import { Link } from 'react-router-dom';

export interface VGNBProps {
Expand Down
4 changes: 2 additions & 2 deletions src/layouts/VLargeGNB.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Link } from 'react-router-dom';
import LogoButton from 'commons/LogoButton';
import UserSelectBox from 'commons/UserDropdownBox';
import LogoButton from 'commons/components/LogoButton';
import UserSelectBox from 'commons/components/UserDropdownBox';

export interface VLargeGNBProps {
handleCategoryButtonClick: () => void;
Expand Down
19 changes: 9 additions & 10 deletions src/layouts/ValidateCheckLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import { getCookie } from 'commons/cookie/cookie';
import LoginGuideModal from 'commons/modals/LoginGuideModal';
import { useEffect } from 'react';
import { Outlet } from 'react-router-dom';
import { lazy, useEffect } from 'react';
import { Outlet, useLocation } from 'react-router-dom';
import { useSetRecoilState } from 'recoil';
import { tokenCheckState } from 'recoil/shelterState';

const LoginGuideModal = lazy(() => import('commons/modals/LoginGuideModal'));

const ValidateCheckLayout = () => {
const setIsLogined = useSetRecoilState(tokenCheckState);
const loginToken = getCookie('loginToken');
const userAccount = getCookie('userAccountInfo');
const loginState = getCookie('loginState');
const location = useLocation();

// userAccount에 대한 정책 수정이 필요
// Layout 먹이는 방식 수정
// 로그인 정보가 담긴 쿠키가 만료된 상태에서 사용자가 api 호출 관련 기능을 쓰기 전에 미리 알려주기
useEffect(() => {
if (!loginToken && userAccount === 'Login') {
// loginToken이 없으면 모달 열기
if (!loginToken && loginState === 'Login') {
setIsLogined(false);
}
console.log('token 로직 동작');
}, [loginToken, userAccount]);
}, [location]);

return (
<>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/detailPet/DetailPetPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import DetailPetData from 'pages/detailPet/DetailPetData';
import ErrorBoundary from 'commons/ErrorBoundary';
import DetailPetData from 'pages/detailPet/components/DetailPetData';
import ErrorBoundary from 'layouts/ErrorBoundary';

const DetailPetPage = () => {
return (
Expand Down
Loading

0 comments on commit fcd6f80

Please sign in to comment.