diff --git a/src/apis/client.ts b/src/apis/client.ts index df8b3b3..092d56f 100644 --- a/src/apis/client.ts +++ b/src/apis/client.ts @@ -45,10 +45,8 @@ let retry = false; client.interceptors.request.use( (config) => { - console.log('response again', config); - const accessToken = useAuthStore.getState().accessToken; - if (config.url !== '/auth/reissue' && accessToken) { + if (config.url !== '/api/reissue' && accessToken) { config.headers.Authorization = `Bearer ${accessToken}`; } return config; diff --git a/src/apis/myPage.ts b/src/apis/myPage.ts index 7d64cc9..638ebc1 100644 --- a/src/apis/myPage.ts +++ b/src/apis/myPage.ts @@ -12,7 +12,7 @@ export const fetchMyPageInfo = async () => { export const getMySharePostList = async () => { try { - const response = await client.get('/api/share-proposals/inbox'); + const response = await client.get('/api/share-posts/me'); if (!response) throw new Error('error while fetching my share post list'); return response.data; } catch (error) { diff --git a/src/apis/share.ts b/src/apis/share.ts index 767b97e..6b60bbf 100644 --- a/src/apis/share.ts +++ b/src/apis/share.ts @@ -53,7 +53,7 @@ export const getSharePostList = async (page: number = 1, size: number = 10) => { }; // 공유 게시글 상세 조회 -export const getSharePostDetail = async (sharePostId: number): Promise => { +export const getSharePostDetail = async (sharePostId: string): Promise => { try { const response = await client.get(`/api/share-posts/${sharePostId}`); console.log(`🔥공유 게시글 상세 데이터`, response.data); @@ -102,7 +102,7 @@ export const postShareProposalApproval = async ( }; // 편지 좋아요 추가, 취소 -export const postSharePostLike = async (sharePostId: number) => { +export const postSharePostLike = async (sharePostId: string) => { try { const response = await client.post(`/api/share-posts/${sharePostId}/likes`); if (!response) throw new Error('error while posting like'); @@ -114,7 +114,7 @@ export const postSharePostLike = async (sharePostId: number) => { }; // 편지 좋아요 갯수 -export const getSharePostLikeCount = async (sharePostId: number) => { +export const getSharePostLikeCount = async (sharePostId: string) => { try { const response = await client.get(`/api/share-posts/${sharePostId}/likes`); if (!response) throw new Error('error while fetching likes'); diff --git a/src/pages/Admin/components/ReportHandlingModal.tsx b/src/pages/Admin/components/ReportHandlingModal.tsx index bfe6562..b2c9f8b 100644 --- a/src/pages/Admin/components/ReportHandlingModal.tsx +++ b/src/pages/Admin/components/ReportHandlingModal.tsx @@ -21,7 +21,7 @@ export default function ReportHandlingModal({ ); }; - const [reportRequest, setReportRequest] = useState({ + const [reportRequest, setReportRequest] = useState({ status: 'RESOLVED', adminMemo: '', }); diff --git a/src/pages/LetterBoard/index.tsx b/src/pages/LetterBoard/index.tsx index 80d26a7..33a53d5 100644 --- a/src/pages/LetterBoard/index.tsx +++ b/src/pages/LetterBoard/index.tsx @@ -66,9 +66,9 @@ const LetterBoardPage = () => { {isLoading ? (

loading

- ) : ( + ) : postLists && postLists?.length > 0 ? (
- {postLists.map((item, index) => { + {postLists?.map((item, index) => { return ( { ); })}
+ ) : ( +

게시글이 없습니다.

)} diff --git a/src/pages/LetterBoardDetail/index.tsx b/src/pages/LetterBoardDetail/index.tsx index 3f8292d..f106647 100644 --- a/src/pages/LetterBoardDetail/index.tsx +++ b/src/pages/LetterBoardDetail/index.tsx @@ -25,69 +25,85 @@ const LetterBoardDetailPage = ({ confirmDisabled }: ShareLetterPreviewProps) => const [isLike, setIsLike] = useState(false); const isWriter = false; const [activeReportModal, setActiveReportModal] = useState(false); + const sharePostId: string = location.pathname.split('/')[3]; + // const location = useLocation(); + const navigate = useNavigate(); + // const isShareLetterPreview = location.state?.isShareLetterPreview || false; + const isShareLetterPreview = false; + const [postDetail, setPostDetail] = useState(); + + const postLike = async () => { + try { + const response = await postSharePostLike(sharePostId); + if (!response) throw new Error('error while fetching like count'); + console.log('✅ 편지 좋아요 추가됨:', response); + } catch (error) { + console.error('❌ 편지 좋아요 추가 중 에러가 발생했습니다', error); + throw new Error('편지 좋아요 추가 실패'); + } + }; const handleToggleLike = () => { setLikeCount((prev) => prev + (isLike ? -1 : 1)); setIsLike((prev) => !prev); + postLike(); }; - const location = useLocation(); - const navigate = useNavigate(); + const handleProposalApproval = async ( + action: 'approve' | 'reject', + shareProposalId: number = location.state?.postDetail?.sharePostId, + ) => { + try { + const result = await postShareProposalApproval(shareProposalId, action); + console.log(`✅ 편지 공유 ${action === 'approve' ? '수락' : '거절'}됨:`, result); - const isShareLetterPreview = location.state?.isShareLetterPreview || false; - const [postDetail, setPostDetail] = useState(); + navigate('/'); + } catch (error) { + console.error(error); + } + }; useEffect(() => { - const { sharePostId } = location.state.postDetail; - const fetchPostDetail = async (postId: number) => { + const fetchPostDetail = async (postId: string) => { try { - console.log('sharePostId:', postId); - const data = await getSharePostDetail(postId); - setPostDetail(data); } catch (error) { console.error('❌ 공유 게시글 상세 조회에 실패했습니다.', error); } }; - const fetchLikeCounts = async (postId: number) => { + const fetchLikeCounts = async (postId: string) => { try { const response = await getSharePostLikeCount(postId); if (!response) throw new Error('error while fetching like count'); - console.log(response); - setLikeCount(response.data.likeCount); + console.log('✅ 편지 좋아요 갯수:', response); + setLikeCount(response.likeCount); + setIsLike(response.liked); } catch (error) { console.error('❌ 편지 좋아요 갯수를 가져오는 중 에러가 발생했습니다', error); throw new Error('편지 좋아요 갯수 가져오기 실패'); } }; - if (location.state?.postDetail) { - fetchPostDetail(sharePostId); - fetchLikeCounts(sharePostId); - } else { - console.warn('postDetail not found in location.state'); - } - }, [location.state]); - - const handleProposalApproval = async ( - action: 'approve' | 'reject', - shareProposalId: number = location.state?.postDetail?.sharePostId, - ) => { - try { - const result = await postShareProposalApproval(shareProposalId, action); - console.log(`✅ 편지 공유 ${action === 'approve' ? '수락' : '거절'}됨:`, result); - - navigate('/'); - } catch (error) { - console.error(error); - } - }; + // if (location.state?.postDetail) { + fetchPostDetail(sharePostId); + fetchLikeCounts(sharePostId); + // } else { + // console.warn('postDetail not found in location.state'); + // } + // }, [location.state]); + }, []); return ( <> - {activeReportModal && setActiveReportModal(false)} />} + {activeReportModal && ( + setActiveReportModal(false)} + /> + )}
{ try { const response = await getMySharePostList(); if (!response) throw new Error('게시글 목록을 불러오는데 실패했습니다.'); - console.log(response); - return response.data; + console.log('myPostList', response); + return response.data as SharePost[]; } catch (e) { console.error(e); } @@ -43,19 +43,20 @@ const MyBoardPage = () => { 내가 올린 게시물 {isLoading ? (

loading

- ) : ( + ) : postLists && postLists?.length > 0 ? (
- {postLists.map((item, index) => ( + {postLists?.map((item, index) => ( ))}
+ ) : ( +

게시글이 없습니다.

)} diff --git a/src/stores/myPageStore.ts b/src/stores/myPageStore.ts index 61b34ac..59730d0 100644 --- a/src/stores/myPageStore.ts +++ b/src/stores/myPageStore.ts @@ -1,6 +1,6 @@ import { create } from 'zustand'; -import { fetchMyPageInfo } from '@/apis/mypage'; +import { fetchMyPageInfo } from '@/apis/myPage'; interface MyPageDataStore { zipCode: string;