diff --git a/src/App.tsx b/src/App.tsx index c8af9ff..5a958a3 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -26,6 +26,7 @@ import OnboardingPage from './pages/Onboarding'; import RandomLettersPage from './pages/RandomLetters'; import RollingPaperPage from './pages/RollingPaper'; import WritePage from './pages/Write'; +import ShareApprovalPage from './pages/Share'; const App = () => { useViewport(); @@ -56,6 +57,7 @@ const App = () => { } /> } /> + } /> }> } /> diff --git a/src/apis/share.ts b/src/apis/share.ts index 15c97d2..37a3087 100644 --- a/src/apis/share.ts +++ b/src/apis/share.ts @@ -39,8 +39,26 @@ export interface ShareProposal { status: 'REJECTED' | 'APPROVED' | 'PENDING'; } +//편지 공유 요청 상세 조회 +export interface ShareProposalLetter { + id: number; + content: string; + writerZipCode: string; + receiverZipCode: string; + createdAt: string; +} + +export interface ShareProposalDetail { + shareProposalId: number; + requesterZipCode: string; + recipientZipCode: string; + message: string; + status: 'PENDING' | 'ACCEPTED' | 'REJECTED'; + letters: ShareProposalLetter[]; +} + // 편지 공유 수락 / 거절 -export interface SharePostApproval { +export interface ShareProposalApproval { shareProposalId: number; status: 'APPROVED' | 'REJECTED'; sharePostId: number; @@ -106,13 +124,27 @@ export const getShareProposalList = async () => { } }; +// 편지 공유 요청 상세 조회 +export const getShareProposalDetail = async ( + shareProposalId: number, +): Promise => { + try { + const response = await client.get(`/api/share-proposals/${shareProposalId}`); + console.log(`😎공유 요청 상세 조회 데이터 `, response.data); + return response.data.data; + } catch (error) { + console.error('❌ 편지 공유 요청을 상세 조회하던 중 에러가 발생했습니다', error); + throw error; + } +}; + // 편지 공유 수락 / 거절 export const postShareProposalApproval = async ( shareProposalId: number, action: 'approve' | 'reject', -): Promise => { +): Promise => { try { - const response = await client.patch(`/api/share-proposal/${shareProposalId}/${action}`); + const response = await client.patch(`/api/share-proposals/${shareProposalId}/${action}`); return response.data; } catch (error) { console.error( diff --git a/src/pages/Home/components/ShowShareAccessModal.tsx b/src/pages/Home/components/ShowShareAccessModal.tsx index 3ed4179..f66576e 100644 --- a/src/pages/Home/components/ShowShareAccessModal.tsx +++ b/src/pages/Home/components/ShowShareAccessModal.tsx @@ -1,7 +1,7 @@ import React, { useEffect, useState } from 'react'; import { useNavigate } from 'react-router'; -import { getSharePostDetail } from '@/apis/share'; +import { getShareProposalDetail } from '@/apis/share'; import { getShareProposalList } from '@/apis/share'; import { ShareProposal } from '@/apis/share'; @@ -30,9 +30,9 @@ const ShowShareAccessModal = ({ onClose }: ShowShareAccessModalProps) => { const handleNavigation = async (shareProposalId: number) => { try { - const postDetail = await getSharePostDetail(shareProposalId); - navigate(`/board/letter/${shareProposalId}`, { - state: { postDetail, isShareLetterPreview: true }, + const proposalDetail = await getShareProposalDetail(shareProposalId); + navigate(`/board/share/${shareProposalId}`, { + state: { proposalDetail }, }); } catch (error) { console.error('❌ 게시글 상세 페이지로 이동하는 데에 실패했습니다.', error); diff --git a/src/pages/MyPage/constants/index.ts b/src/pages/MyPage/constants/index.ts index b605b37..7028ff8 100644 --- a/src/pages/MyPage/constants/index.ts +++ b/src/pages/MyPage/constants/index.ts @@ -5,5 +5,5 @@ export const TEMPERATURE_RANGE = [ { min: 40, max: 55, description: '마음이 따뜻한 따숨님' }, { min: 55, max: 70, description: '훈훈한 따숨님' }, { min: 70, max: 80, description: '정말 따뜻한 따숨님' }, - { min: 85, max: 100, description: '사랑이 넘치는 따숨님' }, + { min: 85, max: 105, description: '사랑이 넘치는 따숨님' }, ]; diff --git a/src/pages/Share/index.tsx b/src/pages/Share/index.tsx new file mode 100644 index 0000000..f2016c6 --- /dev/null +++ b/src/pages/Share/index.tsx @@ -0,0 +1,93 @@ +import { useEffect, useState } from 'react'; +import { useNavigate, useParams } from 'react-router'; + +import { getShareProposalDetail } from '@/apis/share'; +import { postShareProposalApproval, ShareProposalDetail } from '@/apis/share'; + +import { twMerge } from 'tailwind-merge'; +import Letter from '../LetterBoardDetail/components/Letter'; + +import BlurImg from '@/assets/images/landing-blur.png'; + +const ShareApprovalPage = () => { + const navigate = useNavigate(); + const { shareProposalId } = useParams(); + console.log(shareProposalId); + + const [proposalDetail, setProposalDetail] = useState(); + + const handleProposalApproval = async (action: 'approve' | 'reject') => { + try { + const result = await postShareProposalApproval(Number(shareProposalId), action); + console.log(`✅ 편지 공유 ${action === 'approve' ? '수락' : '거절'}됨:`, result); + navigate('/'); + } catch (error) { + console.error('❌공유 요청 처리 중 에러 발생', error); + } + }; + useEffect(() => { + const fetchProposalDetail = async (id: string) => { + try { + const data = await getShareProposalDetail(Number(id)); + setProposalDetail(data); + } catch (error) { + console.error('❌ 공유 요청 상세 조회에 실패했습니다.', error); + throw error; + } + }; + + if (shareProposalId) { + fetchProposalDetail(shareProposalId); + } + }, [shareProposalId]); + + return ( + + + FROM. {proposalDetail?.requesterZipCode} + + {proposalDetail?.message} + + + {proposalDetail?.letters.map((letter, index) => ( + + ))} + + + {proposalDetail && ( + <> + + + handleProposalApproval('reject')} + > + 거부하기 + + + handleProposalApproval('approve')} + > + 승인하기 + + + > + )} + + + ); +}; + +export default ShareApprovalPage;
FROM. {proposalDetail?.requesterZipCode}
+ {proposalDetail?.message} +