- {item && (
-
- )}
-
- {/* 저장된 금액 표시 */}
-
- {annotations ? annotations.map((annotation, idx) => (
-
- )) : ''}
- { modal &&
-
-
-
- setModal(false)}
- sx={{
- position: 'absolute',
- right: 5,
- top: 5,
- zIndex: 111
- }}
- >
-
-
-
-
-
-
- }
+
+
+
+
+ {item && (
+
+ )}
+
+ {/* 저장된 금액 표시 */}
+
+ {annotations
+ ? annotations.map((annotation, idx) => (
+
+ ))
+ : ''}
+ {modal && (
+
+
+
+ setModal(false)}
+ sx={{
+ position: 'absolute',
+ right: 5,
+ top: 5,
+ zIndex: 111
+ }}
+ >
+
+
+
+
+
+
+ )}
+
);
}
-
export default function CarouselAnimation({ ...props }) {
- const { product, data } = props;
+ const { slug, product, data } = props;
const images = product?.images;
const [[page, direction], setPage] = useState([0, 0]);
@@ -133,36 +148,36 @@ export default function CarouselAnimation({ ...props }) {
return (
-
-
- {
- const swipe = swipePower(offset.x, velocity.x);
- if (swipe < -swipeConfidenceThreshold) {
- paginate(1);
- } else if (swipe > swipeConfidenceThreshold) {
- paginate(-1);
- }
- }}
- >
-
-
-
-
+
+ {
+ const swipe = swipePower(offset.x, velocity.x);
+ if (swipe < -swipeConfidenceThreshold) {
+ paginate(1);
+ } else if (swipe > swipeConfidenceThreshold) {
+ paginate(-1);
+ }
+ }}
+ >
+
+
+
+ {/*
))}
-
-
+ */}
+
);
}
CarouselAnimation.propTypes = {
+ slug: PropTypes.string,
product: PropTypes.object,
data: PropTypes.object
};
diff --git a/src/components/chat.jsx b/src/components/chat.jsx
index d792c6a..c8aa51b 100644
--- a/src/components/chat.jsx
+++ b/src/components/chat.jsx
@@ -1,3 +1,4 @@
+import PropTypes from 'prop-types';
import { Stack } from '@mui/material';
import React, { useEffect, useState } from 'react';
import { io } from 'socket.io-client';
@@ -5,7 +6,13 @@ import { useSelector } from 'react-redux';
const socket = io(process.env.BASE_URL); // 서버 URL
-function ChatApp() {
+
+ChatApp.propTypes = {
+ slug: PropTypes.string
+};
+
+function ChatApp({ ...props }) {
+ const { slug } = props;
const { user } = useSelector(({ user }) => user);
const userEmail = user.email;
const adminEmail = 'arkiun@naver.com'; // 관리자 이메일
@@ -18,22 +25,34 @@ function ChatApp() {
socket.emit('join', userEmail);
// 기존 메시지 가져오기
- fetch(`${process.env.BASE_URL}/v1/chat/messages?email=${username},${adminEmail}`)
- .then((res) => res.json())
- .then((data) => setMessages(data));
+ fetch(`${process.env.BASE_URL}/v1/chat/messages?email=${userEmail},${adminEmail}`)
+ .then((res) => {
+ if (!res.ok) {
+ throw new Error('Failed to fetch messages');
+ }
+ return res.json();
+ })
+ .then((data) => setMessages(data))
+ .catch((error) => {
+ console.error('Error fetching messages:', error);
+ });
// 실시간 메시지 수신
socket.on('message', (data) => {
setMessages((prev) => [...prev, data]);
});
+ // Cleanup
return () => {
socket.off('message');
};
- }, [username, adminEmail]);
+ }, [userEmail, adminEmail, slug, username, messages]);
const sendMessage = () => {
- const msg = { username: username, message, targetEmail: adminEmail }; // 관리자 이메일
+ const trimmedMessage = message.trim();
+ if (trimmedMessage === '') return;
+
+ const msg = { username, message: trimmedMessage, targetEmail: adminEmail };
socket.emit('message', msg);
setMessage('');
};