@@ -6,34 +6,57 @@ import { theme } from '../../styles/theme';
66import Profile from '../../../assets/icons/Profile.svg' ;
77import Modal from '../../components/modal/Modal' ;
88import RefreshRequestBox from '../../components/box/RefreshRequestBox' ;
9+ import { USER_INFO_URL as url } from '../../constants/url' ;
10+ import { fetchRequest } from '../../utils/fetchRequest' ;
911
1012const OpenSuccessTabButton = ( ) => {
1113 const [ isModalOpen , setIsModalOpen ] = React . useState ( false ) ;
14+ const [ isLoggedIn , setIsLoggedIn ] = React . useState ( false ) ;
1215
13- const createSuccessProblemTab = ( ) => {
14- if ( chrome . runtime ?. id === undefined ) {
15- setIsModalOpen ( true ) ;
16- return ;
17- }
18-
19- chrome . runtime . sendMessage ( {
20- method : 'createSuccessProblemTab' ,
21- } ) ;
22- } ;
16+ React . useEffect ( ( ) => {
17+ ( async ( ) => {
18+ const { isLoggedIn } = await fetchRequest ( { url } ) ;
19+ setIsLoggedIn ( isLoggedIn ) ;
20+ } ) ( ) ;
21+ } , [ ] ) ;
2322
2423 return (
2524 < >
2625 < Modal isOpen = { isModalOpen } closeModal = { ( ) => setIsModalOpen ( false ) } >
27- < RefreshRequestBox backgroundColor = { theme . color . jetBlack } color = { theme . color . white } />
26+ < RefreshRequestBox backgroundColor = { theme . color . jetBlack } color = { theme . color . white } >
27+ 새로고침을 해주세요!
28+ </ RefreshRequestBox >
2829 </ Modal >
29- < ButtonStyle onClick = { createSuccessProblemTab } >
30- < ToolTipStyle > 나의 풀이 바로가기</ ToolTipStyle >
30+ < ButtonStyle onClick = { ( ) => createSuccessProblemTab ( { isLoggedIn, setIsLoggedIn } ) } >
31+ { isLoggedIn && < ToolTipStyle > 나의 풀이 바로가기</ ToolTipStyle > }
32+ { isLoggedIn || < ToolTipStyle > 로그인을 해주세요!</ ToolTipStyle > }
3133 < Profile />
3234 </ ButtonStyle >
3335 </ >
3436 ) ;
3537} ;
3638
39+ type ProblemTabType = {
40+ isLoggedIn : boolean ;
41+ setIsLoggedIn : ( isModalOpen : boolean ) => void ;
42+ } ;
43+
44+ const createSuccessProblemTab = ( { isLoggedIn, setIsLoggedIn } : ProblemTabType ) => {
45+ if ( ! isLoggedIn ) {
46+ alert ( `프로그래머스에 로그아웃이 된 상태입니다.\n로그인을 해주세요!` ) ;
47+ return ;
48+ }
49+
50+ if ( chrome . runtime ?. id === undefined ) {
51+ setIsLoggedIn ( true ) ;
52+ return ;
53+ }
54+
55+ chrome . runtime . sendMessage ( {
56+ method : 'createSuccessProblemTab' ,
57+ } ) ;
58+ } ;
59+
3760const ButtonStyle = styled . button `
3861 display: flex;
3962 justify-content: space-between;
@@ -42,6 +65,8 @@ const ButtonStyle = styled.button`
4265 top: 85%;
4366 right: 5%;
4467 z-index: 10000;
68+ border: none;
69+ background: none;
4570 svg {
4671 filter: drop-shadow(#707373 0px 5px 5px);
4772 transition: all 0.2s linear;
0 commit comments