Skip to content

Commit 2e74fd4

Browse files
committed
내 연구결과 링크 추가
2 parents 2104fbe + b0b46ac commit 2e74fd4

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { useState } from 'react';
2+
import { css } from '@emotion/react';
3+
4+
import NewFeedbackBadge from '~/components/badge/NewFeedbackBadge';
5+
import InternalLink from '~/components/link/InternalLink';
6+
import useGetSurveyIdByUserStatus from '~/hooks/api/surveys/useGetSurveyIdByUserStatus';
7+
8+
// NOTE: ConditionalCtaLink와 동일, 임시 컴포넌트
9+
// bottom bar가 나오면 제거 예정
10+
const ConditionalSurveyLink = () => {
11+
const [isNotFound, setIsNotFound] = useState(false);
12+
13+
const { data, sessionStatus, isLoading } = useGetSurveyIdByUserStatus({
14+
onError: (error) => {
15+
if (error.code === 404) {
16+
setIsNotFound(true);
17+
}
18+
},
19+
});
20+
21+
if (sessionStatus === 'loading') return null;
22+
if (sessionStatus === 'unauthenticated') return <CreateQuestionFormLink />;
23+
24+
if (isLoading) return null;
25+
if (isNotFound) return <CreateQuestionFormLink />;
26+
27+
if (data) return <ResultLink surveyId={data.survey_id} />;
28+
29+
return <CreateQuestionFormLink />;
30+
};
31+
32+
export default ConditionalSurveyLink;
33+
34+
const CreateQuestionFormLink = () => {
35+
return (
36+
<InternalLink href="/survey" css={linkCss}>
37+
질문 폼 생성으로 시작하기
38+
</InternalLink>
39+
);
40+
};
41+
42+
interface ResultLinkProps {
43+
surveyId: string;
44+
}
45+
46+
const ResultLink = ({ surveyId }: ResultLinkProps) => {
47+
// const { data } = useGetFeedbackSummaryB?ySurveyId(surveyId);
48+
const data = {
49+
new_feedback_count: 10,
50+
};
51+
52+
return (
53+
<InternalLink href="/result" css={linkCss}>
54+
나의 연구 결과 보러가기
55+
{data && data.new_feedback_count > 0 && (
56+
<NewFeedbackBadge newFeedbackCount={data.new_feedback_count} css={badgeCss} />
57+
)}
58+
</InternalLink>
59+
);
60+
};
61+
62+
const linkCss = css`
63+
position: relative;
64+
65+
display: flex;
66+
gap: 4px;
67+
align-items: center;
68+
69+
width: 100%;
70+
71+
color: white;
72+
text-align: left;
73+
text-decoration: none;
74+
`;
75+
76+
const badgeCss = css`
77+
padding: 0 6px;
78+
font-size: 12px;
79+
`;

src/components/sideMenu/MenuSection.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useRouter } from 'next/router';
33
import { css } from '@emotion/react';
44

55
import BookmarkIcon from '~/components/icons/BookmarkIcon';
6+
import ConditionalSurveyLink from '~/components/sideMenu/ConditionalSurveyLink';
67
import useKakaoLogin from '~/hooks/auth/useKakaoLogin';
78

89
function MenuSection() {
@@ -79,6 +80,12 @@ function MenuSection() {
7980

8081
return null;
8182
})}
83+
<button type="button">
84+
<li css={menuItemCss}>
85+
<BookmarkIcon isBookmarked={false} width={20} height={20} color="#fff" />
86+
<ConditionalSurveyLink />
87+
</li>
88+
</button>
8289
</ul>
8390
</section>
8491
);
@@ -101,6 +108,7 @@ const menuItemCss = css`
101108
102109
padding: 8px 20px;
103110
111+
font-size: 16px;
104112
color: #fff;
105113
106114
span {

0 commit comments

Comments
 (0)