Skip to content

Commit d9acd01

Browse files
committed
Merge
2 parents b209a63 + 357a635 commit d9acd01

20 files changed

Lines changed: 314 additions & 209 deletions

File tree

.github/workflows/prod_cicd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
echo "VITE_GOOGLE_CLIENT_ID=${{ secrets.VITE_GOOGLE_CLIENT_ID }}" >> .env
3737
echo "VITE_GOOGLE_CLIENT_SECRET=${{ secrets.VITE_GOOGLE_CLIENT_SECRET }}" >> .env
3838
39-
- run: yarn build-prod
39+
- run: yarn build
4040

4141
- name: deploy to s3
4242
uses: jakejarvis/s3-sync-action@master

src/assets/default/x.svg

Lines changed: 1 addition & 1 deletion
Loading

src/components/NavBar/styles.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const IconWrapper = styled.div`
4141
bottom: 0;
4242
color: white;
4343
text-align: center;
44-
font-family: 'Pretendard'
44+
font-family: 'Pretendard';
4545
font-size: 15px;
4646
font-style: normal;
4747
font-weight: 500;
@@ -108,7 +108,7 @@ export const SideNavBarButton = styled.label`
108108
height: 2.5rem;
109109
display: flex;
110110
justify-content: center;
111-
align-item: center;
111+
align-items: center;
112112
border-radius: 50%;
113113
padding: 0.6rem;
114114
background: white;

