-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from lotteon2/develop
Develop
- Loading branch information
Showing
37 changed files
with
11,376 additions
and
110 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
REACT_APP_API_URL=https://e62e9111-4ca7-4984-93da-a6b562b71a83.mock.pstmn.io | ||
REACT_APP_INICIS=imp31336811 | ||
# REACT_APP_API_URL=https://e62e9111-4ca7-4984-93da-a6b562b71a83.mock.pstmn.io | ||
REACT_APP_INICIS=imp31336811 | ||
REACT_APP_API_URL=https://jeontongju-dev.shop |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import APIService from '../../libs/core/api/APIService'; | ||
import { ReadAllNotiResponse, ReadNotiByNotiIdResponse } from './notificationAPIService.types'; | ||
|
||
const BASE_URL = `${process.env.REACT_APP_API_URL}/order-service/api`; | ||
|
||
class NotificationAPIService extends APIService { | ||
constructor() { | ||
super(); | ||
this.setBaseUrl(BASE_URL); | ||
} | ||
|
||
async readAllNoti() { | ||
const { data } = await this.patch<ReadAllNotiResponse>(`/notification-service/api/notifications`); | ||
return data; | ||
} | ||
|
||
async readNotiByNotiId(notificationId: number) { | ||
const { data } = await this.patch<ReadNotiByNotiIdResponse>( | ||
`/notification-service/api/consumers/notifications/${notificationId}`, | ||
); | ||
return data; | ||
} | ||
} | ||
export const notiApi: NotificationAPIService = NotificationAPIService.shared(); |
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,11 @@ | ||
interface ApiResponse<T> { | ||
code: number; | ||
message: string; | ||
detail?: string; | ||
data: T; | ||
failure?: string; | ||
} | ||
|
||
export type ReadAllNotiResponse = ApiResponse<string>; | ||
|
||
export type ReadNotiByNotiIdResponse = ApiResponse<string>; |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,153 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { EventSourcePolyfill, NativeEventSource } from 'event-source-polyfill'; | ||
import styled from '@emotion/styled'; | ||
import FiSrBellSVG from '../../assets/images/fi-sr-bell.svg'; | ||
import NewFiSrBellSVG from '../../assets/images/fi-sr-new-bell.svg'; | ||
import { Toast } from './Toast'; | ||
import { notiApi } from '../../apis/notification/notificationAPIService'; | ||
|
||
const Notification = () => { | ||
const [newNoti, setNewNoti] = useState<string[]>([]); | ||
const [notiOpen, setNotiOpen] = useState<boolean>(false); | ||
|
||
useEffect(() => { | ||
if (typeof window !== 'undefined') { | ||
const accessToken = localStorage.getItem('accessToken'); | ||
if (!accessToken) return; | ||
|
||
const EventSource = EventSourcePolyfill || NativeEventSource; | ||
const eventSource = new EventSource( | ||
'https://jeontongju-dev.shop/notification-service/api/notifications/connect', | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
Connection: 'keep-alive', | ||
Accept: 'text/event-stream', | ||
}, | ||
heartbeatTimeout: 86400000, | ||
withCredentials: true, | ||
}, | ||
); | ||
|
||
eventSource.onopen = () => { | ||
console.log('OPEN'); | ||
|
||
eventSource.removeEventListener('connect', () => { | ||
console.log('remove connect'); | ||
}); | ||
eventSource.removeEventListener('happy', () => { | ||
console.log('remove happy'); | ||
}); | ||
|
||
eventSource.addEventListener('happy', (event: any) => { | ||
console.log(event); | ||
const currNoti = event.data; | ||
console.log('HI'); | ||
setNewNoti((prev) => [...prev, currNoti]); | ||
}); | ||
|
||
eventSource.addEventListener('connect', (event: any) => { | ||
console.log(event); | ||
const { data: receivedConnectData } = event; | ||
if (receivedConnectData === 'SSE 연결이 완료되었습니다.') { | ||
console.log('SSE CONNECTED'); | ||
} else { | ||
console.log(event); | ||
} | ||
}); | ||
}; | ||
|
||
/* eslint-disable consistent-return */ | ||
return () => { | ||
eventSource.close(); | ||
console.log('SSE CLOSED'); | ||
}; | ||
} | ||
}, []); | ||
|
||
const handleOpenNoti = () => { | ||
setNotiOpen((prev: boolean) => !prev); | ||
}; | ||
|
||
const handleAllRead = async () => { | ||
try { | ||
const data = await notiApi.readAllNoti(); | ||
if (data.code === 200) { | ||
Toast(true, '전체 읽음 처리에 성공했어요.'); | ||
setNewNoti([]); | ||
} | ||
} catch (error) { | ||
Toast(false, '전체 읽음 처리에 실패했어요'); | ||
} | ||
}; | ||
|
||
const handleReadByNotiId = async () => { | ||
try { | ||
const data = await notiApi.readNotiByNotiId(1); | ||
if (data.code === 200) { | ||
Toast(true, '전체 읽음 처리에 성공했어요.'); | ||
setNewNoti([]); | ||
} | ||
} catch (error) { | ||
Toast(false, '전체 읽음 처리에 실패했어요'); | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<img | ||
alt="bell" | ||
width={0} | ||
height={0} | ||
src={newNoti.length > 0 ? NewFiSrBellSVG : FiSrBellSVG} | ||
style={{ | ||
cursor: 'pointer', | ||
width: '2rem', | ||
height: '2rem', | ||
position: 'relative', | ||
}} | ||
onClick={handleOpenNoti} | ||
role="presentation" | ||
/> | ||
|
||
{notiOpen && | ||
(newNoti.length === 0 ? ( | ||
<StyledAlarmBox>알람 확인 완료 끝!</StyledAlarmBox> | ||
) : ( | ||
<StyledAlarmBox> | ||
<StyledReadButton role="presentation" onClick={handleAllRead}> | ||
전체 읽음 | ||
</StyledReadButton> | ||
{newNoti.map((it, i: number) => ( | ||
<StyledAlarmDiv key={i} onClick={() => handleReadByNotiId()}> | ||
{it} | ||
</StyledAlarmDiv> | ||
))} | ||
</StyledAlarmBox> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Notification; | ||
|
||
const StyledAlarmBox = styled.div` | ||
border: 1px solid #ccc; | ||
padding: 1rem 2rem; | ||
border-radius: 12px; | ||
position: absolute; | ||
z-index: 100; | ||
background-color: white; | ||
max-height: 10rem; | ||
overflow-y: scroll; | ||
`; | ||
|
||
const StyledAlarmDiv = styled.div` | ||
padding: 0.5rem 0; | ||
`; | ||
|
||
const StyledReadButton = styled.div` | ||
text-align: right; | ||
margin-bottom: 0.5rem; | ||
cursor: pointer; | ||
`; |
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.