Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions src/APIFunctions/SCEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ApiResponse } from './ApiResponses';

const SCEVENTS_API_URL = 'http://localhost:8002';

// ======== ORIGINAL BACKEND API REQUESTS ========
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this comment

export async function getAllSCEvents() {
const status = new ApiResponse();
try {
Expand Down Expand Up @@ -55,3 +56,94 @@ export async function createSCEvent(eventBody) {
}
return status;
}

export async function updateSCEvent(id, userId, eventUpdates) {
const status = new ApiResponse();
try {
const res = await fetch(`${SCEVENTS_API_URL}/events/${id}?user_id=${userId}`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(eventUpdates),
});
const body = await res.json();
status.responseData = body;
if (!res.ok) {
status.error = true;
}
} catch (err) {
status.error = true;
status.responseData = err;
}
return status;
}
// =================================================


// ======== MOCKED LOCAL STORAGE VERSIONS ========
// const getMockEvents = () => {
// const data = localStorage.getItem('mockSCEvents');
// // Initialize with empty array if null
// return data ? JSON.parse(data) : [];
// };

// const setMockEvents = (events) => {
// localStorage.setItem('mockSCEvents', JSON.stringify(events));
// };

// export async function getAllSCEvents() {
// const status = new ApiResponse();
// // Simulated network delay
// await new Promise(resolve => setTimeout(resolve, 300));
// status.responseData = getMockEvents();
// status.error = false;
// return status;
// }

// export async function getEventByID(id) {
// const status = new ApiResponse();
// await new Promise(resolve => setTimeout(resolve, 300));
// const events = getMockEvents();
// const event = events.find(e => e.id === id || e._id === id);
// if (event) {
// status.responseData = event;
// status.error = false;
// } else {
// status.error = true;
// status.responseData = 'Event not found in mock local storage.';
// }
// return status;
// }

// export async function createSCEvent(eventBody) {
// const status = new ApiResponse();
// await new Promise(resolve => setTimeout(resolve, 300));
// const events = getMockEvents();
// // Simulate backend appending the event
// events.push(eventBody);
// setMockEvents(events);

// status.responseData = eventBody;
// status.error = false;
// return status;
// }

// export async function updateSCEvent(id, userId, eventUpdates) {
// const status = new ApiResponse();
// await new Promise(resolve => setTimeout(resolve, 300));
// const events = getMockEvents();
// const index = events.findIndex(e => e.id === id || e._id === id);
// if (index !== -1) {
// // Note: A real backend would verify `userId` here, but for simple mocked testing:
// events[index] = { ...events[index], ...eventUpdates };
// setMockEvents(events);

// status.responseData = { message: 'Updated successfully in mock local storage' };
// status.error = false;
// } else {
// status.error = true;
// status.responseData = 'Event not found in mock local storage.';
// }
// return status;
// }
19 changes: 17 additions & 2 deletions src/Components/context/SceContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,26 @@ import React, { createContext, useContext } from 'react';

export const SceContext = createContext({
user: {},
setUser: () => {},
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this change needed? if not please remove so we don't cherry pick

setUser: () => { },
authenticated: false,
setAuthenticated: () => {},
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

setAuthenticated: () => { },
});

// ======== ORIGINAL useSCE LOGIC ========
export function useSCE() {
return useContext(SceContext);
}
// ==========================================

// ======== MOCKED VERSION FOR TESTING ========
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again im confused why we have a mock version; was there a reason why we didn't just use Clark locally?

// export function useSCE() {
// const context = useContext(SceContext);
// return {
// ...context,
// user: {
// ...context.user,
// accessLevel: 3, // Temporarily forced to ADMIN for testing
// _id: context.user?._id || 'mocked-id-for-testing'
// }
// };
// }
4 changes: 2 additions & 2 deletions src/Pages/Events/CreateEventPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ export default function CreateEventPage() {
return (
<div className="m-10 max-w-4xl px-4 sm:px-6">
<div className="mb-8 pt-8 pb-2">
<Link to="/events" className="block pb-3 text-sm link link-primary">
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm... this probably doesn't belong in this PR but it's fine

← Events
<Link to="/events" className="btn btn-ghost normal-case text-base pl-0 mb-4 font-medium text-gray-400 hover:text-white hover:bg-transparent">
Back to Events
</Link>
<h1 className="pb-3 text-4xl font-extrabold leading-tight tracking-tight text-gray-900 md:text-5xl dark:text-white">
Create event
Expand Down
Loading
Loading