Skip to content

Commit bcbee7f

Browse files
committed
Merge branch 'dev' of https://github.com/MBTips/FE-MBTips into fix--GA-pageview-수정
2 parents 18f5eb7 + e49e27f commit bcbee7f

File tree

8 files changed

+150
-24
lines changed

8 files changed

+150
-24
lines changed

public/icon/error.svg

Lines changed: 4 additions & 0 deletions
Loading

src/App.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import MbtiTestQuestions from "@/pages/MbtiTestQuestions";
2020
import MbtiTestResult from "@/pages/MbtiTestResult";
2121
import CenteredLayout from "@/components/CenteredLayout";
2222
import { initGA, trackPageView } from "@/libs/analytics";
23+
import Error from "@/pages/Error";
2324

2425
const PageTracker = () => {
2526
const location = useLocation();
@@ -77,16 +78,23 @@ const App = () => {
7778
<Route path="/" element={<Home />} />
7879
<Route path="/select-info" element={<SelectInfo />} />
7980
<Route path="/chat" element={<Chat />} />
80-
<Route path="/chat-recommend" element={<ChatRecommend />} />
81-
<Route path="/chat-tips" element={<ChatTips />} />
82-
<Route path="/chat-temporature" element={<ChatTemporature />} />
81+
<Route
82+
path="/chat-recommend/:virtualFriendId"
83+
element={<ChatRecommend />}
84+
/>
85+
<Route path="/chat-tips/:virtualFriendId" element={<ChatTips />} />
86+
<Route
87+
path="/chat-temporature/:conversationId"
88+
element={<ChatTemporature />}
89+
/>
8390
<Route path="/contents/:id" element={<Content />} />
8491
<Route path="/login" element={<Login />} />
8592
<Route path="/my-info" element={<MyInfo />} />
8693
<Route path="/kakao-login" element={<KaKaoLogin />} />
8794
<Route path="/mbti-test" element={<MbtiTestIntro />} />
8895
<Route path="/mbti-test-progress" element={<MbtiTestQuestions />} />
8996
<Route path="/mbti-test-result" element={<MbtiTestResult />} />
97+
<Route path="*" element={<Error statusCode="500" />} />
9098
</Routes>
9199
</CenteredLayout>
92100
</Router>

src/components/Banner.tsx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useState, useEffect } from "react";
22
import { Link } from "react-router-dom";
33
import { cls } from "@/utils/cls";
44
import Indicator from "@/components/Indicator";
5+
import { trackEvent } from "@/libs/analytics";
56

67
interface BannerImage {
78
sm: string;
@@ -28,12 +29,14 @@ const bannerImages: BannerImage[] = [
2829
md: "/image/home_banner3_md.png",
2930
lg: "/image/home_banner3_lg.png",
3031
description: "MBTI별 피해야 할 대화스타일 및 주제"
31-
},
32+
}
3233
];
3334

