-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0c153e
commit a3dc2c6
Showing
9 changed files
with
169 additions
and
109 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { CouponModal } from '@/pages/payment/components'; | ||
import { couponStore } from '@/stores/modal'; | ||
import { createPortal } from 'react-dom'; | ||
|
||
const CouponPortal = () => { | ||
const { | ||
close, | ||
couponValue: { open }, | ||
} = couponStore(); | ||
const $portal_root = document.getElementById('content-portal'); | ||
return ( | ||
<> | ||
{$portal_root | ||
? createPortal(<div>{open && <CouponModal close={close} />}</div>, $portal_root) | ||
: null} | ||
</> | ||
); | ||
}; | ||
|
||
export default CouponPortal; |
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,9 +1,17 @@ | ||
import { createPortal } from 'react-dom'; | ||
import { Notification } from '.'; | ||
import { memberStore } from '@/stores/member'; | ||
|
||
const NotificationPortal = () => { | ||
const isLogin = !!memberStore((state) => state.accessToken); | ||
const $portal_root = document.getElementById('notification-portal'); | ||
return <>{$portal_root ? createPortal(<Notification />, $portal_root) : null}</>; | ||
return ( | ||
<> | ||
{$portal_root | ||
? createPortal(<div>{isLogin && <Notification />}</div>, $portal_root) | ||
: null} | ||
</> | ||
); | ||
}; | ||
|
||
export default NotificationPortal; |
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,88 @@ | ||
import { useState } from 'react'; | ||
import SockJS from 'sockjs-client'; | ||
import { Client, IMessage } from '@stomp/stompjs'; | ||
import { ChatMessageRequest, ChatMessageResponse } from '@/types/chat'; | ||
|
||
export const useStomp = ( | ||
chatRoomId: number, | ||
accessToken: string, | ||
callback: (msg: ChatMessageResponse) => void, | ||
) => { | ||
const [client, setClient] = useState<Client | null>(null); | ||
|
||
const connect = () => { | ||
const socket = new SockJS(import.meta.env.VITE_SOCKET_URL); | ||
|
||
const client = new Client({ | ||
webSocketFactory: () => socket, | ||
connectHeaders: { | ||
Authorization: `Bearer ${accessToken}`, | ||
}, | ||
reconnectDelay: 5000, | ||
debug: (str) => { | ||
console.log(str); | ||
}, | ||
onConnect: () => { | ||
console.log('Websocket 연결'); | ||
subscribe(); | ||
setClient(client); | ||
}, | ||
}); | ||
|
||
// 에러 메세지 | ||
client.onStompError = (frame) => { | ||
console.error('Stomp error: ' + frame.headers['message']); | ||
console.error('Additional details: ' + frame.body); | ||
}; | ||
|
||
client.onWebSocketError = (event) => { | ||
console.error('WebSocket Error:', event); | ||
}; | ||
|
||
client.onWebSocketClose = (event) => { | ||
console.error('WebSocket Closed:', event); | ||
}; | ||
|
||
client.activate(); | ||
}; | ||
|
||
// callback 함수 수정 | ||
const subscribe = () => { | ||
client?.subscribe( | ||
`/sub/ws/${chatRoomId}`, | ||
(message: IMessage) => { | ||
if (message.body) { | ||
try { | ||
const messageData: ChatMessageResponse = JSON.parse(message.body); | ||
callback(messageData); | ||
} catch (error) { | ||
console.error('Error:', error); | ||
} | ||
} | ||
}, | ||
{ | ||
Authorization: `Bearer ${accessToken}`, | ||
}, | ||
); | ||
console.log('socket 구독'); | ||
}; | ||
|
||
const disconnect = () => { | ||
client?.deactivate(); | ||
setClient(null); | ||
console.log('WebSocket 연결 종료'); | ||
}; | ||
|
||
const sendMessage = (destination: string, content: ChatMessageRequest) => { | ||
if (client && client.connected) { | ||
client.publish({ destination, body: JSON.stringify(content) }); | ||
console.log('메세지 전송'); | ||
} else { | ||
console.error('WebSocket 연결 애러'); | ||
} | ||
}; | ||
|
||
return { connect, disconnect, sendMessage }; | ||
}; | ||
|
||
export default useStomp; |
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