-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ♻️ Refactor: 초대 코드 관련 * 🐛 Fix: 쿼리파라미터로 수정 * 💄 Design: 초대 버튼 만듦
- Loading branch information
1 parent
850ba85
commit e1b4a8c
Showing
6 changed files
with
62 additions
and
23 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,55 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { useParams, useNavigate } from 'react-router-dom'; | ||
import { useLocation, useNavigate } from 'react-router-dom'; | ||
import { Button, Text } from '@chakra-ui/react'; | ||
import postInviteTeam from '@/api/inviteTeamApi/postInviteTeam'; | ||
import * as S from '@/styles/inviteTeam/AcceptInvite'; | ||
|
||
const AcceptInvite: React.FC = () => { | ||
const { invitationId } = useParams<{ invitationId?: string }>(); | ||
const location = useLocation(); | ||
const navigate = useNavigate(); | ||
const [inviteSuccess, setInviteSuccess] = useState(false); | ||
|
||
useEffect(() => { | ||
const acceptInvitation = async () => { | ||
try { | ||
if (invitationId) { | ||
await postInviteTeam(invitationId); | ||
const searchParams = new URLSearchParams(location.search); | ||
const invitationCode = searchParams.get('invitationId'); | ||
|
||
const acceptInvitation = async () => { | ||
try { | ||
if (invitationCode) { | ||
const response = await postInviteTeam(invitationCode); | ||
// 백엔드에서 204 반환해줌 | ||
if (response.status === 204) { | ||
setInviteSuccess(true); // 초대 요청이 성공했을 때 상태를 true로 변경 | ||
} else { | ||
console.error('InvitationId 추출 실패'); | ||
console.error('초대 수락 실패'); | ||
} | ||
} catch (error) { | ||
console.error('에러', error); | ||
} else { | ||
console.error('invitationCode 추출 실패'); | ||
} | ||
}; | ||
|
||
acceptInvitation(); | ||
}, [invitationId]); | ||
} catch (error) { | ||
console.error('에러', error); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
if (inviteSuccess) { | ||
// 초대 성공 시 알림을 띄우고 retrolist 페이지로 navigate | ||
alert('초대 성공했습니다!'); | ||
alert('초대를 성공적으로 수락했습니다!'); | ||
navigate('/retrolist'); | ||
} | ||
}, [inviteSuccess, navigate]); | ||
|
||
return <div>초대를 수락하는 중...</div>; | ||
return ( | ||
<> | ||
<S.Container> | ||
<S.TextContainer> | ||
<Text fontSize="2xl">초대를 수락하시겠습니까?</Text> | ||
</S.TextContainer> | ||
<Button colorScheme="brand" size="lg" onClick={acceptInvitation}> | ||
초대 수락하기 | ||
</Button> | ||
</S.Container> | ||
</> | ||
); | ||
}; | ||
|
||
export default AcceptInvite; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const Container = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
`; | ||
|
||
export const TextContainer = styled.div` | ||
margin-bottom: 2rem; | ||
`; |