Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions src/components/MyPage/FCMTestButton/FCMTestButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import styled from '@emotion/styled';
import { useState } from 'react';

const FCMTestButton = () => {
const [loading, setLoading] = useState(false);
const [result, setResult] = useState<string>('');

const testFCMPush = async () => {
try {
setLoading(true);
setResult('');

const token = localStorage.getItem('access_token');

if (!token) {
setResult('❌ 로그인이 필요합니다');
alert('❌ 로그인이 필요합니다');
return;
}

const response = await fetch('https://api.humanzipyo.com/notification/test-fcm', {
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
},
});

const data = await response.json();

if (response.ok) {
setResult('✅ 테스트 알림 발송 성공!\n앱에서 알림을 확인하세요.');
alert('✅ 테스트 알림 발송 성공!\n앱에서 알림을 확인하세요.');
} else {
setResult(`❌ 실패: ${data.message || '알 수 없는 오류'}`);
alert(`❌ 실패: ${data.message || '알 수 없는 오류'}`);
}
} catch (error) {
const message = error instanceof Error ? error.message : '알 수 없는 오류';
setResult(`❌ 에러: ${message}`);
alert(`❌ 에러: ${message}`);
} finally {
setLoading(false);
}
};

return (
<Container>
<TestButton onClick={testFCMPush} disabled={loading}>
{loading ? '🔄 발송 중...' : '📱 FCM 알림 테스트'}
</TestButton>
{result && <ResultText>{result}</ResultText>}
</Container>
);
};

export default FCMTestButton;

const Container = styled.div`
margin: 20px 0;
padding: 16px;
background-color: ${({ theme }) => theme.colors.sub_gray1};
border-radius: 8px;
border: 1px dashed ${({ theme }) => theme.colors.sub_gray5};
`;

const TestButton = styled.button`
width: 100%;
padding: 12px 16px;
background-color: #007aff;
color: white;
border: none;
border-radius: 8px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: all 0.2s;

&:hover {
opacity: 0.9;
}

&:active {
transform: scale(0.98);
}

&:disabled {
opacity: 0.6;
cursor: not-allowed;
}
`;

const ResultText = styled.pre`
margin-top: 12px;
padding: 12px;
background-color: ${({ theme }) => theme.colors.sub_gray2};
border-radius: 4px;
font-size: 13px;
line-height: 1.5;
white-space: pre-wrap;
color: ${({ theme }) => theme.colors.text1};
`;
2 changes: 2 additions & 0 deletions src/pages/MyPage/MyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useNavigate } from 'react-router-dom';
import useAuthInfo from '@hooks/useAuthInfo';
import { webPath } from '@router/index';
import ConfirmModal from '@components/Modal/Confirm/ConfirmModal';
import FCMTestButton from '@components/MyPage/FCMTestButton/FCMTestButton';
import { fetchAuthLogout } from '@controllers/auth/api';
import { useExperimentStatusQuery } from '@controllers/experiment/query';
import { useBookmarkListQuery } from '@controllers/preference/query';
Expand Down Expand Up @@ -172,6 +173,7 @@ const MyPage = () => {
</MyPageDefaultContainer>
)}
<span className="divider" />
<FCMTestButton />
<MyPageSNSContainer>
<InstagramSVG onClick={handleClickInstagram} />
<LinkedInSVG onClick={handleClickLinkedIn} />
Expand Down