Skip to content

Commit c6de79b

Browse files
committed
feat: 테스트 이력 및 로그인 여부에 따라 버튼, 모달 처리
1 parent 3b813f3 commit c6de79b

File tree

5 files changed

+72
-3
lines changed

5 files changed

+72
-3
lines changed

src/apis/auth/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const useGetKakaoLogin = () => {
1313
mutationFn: ({ code }: { code: string }) => getKakaoLogin(code),
1414
onSuccess: async (response) => {
1515
const userNickname = response.data.data.nickname;
16+
const hasType = response.data.data.hasType;
1617

1718
setCookie('userNickname', userNickname, {
1819
httpOnly: false,
@@ -22,6 +23,14 @@ export const useGetKakaoLogin = () => {
2223
maxAge: 1209600, // 14일
2324
});
2425

26+
setCookie('hasType', hasType, {
27+
httpOnly: false,
28+
secure: process.env.NODE_ENV === 'production',
29+
sameSite: 'lax',
30+
path: '/',
31+
maxAge: 1209600, // 14일
32+
});
33+
2534
// 비회원 상태에서 테스트 완료 후 로그인한 경우 테스트 결과 저장
2635
const type = sessionStorage.getItem('type') as TestType;
2736

@@ -48,6 +57,7 @@ export const usePostLogout = () => {
4857
onSuccess: () => {
4958
localStorage.clear();
5059
deleteCookie('userNickname');
60+
deleteCookie('hasType');
5161

5262
router.push('/');
5363
},
@@ -66,6 +76,7 @@ export const usePostWithdraw = () => {
6676
onSuccess: () => {
6777
localStorage.clear();
6878
deleteCookie('userNickname');
79+
deleteCookie('hasType');
6980
router.push('/');
7081
window.location.reload();
7182
},

src/apis/instance.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ instance.interceptors.response.use(
6868

6969
localStorage.clear();
7070
deleteCookie('userNickname');
71+
deleteCookie('hasType');
7172
console.error(error);
7273
alert(MESSAGES.EXPIRED);
7374
window.location.replace('/');

src/apis/test/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { postJbtiTest, postTestResult } from '@apis/test/axios';
22
import { TestType } from '@constants/test';
33
import { useMutation, useQueryClient } from '@tanstack/react-query';
4+
import { setCookie } from 'cookies-next';
45
import { useRouter } from 'next/navigation';
56

67
export const usePostTestResult = () => {
@@ -17,6 +18,14 @@ export const usePostTestResult = () => {
1718
return data;
1819
},
1920
onSuccess: (data) => {
21+
setCookie('hasType', true, {
22+
httpOnly: false,
23+
secure: process.env.NODE_ENV === 'production',
24+
sameSite: 'lax',
25+
path: '/',
26+
maxAge: 1209600,
27+
});
28+
2029
queryClient.setQueryData(['test-result'], data);
2130
router.push(`/test/result`);
2231
},
@@ -29,5 +38,14 @@ export const usePostTestResult = () => {
2938
export const useSaveTestResult = () => {
3039
return useMutation({
3140
mutationFn: (type: TestType) => postTestResult(type),
41+
onSuccess: () => {
42+
setCookie('hasType', true, {
43+
httpOnly: false,
44+
secure: process.env.NODE_ENV === 'production',
45+
sameSite: 'lax',
46+
path: '/',
47+
maxAge: 1209600,
48+
});
49+
},
3250
});
3351
};

src/app/test/page.tsx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,30 @@ import * as styles from './testPage.css';
1313
import { usePostTestResult } from '@apis/test';
1414
import { useRouter } from 'next/navigation';
1515
import TestHeader from '@components/test/testHeader/TestHeader';
16+
import { getCookie } from 'cookies-next';
17+
import ModalContainer from '@components/common/modal/ModalContainer';
1618

1719
const TestPage = () => {
1820
const router = useRouter();
1921
const [selections, setSelections] = useState<string[]>([]);
22+
const [isModalOpen, setIsModalOpen] = useState(false);
2023
const steps = ['START', ...TEST_STEPS.map((step) => step.id)];
24+
const hasType = getCookie('hasType');
2125

2226
const { Funnel, Step, nextStep, prevStep, currentStep } = useFunnel(steps);
2327
const progressStep = steps.indexOf(currentStep);
2428

2529
const { mutate, isPending, isSuccess } = usePostTestResult();
2630
const isLoading = isPending || isSuccess;
2731

32+
const handleStartClick = () => {
33+
if (hasType) {
34+
setIsModalOpen(true);
35+
} else {
36+
nextStep();
37+
}
38+
};
39+
2840
const handleSelect = (choice: string) => {
2941
const currentStepIndex = steps.indexOf(currentStep) - 1;
3042

@@ -72,7 +84,7 @@ const TestPage = () => {
7284
<Funnel steps={steps}>
7385
{[
7486
<Step key="START" name="START">
75-
<TestStart onClick={nextStep} />
87+
<TestStart onClick={handleStartClick} />
7688
</Step>,
7789

7890
...TEST_STEPS.map(({ id, title, option1, option2 }) => (
@@ -89,6 +101,21 @@ const TestPage = () => {
89101
</Funnel>
90102
</div>
91103
)}
104+
105+
{isModalOpen && (
106+
<ModalContainer
107+
modalTitle="성향테스트를 이미 받으셨어요!"
108+
modalBody="다시 받고싶으시다면 ‘다시하기’를 눌러주세요"
109+
isOpen={isModalOpen}
110+
handleClose={() => setIsModalOpen(false)}
111+
handleSubmit={() => {
112+
setIsModalOpen(false);
113+
nextStep();
114+
}}
115+
leftBtnLabel="뒤로가기"
116+
rightBtnLabel="다시하기"
117+
/>
118+
)}
92119
</div>
93120
);
94121
};

src/app/test/result/page.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ import { toPng } from 'html-to-image';
1616
import TestHeader from '@components/test/testHeader/TestHeader';
1717
import { useRouter } from 'next/navigation';
1818
import ExceptLayout from '@components/except/exceptLayout/ExceptLayout';
19+
import { getCookie } from 'cookies-next';
1920

2021
const ResultPage = () => {
2122
const cardRef = useRef<HTMLDivElement>(null);
2223
const router = useRouter();
2324
const queryClient = useQueryClient();
25+
const userNickname = getCookie('userNickname');
2426

2527
const resultData = queryClient.getQueryData<TestResponse>(['test-result']);
2628

@@ -95,8 +97,18 @@ https://www.gototemplestay.com/test`,
9597
</section>
9698

9799
<div className={styles.buttonSection}>
98-
<Bubble text="나에게 맞는 절을 계속 추천받을 수 있어요!" />
99-
<KakaoBtn page="TEST" type={resultData.code} />
100+
{userNickname ? (
101+
<PageBottomBtn
102+
btnText="3초만에 템플스테이 추천받기"
103+
size="large"
104+
onClick={() => router.push('/')}
105+
/>
106+
) : (
107+
<>
108+
<Bubble text="나에게 맞는 절을 계속 추천받을 수 있어요!" />
109+
<KakaoBtn page="TEST" type={resultData.code} />
110+
</>
111+
)}
100112
<PageBottomBtn btnText="친구에게 공유하기" size="large" onClick={handleShare} />
101113
</div>
102114
</div>

0 commit comments

Comments
 (0)