diff --git a/src/components/Team/addTeamButton.jsx b/src/components/Team/addTeamButton.jsx index a41de58..0757a81 100644 --- a/src/components/Team/addTeamButton.jsx +++ b/src/components/Team/addTeamButton.jsx @@ -2,81 +2,78 @@ import React, { useState } from "react"; import { Plus } from "lucide-react"; import { Button } from "@/components/ui/button"; import { - Dialog, - DialogTrigger, - DialogContent, - DialogHeader, - DialogTitle, - DialogFooter, - DialogClose, + Dialog, + DialogTrigger, + DialogContent, + DialogHeader, + DialogTitle, + DialogFooter, + DialogClose, } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Textarea } from "@/components/ui/textarea"; export default function AddTeamButton({ onCreate, isCreating }) { + const [teamName, setTeamName] = useState(""); + const [teamDesc, setTeamDesc] = useState(""); - const [teamName, setTeamName] = useState(""); - const [teamDesc, setTeamDesc] = useState(""); - + const handleSubmit = () => { + if (!teamName.trim()) return; + onCreate({ + teamName: teamName, + teamDescription: teamDesc, + }); + setTeamName(""); + setTeamDesc(""); + }; - const handleSubmit = () => { - if (!teamName.trim()) return; - onCreate({ - teamName:teamName, - teamDescription:teamDesc - }); - setTeamName(""); - setTeamDesc(""); - }; - - - return ( - - ); + return ( + + ); } diff --git a/src/pages/Dashboard.jsx b/src/pages/Dashboard.jsx index 080ce12..b1084e0 100644 --- a/src/pages/Dashboard.jsx +++ b/src/pages/Dashboard.jsx @@ -84,24 +84,36 @@ const Dashboard = ({ setActiveTab, setSpecData, setTrafficData }) => { // }, // }, // }); - - const [messages, setMessages] = useState([ - { role: "bot", text: "안녕하세요! 무엇을 도와드릴까요?" }, - ]); const [input, setInput] = useState(""); const messagesEndRef = useRef(null); const params = useParams(); const teamCode = params.teamCode; + const inputRef = useRef(null); + // ✅ 팀코드 기반 저장된 메시지 불러오기 + const STORAGE_KEY = `chat_messages_${teamCode}`; + + const [messages, setMessages] = useState(() => { + const saved = sessionStorage.getItem(STORAGE_KEY); + return saved + ? JSON.parse(saved) + : [{ role: "bot", text: "안녕하세요! 무엇을 도와드릴까요?" }]; + }); // 2. useSendMessage 훅을 호출하고, mutate 함수와 로딩 상태(isPending)를 가져옵니다. const { mutate: postPrompt, isPending } = usePostPrompt(); - const scrollToBottom = () => { - messagesEndRef.current?.scrollIntoView({ behavior: "smooth" }); - }; + // const scrollToBottom = () => { + // messagesEndRef.current?.scrollIntoView({ behavior: "smooth" }); + // }; + // ✅ 메시지 저장 useEffect(() => { - scrollToBottom(); + sessionStorage.setItem(STORAGE_KEY, JSON.stringify(messages)); + }, [messages, STORAGE_KEY]); + + // ✅ 스크롤 항상 아래로 + useEffect(() => { + messagesEndRef.current?.scrollIntoView({ behavior: "smooth" }); }, [messages]); const handleSend = (e) => { @@ -149,6 +161,9 @@ const Dashboard = ({ setActiveTab, setSpecData, setTrafficData }) => { }, } ); + if (inputRef.current) { + inputRef.current.style.height = "48px"; + } }; return ( @@ -181,14 +196,31 @@ const Dashboard = ({ setActiveTab, setSpecData, setTrafficData }) => {