src/components/TopBar/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const TopBar: React.FC<TopBarProps> = ({
2828
>
2929
<img src={LeftButtonSrc || ''} alt="뒤로가기" />
3030
</LeftButton>
31-
<StyledTextLayout $textTheme={{ style: 'heading2-bold' }} color={theme.colors.black}>
31+
<StyledTextLayout $textTheme={{ style: 'body1-bold' }} color={theme.colors.black}>
3232
{text}
3333
</StyledTextLayout>
3434
<RightButton

src/components/TopBar/styles.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export const TopbarLayout = styled.header<TopbarLayoutProps>`
99
z-index: 1;
1010
background-color: white;
1111
width: 100%; /* 부모 너비에 맞춤 */
12-
height: 2.75rem;
1312
align-items: center;
1413
padding: 0.5rem 1.25rem;
1514
${({ $withBorder, theme }) =>

src/pages/AccountCancel/index.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import TopBar from '../../components/TopBar';
99
import back from '../../assets/arrow/left.svg';
1010

1111
import BottomButton from '../../components/BottomButton';
12-
import { patchUserWithdrawApi } from '../../apis/user'; // 새로운 API import
12+
import { patchUserWithdrawApi } from '../../apis/user';
1313

1414
const AccountCancel: React.FC = () => {
1515
const [isChecked, setIsChecked] = useState(false);
@@ -27,28 +27,22 @@ const AccountCancel: React.FC = () => {
2727
}
2828

2929
const storedUserId = Number(localStorage.getItem('my_id'));
30-
const token = localStorage.getItem('jwt_token');
30+
const token = localStorage.getItem('new_jwt_token');
3131

3232
if (!storedUserId || !token) {
33-
alert('로그인이 필요합니다. 로그인 페이지로 이동합니다.');
34-
navigate('/login');
3533
return;
3634
}
3735

3836
// API 요청
39-
const response = await patchUserWithdrawApi(storedUserId); // 새로운 API 호출
37+
const response = await patchUserWithdrawApi(storedUserId);
4038

4139
// 요청이 성공했는지 확인
4240
if (response.isSuccess) {
4341
// 성공 메시지 출력
4442
alert('계정이 성공적으로 삭제되었습니다.');
4543

4644
// 계정 삭제 시 localStorage에서 사용자 정보 제거
47-
localStorage.removeItem('my_id');
48-
localStorage.removeItem('jwt_token');
49-
50-
// 로그인 페이지로 리다이렉트
51-
navigate('/login');
45+
localStorage.clear();
5246
} else {
5347
// 요청 실패 시 오류 메시지 출력
5448
console.error('API Error:', response.code || '알 수 없는 오류가 발생했습니다.');

src/pages/AccountSetting/index.tsx

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,48 @@ import { StyledText } from '../../components/Text/StyledText';
88
import theme from '../../styles/theme';
99
import TopBar from '../../components/TopBar';
1010
import back from '../../assets/arrow/left.svg';
11-
import request, { BaseResponse } from '../../apis/core';
12-
import { UserProfileResponse } from '../ProfileEdit/dto';
1311
import imageBasic from '../../assets/default/defaultProfile.svg';
14-
import Loading from '../../components/Loading';
1512
import Profile_s from './../../assets/default/my-page.svg';
1613
import leave from '../../assets/default/leave.svg';
14+
import { getUserInfoApi } from '../../apis/user';
15+
import { UserInfoData } from '../../apis/user/dto';
16+
import Loading from '../../components/Loading';
1717

1818
const AccountSetting: React.FC = () => {
1919
const navigate = useNavigate();
2020
const [isLogoutModalOpen, setIsLogoutModalOpen] = useState(false);
21-
const [userProfile, setUserProfile] = useState<UserProfileResponse | null>(null);
21+
const [userProfile, setUserProfile] = useState<UserInfoData | null>(null);
22+
const [isLoading, setIsLoading] = useState<boolean>(true);
2223

24+
// 사용자 정보 가져오기
2325
useEffect(() => {
24-
const fetchUserProfile = async () => {
26+
const getUserInfo = async () => {
2527
try {
26-
const storedUserId = localStorage.getItem('id'); // 로그인된 사용자 ID 가져오기
27-
28+
const storedUserId = localStorage.getItem('my_id');
2829
if (!storedUserId) {
2930
console.error('User is not logged in');
3031
return;
3132
}
3233

33-
const response = await request.get<BaseResponse<UserProfileResponse>>(`/users/${storedUserId}`);
34-
setUserProfile(response.result);
34+
const userId = Number(storedUserId);
35+
const response = await getUserInfoApi(userId);
36+
setUserProfile(response.data);
3537
} catch (error) {
36-
console.error('Error fetching user profile:', error);
38+
console.error('Error fetching user info:', error);
39+
} finally {
40+
setIsLoading(false);
3741
}
3842
};
3943

40-
fetchUserProfile();
44+
getUserInfo();
4145
}, []);
4246

4347
const handleConfirmLogout = () => {
4448
// localStorage 비우기
4549
localStorage.clear();
4650
console.log('Logout confirmed');
4751
setIsLogoutModalOpen(false);
48-
// 로그인 페이지로 이동
52+
4953
navigate('/login');
5054
};
5155

@@ -62,8 +66,8 @@ const AccountSetting: React.FC = () => {
6266
navigate('/account-cancel');
6367
};
6468

65-
if (!userProfile) {
66-
return <Loading />; // 로딩 상태
69+
if (isLoading) {
70+
return <Loading />;
6771
}
6872

6973
return (
@@ -73,19 +77,19 @@ const AccountSetting: React.FC = () => {
7377

7478
<ProfilePicWrapper>
7579
<ProfilePic>
76-
<img src={userProfile.profilePictureUrl || imageBasic} alt="프로필 사진" />
80+
<img src={userProfile?.profilePictureUrl || imageBasic} alt="프로필 사진" />
7781
</ProfilePic>
7882
<Row>
7983
<Label>
8084
<StyledText $textTheme={{ style: 'body1-medium', lineHeight: 0 }} color={theme.colors.black}>
81-
{userProfile.nickname}
85+
{userProfile?.nickname}
8286
</StyledText>
8387
</Label>
8488
</Row>
8589
<Row>
8690
<Label>
8791
<StyledText $textTheme={{ style: 'body6-regular', lineHeight: 0 }} color={theme.colors.gray3}>
88-
이름 | {userProfile.email}
92+
{userProfile?.name} | {userProfile?.email}
8993
</StyledText>
9094
</Label>
9195
</Row>

src/pages/Chats/ChatRoom/index.tsx

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ import Block from '../../../assets/default/block.svg';
2727
import dayjs from 'dayjs';
2828
import 'dayjs/locale/ko';
2929
import { chatRoomMessagesData } from '../../../apis/chatting/dto';
30+
import { postUserBlockApi } from '../../../apis/user-block';
31+
import { PostUserBlockRequest } from '../../../apis/user-block/dto';
32+
import { handleError } from '../../../apis/util/handleError';
3033

3134
const ChatRoom: React.FC = () => {
3235
const [extendedMessages, setextendedMessages] = useState<ExtendedMessageDto[]>([]);
@@ -36,6 +39,7 @@ const ChatRoom: React.FC = () => {
3639
const [isLeaveModalOpen, setIsLeaveModalOpen] = useState(false);
3740
const [isBlockModalOpen, setIsBlockModalOpen] = useState(false);
3841
const [isStatusModalOpen, setIsStatusModalOpen] = useState(false);
42+
const [modalContent, setModalContent] = useState('');
3943

4044
const [isLoading, setIsLoading] = useState(true);
4145
const [isScroll, setIsScroll] = useState(false);
@@ -50,6 +54,53 @@ const ChatRoom: React.FC = () => {
5054
const nav = useNavigate();
5155
const socket = useSocket();
5256

57+
// 프로필 사진 클릭 시 프로필 페이지로 이동
58+
const handleUserClick = useCallback(() => {
59+
const opponentId = opponentInfo?.id ? opponentInfo.id : -1;
60+
if (opponentId === -1) {
61+
setModalContent('유저 정보를 찾을 수 없습니다.');
62+
setIsStatusModalOpen(true);
63+
} else {
64+
nav(`/users/${opponentId}`);
65+
}
66+
}, [opponentInfo, nav]);
67+
68+
// 유저 차단 api
69+
const postUserBlock = async () => {
70+
try {
71+
const data: PostUserBlockRequest = {
72+
fromUserId: userId,
73+
toUserId: opponentInfo?.id || -1,
74+
action: 'block',
75+
};
76+
const response = await postUserBlockApi(data);
77+
78+
if (response.isSuccess) {
79+
setModalContent('정상적으로 처리되었습니다.');
80+
nav('/chats');
81+
}
82+
} catch (error) {
83+
const errorMessage = handleError(error, 'user');
84+
setModalContent(errorMessage);
85+
} finally {
86+
setIsBlockModalOpen(false);
87+
setIsStatusModalOpen(true);
88+
}
89+
};
90+
91+
// 채팅방 나가기 api
92+
const leaveChatRoom = () => {
93+
if (socket) {
94+
const data = {
95+
chatRoomId: Number(chatRoomId),
96+
userId: userId,
97+
};
98+
socket.emit('leaveChatRoom', data);
99+
nav('/chats', { replace: true });
100+
}
101+
};
102+
103+
// 전체 메시지 조회
53104
const getChatRoomMessages = (data: chatRoomMessagesData[]) => {
54105
setAllMessages(data);
55106
if (data.length > messageLengthRef.current) {
@@ -58,6 +109,7 @@ const ChatRoom: React.FC = () => {
58109
setIsLoading(false);
59110
};
60111

112+
// 새 메시지 수신
61113
const getNewMessage = (data: chatRoomMessagesData) => {
62114
setAllMessages((prevMessages) => [...prevMessages, data]);
63115
setIsScroll((prev) => !prev);
@@ -66,10 +118,10 @@ const ChatRoom: React.FC = () => {
66118
useEffect(() => {
67119
if (socket) {
68120
// 채팅방 입장
69-
socket.emit('joinChatRoom', chatRoomId);
121+
socket.emit('joinChatRoom', { chatRoomId: Number(chatRoomId) });
70122

71123
// 전체 메시지 조회
72-
socket.emit('getChatRoomMessages', chatRoomId);
124+
socket.emit('getChatRoomMessages', { chatRoomId: Number(chatRoomId) });
73125
socket.on('chatRoomMessages', getChatRoomMessages);
74126

75127
// 최근 메시지 조회
@@ -140,7 +192,7 @@ const ChatRoom: React.FC = () => {
140192
isCloseButtonVisible: true,
141193
button: {
142194
content: '나가기',
143-
onClick: () => {},
195+
onClick: leaveChatRoom,
144196
},
145197
onClose: () => {
146198
setIsLeaveModalOpen(false);
@@ -152,15 +204,15 @@ const ChatRoom: React.FC = () => {
152204
isCloseButtonVisible: true,
153205
button: {
154206
content: '차단하기',
155-
onClick: () => {},
207+
onClick: postUserBlock,
156208
},
157209
onClose: () => {
158210
setIsBlockModalOpen(false);
159211
},
160212
};
161213

162214
const statusModalProps: ModalProps = {
163-
content: '사용자 정보가 없습니다',
215+
content: modalContent,
164216
onClose: () => {
165217
setIsStatusModalOpen(false);
166218
},
@@ -176,16 +228,6 @@ const ChatRoom: React.FC = () => {
176228
},
177229
};
178230

179-
// 프로필 사진 클릭 시 프로필 페이지로 이동
180-
const onClickProfile = useCallback(() => {
181-
const opponentId = opponentInfo?.id ? opponentInfo.id : -1;
182-
if (opponentId === -1) {
183-
setIsStatusModalOpen(true);
184-
} else {
185-
nav(`/users/${opponentId}`);
186-
}
187-
}, [opponentInfo, nav]);
188-
189231
return (
190232
<OODDFrame>
191233
{isLoading && <Loading />}
@@ -215,7 +257,7 @@ const ChatRoom: React.FC = () => {
215257
{message.sentMessage ? (
216258
<SentMessage {...message.sentMessage} />
217259
) : message.rcvdMessage ? (
218-
<RcvdMessage {...message.rcvdMessage} onClickProfile={onClickProfile} />
260+
<RcvdMessage {...message.rcvdMessage} onClickProfile={handleUserClick} />
219261
) : null}
220262
</div>
221263
);

src/pages/Chats/ChatRoomItem/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ const ChatRoomItem: React.FC<ChatRoomData> = ({ chatRoomId, otherUser, latestMes
4040

4141
return (
4242
<ChatRoomItemLayout onClick={onClickChatRoom}>
43-
<UserImage src={otherUser.profilePictureUrl || defaultProfile} alt="user" />
43+
<UserImage src={otherUser?.profilePictureUrl || defaultProfile} alt="user" />
4444
<LeftBox>
4545
<StyledText $textTheme={{ style: 'body2-medium' }} color="#1D1D1D">
46-
{otherUser.nickname || '알수없음'}
46+
{otherUser?.nickname || '알수없음'}
4747
</StyledText>
4848
<LatestMessage $textTheme={{ style: 'caption2-regular' }} color="#1D1D1D">
4949
{latestMessage.content}

src/pages/Chats/RecentChat/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const RecentChat: React.FC<RecentChatProps> = () => {
2727
};
2828

2929
if (socket) {
30-
socket.emit('getChatRooms', userId);
30+
socket.emit('getChatRooms', { userId: userId });
3131
socket.on('chatRoomList', getChatRooms);
3232
}
3333

0 commit comments

Comments
 (0)