Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into env-support
Browse files Browse the repository at this point in the history
  • Loading branch information
jzgom067 authored Dec 10, 2024
2 parents c8247c6 + 5bd86a9 commit dbb6ab1
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 291 deletions.
60 changes: 7 additions & 53 deletions src/pages/Availability.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ export default function Availability() {
const location = useLocation();
const { eventName2, isUpdating } = location.state || {};

console.log(eventName2);
console.log(isUpdating);

console.log('RAN');

function getCookieValue(cookieName) {
const cookies = document.cookie.split('; ');
for (const cookie of cookies) {
Expand All @@ -29,15 +24,12 @@ export default function Availability() {
}

let x = document.cookie;
console.log(x);

const eventCode = getCookieValue('code');
var userEmail = getCookieValue('login_email');
var userPW = getCookieValue('login_password');
var guestEmail = getCookieValue('guest_email');
var guestPW = getCookieValue('guest_password');
console.log('Code cookie:', eventCode);
console.log('email', userEmail);

const { isDarkMode, toggleTheme } = useTheme();

Expand Down Expand Up @@ -171,18 +163,12 @@ export default function Availability() {
async function handleEventDetails() {
try {
const data = {
// email: '[email protected]',
// password: '123',
event_code: eventCode,
};

console.log('Before user check:', data);

// Wait for check_user to complete
await check_user(data);

console.log('After user check:', data);

// Proceed with fetch after check_user completes
const response = await fetch(
import.meta.env.VITE_API_HOST + '/event_details',
Expand All @@ -200,7 +186,6 @@ export default function Availability() {
}

const eventData = await response.json();
console.log('Event details:', eventData);

// Update state based on the event details
setEventDetails(eventData);
Expand All @@ -211,7 +196,7 @@ export default function Availability() {
}

if (eventCode) {
handleEventDetails(); // Call the async function
handleEventDetails();
}
}, [eventCode]);

Expand All @@ -230,16 +215,11 @@ export default function Availability() {
} = data;
setEventName(title);

console.log(event_type);
console.log(all_dates[0].weekdayName);

var daysArray = [];
const weekdaysArray = [];
if (event_type == 'date_range') {
const startDate = new Date(start_date + ' ' + start_time);
const endDate = new Date(end_date + ' ' + end_time);
console.log(startDate);
console.log(endDate);

// Format the dates to the desired format
const formattedStartDate = startDate.toLocaleDateString('en-US', {
Expand Down Expand Up @@ -272,7 +252,6 @@ export default function Availability() {
} else {
setIsGenericWeek(true);
setEventDates(`${start_day} - ${end_day}`);
console.log('here');

const abbreviations = all_dates[0].weekdayName.map((day) => {
switch (day) {
Expand Down Expand Up @@ -315,7 +294,6 @@ export default function Availability() {
setTotalDays(daysArray.length);
};

console.log('ALLDAYS', allDays);
const displayedDays = allDays.slice(
currentPage * daysPerPage,
(currentPage + 1) * daysPerPage
Expand All @@ -326,12 +304,9 @@ export default function Availability() {
(currentPage + 1) * daysPerPage
);

console.log('CurrentPage: ', currentPage);
console.log('TOTAL DAYS: ', totalDays);

useEffect(() => {
console.log('Availability updated:', availability);
}, [availability]);
// useEffect(() => {
// console.log('Availability updated:', availability);
// }, [availability]);

const goToPrevPage = () => {
if (currentPage > 0) {
Expand Down Expand Up @@ -411,7 +386,6 @@ export default function Availability() {
return;
}
const transposedAvailability = transpose(availability);
console.log(transposedAvailability);

var credentials = {
event_code: eventCode,
Expand All @@ -420,13 +394,8 @@ export default function Availability() {
};

if (isUpdating === true) {
console.log('UPDATINGGGGGGGGGGGGGGGGGGGG');
console.log(availability);

check_user(credentials);

console.log(credentials);

try {
const response = await fetch(
import.meta.env.VITE_API_HOST + '/update_availability',
Expand All @@ -438,15 +407,13 @@ export default function Availability() {
body: JSON.stringify(credentials),
}
);
console.log(credentials);

if (response.ok) {
const result = await response.json();
console.log(result.message);
if (result.message.localeCompare('Availability updated') === 0) {
navigate('/dashboard');
} else {
console.log(result);
}

// session management with dashboard
} else {
console.error('Failed to record time:', response.statusText);
Expand All @@ -455,15 +422,10 @@ export default function Availability() {
console.error('Error:', error);
}
} else {
console.log('Ran this random thing');
// console.log(name);
// console.log(availability);

if (userEmail == null && userPW == null) {
if (guestEmail != null && guestPW != null) {
credentials.guest_id = parseInt(guestEmail);
credentials.guest_password = guestPW;
console.log('SET GUEST STUFF');
} else {
await fetch(import.meta.env.VITE_API_HOST + '/create_guest', {
method: 'GET',
Expand All @@ -475,15 +437,12 @@ export default function Availability() {
.then((data) => {
credentials.guest_id = data.guest_id;
credentials.guest_password = data.guest_password;
console.log(credentials.guest_id);
});
}
console.log('HEREEEEFORTHEUSERAND');
} else {
credentials.email = userEmail;
credentials.password = userPW;
}
console.log(credentials);
try {
const response = await fetch(
import.meta.env.VITE_API_HOST + '/add_availability',
Expand All @@ -495,17 +454,14 @@ export default function Availability() {
body: JSON.stringify(credentials),
}
);
console.log(credentials);

if (response.ok) {
const result = await response.json();

if (result.message != 'Availability added') {
handleError(result.message);
return;
}
console.log('Time Set Successfully', result);

// session management with dashboard
navigate('/results', { state: { eventCode, eventName } });
} else {
console.error('Failed to record time:', response.statusText);
Expand All @@ -516,8 +472,6 @@ export default function Availability() {
}
};

console.log('EVENT DATES', eventDates);

return (
<div
className={`relative flex flex-col min-h-screen lg:h-[100vh] p-4 ${isDarkMode ? 'bg-[#3E505B]' : 'bg-[#F5F5F5]'}`}
Expand Down
6 changes: 3 additions & 3 deletions src/pages/ConfirmCreated.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ export default function ConfirmCreated() {
const navigate = useNavigate();
const location = useLocation();
const { eventCode, eventName } = location.state || {};
console.log('here');
console.log(eventName);

document.cookie = 'code=' + eventCode;
console.log(document.cookie);

const { isDarkMode, toggleTheme } = useTheme();

const [copySuccess, setCopySuccess] = useState(false);

const handleCopy = () => {
// Please uncomment this when the server does have HTTPS certifications

// navigator.clipboard
// .writeText(eventCode)
// .then(() => {
Expand Down
13 changes: 0 additions & 13 deletions src/pages/CreateEvent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ export default function CreateEvent() {

const get_event_data = async () => {
const data = {
// email: '[email protected]',
// password: '123',
title: eventName,
description: eventDescription,
duration: parseInt(selectedInterval),
Expand All @@ -164,7 +162,6 @@ export default function CreateEvent() {

const cookies = document.cookie; // Get all cookies as a single string
const cookieObj = {};
console.log('Ran here 1');

cookies.split(';').forEach((cookie) => {
const [key, value] = cookie.split('=').map((part) => part.trim());
Expand Down Expand Up @@ -212,8 +209,6 @@ export default function CreateEvent() {
}
}

console.log('data sent:', data);

if (selectDaysOfWeek) {
data.event_type = 'generic_week';
data.start_day = selectedStartDay.toLowerCase();
Expand All @@ -222,13 +217,8 @@ export default function CreateEvent() {
data.event_type = 'date_range';
data.start_date = startCalendarDay;
data.end_date = endCalendarDay;
console.log(data.start_date);
console.log(data.end_date);
}

console.log(data);
console.log('works');

try {
const response = await fetch(
import.meta.env.VITE_API_HOST + '/create_event',
Expand All @@ -243,11 +233,8 @@ export default function CreateEvent() {

if (response.ok) {
const responseData = await response.json();
console.log('Response Data:', responseData);
console.log(responseData);

if (responseData.message != 'Event created') {
console.log('ERROR');
handleError(responseData.message);
return;
}
Expand Down
20 changes: 5 additions & 15 deletions src/pages/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function deleteAllCookies() {
}

const check_user = async (dataToUse) => {
const cookies = document.cookie; // Get all cookies as a single string
const cookies = document.cookie;
const cookieObj = {};

cookies.split(';').forEach((cookie) => {
Expand All @@ -27,7 +27,7 @@ const check_user = async (dataToUse) => {
const parsedValue = JSON.parse(decodeURIComponent(value));
cookieObj[key] = String(parsedValue);
} catch {
cookieObj[key] = String(decodeURIComponent(value)); // Handle plain strings
cookieObj[key] = String(decodeURIComponent(value));
}
}
});
Expand Down Expand Up @@ -86,6 +86,7 @@ export default function Dashboard() {
}
document.body.removeChild(textArea);

// Please uncomment this when the server does have HTTPS certifications
// try {
// navigator.clipboard.writeText(event.code).then(() => {
// setNotification('Link copied to clipboard');
Expand All @@ -107,29 +108,21 @@ export default function Dashboard() {
};

const handleEditEvent = async (event) => {
console.log('ran');
console.log(event);
try {
const codeChange = `code=${encodeURIComponent(JSON.stringify(event.code))}; path=/;`;
document.cookie = codeChange;
navigate('/availability', {
state: { eventName2: event.title, isUpdating: true },
});
// console.log(event);
// navigate(data.editUrl);
} catch (error) {
console.error('Error editing availability:', error);
}
};

const get_all_events = async () => {
const data = {
// email: '[email protected]',
// password: '123',
};
const data = {};

check_user(data);
console.log(data);

try {
const response = await fetch(
Expand All @@ -145,8 +138,6 @@ export default function Dashboard() {

if (response.ok) {
const result = await response.json();
console.log('Events retrieved successfully', result);
console.log(result);
const createdEvents = result.my_events;
const participatingEvents = result.other_events;

Expand All @@ -162,11 +153,10 @@ export default function Dashboard() {
}

setArrayTwo(alpha);
// console.log(mockIndividualEvents);

id = 1;
var beta = [];
for (const [key, value] of Object.entries(participatingEvents)) {
console.log(key, value);
const myDictionary = {};
myDictionary.id = id;
myDictionary.code = key;
Expand Down
7 changes: 0 additions & 7 deletions src/pages/Landing.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ export default function Landing() {
const { isDarkMode, toggleTheme } = useTheme();
const { isSmallScreen, isLargeScreen } = useScreenSize();

// document.cookie = 'code=' + code;
console.log(document.cookie);

const handelFocus = () => {
setIsFocused;
};

return (
<div
className={`z-50 relative flex flex-col items-center min-h-screen px-4 sm:px-8 ${
Expand Down
Loading

0 comments on commit dbb6ab1

Please sign in to comment.