Skip to content

Commit c96daf0

Browse files
committed
Merge branch 'develop' of https://github.com/prgrms-web-devcourse-final-project/WEB2_3_9crops_FE into 91-rolling-paper-additionial
2 parents b7ffbac + 266d0e5 commit c96daf0

File tree

8 files changed

+216
-123
lines changed

8 files changed

+216
-123
lines changed

src/apis/incomingLetters.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import client from './client';
22

3-
export const getIncomingLetters = async (token: string) => {
3+
export const getIncomingLetters = async () => {
44
try {
5-
const { data } = await client.get('/api/letters?status=delivery', {
6-
headers: {
7-
Authorization: `Bearer ${token}`,
8-
},
9-
});
10-
console.log('불러온 데이터', data);
5+
const { data } = await client.get('/api/letters?status=delivery');
6+
console.log('오고있는 편지 데이터', data);
117
return data;
128
} catch (error) {
139
console.error('❌오고 있는 편지 목록을 불러오던 중 에러 발생', error);

src/apis/share.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface SharePost {
2121
letters: ShareLetter[];
2222
}
2323

24-
// 페이징 포함
24+
// 공유 게시글 목록 조회 - 페이징 포함
2525
export interface SharePostResponse {
2626
content: SharePost[];
2727
currentPage: number;
@@ -30,6 +30,15 @@ export interface SharePostResponse {
3030
totalPages: number;
3131
}
3232

33+
// 편지 공유 요청 수신 조회
34+
export interface ShareProposal {
35+
shareProposalId: number;
36+
requesterZipCode: string;
37+
recipientZipCode: string;
38+
message: string;
39+
status: 'REJECTED' | 'APPROVED' | 'PENDING';
40+
}
41+
3342
// 편지 공유 수락 / 거절
3443
export interface SharePostApproval {
3544
shareProposalId: number;
@@ -84,6 +93,19 @@ export const postShareProposals = async (
8493
}
8594
};
8695

96+
// 편지 공유 요청 수신 조회
97+
export const getShareProposalList = async () => {
98+
try {
99+
const response = await client.get('/api/share-proposals/inbox');
100+
console.log(`🌟공유 요청 목록`, response.data);
101+
102+
return response.data.data;
103+
} catch (error) {
104+
console.error('❌ 편지 공유 요청을 조회하던 중 에러가 발생했습니다', error);
105+
throw error;
106+
}
107+
};
108+
87109
// 편지 공유 수락 / 거절
88110
export const postShareProposalApproval = async (
89111
shareProposalId: number,

src/pages/Admin/Report.tsx

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { AlarmIcon } from '@/assets/icons';
55

66
import AdminPageTitle from './components/AdminPageTitle';
77
import ListHeaderFrame from './components/ListHeaderFrame';
8+
import PagenationNavigation from './components/PagenationNavigation';
89
import ReportDetailModal from './components/ReportDetailModal';
910
import ReportHandlingModal from './components/ReportHandlingModal';
1011
import ReportListItem from './components/ReportListItem';
@@ -19,28 +20,33 @@ export default function ReportManage() {
1920
currentPage: '1',
2021
totalPages: '0',
2122
});
23+
2224
const [selectedReport, setSelectReport] = useState<Report | null>(null);
2325
const [selectedReportId, setSelectedReportId] = useState<number | null>(null);
2426

25-
// const [allReports, setAllReports] = useState();
26-
2727
const [reportQueryString, setReportQueryString] = useState<ReportQueryString>({
2828
reportType: null,
2929
status: 'PENDING',
3030
page: '1',
31-
size: '3',
31+
size: '2',
3232
});
33+
3334
const handleGetReports = async (reportQueryString: ReportQueryString) => {
3435
const res = await getReports(reportQueryString);
3536
if (res?.status === 200) {
36-
console.log(res.data.data.content);
37-
setReports(res.data.data.content);
37+
const data = res.data.data;
38+
setReports(data.content);
3839
setReportPages(() => ({
39-
currentPage: res.data.data.currentPage,
40-
totalPages: res.data.data.totalPages,
40+
currentPage: data.currentPage,
41+
totalPages: data.totalPages,
4142
}));
4243
}
4344
};
45+
46+
const handleNowPage = (page: string) => {
47+
setReportQueryString((cur) => ({ ...cur, page: page }));
48+
};
49+
4450
useEffect(() => {
4551
handleGetReports(reportQueryString);
4652
}, [reportQueryString]);
@@ -68,39 +74,11 @@ export default function ReportManage() {
6874
setSelectReport={setSelectReport}
6975
/>
7076
))}
71-
<div className="bg-accent-1 mt-5 flex h-10 w-full items-center justify-center">
72-
<div className="flex gap-2">
73-
<button
74-
className="h-full w-10 rounded-2xl border bg-white"
75-
onClick={() => {
76-
const nowPage = Number(reportQueryString.page);
77-
if (nowPage > 1) {
78-
const newPage = (nowPage - 1).toString();
79-
setReportQueryString((cur) => ({ ...cur, page: newPage }));
80-
}
81-
}}
82-
>
83-
84-
</button>
85-
<span>
86-
{reportPages.currentPage}/{reportPages.totalPages}
87-
</span>
88-
<button
89-
className="h-full w-10 rounded-2xl border bg-white"
90-
onClick={() => {
91-
const nowPage = Number(reportQueryString.page);
92-
const totalPage = Number(reportPages.totalPages);
93-
if (nowPage < totalPage) {
94-
const newPage = (nowPage + 1).toString();
95-
console.log(newPage);
96-
setReportQueryString((cur) => ({ ...cur, page: newPage }));
97-
}
98-
}}
99-
>
100-
101-
</button>
102-
</div>
103-
</div>
77+
<PagenationNavigation
78+
totalPage={Number(reportPages.totalPages)}
79+
buttonLength={3}
80+
handlePageNumberButtonClick={handleNowPage}
81+
/>
10482
</section>
10583
{detailModalOpen && (
10684
<ReportDetailModal selectedReport={selectedReport} closeEvent={setDetailModalOpen} />
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import { useState } from 'react';
2+
import { twMerge } from 'tailwind-merge';
3+
4+
interface PagenationNavigation {
5+
totalPage: number;
6+
buttonLength: number;
7+
handlePageNumberButtonClick: (page: string) => void;
8+
}
9+
export default function PagenationNavigation({
10+
totalPage,
11+
buttonLength,
12+
handlePageNumberButtonClick,
13+
}: PagenationNavigation) {
14+
const totalSection = Math.ceil(totalPage / buttonLength) - 1;
15+
const [nowSection, setNowSection] = useState<number>(0);
16+
const [nowPageNumberAt, setNowPageNumberAt] = useState(1);
17+
18+
// 네비게이션 시작점, 끝점
19+
const navigationRange = {
20+
start: nowSection * buttonLength + 1,
21+
end: nowSection * buttonLength + buttonLength,
22+
};
23+
24+
// 페이지 버튼 배열
25+
const pageNumberButtonArray = Array.from(
26+
{ length: navigationRange.end - navigationRange.start + 1 },
27+
(_, index) => navigationRange.start + index,
28+
);
29+
30+
// 페이지 버튼 클릭시 해당 번호값이 파라미터에 담김
31+
const handlePageButtonClick = (page: number) => {
32+
const pageString = page.toString();
33+
handlePageNumberButtonClick(pageString);
34+
setNowPageNumberAt(page);
35+
};
36+
37+
const handlePrevButtonClick = () => {
38+
if (nowSection > 0) {
39+
const prev = (nowSection - 1) * buttonLength + buttonLength;
40+
setNowSection((cur) => cur - 1);
41+
handlePageButtonClick(prev);
42+
}
43+
};
44+
45+
const handleNextButtonClick = () => {
46+
if (nowSection < totalSection) {
47+
const next = (nowSection + 1) * buttonLength + 1;
48+
setNowSection((cur) => cur + 1);
49+
handlePageButtonClick(next);
50+
}
51+
};
52+
53+
const buttonStyle = 'border bg-white px-2 py-1 disabled:bg-gray-20';
54+
55+
return (
56+
<div className="mt-5 flex h-10 w-full items-center justify-center">
57+
<div className="flex items-center">
58+
<button
59+
className={twMerge(buttonStyle)}
60+
disabled={nowSection <= 0}
61+
onClick={() => {
62+
handlePrevButtonClick();
63+
}}
64+
>
65+
prev
66+
</button>
67+
{pageNumberButtonArray.map((num) => {
68+
if (totalPage < num) return null;
69+
return (
70+
<button
71+
key={num}
72+
className={twMerge(buttonStyle, nowPageNumberAt === num && 'bg-accent-3')}
73+
onClick={() => {
74+
handlePageButtonClick(num);
75+
}}
76+
>
77+
{num}
78+
</button>
79+
);
80+
})}
81+
<button
82+
className={twMerge(buttonStyle)}
83+
disabled={nowSection >= totalSection}
84+
onClick={() => {
85+
handleNextButtonClick();
86+
}}
87+
>
88+
next
89+
</button>
90+
</div>
91+
</div>
92+
);
93+
}

src/pages/Home/components/ShowDraftModal.tsx

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,26 @@ const ShowDraftModal = ({ onClose }: ShowDraftModalProps) => {
6060
<p className="caption-r text-black">로그아웃 시 임시 저장된 편지는 사라집니다</p>
6161
</div>
6262
<div className="mt-6 flex max-h-60 min-h-auto w-[251px] flex-col gap-[10px] overflow-y-scroll [&::-webkit-scrollbar]:hidden">
63-
{draftLetters.map((draft) => (
64-
<div
65-
className="text-gray-80 body-m flex h-10 w-full items-center justify-between gap-1 rounded-lg bg-white p-3"
66-
key={draft.letterId}
67-
// onClick={() => handleNavigation(draft.letterId)}
68-
>
69-
<p className="truncate">{draft.title}</p>
63+
{draftLetters.length > 0 ? (
64+
draftLetters.map((draft) => (
7065
<div
71-
className="text-gray-20 active:text-gray-600"
72-
tabIndex={0}
73-
onClick={() => handleDeleteDraftLetters(draft.letterId)}
66+
className="text-gray-80 body-m flex h-10 w-full items-center justify-between gap-1 rounded-lg bg-white p-3"
67+
key={draft.letterId}
68+
// onClick={() => handleNavigation(draft.letterId)}
7469
>
75-
<DeleteOutlineRoundedIcon />
70+
<p className="truncate">{draft.title}</p>
71+
<div
72+
className="text-gray-20 active:text-gray-600"
73+
tabIndex={0}
74+
onClick={() => handleDeleteDraftLetters(draft.letterId)}
75+
>
76+
<DeleteOutlineRoundedIcon />
77+
</div>
7678
</div>
77-
</div>
78-
))}
79+
))
80+
) : (
81+
<p className="caption-m text-center text-gray-50">작성 중인 편지가 없어요</p>
82+
)}
7983
</div>
8084
</ModalBackgroundWrapper>
8185
</div>

src/pages/Home/components/ShowIncomingLettersModal.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,19 @@ const ShowIncomingLettersModal = ({ onClose }: ShowIncomingLettersModalProps) =>
2929
<p className="caption-r text-black">시간은 실제 시간을 기반으로 책정됩니다.</p>
3030
</div>
3131
<div className="mt-6 flex max-h-60 min-h-auto w-[251px] flex-col gap-[10px] overflow-y-scroll [&::-webkit-scrollbar]:hidden">
32-
{data.map((letter) => (
33-
<div
34-
className="text-gray-80 body-m flex h-10 w-full items-center justify-between gap-1 rounded-lg bg-white p-3"
35-
key={letter.letterId}
36-
>
37-
<p className="truncate">{letter.title}</p>
38-
<p>{letter.remainingTime}</p>
39-
</div>
40-
))}
32+
{data.length > 0 ? (
33+
data.map((letter) => (
34+
<div
35+
className="text-gray-80 body-m flex h-10 w-full items-center justify-between gap-1 rounded-lg bg-white p-3"
36+
key={letter.letterId}
37+
>
38+
<p className="truncate">{letter.title}</p>
39+
<p>{letter.remainingTime}</p>
40+
</div>
41+
))
42+
) : (
43+
<p className="caption-m text-center text-gray-50">오고 있는 편지가 없어요</p>
44+
)}
4145
</div>
4246
</ModalBackgroundWrapper>
4347
</div>

0 commit comments

Comments
 (0)