|
| 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 | +`; |
0 commit comments