3435
const Banner = () => {
3536
const [order, setOrder] = useState<number>(0);
3637

38+
const bannerEventElements = ["배너 1", "배너 2", "배너 3"];
39+
3740
useEffect(() => {
3841
const interval = setInterval(() => {
3942
setOrder((prev) => (prev + 1) % bannerImages.length);
@@ -43,18 +46,33 @@ const Banner = () => {
4346

4447
return (
4548
<div className="relative flex h-[184px] w-full">
46-
<Link to={order === 0 ? "/mbti-test" : `/contents/${order}`} className="absolute w-full h-full">
49+
<Link
50+
to={order === 0 ? "/mbti-test" : `/contents/${order}`}
51+
className="absolute h-full w-full"
52+
onClick={() => {
53+
if (bannerEventElements[order]) {
54+
trackEvent("Click", {
55+
page: "홈",
56+
element: bannerEventElements[order]
57+
});
58+
}
59+
}}
60+
>
4761
{bannerImages.map((image, index) => (
4862
<picture
4963
key={index}
5064
className={cls(
51-
"absolute transition-opacity duration-500 w-full h-full",
65+
"absolute h-full w-full transition-opacity duration-500",
5266
order === index ? "opacity-100" : "opacity-0"
5367
)}
5468
>
5569
<source media="(min-width: 500px)" srcSet={image.lg} />
5670
<source media="(min-width: 375px)" srcSet={image.md} />
57-
<img src={image.sm} alt={image.description} className="w-full h-full object-cover" />
71+
<img
72+
src={image.sm}
73+
alt={image.description}
74+
className="h-full w-full object-cover"
75+
/>
5876
</picture>
5977
))}
6078
</Link>

src/components/button/ChatStartButton.tsx

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,36 @@
11
import { useNavigate } from "react-router-dom";
2-
3-
const ChatStartButton = ({mode} : {mode: "go-fast" | "go-virtual" | "go-chat"}) => {
2+
import { trackEvent } from "@/libs/analytics";
3+
const ChatStartButton = ({
4+
mode
5+
}: {
6+
mode: "go-fast" | "go-virtual" | "go-chat";
7+
}) => {
48
const navigate = useNavigate();
59

610
const handleNavigate = () => {
7-
switch(mode) {
8-
case "go-fast" : navigate("/select-info", {state:"fastFriend"});
9-
break;
10-
case "go-virtual" : navigate("/select-info", {state:"virtualFriend"});
11-
break;
12-
case "go-chat" : navigate("/chat");
13-
break;
14-
default : console.error("mode is invalid", mode);
15-
return;
11+
switch (mode) {
12+
case "go-fast":
13+
trackEvent("Click", {
14+
page: "홈",
15+
element: "빠른 대화 시작"
16+
});
17+
navigate("/select-info", { state: "fastFriend" });
18+
break;
19+
case "go-virtual":
20+
trackEvent("Click", {
21+
page: "홈",
22+
element: "친구 - 바로 대화하기"
23+
});
24+
navigate("/select-info", { state: "virtualFriend" });
25+
break;
26+
case "go-chat":
27+
navigate("/chat");
28+
break;
29+
default:
30+
console.error("mode is invalid", mode);
31+
return;
1632
}
17-
}
33+
};
1834
return (
1935
<button
2036
className="flex h-[56px] w-[320px] items-center justify-center rounded-lg bg-primary-normal font-bold text-white md:w-[335px] lg:w-[460px]"

src/pages/Chat.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import ChatActionBar from "@/components/ChatActionBar";
66
import pickMbtiImage from "@/utils/pickMbtiImage";
77
import instance from "@/api/axios";
88
import { useLocation } from "react-router-dom";
9-
import { cls } from "@/utils/cls";
109
import TipsMenuContainer from "@/components/tips/TipsMenuContainer";
10+
import { trackEvent } from "@/libs/analytics";
1111

1212
interface Message {
1313
role: "user" | "assistant";
@@ -27,13 +27,24 @@ const Chat = () => {
2727
const [isOpen, setIsOpen] = useState(false);
2828
const bottomRef = useRef<HTMLDivElement | null>(null);
2929

30+
const chatTitle = `${mbti}와 대화`;
31+
const assistantInfo = mbti;
32+
const assistantImgUrl = pickMbtiImage(assistantInfo);
33+
3034
useEffect(() => {
3135
bottomRef.current?.scrollIntoView({ behavior: "smooth" });
3236
}, [messages, isOpen]);
3337

34-
const chatTitle = `${mbti}와 대화`;
35-
const assistantInfo = mbti;
36-
const assistantImgUrl = pickMbtiImage(assistantInfo);
38+
const handleToggleTips = () => {
39+
const nextAction = !isOpen;
40+
41+
trackEvent("Click", {
42+
page: "채팅방",
43+
element: nextAction ? "콘텐츠 열기" : "콘텐츠 닫기"
44+
});
45+
46+
setIsOpen(nextAction);
47+
};
3748

3849
const handleSend = async (messageToSend: string) => {
3950
if (!messageToSend.trim()) return;
@@ -127,7 +138,7 @@ const Chat = () => {
127138
</div>
128139
<ChatActionBar
129140
isOpen={isOpen}
130-
setIsOpen={setIsOpen}
141+
setIsOpen={handleToggleTips}
131142
value={input}
132143
onChange={handleChange}
133144
onKeyUp={handleKeyup}

src/pages/Error.tsx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import PrimaryButton from "@/components/button/PrimaryButton";
2+
import { useNavigate } from "react-router-dom";
3+
4+
const Error = ({ statusCode }: { statusCode: "401" | "404" | "500" }) => {
5+
const navigate = useNavigate();
6+
7+
const content = {
8+
401: {
9+
title: "세션이 만료되었습니다.",
10+
description: `활동이 없어 자동으로 로그아웃되었어요.\n채팅을 이어가려면 다시 로그인해 주세요.`,
11+
buttonTitle: "홈으로 가기",
12+
onClick: () => {
13+
navigate("/");
14+
}
15+
},
16+
404: {
17+
title: "페이지를 찾을 수 없습니다.",
18+
description: `입력하신 주소가 올바르지 않거나,\n요청하신 페이지가 삭제되었을 수 있습니다.`,
19+
buttonTitle: "홈으로 가기",
20+
onClick: () => {
21+
navigate("/");
22+
}
23+
},
24+
500: {
25+
title: "앗! 잠시 오류가 일어났어요",
26+
description: `일시적인 문제가 발생했습니다.\n잠시 후 다시 시도해 주세요.`,
27+
buttonTitle: "새로고침 버튼",
28+
onClick: () => {
29+
window.location.reload();
30+
}
31+
}
32+
};
33+
return (
34+
<main className="relative flex flex-col items-center bg-white">
35+
<div className="absolute bottom-[372px] flex h-[196px] flex-col items-center justify-between">
36+
<img src="/icon/error.svg" alt="에러 아이콘" width={63} height={63} />
37+
<h1 className="text-2xl font-bold ">{content[statusCode].title}</h1>
38+
<p className="text-center whitespace-pre-wrap text-gray-600">
39+
{content[statusCode].description}
40+
</p>
41+
</div>
42+
<div className="absolute bottom-[60px]">
43+
<PrimaryButton size="md" onClick={content[statusCode].onClick}>
44+
{content[statusCode].buttonTitle}
45+
</PrimaryButton>
46+
</div>
47+
</main>
48+
);
49+
};
50+
51+
export default Error;

src/pages/MyInfo.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import ActionConfirmModal from "@/components/modal/ActionConfirmModal";
44
import useAuthStore from "@/store/useAuthStore";
55
import { useNavigate } from "react-router-dom";
66
import TermsAndPrivacyModal from "@/components/modal/TermsAndPrivacyModal";
7+
import { trackEvent } from "@/libs/analytics";
78

89
type ModalType = "logout" | "withdraw" | "terms" | "privacy" | null;
910

@@ -33,9 +34,17 @@ const MyInfo = () => {
3334

3435
const handleConfirm = () => {
3536
if (modalType === "logout") {
37+
trackEvent("Click", {
38+
page: "내 정보",
39+
element: "로그아웃"
40+
});
3641
logout();
3742
navigate("/login");
3843
} else if (modalType === "withdraw") {
44+
trackEvent("Click", {
45+
page: "내 정보",
46+
element: "회원탈퇴"
47+
});
3948
console.log("회원탈퇴 실행"); //TODO: 회원탈퇴 기능 구현 시 추가 필요
4049
}
4150
setModalType(null);

src/pages/SelectInfo.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Header from "@/components/header/Header";
55
import { getMBTIgroup, mapAgeToNumber } from "@/utils/helpers";
66
import instance from "@/api/axios";
77
import ToastMessage from "@/components/ToastMessage";
8+
import { trackEvent } from "@/libs/analytics";
89

910
type FastFriendResponse = {
1011
header: {
@@ -182,6 +183,10 @@ const SelectInfo = () => {
182183
const responseData = response.data.data;
183184

184185
if (mode === "virtualFriend" && isVirtualFriendResponse(responseData)) {
186+
trackEvent("Click", {
187+
page: "친구 저장",
188+
element: "대화 시작하기"
189+
});
185190
navigate("/chat", {
186191
state: {
187192
mbti,
@@ -190,6 +195,10 @@ const SelectInfo = () => {
190195
}
191196
});
192197
} else if (mode === "fastFriend" && typeof responseData === "number") {
198+
trackEvent("Click", {
199+
page: "빠른 대화 설정",
200+
element: "대화 시작하기"
201+
});
193202
navigate("/chat", {
194203
state: {
195204
mbti,

0 commit comments

Comments
 (0)