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

[feat] 관리페이지 route수정 & API요청 hook 작성 #98

Merged
merged 4 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
15 changes: 9 additions & 6 deletions src/components/myPage/MyPageContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useLocation, useNavigate, Outlet } from 'react-router-dom';
const MyPageContainerLayout = () => {
const location = useLocation();
const navigate = useNavigate();
const managePage = location.pathname.startsWith('/my-page/my-created-travel/manage-my-travel/');

useEffect(() => {
if (location.pathname === '/my-page/') {
Expand All @@ -14,19 +15,21 @@ const MyPageContainerLayout = () => {
}, [location.pathname, navigate]);

return (
<div css={myPageLayout}>
<MyPageSideMenu />
<section>
<Outlet />
</section>
<div css={myPageLayout(managePage)}>
{managePage ? null : <MyPageSideMenu />}
<Outlet />
</div>
);
};

const myPageLayout = css`
const myPageLayout = (managePage: boolean) => css`
display: flex;
gap: 60px;
position: relative;
${managePage &&
`
display: block;
`}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

LGTM: myPageLayout 함수 개선, 가독성 개선 제안

myPageLayout 함수의 변경은 managePage 상태에 따라 동적으로 스타일을 조정할 수 있게 해주어 좋습니다. 이는 PR 목표에 부합하며 레이아웃의 유연성을 향상시킵니다.

가독성을 더욱 개선하기 위해, 조건부 스타일링을 다음과 같이 변경하는 것을 고려해보세요:

const myPageLayout = (managePage: boolean) => css`
  display: ${managePage ? 'block' : 'flex'};
  gap: 60px;
  position: relative;
`;

이렇게 하면 코드가 더 간결해지고 이해하기 쉬워질 것 같습니다.

`;

export default MyPageContainerLayout;
23 changes: 23 additions & 0 deletions src/hooks/useManageTravelData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useQuery } from '@tanstack/react-query';
import axios from 'axios';

interface useManageTravelDataPM {
travelId: string;
enabled: boolean;
}

const useManageTravelData = ({ travelId, enabled }: useManageTravelDataPM) => {
return useQuery({
queryKey: ['manageTravel', travelId],
queryFn: async () => {
try {
const res = await axios.get(`/api/v1/travels/manage-my-travel/${travelId}`);
return res.data;
} catch (error) {
console.error('관리할 여행 데이터 로드 실패:', error);
}
},
enabled,
});
};
export default useManageTravelData;
2 changes: 1 addition & 1 deletion src/layouts/Auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import useLoginStore from '@/stores/useLoginStore';
import * as Dialog from '@radix-ui/react-dialog';
import useModalStore from '@/stores/useModalStore';
import { X } from 'lucide-react';
import logo from 'src/assets/logo-black.png';
import logo from '/src/assets/logo-black.png';
import googleLogo from '/src/assets/google-icon.svg';
import kakaoLogo from '/src/assets/kakao-icon.svg';
import basicProfile from '/src/assets/basicProfile.png';
Expand Down
1 change: 1 addition & 0 deletions src/layouts/Breadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const breadcrumbsMap: { [key: string]: string } = {
'my-travel-list': '참여한 여행',
'my-account': '계정',
'my-created-travel': '내가 만든 여행',
'manage-my-travel': '내 여행 관리',
'my-travel': '내 여행',
'travel-detail': '여행 상세',
};
Expand Down
10 changes: 8 additions & 2 deletions src/pages/ManageMyTravel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,31 @@ import TravelTeam from '@/components/manageMyTravel/TravelTeam';
import TravelManageHeader from '@/components/manageMyTravel/TravelManageHeader';
import teamDataFilter from '@/utils/teamDataFilter';
import usePageStore from '@/stores/usePageStore';
import { useParams } from 'react-router-dom';

const ManageMyTravel = () => {
const [tab, setTab] = useState(true);
const setMultiPagination = usePageStore((state) => state.setMultiPagination);
const { travelId } = useParams();

useEffect(() => {
const filterData = teamDataFilter(data, tab ? 'ongoing' : 'completed');
setMultiPagination(filterData.length);
}, [tab]);

if (data.id !== travelId) {
return;
}
nakyeonko3 marked this conversation as resolved.
Show resolved Hide resolved

return (
<section css={{ color: '#333' }}>
<div css={{ color: '#333' }}>
<TravelManageHeader travelData={data} tab={tab} setTab={setTab} />
{tab ? (
<TravelTeam data={teamDataFilter(data, 'ongoing')} />
) : (
<TravelTeam data={teamDataFilter(data, 'completed')} />
)}
</section>
</div>
);
};

Expand Down
11 changes: 9 additions & 2 deletions src/pages/MyCreatedTravel.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import MyTravelContent from '@/components/myTravel/MyTravelContent';
import MyTravelTab from '@/components/myTravel/MyTravelTab';
import { useTabStore } from '@/stores/useTabStore';
import { Outlet } from 'react-router-dom';

const MyCreatedTravel = () => {
const { selectedTab } = useTabStore();
const managePage = location.pathname.startsWith('/my-page/my-created-travel/manage-my-travel/');

return (
<div>
<MyTravelTab />
{selectedTab === '내가 만든 여행' && <MyTravelContent />}
{managePage ? null : (
<>
<MyTravelTab />
{selectedTab === '내가 만든 여행' && <MyTravelContent />}
</>
)}
<Outlet />
</div>
);
};
Expand Down
10 changes: 6 additions & 4 deletions src/routes/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ const router = createBrowserRouter([
<MyCreatedTravel />
</div>
),
children: [
{
path: 'manage-my-travel/:travelId',
element: <ManageMyTravel />,
},
],
},
{
path: 'my-reviews',
Expand All @@ -93,10 +99,6 @@ const router = createBrowserRouter([
},
],
},
{
path: 'manage-my-travel',
element: <ManageMyTravel />,
},
{
path: 'add-travel',
element: <AddTravel />,
Expand Down