Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/apis/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/apis/myPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/apis/share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const getSharePostList = async (page: number = 1, size: number = 10) => {
};

// 공유 게시글 상세 조회
export const getSharePostDetail = async (sharePostId: number): Promise<SharePost> => {
export const getSharePostDetail = async (sharePostId: string): Promise<SharePost> => {
try {
const response = await client.get(`/api/share-posts/${sharePostId}`);
console.log(`🔥공유 게시글 상세 데이터`, response.data);
Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Admin/components/ReportHandlingModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function ReportHandlingModal({
);
};

const [reportRequest, setReportRequest] = useState<ReportRequest>({
const [reportRequest, setReportRequest] = useState<PatchReportRequest>({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

감사합니당 ㅎㅎ

status: 'RESOLVED',
adminMemo: '',
});
Expand Down
6 changes: 4 additions & 2 deletions src/pages/LetterBoard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ const LetterBoardPage = () => {
</>
{isLoading ? (
<p>loading</p>
) : (
) : postLists && postLists?.length > 0 ? (
<section className="mt-6 grid grid-cols-2 gap-x-5 gap-y-4">
{postLists.map((item, index) => {
{postLists?.map((item, index) => {
return (
<LetterPreview
key={index}
Expand All @@ -81,6 +81,8 @@ const LetterBoardPage = () => {
);
})}
</section>
) : (
<p className="body-m text-gray-60 mt-10 text-center">게시글이 없습니다.</p>
)}
</main>
<BackgroundBottom />
Expand Down
84 changes: 50 additions & 34 deletions src/pages/LetterBoardDetail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오잉 데이터가 어떻게 넘어오는진 모르겠지만 문자열을 split해서 배열로 만드시네용 백엔드분이 데이터를 보내주실때 그렇게 받아지는건가용?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아니면 params로 값을 출력하는 방식이 아니라 url path에서 아이디값을 저렇게 가져오고 계신건가용?
/:id 이런식으로 params 설정이 App.tsx에 라우팅 설정이 되어있으면 useParams훅이었나? 그걸로 해당하는 id값을 가져올 수 있을거 같습니다!

// const location = useLocation();
const navigate = useNavigate();
// const isShareLetterPreview = location.state?.isShareLetterPreview || false;
const isShareLetterPreview = false;
const [postDetail, setPostDetail] = useState<SharePost>();

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<SharePost>();
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 && <ReportModal onClose={() => setActiveReportModal(false)} />}
{activeReportModal && (
<ReportModal
reportType="POST"
letterId={parseInt(sharePostId)}
onClose={() => setActiveReportModal(false)}
/>
)}
<div className="grow bg-white">
<Header
likeCount={likeCount}
Expand Down
19 changes: 10 additions & 9 deletions src/pages/MyPage/components/MyBoardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useQuery } from '@tanstack/react-query';
import { useNavigate } from 'react-router';
import { twMerge } from 'tailwind-merge';

import { getMySharePostList } from '@/apis/mypage';
import { getMySharePostList } from '@/apis/myPage';
import BackgroundBottom from '@/components/BackgroundBottom';
import PageTitle from '@/components/PageTitle';

Expand All @@ -15,8 +15,8 @@ const MyBoardPage = () => {
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);
}
Expand All @@ -43,19 +43,20 @@ const MyBoardPage = () => {
<PageTitle className="mx-auto mb-11">내가 올린 게시물</PageTitle>
{isLoading ? (
<p>loading</p>
) : (
) : postLists && postLists?.length > 0 ? (
<section className="mt-6 grid grid-cols-2 gap-x-5 gap-y-4">
{postLists.map((item, index) => (
{postLists?.map((item, index) => (
<LetterPreview
key={index}
id={item.sharePostId}
to={item.writerZipCode}
from="12E21"
content="저희가 주고 받은 행운의 편지 저희가 주고 받은 행운의 편지 저희가 주고 받은 행운의 편지
저희가 주고 받은 행운의 편지"
to={item.receiverZipCode}
from={item.writerZipCode}
content={item.content}
/>
))}
</section>
) : (
<p className="body-m text-gray-60 text-center">게시글이 없습니다.</p>
)}
</main>
<BackgroundBottom />
Expand Down
2 changes: 1 addition & 1 deletion src/stores/myPageStore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { create } from 'zustand';

import { fetchMyPageInfo } from '@/apis/mypage';
import { fetchMyPageInfo } from '@/apis/myPage';

interface MyPageDataStore {
zipCode: string;
Expand Down