Skip to content

Commit 88ef5d1

Browse files
authored
Merge pull request #77 from cskime/feature/#52
[#52] API 연동(2)
2 parents 60b0960 + f24d073 commit 88ef5d1

23 files changed

+379
-127
lines changed

src/components/badge/badge-type.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const BADGE_TYPE = Object.freeze({
2-
acquaintance: "acquaintance",
3-
coworker: "coworker",
4-
family: "family",
5-
friend: "friend",
2+
지인: "지인",
3+
동료: "동료",
4+
가족: "가족",
5+
친구: "친구",
66
});
77

88
export default BADGE_TYPE;

src/components/badge/badge.jsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,24 @@ import Colors from "../color/colors";
33
import BADGE_TYPE from "./badge-type";
44

55
const styles = {
6-
[BADGE_TYPE.acquaintance]: {
6+
[BADGE_TYPE.지인]: {
77
backgroundColor: Colors.beige(100),
88
color: Colors.beige(500),
99
},
10-
[BADGE_TYPE.coworker]: {
10+
[BADGE_TYPE.동료]: {
1111
backgroundColor: Colors.purple(100),
1212
color: Colors.purple(600),
1313
},
14-
[BADGE_TYPE.family]: {
14+
[BADGE_TYPE.가족]: {
1515
backgroundColor: Colors.green(100),
1616
color: Colors.green(500),
1717
},
18-
[BADGE_TYPE.friend]: {
18+
[BADGE_TYPE.친구]: {
1919
backgroundColor: Colors.blue(100),
2020
color: Colors.blue(500),
2121
},
2222
};
2323

24-
const title = {
25-
[BADGE_TYPE.acquaintance]: "지인",
26-
[BADGE_TYPE.coworker]: "동료",
27-
[BADGE_TYPE.family]: "가족",
28-
[BADGE_TYPE.friend]: "친구",
29-
};
30-
3124
const StyledBadge = styled.div`
3225
background-color: ${({ $type }) => styles[$type].backgroundColor};
3326
color: ${({ $type }) => styles[$type].color};
@@ -39,7 +32,7 @@ const StyledBadge = styled.div`
3932
`;
4033

4134
function Badge({ type }) {
42-
return <StyledBadge $type={type}>{title[type]}</StyledBadge>;
35+
return <StyledBadge $type={type}>{type}</StyledBadge>;
4336
}
4437

4538
export default Badge;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import Colors from "./colors";
2+
3+
const BACKGROUND_COLOR = Object.freeze({
4+
beige: Colors.beige(200),
5+
purple: Colors.purple(200),
6+
blue: Colors.blue(200),
7+
green: Colors.green(200),
8+
});
9+
10+
export default BACKGROUND_COLOR;

src/components/option/background-select.jsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import { useEffect, useState } from "react";
12
import styled from "styled-components";
2-
import Colors from "../color/colors";
33
import CheckImage from "../../assets/ic-check.svg";
4-
import { useEffect, useState } from "react";
54
import { OutlinedButton } from "../button/button";
65
import BUTTON_SIZE from "../button/button-size";
6+
import BACKGROUND_COLOR from "../color/background-color";
7+
import Colors from "../color/colors";
78

89
const BackgroundWrapper = styled.div`
910
padding-top: 50px;
@@ -44,10 +45,10 @@ function BackgroundSelect({ type, selected, onSelect }) {
4445
const [imageUrls, setImageUrls] = useState([]);
4546

4647
const colorOptions = [
47-
{ color: Colors.beige(200) },
48-
{ color: Colors.purple(200) },
49-
{ color: Colors.blue(200) },
50-
{ color: Colors.green(200) },
48+
{ color: BACKGROUND_COLOR.beige },
49+
{ color: BACKGROUND_COLOR.purple },
50+
{ color: BACKGROUND_COLOR.blue },
51+
{ color: BACKGROUND_COLOR.green },
5152
];
5253

5354
/* useEffect(() => {

src/components/popover/popover.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function Popover({ id, alignment, action, children }) {
3737

3838
const handleClick = () => handleTargetClick(true);
3939
const handleBackdropClick = () => setShowsPopover(false);
40+
const handlePopoverClick = (event) => event.stopPropagation();
4041

4142
return (
4243
<>
@@ -46,7 +47,9 @@ function Popover({ id, alignment, action, children }) {
4647
{showsPopover && (
4748
<Portal id="popover">
4849
<Container onClick={handleBackdropClick}>
49-
<StyledPopover $position={position}>{children}</StyledPopover>
50+
<StyledPopover $position={position} onClick={handlePopoverClick}>
51+
{children}
52+
</StyledPopover>
5053
</Container>
5154
</Portal>
5255
)}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { apiClient } from "../../../api/client";
2+
3+
async function getMessages({ recipientId, limit, page = 1 }) {
4+
const searchParams = new URLSearchParams();
5+
searchParams.append("page", page);
6+
if (limit) {
7+
searchParams.append("limit", limit);
8+
}
9+
10+
const response = await apiClient.get(
11+
`recipients/${recipientId}/messages/?${searchParams.toString()}`
12+
);
13+
if (response.status !== 200) {
14+
throw new Error("Message data를 가져오는데 실패했습니다.");
15+
}
16+
17+
const data = response.data;
18+
return data.results;
19+
}
20+
21+
export { getMessages };

src/features/message/components/message-card-detail.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ function MessageCardDetail({ message }) {
4848
<StyledMessageCardDetail>
4949
<Header>
5050
<MessageSender
51-
profileImage={message.profileImage}
51+
profileImageUrl={message.profileImageURL}
52+
relationship={message.relationship}
5253
name={message.sender}
5354
/>
5455
<CreatedDate>{formatDate(message.createdAt, ".")}</CreatedDate>

src/features/message/components/message-card.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ function MessageCard({ isEditing, message, onDelete }) {
5757
<StyledMessageCard>
5858
<Header>
5959
<MessageSender
60-
profileImage={message.profileImage}
60+
profileImageUrl={message.profileImageURL}
61+
relationship={message.relationship}
6162
name={message.sender}
6263
/>
6364
{isEditing && (

src/features/message/components/message-sender.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ const StyledMessageSender = styled.div`
4242
gap: 14px;
4343
`;
4444

45-
function MessageSender({ profileImage, name }) {
45+
function MessageSender({ profileImageUrl, relationship, name }) {
4646
return (
4747
<StyledMessageSender>
48-
<Avatar source={profileImage} />
49-
<SenderInfo name={name} type={BADGE_TYPE.coworker} />
48+
<Avatar source={profileImageUrl} />
49+
<SenderInfo name={name} type={BADGE_TYPE[relationship]} />
5050
</StyledMessageSender>
5151
);
5252
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { apiClient } from "../../../api/client";
2+
3+
async function getReactions({ recipientId }) {
4+
const response = await apiClient.get(`recipients/${recipientId}/reactions/`);
5+
if (response.status !== 200) {
6+
throw new Error("Reactions data를 가져오는데 실패했습니다.");
7+
}
8+
9+
const data = response.data;
10+
return data.results;
11+
}
12+
13+
async function addReaction({ recipientId, emoji }) {
14+
const response = await apiClient.post(
15+
`recipients/${recipientId}/reactions/`,
16+
{
17+
emoji,
18+
type: "increase",
19+
}
20+
);
21+
if (response.status !== 201) {
22+
throw new Error("Reaction을 추가하는데 실패했습니다.");
23+
}
24+
25+
const data = response.data;
26+
return data;
27+
}
28+
29+
export { addReaction, getReactions };

0 commit comments

Comments
 (0)