Skip to content

Commit

Permalink
[FE] 강퇴당한 사용자에게 Dialog를 띄운다. (#178)
Browse files Browse the repository at this point in the history
* feat: 재사용 가능한 AlertDialog 컴포넌트 생성

* feat: 현재 게임방 이름 세션 스토리지 저장 후 강퇴 시 CustomAlertDialog 띄우기
  • Loading branch information
studioOwol authored Nov 27, 2024
1 parent d41a38a commit 83a62b2
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
45 changes: 45 additions & 0 deletions fe/src/components/common/CustomAlertDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {
AlertDialog,
AlertDialogAction,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from '@/components/ui/alert-dialog';

interface CustomAlertDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
title: string;
description?: string;
actionText?: string;
}

const CustomAlertDialog = ({
open,
onOpenChange,
title,
description,
actionText = '확인',
}: CustomAlertDialogProps) => {
return (
<AlertDialog open={open} onOpenChange={onOpenChange}>
<AlertDialogContent className="font-galmuri sm:max-w-[22rem]">
<AlertDialogHeader>
<AlertDialogTitle>{title}</AlertDialogTitle>
{description && (
<AlertDialogDescription>{description}</AlertDialogDescription>
)}
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogAction className="bg-primary hover:bg-primary/90">
{actionText}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
);
};

export default CustomAlertDialog;
21 changes: 21 additions & 0 deletions fe/src/pages/RoomListPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,36 @@ import SearchBar from '@/components/common/SearchBar';
import RoomHeader from './RoomHeader/RoomHeader';
import RoomList from './RoomList/RoomList';
import { useRoomsSSE } from '@/hooks/useRoomsSSE';
import { useEffect, useState } from 'react';
import CustomAlertDialog from '@/components/common/CustomAlertDialog';

const RoomListPage = () => {
const [showAlert, setShowAlert] = useState(false);
const [kickedRoomName, setKickedRoomName] = useState('');

useRoomsSSE();

useEffect(() => {
const kickedRoomName = sessionStorage.getItem('kickedRoomName');

if (kickedRoomName) {
setKickedRoomName(kickedRoomName);
setShowAlert(true);
sessionStorage.removeItem('kickedRoomName');
}
}, []);

return (
<div>
<RoomHeader />
<SearchBar />
<RoomList />
<CustomAlertDialog
open={showAlert}
onOpenChange={setShowAlert}
title="알림"
description={`${kickedRoomName}방에서 강퇴되었습니다.`}
/>
</div>
);
};
Expand Down
2 changes: 2 additions & 0 deletions fe/src/services/gameSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class GameSocket extends SocketService {
if (!currentRoom) return;

if (currentPlayer === playerNickname) {
sessionStorage.setItem('kickedRoomName', currentRoom.roomName);

setCurrentRoom(null);
setCurrentPlayer(null);
window.location.href = '/';
Expand Down

0 comments on commit 83a62b2

Please sign in to comment.