Skip to content

Commit

Permalink
feat: 스터디 탈퇴 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
yeonddori committed Jan 12, 2025
1 parent b55233d commit 2af6aee
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 44 deletions.
12 changes: 11 additions & 1 deletion src/app/team/[teamId]/study/[studyId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ import { useGetFetchWithToken } from '@/hooks/useFetchWithToken';
import useGetMyTeam from '@/hooks/useGetMyTeam';
import useGetUser from '@/hooks/useGetUser';
import { DocumentList, ParticipantType, Study, StudyMember } from '@/types';
import LeaveStudyModal from '@/containers/study/Modal/LeaveStudyModal';

const Page = ({ params }: { params: { teamId: number; studyId: number } }) => {
const [studyData, setStudyData] = useState<Study>();
const [isEditModalOpen, setIsEditModalOpen] = useState<boolean>(false);
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState<boolean>(false);
const [isTerminateModalOpen, setIsTerminateModalOpen] = useState<boolean>(false);
const [isLeaveModalOpen, setIsLeaveModalOpen] = useState<boolean>(false);
const [documentArray, setDocumentArray] = useState<DocumentList[]>([]);
const [isCreateDocumentModalOpen, setIsCreateDocumentModalOpen] = useState<boolean>(false);
const categoryData: CreateDocument = { groupId: params.studyId, groupType: 'studies' };
Expand Down Expand Up @@ -97,9 +99,11 @@ const Page = ({ params }: { params: { teamId: number; studyId: number } }) => {
</Flex>
{studyData && studyData?.status !== 'ENDED' && user && user.memberId === studyData?.studyLeaderId && (
<StudyControlPanel
isStudyLeader={user.memberId === studyData.studyLeaderId}
editModalOpen={setIsEditModalOpen}
terminateModalOpen={setIsTerminateModalOpen}
deleteModalOpen={setIsDeleteModalOpen}
leaveModalOpen={setIsLeaveModalOpen}
/>
)}
<Grid gap="4" templateColumns={{ base: '', xl: '2fr 1fr' }} w="100%" my="4">
Expand Down Expand Up @@ -199,7 +203,13 @@ const Page = ({ params }: { params: { teamId: number; studyId: number } }) => {
isOpen={isDeleteModalOpen}
setIsOpen={setIsDeleteModalOpen}
/>

<LeaveStudyModal
id={params.studyId}
name={studyData?.name || ''}
teamId={params.teamId}
isOpen={isLeaveModalOpen}
setIsOpen={setIsLeaveModalOpen}
/>
<CreateDocumentModal
isOpen={isCreateDocumentModalOpen}
onClose={() => setIsCreateDocumentModalOpen(false)}
Expand Down
112 changes: 69 additions & 43 deletions src/containers/study/StudyControlPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,77 @@ import { Button, Flex } from '@chakra-ui/react';

import { StudyControlPanelProps } from './types';

const StudyControlPanel = ({ editModalOpen, terminateModalOpen, deleteModalOpen }: StudyControlPanelProps) => {
const StudyControlPanel = ({
isStudyLeader,
editModalOpen,
terminateModalOpen,
deleteModalOpen,
leaveModalOpen,
}: StudyControlPanelProps) => {
return (
<Flex gap="2">
<Button
w="fit-content"
px="4"
py="1"
color="white"
bg="orange"
shadow="md"
_hover={{ bg: 'orange' }}
aria-label=""
onClick={() => editModalOpen(true)}
size="xs"
>
수정
</Button>
<Button
w="fit-content"
px="4"
py="1"
color="white"
bg="orange_dark"
shadow="md"
_hover={{ bg: 'orange_dark' }}
aria-label=""
onClick={() => terminateModalOpen(true)}
size="xs"
>
종료
</Button>
<Button
w="fit-content"
px="4"
py="1"
color="black"
bg="white"
shadow="md"
_hover={{ bg: 'white' }}
aria-label=""
onClick={() => deleteModalOpen(true)}
size="xs"
>
삭제
</Button>
{isStudyLeader && (
<>
<Button
w="fit-content"
px="4"
py="1"
color="white"
bg="orange"
shadow="md"
_hover={{ bg: 'orange' }}
aria-label=""
onClick={() => editModalOpen(true)}
size="xs"
>
수정
</Button>
<Button
w="fit-content"
px="4"
py="1"
color="white"
bg="orange_dark"
shadow="md"
_hover={{ bg: 'orange_dark' }}
aria-label=""
onClick={() => terminateModalOpen(true)}
size="xs"
>
종료
</Button>
<Button
w="fit-content"
px="4"
py="1"
color="black"
bg="white"
shadow="md"
_hover={{ bg: 'white' }}
aria-label=""
onClick={() => deleteModalOpen(true)}
size="xs"
>
삭제
</Button>
</>
)}
{!isStudyLeader && (
<Button
w="fit-content"
px="4"
py="1"
color="black"
bg="white"
shadow="md"
_hover={{ bg: 'white' }}
aria-label=""
onClick={() => leaveModalOpen(true)}
size="xs"
>
탈퇴
</Button>
)}
</Flex>
);
};
Expand Down
2 changes: 2 additions & 0 deletions src/containers/study/StudyControlPanel/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export interface StudyControlPanelProps {
isStudyLeader: boolean;
editModalOpen: React.Dispatch<React.SetStateAction<boolean>>;
terminateModalOpen: React.Dispatch<React.SetStateAction<boolean>>;
deleteModalOpen: React.Dispatch<React.SetStateAction<boolean>>;
leaveModalOpen: React.Dispatch<React.SetStateAction<boolean>>;
}

0 comments on commit 2af6aee

Please sign in to comment.