diff --git a/api/room.ts b/api/room.ts index 14cd6c0..473e8ff 100644 --- a/api/room.ts +++ b/api/room.ts @@ -42,3 +42,12 @@ export const getRoom = async (id: string) => { }, }); }; + +export const deleteRoom = async (id: string) => { + return fetchData(`/api/v1/rooms/${id}?id=${id}`, { + method: 'DELETE', + headers: { + 'Content-Type': 'application/json', + }, + }); +}; diff --git a/components/Modal/Modal.module.scss b/components/Modal/Modal.module.scss index 863cd9c..c373ed5 100644 --- a/components/Modal/Modal.module.scss +++ b/components/Modal/Modal.module.scss @@ -9,7 +9,7 @@ } .overlay { - @apply bg-[rgba(0,0,0,0.2)] w-full h-full fixed top-0 z-[1000]; + @apply bg-[rgba(0,0,0,0.2)] w-full h-full fixed top-0 z-[1000] max-w-[440px] min-w-[320px]; } .full { diff --git a/pages/room/[id].tsx b/pages/room/[id].tsx index 8c0bc5f..7e12b6e 100644 --- a/pages/room/[id].tsx +++ b/pages/room/[id].tsx @@ -14,52 +14,63 @@ import ReceiptBadge from '@/public/icons/receipt-badge.svg'; import Badge from '@/components/Badge/Badge'; import Like from '@/public/icons/like.svg'; import MyImageSvg from '@/components/ImageSvg/ImageSvg'; -import { fetchFurnishings, getRoom } from '@/api/room'; -import { Option } from '@/components/Select/Select'; +import { deleteRoom, fetchFurnishings, getRoom } from '@/api/room'; +import useModal from '@/hooks/useModal'; +import { useSession } from 'next-auth/react'; import styles from './room.module.scss'; -const RoomDetailLayout = ({ children }: any) => { - const [showModal, setShowModal] = React.useState(false); +// const RoomDetailLayout = ({ children }: any) => { +// const router = useRouter(); +// const { id } = router.query; - const handleButtonClick = () => { - window.history.back(); - }; +// const { openModal, closeModal } = useModal(); - const showDeleteModal = () => { - setShowModal(true); - }; +// const handleButtonClick = () => { +// window.history.back(); +// }; - const handleDeleteRoom = () => { - alert('삭제 레츠고,,,,'); - setShowModal(false); - }; +// const removeRoom = async () => { +// if (typeof id === 'string') { +// await deleteRoom(id); +// } +// }; - return ( - <> -
-
{children}
- {showModal && ( - setShowModal(false)} - handleSecondButton={handleDeleteRoom} - /> - )} - - ); -}; +// const showDeleteModal = () => { +// openModal({ +// props: { +// title: 'Delete this post?', +// content: 'You will not be able to restore this post.', +// buttonType: 'both', +// buttonName: 'Cancel', +// buttonName2: 'Delete', +// hasCloseButton: true, +// handleClose: () => { +// closeModal(); +// }, +// handleSecondButton: async () => { +// await removeRoom(); +// router.push('/'); +// closeModal(); +// }, +// }, +// }); +// }; -const Page = () => { +// return ( +// <> +//
+//
{children}
+// +// ); +// }; + +export default function RoomDetail() { const router = useRouter(); const { id } = router.query; @@ -74,13 +85,6 @@ const Page = () => { const roomType = room?.roomInfo.roomType === ROOM_TYPE.ONE_ROOM ? '1bed flats' : ''; - const fetchRoom = async () => { - if (id && typeof id === 'string') { - const data = await getRoom(id); - setRoom(data); - } - }; - const [furnishings, setFurnishings] = useState([]); const getFurnishings = async () => { @@ -153,153 +157,198 @@ const Page = () => { ); }, [room?.maintenance]); + const { openModal, closeModal } = useModal(); + + const handleButtonClick = () => { + window.history.back(); + }; + + const removeRoom = async () => { + if (typeof id === 'string') { + await deleteRoom(id); + } + }; + + const session = useSession(); + const email = session?.data?.user?.email; + + const showDeleteModal = () => { + openModal({ + props: { + title: 'Delete this post?', + content: 'You will not be able to restore this post.', + buttonType: 'both', + buttonName: 'Cancel', + buttonName2: 'Delete', + hasCloseButton: true, + handleClose: () => { + closeModal(); + }, + handleSecondButton: async () => { + await removeRoom(); + router.push('/'); + closeModal(); + }, + }, + }); + }; + return ( -
- {room && ( - <> -
- {room.imageFiles.length > 0 ? ( - handleSlideChange(event.realIndex)} - > - {room.imageFiles.map((image, idx) => ( - - {`room-${idx}`} - - ))} -
- {currentSlide + 1}/{room.imageFiles.length} + <> +
+
+ {room && ( + <> +
+ {room.imageFiles.length > 0 ? ( + handleSlideChange(event.realIndex)} + > + {room.imageFiles.map((image, idx) => ( + + {`room-${idx}`} + + ))} +
+ {currentSlide + 1}/{room.imageFiles.length} +
+
+ ) : ( +
+ )} +
+ +
+
{room.user.firstName}
+
+ {age} years old +  |  + {room.user.gender} +
- - ) : ( -
- )} -
- -
-
{room.user.firstName}
-
- {age} years old -  |  - {room.user.gender} + +
+
- -
- -
-
- {isShowDetail &&
{room.user.description}
} -
-
-
- - {room.location.name}, {room.location.upperLocation?.name} -
-
- - From {formatDate(room.availableDate)} -
-
-
-
- -

{roomType}

-
- {room.roomInfo.bedrooms} bedrooms - - {room.roomInfo.bathrooms} bathrooms - - {room.roomInfo.roommates} housemates in total -
-
-
-
- -
-
- Deposit - - ₩ {formatPrice(room.deposit.amount)} / month + {isShowDetail &&
{room.user.description}
} +
+
+
+ + {room.location.name}, {room.location.upperLocation?.name}
-
- Maintenance fee - - - {room.maintenance.maintenanceFee.amount ? formatPrice(room.maintenance.maintenanceFee.amount) : 0} / - month - +
+ + From {formatDate(room.availableDate)}
-

Included

-
- {includeServices && - includeServices.map((item, idx) => )} +
+
+ +

{roomType}

+
+ {room.roomInfo.bedrooms} bedrooms + + {room.roomInfo.bathrooms} bathrooms + + {room.roomInfo.roommates} housemates in total +
-
-
- {room.furnishingsData && room.furnishingsData?.length > 0 && ( +
-

Furnishing

-
- {room.furnishingsData.map((item, idx) => ( - - ))} + +
+
+ Deposit + + ₩ {formatPrice(room.deposit.amount)} / month +
+
+ Maintenance fee + + + {room.maintenance.maintenanceFee.amount ? formatPrice(room.maintenance.maintenanceFee.amount) : 0}{' '} + / month + +
+
+

Included

+
+ {includeServices && + includeServices.map((item, idx) => )}
- )} -
-
-

About the house

-
{room.description}
-
-
-
- Do you want to report this post? - - Report - +
+ {room.furnishingsData && room.furnishingsData?.length > 0 && ( +
+

Furnishing

+
+ {room.furnishingsData.map((item, idx) => ( + + ))} +
+
+ )} +
+
+

About the house

+
{room.description}
+
+
+
+ Do you want to report this post? + + Report + +
-
-
-
- - ₩ {formatPrice(room.deposit.amount)}  - / month -
- +
+
+ + ₩ {formatPrice(room.deposit.amount)}  + / month +
+ +
-
- - )} - {showReport && ( - setShowReport(false)} - handleReport={handleReport} - /> - )} -
- ); -}; - -export default function RoomDetail() { - return ( - - - + + )} + {showReport && ( + setShowReport(false)} + handleReport={handleReport} + /> + )} +
+ ); } + +// export default function RoomDetail() { +// return ( +// +// +// +// ); +// }