Skip to content
Snippets Groups Projects
Commit 09faa4d8 authored by Min Dong Hyeun's avatar Min Dong Hyeun
Browse files
parents d6f7689b 494e2a03
No related branches found
No related tags found
No related merge requests found
...@@ -6,62 +6,34 @@ import PasswordModal from "./PasswordModal.jsx"; ...@@ -6,62 +6,34 @@ import PasswordModal from "./PasswordModal.jsx";
import "../styles/ResultEnd.css"; import "../styles/ResultEnd.css";
import "../styles/CalendarWeek.css"; import "../styles/CalendarWeek.css";
function formatDateTime(dateTime) { function formatDateTime(date, timeIndex) {
console.log("원본 시간 데이터:", dateTime); // 원본 데이터 로그 const year = date.substring(0, 4);
const month = date.substring(5, 7);
const parts = dateTime.split("-"); const day = date.substring(8, 10);
const datePart = parts.slice(0, 3).join("-"); const hours = Math.floor(timeIndex / 2)
const timePart = parseInt(parts[3], 10);
const hours = Math.floor(timePart / 2);
const minutes = (timePart % 2) * 30;
// UTC 시간으로 변환
const utcDate = new Date(
`${datePart}T${hours.toString().padStart(2, "0")}:${minutes
.toString() .toString()
.padStart(2, "0")}:00Z` .padStart(2, "0");
); const minutes = (timeIndex % 2) * 30;
const year = utcDate.getUTCFullYear();
const month = (utcDate.getUTCMonth() + 1).toString().padStart(2, "0");
const day = utcDate.getUTCDate().toString().padStart(2, "0");
const utcHours = utcDate.getUTCHours().toString().padStart(2, "0");
const utcMinutes = utcDate.getUTCMinutes().toString().padStart(2, "0");
const formattedDateTime = `${year}${month}${day}${utcHours}${utcMinutes}분`;
return formattedDateTime; return `${year}${month}${day}${hours}${minutes
.toString()
.padStart(2, "0")}분`;
} }
function formatConfirmedTime(isoString) { function formatKSTDateTime(utcDateTime) {
const utcDate = new Date(isoString); const date = new Date(utcDateTime);
const kstDate = new Date(utcDate.getTime() + 9 * 60 * 60 * 1000); // UTC+9 시간을 더함
const year = kstDate.getFullYear(); const year = date.getFullYear();
const month = (kstDate.getMonth() + 1).toString().padStart(2, "0"); const month = (date.getMonth() + 1).toString().padStart(2, "0");
const day = kstDate.getDate().toString().padStart(2, "0"); const day = date.getDate().toString().padStart(2, "0");
const hours = kstDate.getHours().toString().padStart(2, "0"); const hours = date.getHours().toString().padStart(2, "0");
const minutes = kstDate.getMinutes().toString().padStart(2, "0"); const minutes = date.getMinutes().toString().padStart(2, "0");
return ( if (minutes === "00") {
`${year}${month}${day}${hours}시` + return `${year}${month}${day}${hours}시`;
(minutes !== "00" ? ` ${minutes}분` : "") } else {
); return `${year}${month}${day}${hours}${minutes}분`;
} }
function convertToISOFormat(dateTimeString) {
const parts = dateTimeString.split("-");
const datePart = parts.slice(0, 3).join("-");
const timePart = parts[3];
const hours = Math.floor(parseInt(timePart, 10) / 2);
const minutes = (parseInt(timePart, 10) % 2) * 30;
// 지역 시간을 생성 (KST)
const localDate = new Date(`${datePart} ${hours}:${minutes}:00`);
// UTC 시간으로 변환
const utcDate = new Date(localDate.getTime() - 9 * 60 * 60 * 1000);
return utcDate.toISOString();
} }
export default function ResultEndForm() { export default function ResultEndForm() {
...@@ -71,20 +43,21 @@ export default function ResultEndForm() { ...@@ -71,20 +43,21 @@ export default function ResultEndForm() {
const [hoveredInfo, setHoveredInfo] = useState(null); const [hoveredInfo, setHoveredInfo] = useState(null);
const { meeting_id } = useParams(); const { meeting_id } = useParams();
const [isModalOpen, setIsModalOpen] = useState(false); const [isModalOpen, setIsModalOpen] = useState(false);
const [topThreeConfirmedTimes, setTopThreeConfirmedTimes] = useState([]);
const purposeText = { const purposeText = {
STUDY: "스터디", STUDY: "스터디를 진행하는 ",
MEETING: "회의", MEETING: "회의를 진행하는 ",
PLAYING: "놀기", PLAYING: "노는 약속을 잡은 ",
FOOD: "식사", FOOD: "식사를 하는 ",
ETC: "기타", ETC: "기타의 모임을 잡은 ",
}; };
console.log(possibleDates);
const fetchMeetingData = async () => { const fetchMeetingData = async () => {
try { try {
const response = await fetch(`/meetings/${meeting_id}/details`); const response = await fetch(`/meetings/${meeting_id}/details`);
const data = await response.json(); const data = await response.json();
setMeetingData(data); setMeetingData(data);
// 가능한 시간 집계
let availabilityMap = {}; let availabilityMap = {};
data.participants.forEach((participant) => { data.participants.forEach((participant) => {
participant.availableSchedules.forEach((schedule) => { participant.availableSchedules.forEach((schedule) => {
...@@ -98,12 +71,10 @@ export default function ResultEndForm() { ...@@ -98,12 +71,10 @@ export default function ResultEndForm() {
}); });
}); });
// 가장 많이 겹치는 시간 찾기
const sortedAvailability = Object.entries(availabilityMap).sort( const sortedAvailability = Object.entries(availabilityMap).sort(
(a, b) => b[1] - a[1] (a, b) => b[1] - a[1]
); );
// 겹치는 시간이 가장 많은 상위 항목만 뽑기
const mostAvailableTimes = sortedAvailability const mostAvailableTimes = sortedAvailability
.filter((item, index, arr) => item[1] === arr[0][1]) .filter((item, index, arr) => item[1] === arr[0][1])
.map((item) => item[0]); .map((item) => item[0]);
...@@ -117,6 +88,26 @@ export default function ResultEndForm() { ...@@ -117,6 +88,26 @@ export default function ResultEndForm() {
fetchMeetingData(); fetchMeetingData();
}, [meeting_id]); }, [meeting_id]);
useEffect(() => {
const fetchTop3Time = async () => {
try {
if (meetingData && meetingData.purpose) {
const response = await axios.get(
`/meetings/top-three-confirmed-times`,
{
params: { purpose: meetingData.purpose },
withCredentials: true,
}
);
setTopThreeConfirmedTimes(response.data.topThreeConfirmedTimes);
}
} catch (error) {
console.error("Top 3 시간대 가져오기 실패:", error);
}
};
fetchTop3Time();
}, [meetingData]);
const handleDateChange = (event) => { const handleDateChange = (event) => {
setSelectedDate(event.target.value); setSelectedDate(event.target.value);
}; };
...@@ -126,6 +117,23 @@ export default function ResultEndForm() { ...@@ -126,6 +117,23 @@ export default function ResultEndForm() {
alert("시간을 선택해주세요."); alert("시간을 선택해주세요.");
return; return;
} }
const lastIndex = selectedDate.lastIndexOf("-");
const date = selectedDate.substring(0, lastIndex);
const timeIndex = selectedDate.substring(lastIndex + 1);
const hours = Math.floor(parseInt(timeIndex) / 2);
const minutes = (parseInt(timeIndex) % 2) * 30;
const kstDate = new Date(
`${date}T${hours.toString().padStart(2, "0")}:${minutes
.toString()
.padStart(2, "0")}:00.000+09:00`
);
const utcTimeISO = kstDate.toISOString();
setSelectedDate(utcTimeISO);
setIsModalOpen(true); setIsModalOpen(true);
}; };
...@@ -133,7 +141,22 @@ export default function ResultEndForm() { ...@@ -133,7 +141,22 @@ export default function ResultEndForm() {
if (possibleDates.length > 0) { if (possibleDates.length > 0) {
const randomIndex = Math.floor(Math.random() * possibleDates.length); const randomIndex = Math.floor(Math.random() * possibleDates.length);
const randomDateTime = possibleDates[randomIndex]; const randomDateTime = possibleDates[randomIndex];
setSelectedDate(randomDateTime);
const lastIndex = randomDateTime.lastIndexOf("-");
const date = randomDateTime.substring(0, lastIndex);
const timeIndex = randomDateTime.substring(lastIndex + 1);
const hours = Math.floor(parseInt(timeIndex) / 2);
const minutes = (parseInt(timeIndex) % 2) * 30;
const kstDate = new Date(
`${date}T${hours.toString().padStart(2, "0")}:${minutes
.toString()
.padStart(2, "0")}:00.000+09:00`
);
const utcTimeISO = kstDate.toISOString();
setSelectedDate(utcTimeISO);
setIsModalOpen(true); setIsModalOpen(true);
} else { } else {
alert("선택 가능한 날짜와 시간이 없습니다."); alert("선택 가능한 날짜와 시간이 없습니다.");
...@@ -147,12 +170,11 @@ export default function ResultEndForm() { ...@@ -147,12 +170,11 @@ export default function ResultEndForm() {
const handlePasswordSubmit = async (password) => { const handlePasswordSubmit = async (password) => {
setIsModalOpen(false); setIsModalOpen(false);
try { try {
const confirmedTimeISO = convertToISOFormat(selectedDate);
const response = await axios.patch( const response = await axios.patch(
`http://localhost:3000/meetings/${meeting_id}/confirm-time`, `/meetings/${meeting_id}/confirm-time`,
{ {
adminPassword: password, adminPassword: password,
confirmedTime: confirmedTimeISO, confirmedTime: selectedDate, // UTC로 조정된 시간
} }
); );
...@@ -167,6 +189,7 @@ export default function ResultEndForm() { ...@@ -167,6 +189,7 @@ export default function ResultEndForm() {
} }
} }
}; };
if (!meetingData) { if (!meetingData) {
return <div>로딩 중...</div>; return <div>로딩 중...</div>;
} }
...@@ -187,7 +210,7 @@ export default function ResultEndForm() { ...@@ -187,7 +210,7 @@ export default function ResultEndForm() {
{meetingData.confirmedTime && ( {meetingData.confirmedTime && (
<div> <div>
<p style={{ color: "blue" }}> <p style={{ color: "blue" }}>
약속 시간은 {formatConfirmedTime(meetingData.confirmedTime)} 약속 시간은 {formatKSTDateTime(meetingData.confirmedTime)}
입니다. 입니다.
</p> </p>
<div> <div>
...@@ -199,13 +222,22 @@ export default function ResultEndForm() { ...@@ -199,13 +222,22 @@ export default function ResultEndForm() {
{!meetingData.confirmedTime && ( {!meetingData.confirmedTime && (
<span className="closedFalse"> <span className="closedFalse">
<p> <p>
{meetingData.purpose && purposeText[meetingData.purpose]}를 하는 {meetingData.purpose && purposeText[meetingData.purpose]}
다른 사람들은 주로 평일 낮 시간대에 많이 만나요 다른 사람들은 주로{" "}
{topThreeConfirmedTimes
.map((time) => `${time.hour}시`)
.join(", ")}
에 많이 만나요
</p> </p>
<form className="form-container"> <form className="form-container">
{possibleDates.length > 0 ? ( {possibleDates.length > 0 ? (
possibleDates.map((dateTime, index) => ( possibleDates.map((dateTime, index) => {
const lastIndex = dateTime.lastIndexOf("-");
const date = dateTime.slice(0, lastIndex);
const timeIndex = dateTime.slice(lastIndex + 1);
return (
<label key={index}> <label key={index}>
<input <input
type="radio" type="radio"
...@@ -214,9 +246,10 @@ export default function ResultEndForm() { ...@@ -214,9 +246,10 @@ export default function ResultEndForm() {
checked={selectedDate === dateTime} checked={selectedDate === dateTime}
onChange={handleDateChange} onChange={handleDateChange}
/> />
{formatDateTime(dateTime)} {formatDateTime(date, parseInt(timeIndex))}
</label> </label>
)) );
})
) : ( ) : (
<h2>겹치는 시간대가 없습니다.</h2> <h2>겹치는 시간대가 없습니다.</h2>
)} )}
......
...@@ -18,10 +18,9 @@ function ResultMakeForm() { ...@@ -18,10 +18,9 @@ function ResultMakeForm() {
const fetchMeetingData = async () => { const fetchMeetingData = async () => {
setIsLoading(true); setIsLoading(true);
try { try {
const response = await axios.get( const response = await axios.get(`/meetings/${meeting_id}/details`, {
`http://localhost:3000/meetings/${meeting_id}/details`, withCredentials: true,
{ withCredentials: true } });
);
setMeetingData(response.data); setMeetingData(response.data);
setIsLoading(false); setIsLoading(false);
} catch (error) { } catch (error) {
...@@ -38,11 +37,16 @@ function ResultMakeForm() { ...@@ -38,11 +37,16 @@ function ResultMakeForm() {
if (!meetingData || !meetingData.voteExpiresAt) { if (!meetingData || !meetingData.voteExpiresAt) {
return { days: 0, hours: 0, minutes: 0, seconds: 0 }; return { days: 0, hours: 0, minutes: 0, seconds: 0 };
} }
const nowUTC = new Date(
new Date().getTime() + new Date().getTimezoneOffset() * 60 * 1000 // 서버의 voteExpiresAt 값을 한국 시간대로 가정하여 파싱
); const voteExpiresKST = new Date(meetingData.voteExpiresAt);
const voteExpiresUTC = new Date(meetingData.voteExpiresAt);
const difference = voteExpiresUTC - nowUTC; // 현재 로컬 시간 (브라우저 시간대를 한국 시간대로 조정)
const now = new Date();
const nowKST = new Date(now.getTime() + 9 * 60 * 60 * 1000); // UTC 시간에 9시간을 더해 KST로 조정
// 남은 시간 계산
const difference = voteExpiresKST - nowKST;
if (difference > 0) { if (difference > 0) {
return { return {
...@@ -72,9 +76,7 @@ function ResultMakeForm() { ...@@ -72,9 +76,7 @@ function ResultMakeForm() {
const handleEdit = async () => { const handleEdit = async () => {
try { try {
const response = await axios.get( const response = await axios.get(`/meetings/${meeting_id}/`);
`http://localhost:3000/meetings/${meeting_id}/`
);
const { const {
startDate, startDate,
endDate, endDate,
...@@ -84,7 +86,7 @@ function ResultMakeForm() { ...@@ -84,7 +86,7 @@ function ResultMakeForm() {
try { try {
const scheduleResponse = await axios.get( const scheduleResponse = await axios.get(
`http://localhost:3000/meetings/${meeting_id}/my/schedules` `/meetings/${meeting_id}/my/schedules`
); );
navigate(`/homeparticipate/${meeting_id}/usertimeinfo/`, { navigate(`/homeparticipate/${meeting_id}/usertimeinfo/`, {
state: { state: {
...@@ -115,7 +117,7 @@ function ResultMakeForm() { ...@@ -115,7 +117,7 @@ function ResultMakeForm() {
const handlePasswordSubmit = async (password) => { const handlePasswordSubmit = async (password) => {
setIsModalOpen(false); setIsModalOpen(false);
try { try {
await axios.patch(`http://localhost:3000/meetings/${meeting_id}/close`, { await axios.patch(`/meetings/${meeting_id}/close`, {
adminPassword: password, adminPassword: password,
}); });
navigate(`/resultend/${meeting_id}`); navigate(`/resultend/${meeting_id}`);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment