@@ -5,14 +5,27 @@ import { VirtualFriend } from "@/types/virtualFreind";
55import trackClickEvent from "@/utils/trackClickEvent" ;
66
77interface ProfileProps {
8- info : VirtualFriend ;
9- deleteIndex : number ;
10- setVirtualFriendList : React . Dispatch < SetStateAction < VirtualFriend [ ] > > ;
8+ mode : "friend" | "topic" ;
9+ info ?: VirtualFriend ;
10+ deleteIndex ?: number ;
11+ setVirtualFriendList ?: React . Dispatch < SetStateAction < VirtualFriend [ ] > > ;
12+ topicData ?: {
13+ chatTitle : string ;
14+ description : string ;
15+ } ;
1116}
12- const Profile = ( { info, deleteIndex, setVirtualFriendList } : ProfileProps ) => {
17+ const Profile = ( {
18+ mode,
19+ info,
20+ deleteIndex,
21+ setVirtualFriendList,
22+ topicData
23+ } : ProfileProps ) => {
1324 const navigate = useNavigate ( ) ;
1425
1526 const handleDelete = async ( ) => {
27+ if ( ! info || ! setVirtualFriendList || deleteIndex === undefined ) return ;
28+
1629 trackClickEvent ( "홈" , "친구 - 삭제" ) ;
1730 const res = await authInstance . delete (
1831 `/api/virtual-friend/${ info . virtualFriendId } `
@@ -25,49 +38,104 @@ const Profile = ({ info, deleteIndex, setVirtualFriendList }: ProfileProps) => {
2538 } ;
2639
2740 const handleNavigate = ( ) => {
28- trackClickEvent ( "홈" , "친구 - 바로 대화하기" ) ;
29- navigate ( "/chat" , {
30- state : {
31- mode : "virtualFriend" ,
32- mbti : info . mbti ,
33- id : info . virtualFriendId ,
34- name : info . virtualFriendName
35- }
36- } ) ;
41+ if ( mode === "friend" && info ) {
42+ trackClickEvent ( "홈" , "친구 - 바로 대화하기" ) ;
43+ navigate ( "/chat" , {
44+ state : {
45+ mode : "virtualFriend" ,
46+ mbti : info . mbti ,
47+ id : info . virtualFriendId ,
48+ name : info . virtualFriendName
49+ }
50+ } ) ;
51+ } else if ( mode === "topic" && topicData ) {
52+ trackClickEvent ( "홈" , "주제별 대화방" ) ; //FIXME: 기획 내용 정해지면 수정
53+ navigate ( "/select-info" , {
54+ state : {
55+ type : "topicChat" ,
56+ chatTitle : topicData . chatTitle ,
57+ description : topicData . description
58+ }
59+ } ) ;
60+ }
61+ } ;
62+
63+ const getImageSrc = ( ) => {
64+ if ( mode === "friend" && info ) {
65+ return `/public/image/${ info . mbti } _profile.png` ;
66+ } else if ( mode === "topic" && topicData ) {
67+ //FIXME: 디자인 정해지면 수정
68+ return "/icon/starbubble.svg" ;
69+ }
70+ return "" ;
71+ } ;
72+
73+ const getTitle = ( ) => {
74+ if ( mode === "friend" && info ) {
75+ return info . virtualFriendName ;
76+ } else if ( mode === "topic" && topicData ) {
77+ return topicData . chatTitle ;
78+ }
79+ return "" ;
80+ } ;
81+
82+ const getSubtitle = ( ) => {
83+ if ( mode === "friend" && info ) {
84+ return info . mbti ;
85+ } else if ( mode === "topic" && topicData ) {
86+ return "" ;
87+ }
88+ return "" ;
89+ } ;
90+
91+ const getDescription = ( ) => {
92+ if ( mode === "friend" && info ) {
93+ return `${ info . virtualFriendAge } · ${ info . virtualFriendSex } · ${ info . virtualFriendRelationship } ` ;
94+ } else if ( mode === "topic" && topicData ) {
95+ return topicData . description ;
96+ }
97+ return "" ;
98+ } ;
99+
100+ const getButtonText = ( ) => {
101+ return mode === "friend" ? "바로 대화하기" : "오픈채팅 입장하기" ;
37102 } ;
38103
39104 return (
40105 < div className = "relative h-[192px] w-[157px] overflow-hidden rounded-[8px] border border-[#EEEEEE] bg-white lg:w-[200px]" >
41- < button onClick = { handleDelete } >
42- < img
43- src = "/icon/dustbin.svg"
44- alt = "Delete"
45- className = "absolute top-3 right-3 h-5 w-5 cursor-pointer"
46- width = { 16 }
47- height = { 16 }
48- />
49- </ button >
106+ { mode === "friend" && (
107+ < button onClick = { handleDelete } >
108+ < img
109+ src = "/public/icon/dustbin.svg"
110+ alt = "Delete"
111+ className = "absolute top-3 right-3 h-5 w-5 cursor-pointer"
112+ width = { 16 }
113+ height = { 16 }
114+ />
115+ </ button >
116+ ) }
50117 < img
51- src = { `/image/ ${ info . mbti } _profile.png` }
118+ src = { getImageSrc ( ) }
52119 alt = "Profile"
53120 className = "absolute top-[12px] left-[11px] h-12 w-12 rounded-full object-cover"
54121 />
55122
56123 < div className = "px-4 pt-[69px]" >
57124 < h2 className = "flex items-center space-x-1 text-base" >
58- < span className = "font-bold" > { info . virtualFriendName } </ span >
59- < span className = "font-light text-gray-600" > { info . mbti } </ span >
125+ < span className = "font-bold" > { getTitle ( ) } </ span >
126+ { getSubtitle ( ) && (
127+ < span className = "font-light text-gray-600" > { getSubtitle ( ) } </ span >
128+ ) }
60129 </ h2 >
61- < p className = "mt-2 text-xs font-light text-gray-600" >
62- { info . virtualFriendAge } · { info . virtualFriendSex } ·{ " " }
63- { info . virtualFriendRelationship }
130+ < p className = "mt-2 text-sm font-normal text-gray-600" >
131+ { getDescription ( ) }
64132 </ p >
65133 </ div >
66134 < button
67135 className = "absolute bottom-0 h-[41px] w-full bg-primary-pale py-2 text-sm font-bold text-primary-normal"
68136 onClick = { handleNavigate }
69137 >
70- 바로 대화하기
138+ { getButtonText ( ) }
71139 </ button >
72140 </ div >
73141 ) ;
0 commit comments