Skip to content

Commit 48ceaef

Browse files
authored
Merge pull request #204 from Soohyuniii/feat/mbti-test-결과를-select-info에-반영
feat: mbti test 결과를 select info에 반영
2 parents 16f43af + 24f4856 commit 48ceaef

File tree

3 files changed

+94
-61
lines changed

3 files changed

+94
-61
lines changed

src/components/button/ChatStartButton.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { useNavigate } from "react-router-dom";
22
import { trackEvent } from "@/libs/analytics";
3-
const ChatStartButton = ({
4-
mode
5-
}: {
3+
4+
type ChatStartButtonProps = {
65
mode: "go-fast" | "go-virtual" | "go-chat";
7-
}) => {
6+
mbti?: string;
7+
};
8+
9+
const ChatStartButton = ({ mode, mbti }: ChatStartButtonProps) => {
810
const navigate = useNavigate();
911

1012
const handleNavigate = () => {
@@ -14,14 +16,14 @@ const ChatStartButton = ({
1416
page: "홈",
1517
element: "빠른 대화 시작"
1618
});
17-
navigate("/select-info", { state: "fastFriend" });
19+
navigate("/select-info", { state: { type: "fastFriend", mbti } });
1820
break;
1921
case "go-virtual":
2022
trackEvent("Click", {
2123
page: "홈",
2224
element: "친구 - 바로 대화하기"
2325
});
24-
navigate("/select-info", { state: "virtualFriend" });
26+
navigate("/select-info", { state: { type: "virtualFriend", mbti } });
2527
break;
2628
case "go-chat":
2729
navigate("/chat");

src/pages/MbtiTestResult.tsx

Lines changed: 59 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,51 +7,66 @@ import useLayoutSize from "@/hooks/useLayoutSize";
77
import Header from "@/components/header/Header";
88

99
const MbtiTestResult = () => {
10+
const mbti = localStorage.getItem("mbti-test-mbti") ?? "";
11+
const result = MBTI_RESULT_INFO[mbti as keyof typeof MBTI_RESULT_INFO];
12+
const size = useLayoutSize();
13+
const imageURL =
14+
size === "sm"
15+
? `/image/mbti-test/360px/image_${mbti?.toLocaleLowerCase()}_360.png`
16+
: size === "md"
17+
? `/image/mbti-test/375px/image_${mbti?.toLocaleLowerCase()}_375.png`
18+
: `/image/mbti-test/500px/image_${mbti?.toLocaleLowerCase()}_500.png`;
1019

11-
const mbti = localStorage.getItem("mbti-test-mbti");
12-
const result = MBTI_RESULT_INFO[mbti as keyof typeof MBTI_RESULT_INFO];
13-
const size = useLayoutSize();
14-
const imageURL = size === "sm" ? `/image/mbti-test/360px/image_${mbti?.toLocaleLowerCase()}_360.png` : (size === "md" ? `/image/mbti-test/375px/image_${mbti?.toLocaleLowerCase()}_375.png` : `/image/mbti-test/500px/image_${mbti?.toLocaleLowerCase()}_500.png`);
15-
console.log(imageURL);
16-
17-
const handleClick = (e: MouseEvent) => {
18-
e.preventDefault();
19-
}
20+
if (!result) return <div>404 error occured</div>;
2021

21-
if (!result) return <div>404 error occured</div>;
22-
23-
return (
24-
<div className="flex flex-col sm:w-[360px] md:w-[375px] lg:w-[500px] h-[1008px]">
25-
<Header title="결과" showShareIcon={false}/>
26-
<main className="flex flex-col flex-grow items-center w-full px-5 bg-white h-screen py-5">
27-
<img src={imageURL} alt="mbti 테스트 결과 이미지" className="sm:w-[320px] md:w-[335px] lg:w-[460px] h-[292px]"/>
28-
<h2 className="mt-6 font-bold text-2xl">{mbti?.toUpperCase()}는 이런 성향이에요!</h2>
29-
<ul className="flex gap-3 mt-4">
30-
<li style={{ backgroundColor: result.bgColor, color: result.textColor }} className="px-4 py-1 rounded-[40px] font-bold">{result.tag[0]}</li>
31-
<li style={{ backgroundColor: result.bgColor, color: result.textColor }} className="px-4 py-1 rounded-[40px] font-bold">{result.tag[1]}</li>
32-
</ul>
33-
<div className="flex flex-col bg-white mt-4 p-[28px] border-[#EDEDED] border-1 rounded-[20px]">
34-
<h3 className="font-bold text-lg">좋아하는 대화 주제</h3>
35-
<ul className="ml-5 list-disc">
36-
<li>{result.topic[0]}</li>
37-
<li>{result.topic[1]}</li>
38-
</ul>
39-
<h3 className="mt-6 font-bold text-lg">좋아하는 대화 태도</h3>
40-
<ul className="ml-5 list-disc">
41-
<li>{result.attitude[0]}</li>
42-
<li>{result.attitude[1]}</li>
43-
</ul>
44-
</div>
45-
<div className="mt-[22px] w-full">
46-
<ChatStartButton mode={"go-virtual"}/>
47-
</div>
48-
<div className="flex gap-4 mt-5 w-full">
49-
<RestartButton/>
50-
<ShareButton />
51-
</div>
52-
</main>
22+
return (
23+
<div className="flex h-[1008px] flex-col sm:w-[360px] md:w-[375px] lg:w-[500px]">
24+
<Header title="결과" showShareIcon={false} />
25+
<main className="flex h-screen w-full flex-grow flex-col items-center bg-white px-5 py-5">
26+
<img
27+
src={imageURL}
28+
alt="mbti 테스트 결과 이미지"
29+
className="h-[292px] sm:w-[320px] md:w-[335px] lg:w-[460px]"
30+
/>
31+
<h2 className="mt-6 text-2xl font-bold">
32+
{mbti?.toUpperCase()}는 이런 성향이에요!
33+
</h2>
34+
<ul className="mt-4 flex gap-3">
35+
<li
36+
style={{ backgroundColor: result.bgColor, color: result.textColor }}
37+
className="rounded-[40px] px-4 py-1 font-bold"
38+
>
39+
{result.tag[0]}
40+
</li>
41+
<li
42+
style={{ backgroundColor: result.bgColor, color: result.textColor }}
43+
className="rounded-[40px] px-4 py-1 font-bold"
44+
>
45+
{result.tag[1]}
46+
</li>
47+
</ul>
48+
<div className="mt-4 flex flex-col rounded-[20px] border-1 border-[#EDEDED] bg-white p-[28px]">
49+
<h3 className="text-lg font-bold">좋아하는 대화 주제</h3>
50+
<ul className="ml-5 list-disc">
51+
<li>{result.topic[0]}</li>
52+
<li>{result.topic[1]}</li>
53+
</ul>
54+
<h3 className="mt-6 text-lg font-bold">좋아하는 대화 태도</h3>
55+
<ul className="ml-5 list-disc">
56+
<li>{result.attitude[0]}</li>
57+
<li>{result.attitude[1]}</li>
58+
</ul>
59+
</div>
60+
<div className="mt-[22px] w-full">
61+
<ChatStartButton mode={"go-fast"} mbti={mbti} />
62+
</div>
63+
<div className="mt-5 flex w-full gap-4">
64+
<RestartButton />
65+
<ShareButton />
5366
</div>
54-
);
55-
}
67+
</main>
68+
</div>
69+
);
70+
};
5671

57-
export default MbtiTestResult;
72+
export default MbtiTestResult;

src/pages/SelectInfo.tsx

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChangeEvent, useState } from "react";
1+
import { ChangeEvent, useEffect, useState } from "react";
22
import { useLocation, useNavigate } from "react-router-dom";
33
import FormButton from "@/components/button/FormButton";
44
import Header from "@/components/header/Header";
@@ -42,15 +42,20 @@ function isVirtualFriendResponse(
4242
const SelectInfo = () => {
4343
const navigate = useNavigate();
4444
const location = useLocation();
45-
const mode = location.state; // mode: fastFriend, virtualFriend 두 종류 존재
46-
const isNameRequired = mode === "virtualFriend";
45+
const { type, mbti: testResultMBTI } = location.state; // type: fastFriend, virtualFriend 두 종류 존재
46+
const isNameRequired = type === "virtualFriend";
4747
const headerTitle =
48-
mode === "fastFriend" ? "상대방 정보선택" : "친구 저장하기";
48+
type === "fastFriend" ? "상대방 정보선택" : "친구 저장하기";
4949
const selectInfoTitle =
50-
mode === "fastFriend"
50+
type === "fastFriend"
5151
? `상대방의 MBTI를 선택하면\n대화를 시뮬레이션 해볼 수 있어요`
5252
: `친구의 MBTI를\n선택해주세요`;
5353

54+
const mbtiTestResult =
55+
typeof location.state === "object" && testResultMBTI !== null
56+
? testResultMBTI
57+
: undefined;
58+
5459
const [selectedMBTI, setSelectedMBTI] = useState<{
5560
[key: string]: string | null;
5661
}>({
@@ -66,6 +71,17 @@ const SelectInfo = () => {
6671
const [interest, setInterest] = useState<string[]>([]);
6772
const [toastMessage, setToastMessage] = useState<string | null>(null);
6873

74+
useEffect(() => {
75+
if (mbtiTestResult && mbtiTestResult.length === 4) {
76+
setSelectedMBTI({
77+
E: mbtiTestResult[0],
78+
N: mbtiTestResult[1],
79+
F: mbtiTestResult[2],
80+
P: mbtiTestResult[3]
81+
});
82+
}
83+
}, [mbtiTestResult]);
84+
6985
const mbtiOptions = ["E", "N", "F", "P", "I", "S", "T", "J"];
7086
const ageOptions = ["10대", "20대", "30대 이상"];
7187
const genderOptions = ["여자", "남자"];
@@ -158,7 +174,7 @@ const SelectInfo = () => {
158174
};
159175

160176
const selectedData =
161-
mode === "virtualFriend"
177+
type === "virtualFriend"
162178
? {
163179
...commonData,
164180
friendName: name,
@@ -173,7 +189,7 @@ const SelectInfo = () => {
173189
};
174190

175191
const apiUrl =
176-
mode === "virtualFriend" ? "api/virtual-friend" : "api/fast-friend";
192+
type === "virtualFriend" ? "api/virtual-friend" : "api/fast-friend";
177193

178194
try {
179195
const response = await instance.post<FriendResponse>(
@@ -182,27 +198,27 @@ const SelectInfo = () => {
182198
);
183199
const responseData = response.data.data;
184200

185-
if (mode === "virtualFriend" && isVirtualFriendResponse(responseData)) {
201+
if (type === "virtualFriend" && isVirtualFriendResponse(responseData)) {
186202
trackEvent("Click", {
187203
page: "친구 저장",
188204
element: "대화 시작하기"
189205
});
190206
navigate("/chat", {
191207
state: {
192208
mbti,
193-
mode,
209+
mode: type,
194210
id: responseData.conversationId
195211
}
196212
});
197-
} else if (mode === "fastFriend" && typeof responseData === "number") {
213+
} else if (type === "fastFriend" && typeof responseData === "number") {
198214
trackEvent("Click", {
199215
page: "빠른 대화 설정",
200216
element: "대화 시작하기"
201217
});
202218
navigate("/chat", {
203219
state: {
204220
mbti,
205-
mode,
221+
mode: type,
206222
id: responseData
207223
}
208224
});

0 commit comments

Comments
 (0)