-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat : nofication hook 제거 * feat : fcm 토큰 등록 * feat : 지도 타겟 편지 개발 * chore : 사용하지 않는 콘솔 제거
- Loading branch information
Showing
10 changed files
with
268 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { getToken, onMessage } from 'firebase/messaging'; | ||
import { firebaseMessaging } from '@/util/firebase'; | ||
import { postToken } from '@/service/nofication/postToken'; | ||
|
||
// 푸시 알림 권한 요청 및 토큰 가져오기 | ||
const handlePushNotificationPermission = () => { | ||
if (Notification.permission === 'granted') { | ||
// 권한이 허용된 경우 | ||
getToken(firebaseMessaging, { | ||
vapidKey: import.meta.env.VITE_FCM_VAPID_KEY | ||
}) | ||
.then((token) => { | ||
console.log('알람 설정을 성공했습니다.'); | ||
postToken({ token }); // 서버에 토큰 전송 | ||
}) | ||
.catch((error) => { | ||
console.error('FCM Error:', error); | ||
}); | ||
} else if (Notification.permission === 'denied') { | ||
console.log('알람 설정을 거부했습니다.'); | ||
} else { | ||
// 권한을 아직 요청하지 않은 경우 | ||
Notification.requestPermission().then((permission) => { | ||
if (permission === 'granted') { | ||
getToken(firebaseMessaging, { | ||
vapidKey: import.meta.env.VITE_FCM_VAPID_KEY | ||
}) | ||
.then((token) => { | ||
console.log('알람 설정을 성공했습니다.'); | ||
postToken({ token }); // 서버에 토큰 전송 | ||
}) | ||
.catch((error) => { | ||
console.error('FCM Error:', error); | ||
}); | ||
} else { | ||
console.log('알람 설정을 거부했습니다.'); | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
// 푸시 알림 메시지 수신 처리 | ||
const setupPushNotificationListener = () => { | ||
return onMessage(firebaseMessaging, (payload) => { | ||
if (payload.notification) { | ||
console.log(`푸시 알림: ${payload.notification.body}`); | ||
} | ||
}); | ||
}; | ||
|
||
// 푸시 알림 설정 및 메시지 리스너 설정을 하나로 묶은 함수 | ||
export const setupPushNotifications = () => { | ||
handlePushNotificationPermission(); // 푸시 알림 권한 설정 | ||
return setupPushNotificationListener(); // 푸시 알림 메시지 리스너 설정 | ||
}; |
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,30 @@ | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { useToastStore } from './useToastStore'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { createMapTargerLetter } from '@/service/letter/create/createMapTargerLetter'; | ||
|
||
export const useCreateTargetMapLetter = () => { | ||
const { addToast } = useToastStore(); | ||
const navigate = useNavigate(); | ||
const mutation = useMutation({ | ||
mutationFn: createMapTargerLetter, | ||
onSuccess: () => { | ||
addToast('지도 편지를 전송했습니다.', 'success'); | ||
navigate('/letter/success'); | ||
localStorage.removeItem('maptitle'); | ||
localStorage.removeItem('mapcontent'); | ||
localStorage.removeItem('mapdescription'); | ||
localStorage.removeItem('mapfont'); | ||
localStorage.removeItem('mapletter'); | ||
localStorage.removeItem('maplat'); | ||
localStorage.removeItem('maplot'); | ||
localStorage.removeItem('mapnickname'); | ||
}, | ||
onError: (error) => { | ||
console.error(error); | ||
|
||
addToast('지도 편지를 실패했습니다.', 'error'); | ||
} | ||
}); | ||
return mutation; | ||
}; |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.