From 0897f5e191d2b878740de5cbf1d82897ee98bdd2 Mon Sep 17 00:00:00 2001 From: elaineZhang67 <144281338+elaineZhang67@users.noreply.github.com> Date: Thu, 7 Dec 2023 03:04:45 -0500 Subject: [PATCH 1/2] Update AddEvent.jsx --- front-end/src/components/AddEvent.jsx | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/front-end/src/components/AddEvent.jsx b/front-end/src/components/AddEvent.jsx index 88a159a..4dda111 100644 --- a/front-end/src/components/AddEvent.jsx +++ b/front-end/src/components/AddEvent.jsx @@ -119,33 +119,6 @@ function AddEvent({addEvent, onClose}){ } } -/* - useEffect(() => { - // Retrieve the current user from local storage - const token = localStorage.getItem("token"); - const decodedUser = jwtDecode(token); - if (decodedUser && decodedUser.id) { - console.log(decodedUser.id) - setselectedMember(prevMembers => { - // Check if the current user's ID is already in the selected members - if (prevMembers.some(member => member.id === decodedUser.id)) { - return prevMembers; - } - // Add the current user's ID to the selected members - return [...prevMembers, decodedUser.id]; - }); - } else { - console.error("No valid user found in local storage."); - } - }, []); - */ - - /* - useEffect(() => { - console.log('Selected Members:', selectedMember); - }, [selectedMember]); - */ - const handleSearch = () => { const token = localStorage.getItem("token"); const decodedUser = jwtDecode(token); From 0711e69fc577e00395afd02793d4f8d4846fa7c9 Mon Sep 17 00:00:00 2001 From: elaineZhang67 <144281338+elaineZhang67@users.noreply.github.com> Date: Thu, 7 Dec 2023 03:57:42 -0500 Subject: [PATCH 2/2] fix the time and add events bug --- front-end/src/components/AddEvent.jsx | 9 ++++---- front-end/src/components/Event.js | 28 ++++++++++++------------- front-end/src/components/Events.jsx | 29 ++++++++++++-------------- front-end/src/components/Expense.jsx | 30 +++++++++++++-------------- 4 files changed, 44 insertions(+), 52 deletions(-) diff --git a/front-end/src/components/AddEvent.jsx b/front-end/src/components/AddEvent.jsx index 024c144..26ab02b 100644 --- a/front-end/src/components/AddEvent.jsx +++ b/front-end/src/components/AddEvent.jsx @@ -110,12 +110,11 @@ function AddEvent({ addEvent, onClose }) { if (decodedUser && decodedUser.id) { friendsCL(decodedUser.id); setselectedMember((prevMembers) => { - // Check if the current user's ID is already in the selected members - if (prevMembers.some((member) => member.id === decodedUser.id)) { - return prevMembers; + // Correctly check if the user ID is already in the array + if (!prevMembers.includes(decodedUser.id)) { + return [...prevMembers, decodedUser.id]; } - // Add the current user's ID to the selected members - return [...prevMembers, decodedUser.id]; + return prevMembers; }); } else { } diff --git a/front-end/src/components/Event.js b/front-end/src/components/Event.js index dfc8d2a..a27747a 100644 --- a/front-end/src/components/Event.js +++ b/front-end/src/components/Event.js @@ -11,29 +11,27 @@ const Event = (props) => { const isDarkMode = props.isDarkMode; const { eventId } = useParams(); + function reformatDate(dateStr) { + const months = [ - "Jan", - "Feb", - "Mar", - "Apr", - "May", - "Jun", - "Jul", - "Aug", - "Sep", - "Oct", - "Nov", - "Dec", + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", ]; + + // Create a new Date object in local time zone const date = new Date(dateStr); - - const monthName = months[date.getMonth()]; - const day = date.getDate(); + + // Convert it back to UTC + date.setMinutes(date.getMinutes() + date.getTimezoneOffset()); + + const monthName = months[date.getUTCMonth()]; + const day = date.getUTCDate(); return `${monthName} ${day}`; } + // This effect runs when the `isDarkMode` value changes useEffect(() => { if (isDarkMode) { diff --git a/front-end/src/components/Events.jsx b/front-end/src/components/Events.jsx index 682fbed..302861a 100644 --- a/front-end/src/components/Events.jsx +++ b/front-end/src/components/Events.jsx @@ -15,29 +15,26 @@ function Events({ isDarkMode }) { const [searchTerm, setSearchTerm] = useState(""); function reformatDate(dateStr) { + const months = [ - "Jan", - "Feb", - "Mar", - "Apr", - "May", - "Jun", - "Jul", - "Aug", - "Sep", - "Oct", - "Nov", - "Dec", + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", ]; + + // Create a new Date object in local time zone const date = new Date(dateStr); - - const monthName = months[date.getMonth()]; - const day = date.getDate(); - const year = date.getFullYear(); + + // Convert it back to UTC + date.setMinutes(date.getMinutes() + date.getTimezoneOffset()); + + const monthName = months[date.getUTCMonth()]; + const day = date.getUTCDate(); + const year = date.getUTCFullYear(); return `${monthName} ${day} ${year}`; } + // Toggle the 'body-dark-mode' class on the body element useEffect(() => { if (isDarkMode) { diff --git a/front-end/src/components/Expense.jsx b/front-end/src/components/Expense.jsx index 3521097..5eafd28 100644 --- a/front-end/src/components/Expense.jsx +++ b/front-end/src/components/Expense.jsx @@ -13,30 +13,28 @@ function Expense({ isDarkMode }) { const navigate = useNavigate(); const { expenseId } = useParams(); + function reformatDate(dateStr) { + const months = [ - "Jan", - "Feb", - "Mar", - "Apr", - "May", - "Jun", - "Jul", - "Aug", - "Sep", - "Oct", - "Nov", - "Dec", + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", ]; + + // Create a new Date object in local time zone const date = new Date(dateStr); - - const monthName = months[date.getMonth()]; - const day = date.getDate(); - const year = date.getFullYear(); + + // Convert it back to UTC + date.setMinutes(date.getMinutes() + date.getTimezoneOffset()); + + const monthName = months[date.getUTCMonth()]; + const day = date.getUTCDate(); + const year = date.getUTCFullYear(); return `${monthName} ${day} ${year}`; } + const fetchData = async () => { try { const response = await axios.get(