Skip to content

Commit

Permalink
Merge pull request #197 from Step3-kakao-tech-campus/feat/#165
Browse files Browse the repository at this point in the history
멘토링 내용 적용 - 에러캐칭, GNB 컨텐츠 노출 수정, meta og 속성 수정
  • Loading branch information
JeonDoGyun authored Nov 10, 2023
2 parents 8fe01b1 + 6d428cb commit 9540937
Show file tree
Hide file tree
Showing 17 changed files with 477 additions and 266 deletions.
5 changes: 4 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
/>
<meta property="og:title" content="ANIMORY" />
<meta property="og:type" content="website" />
<meta property="og:image" content="%PUBLIC_URL%/favicon.ico" />
<meta
property="og:image"
content="http://ec2-3-37-14-140.ap-northeast-2.compute.amazonaws.com/favicon.ico"
/>
<meta
property="og:description"
content="ANIMORY : 새로운 가족을 기다리는 유기동물을 연결해주는 입양 도움 서비스"
Expand Down
6 changes: 5 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
RouteObject,
RouterProvider,
} from 'react-router-dom';
import { Suspense } from 'react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import DetailPetPage from 'pages/detailPet/DetailPetPage';
import ProfileListPage from 'pages/profileList/profileListHome/ProfileListPage';
Expand All @@ -21,6 +22,7 @@ import GNB from 'layouts/GNB';
import NotFound from 'pages/notFound/NotFound';
import HomePage from 'pages/home/HomePage';
import UpdatePage from 'pages/update/UpdatePage';
import { ClipLoader } from 'react-spinners';

const queryClient = new QueryClient({
defaultOptions: {
Expand Down Expand Up @@ -113,7 +115,9 @@ function App() {
return (
<QueryClientProvider client={queryClient}>
<RecoilRoot>
<RouterProvider router={router} />
<Suspense fallback={<ClipLoader />}>
<RouterProvider router={router} />
</Suspense>
</RecoilRoot>
</QueryClientProvider>
);
Expand Down
2 changes: 1 addition & 1 deletion src/commons/apis/usePostFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useState } from 'react';
const usePostFetch = (url: string, options: object) => {
const [data, setData] = useState<Promise<any>>();
const [error, setError] = useState<Promise<Error>>();
const [postStatusCode, setStatusCode] = useState<number>();
const [postStatusCode, setStatusCode] = useState<number>(200);
const [postloading, setLoading] = useState<boolean>(false);

const postData = async () => {
Expand Down
27 changes: 27 additions & 0 deletions src/commons/modals/TextGuideModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
interface TextGuideModalProps {
open: boolean;
text: string;
onClose: () => void;
}

const TextGuideModal = ({ text, open, onClose }: TextGuideModalProps) => {
if (!open) {
return null;
}

return (
<dialog open={open} className="border-2 rounded-xl w-[300px] h-[250px]">
<div className="flex flex-col w-full h-full py-6 justify-around items-center">
<div className="font-bold text-xl">{text}</div>
<button
onClick={onClose}
className="text-white w-[100px] bg-brand-color px-4 py-1 rounded-lg"
>
확인
</button>
</div>
</dialog>
);
};

export default TextGuideModal;
4 changes: 2 additions & 2 deletions src/layouts/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ErrorBoundary extends Component<Props, State> {
<h2 className="text-2xl font-bold">{this.state.error.message}</h2>
<Link
to="/"
className="border flex items-center justify-center box-border border-brand-color border-2 bg-brand-color text-white rounded-md w-20 py-1 hover:bg-white hover:text-brand-color transition duration-300 ease-in-out"
className="flex items-center justify-center box-border border-brand-color border-2 bg-brand-color text-white rounded-md w-20 py-1 hover:bg-white hover:text-brand-color transition duration-300 ease-in-out"
>
홈으로
</Link>
Expand All @@ -64,7 +64,7 @@ class ErrorBoundary extends Component<Props, State> {
</h2>
<Link
to="/"
className="border flex items-center justify-center box-border border-brand-color border-2 bg-brand-color text-white rounded-md w-20 py-1 hover:bg-white hover:text-brand-color transition duration-300 ease-in-out"
className="flex items-center justify-center box-border border-brand-color border-2 bg-brand-color text-white rounded-md w-20 py-1 hover:bg-white hover:text-brand-color transition duration-300 ease-in-out"
>
홈으로
</Link>
Expand Down
21 changes: 13 additions & 8 deletions src/layouts/VGNB.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import LogoButton from 'commons/components/LogoButton';
import UserToggleBox from 'commons/components/UserToggleBox';
import { getCookie } from 'commons/cookie/cookie';
import { Link } from 'react-router-dom';

export interface VGNBProps {
Expand All @@ -21,6 +22,8 @@ const VGNB = (props: VGNBProps) => {
handleToggleClick,
} = props;

const token = getCookie('loginToken');

return (
<>
{/* 좁은 화면 */}
Expand Down Expand Up @@ -66,14 +69,16 @@ const VGNB = (props: VGNBProps) => {
>
<Link to="/find-shelter">내 주변 보호소 찾기</Link>
</li>
<li
className={`${
isRegisterPage ? 'text-brand-color' : ''
} border-b pb-4`}
onClick={handleToggleClick}
>
<Link to="/register">등록하기</Link>
</li>
{token && (
<li
className={`${
isRegisterPage ? 'text-brand-color' : ''
} border-b pb-4`}
onClick={handleToggleClick}
>
<Link to="/register">등록하기</Link>
</li>
)}
</ol>
</div>
</div>
Expand Down
22 changes: 13 additions & 9 deletions src/layouts/VLargeGNB.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Link } from 'react-router-dom';
import LogoButton from 'commons/components/LogoButton';
import UserSelectBox from 'commons/components/UserDropdownBox';
import { getCookie } from 'commons/cookie/cookie';

export interface VLargeGNBProps {
handleCategoryButtonClick: () => void;
Expand All @@ -16,6 +17,7 @@ const VLargeGNB = (props: VLargeGNBProps) => {
isFindShelterPage,
isRegisterPage,
} = props;
const token = getCookie('loginToken');

return (
<div className="lg:flex hidden w-full h-10 my-5 justify-center">
Expand Down Expand Up @@ -48,15 +50,17 @@ const VLargeGNB = (props: VLargeGNBProps) => {
>
<Link to="/find-shelter">내 주변 보호소 찾기</Link>
</li>
<li
className={`${
isRegisterPage
? 'text-brand-color'
: 'hover:text-brand-color hover:border-b-2 hover:border-brand-color'
}`}
>
<Link to="/register">등록하기</Link>
</li>
{token && (
<li
className={`${
isRegisterPage
? 'text-brand-color'
: 'hover:text-brand-color hover:border-b-2 hover:border-brand-color'
}`}
>
<Link to="/register">등록하기</Link>
</li>
)}
</ol>
<UserSelectBox />
</div>
Expand Down
71 changes: 7 additions & 64 deletions src/pages/editProfile/EditProfilePage.tsx
Original file line number Diff line number Diff line change
@@ -1,70 +1,13 @@
import { useMutation } from '@tanstack/react-query';
import { useParams } from 'react-router-dom';
import { useRecoilState } from 'recoil';
import { shelterSignupState } from 'recoil/shelterState';
import { getCookie } from 'commons/cookie/cookie';
import usePostFetch from 'commons/apis/usePostFetch';
import useGetFetch from 'commons/apis/useGetFetch';
import { useEffect } from 'react';
import VEditProfilePage from './VEditProfilePage';
import React from 'react';
import ErrorBoundary from 'layouts/ErrorBoundary';
import EditProfileTemplate from './components/EditProfileTemplate';

const EditProfilePage = () => {
const params = useParams();
const shelterId = params.id;
const token = getCookie('loginToken');
const [shelterInfo, setShelterInfo] = useRecoilState(shelterSignupState);

const { getStatusCode, getLoading, getData } = useGetFetch(
`${process.env.REACT_APP_URI}/shelter/${shelterId}?page=1`,
return (
<ErrorBoundary fallback={'Error...'}>
<EditProfileTemplate />
</ErrorBoundary>
);

const { postStatusCode, postloading, postData } = usePostFetch(
`${process.env.REACT_APP_URI}/shelter/${shelterId}`,
{
method: 'PUT',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},

body: JSON.stringify({
name: shelterInfo.name,
contact: shelterInfo.contact,
shelterAddressUpdateDto: shelterInfo.address,
}),
},
);

const mutation = useMutation(getData, {
onSuccess: (info) => {
setShelterInfo({
...shelterInfo,
name: info.response.shelter.name,
contact: info.response.shelter.contact,
address: {
...info.response.shelter.address,
},
});
},
});

const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
postData();
};

useEffect(() => {
mutation.mutate();
}, []);

const EditProfileProps = {
getLoading,
postloading,
handleSubmit,
shelterInfo,
};

return <VEditProfilePage {...EditProfileProps} />;
};

export default EditProfilePage;
115 changes: 115 additions & 0 deletions src/pages/editProfile/components/EditProfileTemplate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { useMutation } from '@tanstack/react-query';
import { useParams } from 'react-router-dom';
import { useRecoilState } from 'recoil';
import { shelterSignupState } from 'recoil/shelterState';
import { getCookie } from 'commons/cookie/cookie';
import usePostFetch from 'commons/apis/usePostFetch';
import useGetFetch from 'commons/apis/useGetFetch';
import { useEffect, useState } from 'react';
import VEditProfilePage from './VEditProfileTemplate';

const EditProfileTemplate = () => {
const params = useParams();
const shelterId = params.id;
const token = getCookie('loginToken');
const [shelterInfo, setShelterInfo] = useRecoilState(shelterSignupState);
const [modalOpen, setModalOpen] = useState<boolean>(false);
const [modalText, setModalText] = useState<string>('');

const { getStatusCode, getLoading, getData } = useGetFetch(
`${process.env.REACT_APP_URI}/shelter/${shelterId}?page=1`,
);

const { postStatusCode, postloading, postData } = usePostFetch(
`${process.env.REACT_APP_URI}/shelter/${shelterId}`,
{
method: 'PUT',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},

body: JSON.stringify({
name: shelterInfo.name,
contact: shelterInfo.contact,
shelterAddressUpdateDto: shelterInfo.address,
}),
},
);

const mutation = useMutation(getData, {
onSuccess: (info) => {
setShelterInfo({
...shelterInfo,
name: info.response.shelter.name,
contact: info.response.shelter.contact,
address: {
...info.response.shelter.address,
},
});
},
onError: () => {
if (getStatusCode === 404) {
setModalText('해당 보호소는 없는 보호소입니다.');
setModalOpen(true);
}
if (getStatusCode === 500) {
setModalText('서버에 오류가 발생했습니다.');
setModalOpen(true);
}
},
});

const getInputValue = (target: HTMLInputElement) => {
const inputKey = target.dataset.inputType as string;
setShelterInfo((prev) => ({ ...prev, [inputKey]: target.value }));
};

const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const target = event.target as HTMLInputElement;
getInputValue(target);
};

const handleModalClose = () => {
setModalOpen(false);
};

const handlePutStatusCode = (status: number) => {
if (status === 403) {
setModalText('타 보호소 정보 수정에 대한 접근 권한이 없습니다.');
setModalOpen(true);
}
if (status === 404) {
setModalText('존재하지 않는 보호소 계정입니다.');
setModalOpen(true);
}
if (status === 500) {
setModalText('서버에 오류가 발생했습니다.');
setModalOpen(true);
}
};

const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
postData();
handlePutStatusCode(postStatusCode);
};

useEffect(() => {
mutation.mutate();
}, []);

const EditProfileProps = {
getLoading,
postloading,
modalOpen,
modalText,
handleSubmit,
handleChange,
handleModalClose,
};

return <VEditProfilePage {...EditProfileProps} />;
};

export default EditProfileTemplate;
Loading

0 comments on commit 9540937

Please sign in to comment.