Skip to content

Commit 03bffb1

Browse files
committed
feat: 이미 공감한 글 alert 처리 추가
1 parent 311b479 commit 03bffb1

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

src/api/index.ts

+15-8
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import {
66
REACTION_TYPE,
77
ReactionsResponse,
88
} from "./response";
9+
import { isAxiosError } from "axios";
910

10-
interface Response<T> {
11+
export interface Response<T> {
1112
status: number;
1213
data: T;
1314
timestamp: Date;
@@ -46,14 +47,20 @@ export const postReactions = async (
4647
reactionType: keyof typeof REACTION_TYPE,
4748
boardId: number
4849
) => {
49-
const { data } = await client.post<Response<ReactionsResponse>>(
50-
`/reactions`,
51-
{
52-
reactionType,
53-
boardId,
50+
try {
51+
const { data } = await client.post<Response<ReactionsResponse>>(
52+
`/reactions`,
53+
{
54+
reactionType,
55+
boardId,
56+
}
57+
);
58+
return data;
59+
} catch (err) {
60+
if (isAxiosError(err)) {
61+
return err.response?.data;
5462
}
55-
);
56-
return data;
63+
}
5764
};
5865

5966
export const getRandomDaybooks = async () => {

src/components/DetailCardFooter.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import styled from "@emotion/styled";
22
import getFontStyle from "@theme/font/getFontSize";
33
import { colors } from "@theme";
4-
import { postReactions } from "@api";
4+
import { Response, postReactions } from "@api";
55
import { REACTION_TYPE, ReactionObject } from "@api/response";
66
import { getReactionCount } from "@utils/getReactionCount";
77

@@ -13,10 +13,12 @@ interface DetailCardFooterProps {
1313
const DetailCardFooter = ({ boardId, reactions }: DetailCardFooterProps) => {
1414

1515
const post = async (reactionType: keyof typeof REACTION_TYPE, id: number) => {
16-
const res = await postReactions(reactionType, id);
16+
const res = (await postReactions(reactionType, id)) as Response<unknown>;
1717
if (res.status === 409) {
18-
alert("이미 공감한 글입니다!")
18+
window.alert('이미 공감한 글입니다!')
19+
return;
1920
}
21+
window.location.reload();
2022
}
2123

2224
const { ADMIRE, GREAT, MOVING } = getReactionCount(reactions);

0 commit comments

Comments
 (0)