Skip to content

Commit

Permalink
refactor : page 서버컴포넌트 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
qkdl60 committed May 9, 2024
1 parent 436fcab commit 39cceb0
Showing 1 changed file with 19 additions and 137 deletions.
156 changes: 19 additions & 137 deletions src/app/plans/[planId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,142 +1,24 @@
'use client';

import { QUERY_KEY } from '@/constants';
import {
Button,
Icon,
KakaoShareButton,
ModalBasic,
Popover,
ReadOnlyPlan,
TooltipButton,
} from '@/components';
import classNames from 'classnames';
import Link from 'next/link';
import NotPublic from './_components/NotPublic/NotPublic';
import SearchingPlan from './_components/SearchingPlan/SearchingPlan';
import usePlanPage from './hooks/usePlanPage';
import './index.scss';

export default function PlanIdPage({ params }: { params: { planId: string } }) {
const {
plan,
planId,
isMyPlan,
isSearching,
isAccessible,
isEditable,
currentURL,
handleCopyLink,
handleDeletePlan,
} = usePlanPage(params.planId);
HydrationBoundary,
QueryClient,
dehydrate,
} from '@tanstack/react-query';
import { cookies } from 'next/headers';
import { getPlanServer } from '@apis/server/getPlanServer';
import PlanContent from './_components/PlanContent/PlanContent';

export default async function Page({ params }: { params: { planId: string } }) {
const queryClient = new QueryClient();
const { planId } = params;
const isLogin = !!cookies().get('auth');
await queryClient.prefetchQuery({
queryKey: [{ planId: Number(planId) }, QUERY_KEY.PLAN],
queryFn: () => getPlanServer(Number(planId), isLogin),
});
return (
<>
<div className={classNames('plans-page')}>
<div className="plans-page__main">
<div className="plans-page__breadcrumb font-size-base color-origin-text-100">
{isMyPlan ? (
<Link href="/home"></Link>
) : (
<Link href="/explore">둘러보기</Link>
)}
{'>'}
<span>계획</span>
</div>
<div className="plans-page__content">
{(() => {
if (isSearching) {
return <SearchingPlan />;
} else if (!isAccessible) {
return <NotPublic />;
} else {
return (
<ReadOnlyPlan isMine={isMyPlan} planData={{ ...plan }}>
{isEditable && (
<div className="plan__header--buttons">
<Link href={`/plans/edit/${planId}`}>수정</Link>|
<Popover.Main>
<Popover.Trigger>
<span>삭제</span>
</Popover.Trigger>
<Popover.ModalContent
renderModalContent={(onClickNo) => (
<ModalBasic
onClickYes={handleDeletePlan}
onClickNo={onClickNo}
confirmSentense="삭제 하기">
정말 해당 계획을 삭제하시겠습니까 ?
</ModalBasic>
)}
/>
</Popover.Main>
</div>
)}
</ReadOnlyPlan>
);
}
})()}
{isMyPlan && (
<div className="plans-page--share">
<h2>공유하기</h2>
<TooltipButton.Main optionsPosition="top">
<TooltipButton.Options>
<label className="font-size-xs" onClick={handleCopyLink}>
<Icon name="COPY" color="text-100" size="md" />
링크 복사
</label>
<label className="font-size-xs">
<KakaoShareButton linkURL={currentURL} />
카카오톡
</label>
</TooltipButton.Options>
<TooltipButton.Trigger>
<label>
<Icon name="SHARE" color="text-100" size="md" />
공유하기
</label>
</TooltipButton.Trigger>
</TooltipButton.Main>
{/*TODO 기존 공유버튼 삭제 예정 */}
{/* <div className="plans-page--share--buttons">
<label className="font-size-xs" onClick={handleCopyLink}>
<Icon name="COPY" color="text-100" size="md" />
링크 복사
</label>
<label className="font-size-xs">
<KakaoShareButton linkURL={currentURL} />
카카오톡
</label>
</div> */}
</div>
)}
</div>
</div>

{isMyPlan && (
<div className="plans-page__bottom">
<div className={classNames('plans-page__bottom--buttons')}>
<Link href={`/reminds/${planId}`}>
<Button
background="primary"
color="white-100"
size="lg"
border={false}>
리마인드 보기
</Button>
</Link>
<Link href={`/feedback/${planId}`}>
<Button
background="primary"
color="white-100"
size="lg"
border={false}>
피드백 보기
</Button>
</Link>
</div>
</div>
)}
</div>
</>
<HydrationBoundary state={dehydrate(queryClient)}>
<PlanContent />
</HydrationBoundary>
);
}

0 comments on commit 39cceb0

Please sign in to comment.