Skip to content

Commit f8e3aef

Browse files
authored
Merge pull request #72 from billilge/feat/#71-dashboard-rental-api
2 parents 9bfe01c + b12dc2b commit f8e3aef

File tree

3 files changed

+61
-14
lines changed

3 files changed

+61
-14
lines changed

src/app/mobile/admin/dashboard/_components/DashboardItem.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default function DashboardItem({
1414
}: DashboardProps) {
1515
const RentalApproveBtnText: Record<string, string> = {
1616
PENDING: '대여 승인',
17+
CONFIRMED: '대여 완료',
1718
RETURN_PENDING: '반납 승인',
1819
RETURN_CONFIRMED: '반납 완료',
1920
};

src/app/mobile/admin/dashboard/page.tsx

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,19 @@ import IconArrow from 'public/assets/icons/icon-arrow.svg';
99
import { cn } from '@/lib/utils';
1010
import { adminDashboardGet, adminRentalPatch } from '@/services/dashboard';
1111
import { DashboardProps } from '@/types/dashboardType';
12+
import { RentalStatusText } from '@/constants/rentalStatus';
1213
import DashboardItem from './_components/DashboardItem';
1314

1415
type DashboardType = DashboardProps;
1516

1617
interface RentalRequestProps {
1718
rentalHistoryId: number;
19+
itemName: string;
20+
renterName: string;
1821
status: string;
1922
}
2023

2124
export default function Dashboard() {
22-
const RentalFilterText: Record<string, string> = {
23-
ALL: '전체',
24-
PENDING: '대여 신청',
25-
RETURN_PENDING: '반납 신청',
26-
RETURN_CONFIRMED: '반납 대기',
27-
};
28-
2925
const [dashboardDetail, setDashboardDetail] = useState<DashboardType[]>([]);
3026
const [filter, setFilter] = useState('ALL');
3127
const [refreshTrigger, setRefreshTrigger] = useState(false);
@@ -47,9 +43,10 @@ export default function Dashboard() {
4743

4844
const dropdownActions = [
4945
{ title: '전체', func: () => handleFilter('ALL') },
50-
{ title: '대여 신청', func: () => handleFilter('PENDING') },
51-
{ title: '반납 신청', func: () => handleFilter('RETURN_PENDING') },
52-
{ title: '반납 대기', func: () => handleFilter('RETURN_CONFIRMED') },
46+
{ title: '대여 요청', func: () => handleFilter('PENDING') },
47+
{ title: '대여 승인', func: () => handleFilter('CONFIRMED') },
48+
{ title: '반납 요청', func: () => handleFilter('RETURN_PENDING') },
49+
{ title: '반납 승인', func: () => handleFilter('RETURN_CONFIRMED') },
5350
];
5451

5552
useEffect(() => {
@@ -65,26 +62,43 @@ export default function Dashboard() {
6562

6663
const handleApproveBtnClick = async ({
6764
rentalHistoryId,
65+
itemName,
66+
renterName,
6867
status,
6968
}: RentalRequestProps) => {
7069
const statusMap: Record<string, string> = {
7170
PENDING: 'CONFIRMED',
71+
CONFIRMED: 'RENTAL',
7272
RETURN_PENDING: 'RETURN_CONFIRMED',
7373
RETURN_CONFIRMED: 'RETURNED',
7474
};
7575

76-
const newStatus = statusMap[status] ?? status;
76+
const newStatus = statusMap[status!] ?? status;
7777

7878
const data = { rentalHistoryId, rentalStatus: newStatus };
7979
await adminRentalPatch(data);
80+
81+
alert(
82+
`${renterName} 님의 ${itemName} ${RentalStatusText[status]} 요청이 처리되었습니다.`,
83+
);
84+
8085
// TODO : 현재 임시로 상태로 관리 -> 추후 refetch로 변경
8186
setRefreshTrigger((prev) => !prev);
8287
};
8388

84-
const handleCancelBtnClick = async (rentalHistoryId: number) => {
89+
const handleCancelBtnClick = async ({
90+
rentalHistoryId,
91+
itemName,
92+
renterName,
93+
status,
94+
}: RentalRequestProps) => {
8595
const data = { rentalHistoryId, rentalStatus: 'CANCEL' };
8696
await adminRentalPatch(data);
8797

98+
alert(
99+
`${renterName} 님의 ${itemName} ${RentalStatusText[status]} 요청이 처리되었습니다.`,
100+
);
101+
88102
// TODO : 현재 임시로 상태로 관리 -> 추후 refetch로 변경
89103
setRefreshTrigger((prev) => !prev);
90104
};
@@ -103,7 +117,7 @@ export default function Dashboard() {
103117
className={`flex items-center gap-2.5 ${isDropdownVisible && 'pointer-events-none'}`}
104118
>
105119
<div className="flex text-sm font-semibold">
106-
{RentalFilterText[filter]}
120+
{filter === 'ALL' ? '전체' : RentalStatusText[filter]}
107121
</div>
108122
<IconArrow
109123
className={
@@ -130,13 +144,20 @@ export default function Dashboard() {
130144
if (item.rentalHistoryId !== undefined) {
131145
handleApproveBtnClick({
132146
rentalHistoryId: item.rentalHistoryId,
147+
itemName: item.itemName,
148+
renterName: item.renterName,
133149
status: item.status,
134150
});
135151
}
136152
}}
137153
handleCancelBtnClick={() => {
138154
if (item.rentalHistoryId !== undefined) {
139-
handleCancelBtnClick(item.rentalHistoryId);
155+
handleCancelBtnClick({
156+
rentalHistoryId: item.rentalHistoryId,
157+
itemName: item.itemName,
158+
renterName: item.renterName,
159+
status: item.status,
160+
});
140161
}
141162
}}
142163
/>

src/constants/rentalStatus.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export const RENTAL_STATUS = {
2+
PENDING: 'PENDING',
3+
CANCEL: 'CANCEL',
4+
REJECTED: 'REJECTED',
5+
CONFIRMED: 'CONFIRMED',
6+
RENTAL: 'RENTAL',
7+
RETURN_PENDING: 'RETURN_PENDING',
8+
RETURN_CONFIRMED: 'RETURN_CONFIRMED',
9+
RETURNED: 'RETURNED',
10+
};
11+
12+
export type RentalStatus = (typeof RENTAL_STATUS)[keyof typeof RENTAL_STATUS];
13+
14+
export const RentalStatusText: Record<RentalStatus, string> = {
15+
[RENTAL_STATUS.PENDING]: '대여 요청',
16+
[RENTAL_STATUS.CANCEL]: '대기 취소',
17+
[RENTAL_STATUS.REJECTED]: '대여 반려',
18+
[RENTAL_STATUS.CONFIRMED]: '대여 승인',
19+
[RENTAL_STATUS.RENTAL]: '대여 중',
20+
[RENTAL_STATUS.RETURN_PENDING]: '반납 요청',
21+
[RENTAL_STATUS.RETURN_CONFIRMED]: '반납 승인',
22+
[RENTAL_STATUS.RETURNED]: '반납 완료',
23+
} as const;
24+
25+
export type RentalStatusTypes = keyof typeof RentalStatusText;

0 commit comments

Comments
 (0)