Skip to content

Commit

Permalink
feat: 설문이 있을 때 핸들링
Browse files Browse the repository at this point in the history
  • Loading branch information
hyesungoh committed Mar 20, 2024
1 parent 3a3b318 commit 678bbb6
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/pages/survey/base.page.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
import { useEffect } from 'react';
import { type NextPage } from 'next';
import Image from 'next/image';
import Link from 'next/link';
import { useRouter } from 'next/router';
import { css, type Theme } from '@emotion/react';

import BottomBar from '~/components/bottomBar/BottomBar';
import Button from '~/components/button/Button';
import FixedSpinner from '~/components/loading/FixedSpinner';
import LoadingHandler from '~/components/loading/LoadingHandler';
import useGetSurveyIdByUserStatus from '~/hooks/api/surveys/useGetSurveyIdByUserStatus';
import { HEAD_1 } from '~/styles/typo';

const SurveyBasePage: NextPage = () => {
const router = useRouter();
const { data, isLoading } = useGetSurveyIdByUserStatus();
const hasSurvey = Boolean(data?.survey_id);

useEffect(
function replaceWhenHasSurvey() {
if (isLoading) return;
if (hasSurvey) router.replace('/result');
},
[hasSurvey, isLoading, router],
);

return (
<>
<LoadingHandler isLoading={isLoading} fallback={<FixedSpinner />}>
<main css={mainCss}>
<h1 css={h1Css}>
질문 폼을 생성하고
Expand All @@ -27,7 +44,7 @@ const SurveyBasePage: NextPage = () => {
</main>

<BottomBar />
</>
</LoadingHandler>
);
};

Expand Down

0 comments on commit 678bbb6

Please sign in to comment.