|
1 | | -const Profile = () => { |
2 | | - return ( |
3 | | - <div className="w-[157px] h-[192px] bg-white rounded-[8px] overflow-hidden relative border border-[#EEEEEE]"> |
4 | | - <img |
5 | | - src="/public/icon/dustbin.svg" |
6 | | - alt="Delete" |
7 | | - className="absolute top-3 right-3 w-5 h-5 cursor-pointer" |
8 | | - width={16} |
9 | | - height={16} |
10 | | - /> |
| 1 | +import { SetStateAction } from "react"; |
| 2 | +import { useNavigate } from "react-router-dom"; |
| 3 | +import { authInstance } from "@/api/axios"; |
| 4 | +import { VirtualFriend } from "@/types/virtualFreind"; |
| 5 | + |
| 6 | +interface ProfileProps { |
| 7 | + info: VirtualFriend; |
| 8 | + deleteIndex: number; |
| 9 | + setVirtualFriendList: React.Dispatch<SetStateAction<VirtualFriend[]>>; |
| 10 | +} |
| 11 | +const Profile = ({ info, deleteIndex, setVirtualFriendList }: ProfileProps) => { |
| 12 | + const navigate = useNavigate(); |
| 13 | + |
| 14 | + const handleDelete = async () => { |
| 15 | + const res = await authInstance.delete( |
| 16 | + `/api/virtual-friend/${info.virtualFriendId}` |
| 17 | + ); |
| 18 | + if (res.status === 200) { |
| 19 | + setVirtualFriendList((prevList) => |
| 20 | + prevList.filter((_, index) => index !== deleteIndex) |
| 21 | + ); |
| 22 | + } |
| 23 | + }; |
11 | 24 |
|
| 25 | + const handleNavigate = () => { |
| 26 | + navigate("/chat", { |
| 27 | + state: { |
| 28 | + mode: "virtualFriend", |
| 29 | + mbti: info.mbti, |
| 30 | + id: info.virtualFriendId |
| 31 | + } |
| 32 | + }); |
| 33 | + }; |
| 34 | + |
| 35 | + return ( |
| 36 | + <div className="relative h-[192px] w-[157px] overflow-hidden rounded-[8px] border border-[#EEEEEE] bg-white lg:w-[200px]"> |
| 37 | + <button onClick={handleDelete}> |
| 38 | + <img |
| 39 | + src="/public/icon/dustbin.svg" |
| 40 | + alt="Delete" |
| 41 | + className="absolute top-3 right-3 h-5 w-5 cursor-pointer" |
| 42 | + width={16} |
| 43 | + height={16} |
| 44 | + /> |
| 45 | + </button> |
12 | 46 | <img |
13 | | - src="/public/image/ENTP.png" |
| 47 | + src={`/public/image/${info.mbti}_profile.png`} |
14 | 48 | alt="Profile" |
15 | | - className="absolute top-[12px] left-[11px] w-12 h-12 object-cover rounded-full" |
| 49 | + className="absolute top-[12px] left-[11px] h-12 w-12 rounded-full object-cover" |
16 | 50 | /> |
17 | 51 |
|
18 | | - <div className="pt-[69px] px-4"> |
19 | | - <h2 className="text-base flex items-center space-x-1"> |
20 | | - <span className="font-bold">김엠비</span> |
21 | | - <span className="font-light text-gray-600">ENTP</span> |
| 52 | + <div className="px-4 pt-[69px]"> |
| 53 | + <h2 className="flex items-center space-x-1 text-base"> |
| 54 | + <span className="font-bold">{info.virtualFriendName}</span> |
| 55 | + <span className="font-light text-gray-600">{info.mbti}</span> |
22 | 56 | </h2> |
23 | | - <p className="text-xs text-gray-600 mt-2 font-light"> |
24 | | - 20대 · 여자 · 직장동료 · 여행 · 사회생활 |
| 57 | + <p className="mt-2 text-xs font-light text-gray-600"> |
| 58 | + {info.virtualFriendAge} · {info.virtualFriendSex} ·{" "} |
| 59 | + {info.virtualFriendRelationship} |
25 | 60 | </p> |
26 | 61 | </div> |
27 | | - |
28 | | - <button className="w-full h-[41px] bg-primary-pale text-primary-normal font-bold py-2 text-sm absolute bottom-0"> |
| 62 | + <button |
| 63 | + className="absolute bottom-0 h-[41px] w-full bg-primary-pale py-2 text-sm font-bold text-primary-normal" |
| 64 | + onClick={handleNavigate} |
| 65 | + > |
29 | 66 | 바로 대화하기 |
30 | 67 | </button> |
31 | 68 | </div> |
|
0 commit comments