-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
216 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ type IconKind = | |
| "search" | ||
| "add" | ||
| "delete" | ||
| "edit"; | ||
| "edit" | ||
| "control"; | ||
|
||
export default IconKind; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
frontend/src/components/roomDetailPage/controlButton/ControlButton.style.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import styled, { keyframes } from "styled-components"; | ||
|
||
const dropdown = keyframes` | ||
0% { | ||
transform: translateY(-10%); | ||
opacity: 0; | ||
} | ||
100% { | ||
transform: translateY(0); | ||
opacity: 1; | ||
} | ||
`; | ||
|
||
export const ControlButtonContainer = styled.div` | ||
position: relative; | ||
`; | ||
|
||
export const IconWrapper = styled.div<{ $isOpen: boolean }>` | ||
cursor: pointer; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
width: 40px; | ||
height: 40px; | ||
background-color: ${({ theme, $isOpen }) => $isOpen && theme.COLOR.grey0}; | ||
border-radius: 50%; | ||
&:hover { | ||
background-color: ${({ theme }) => theme.COLOR.grey0}; | ||
} | ||
`; | ||
|
||
export const DropdownMenu = styled.div` | ||
position: absolute; | ||
z-index: 1; | ||
right: 0; | ||
display: flex; | ||
flex-direction: column; | ||
min-width: 180px; | ||
padding: 1rem; | ||
background-color: white; | ||
border: 1px solid ${({ theme }) => theme.COLOR.grey2}; | ||
border-radius: 5px; | ||
animation: ${dropdown} 0.2s ease; | ||
`; | ||
|
||
export const DropdownItemWrapper = styled.ul` | ||
display: flex; | ||
flex-direction: column; | ||
gap: 0.5rem; | ||
margin: 0.5rem; | ||
:last-child { | ||
gap: 0; | ||
border-top: 1px solid ${({ theme }) => theme.COLOR.grey1}; | ||
} | ||
`; | ||
|
||
export const DropdownItem = styled.li` | ||
cursor: pointer; | ||
display: flex; | ||
gap: 0.3rem; | ||
align-items: center; | ||
padding: 0.5rem; | ||
font: ${({ theme }) => theme.TEXT.small}; | ||
color: ${({ theme }) => theme.COLOR.grey4}; | ||
&:hover { | ||
font: ${({ theme }) => theme.TEXT.small_bold}; | ||
background-color: ${({ theme }) => theme.COLOR.grey0}; | ||
} | ||
`; |
115 changes: 115 additions & 0 deletions
115
frontend/src/components/roomDetailPage/controlButton/ControlButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import React from "react"; | ||
import { useNavigate } from "react-router-dom"; | ||
import useDropdown from "@/hooks/common/useDropdown"; | ||
import useModal from "@/hooks/common/useModal"; | ||
import useMutateRoom from "@/hooks/mutations/useMutateRoom"; | ||
import FocusTrap from "@/components/common/focusTrap/FocusTrap"; | ||
import Icon from "@/components/common/icon/Icon"; | ||
import ConfirmModal from "@/components/common/modal/confirmModal/ConfirmModal"; | ||
import * as S from "@/components/roomDetailPage/controlButton/ControlButton.style"; | ||
import { ParticipationStatus, RoomInfo } from "@/@types/roomInfo"; | ||
import MESSAGES from "@/constants/message"; | ||
|
||
export type DropdownItem = { | ||
name: string; | ||
action: string; | ||
}; | ||
|
||
export const dropdownItemsConfig: Record<string, DropdownItem[]> = { | ||
MANAGER: [ | ||
{ name: "수정하기", action: "editRoom" }, | ||
{ name: "삭제하기", action: "deleteRoom" }, | ||
], | ||
PARTICIPATED: [{ name: "방 나가기", action: "exitRoom" }], | ||
}; | ||
|
||
interface ControlButtonProps { | ||
roomInfo: RoomInfo; | ||
participationStatus: ParticipationStatus; | ||
} | ||
|
||
const ControlButton = ({ roomInfo, participationStatus }: ControlButtonProps) => { | ||
const navigate = useNavigate(); | ||
const { isModalOpen, handleOpenModal, handleCloseModal } = useModal(); | ||
const { isDropdownOpen, handleToggleDropdown, dropdownRef } = useDropdown(); | ||
const { deleteParticipateInMutation, deleteParticipatedRoomMutation } = useMutateRoom(); | ||
|
||
const dropdownItems = dropdownItemsConfig[participationStatus] || []; | ||
|
||
const handleControlButtonClick = (event: React.MouseEvent) => { | ||
event.preventDefault(); | ||
handleToggleDropdown(); | ||
}; | ||
|
||
const handleDropdownItemClick = (action: string) => { | ||
switch (action) { | ||
case "editRoom": | ||
navigate(`/rooms/edit/${roomInfo.id}`); | ||
break; | ||
case "deleteRoom": | ||
handleOpenModal(); | ||
break; | ||
case "exitRoom": | ||
handleOpenModal(); | ||
break; | ||
default: | ||
break; | ||
} | ||
}; | ||
|
||
const handleConfirm = () => { | ||
if (roomInfo.participationStatus === "MANAGER") { | ||
deleteParticipatedRoomMutation.mutate(roomInfo.id, { | ||
onSuccess: () => navigate("/"), | ||
}); | ||
return; | ||
} | ||
deleteParticipateInMutation.mutate(roomInfo.id, { | ||
onSuccess: () => navigate("/"), | ||
}); | ||
}; | ||
|
||
return ( | ||
<> | ||
<ConfirmModal | ||
isOpen={isModalOpen} | ||
onClose={handleCloseModal} | ||
onConfirm={handleConfirm} | ||
onCancel={handleCloseModal} | ||
> | ||
{roomInfo.participationStatus === "MANAGER" | ||
? MESSAGES.GUIDANCE.DELETE_ROOM | ||
: MESSAGES.GUIDANCE.EXIT_ROOM} | ||
</ConfirmModal> | ||
|
||
<S.ControlButtonContainer ref={dropdownRef}> | ||
<S.IconWrapper $isOpen={isDropdownOpen}> | ||
<Icon kind="control" size="3rem" color="grey" onClick={handleControlButtonClick} /> | ||
</S.IconWrapper> | ||
|
||
{isDropdownOpen && ( | ||
<S.DropdownMenu> | ||
<FocusTrap onEscapeFocusTrap={() => handleToggleDropdown()}> | ||
<S.DropdownItemWrapper> | ||
{dropdownItems.map((item: DropdownItem) => ( | ||
<S.DropdownItem | ||
key={item.name} | ||
onClick={() => handleDropdownItemClick(item.action)} | ||
tabIndex={0} | ||
onKeyDown={(e) => { | ||
if (e.key === "Enter") handleDropdownItemClick(item.action); | ||
}} | ||
> | ||
{item.name} | ||
</S.DropdownItem> | ||
))} | ||
</S.DropdownItemWrapper> | ||
</FocusTrap> | ||
</S.DropdownMenu> | ||
)} | ||
</S.ControlButtonContainer> | ||
</> | ||
); | ||
}; | ||
|
||
export default ControlButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters