Skip to content
Merged
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
11 changes: 11 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ http {
}

#Load balancer
location /api/scevents/ {
resolver 127.0.0.11 valid=15s;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

set $upstream http://scevents-server:8002;
rewrite ^/api/scevents/?(.*)$ /$1 break;
proxy_pass $upstream;
}
location /api {
proxy_pass http://mainendpoints;
}
Expand Down
3 changes: 2 additions & 1 deletion src/APIFunctions/SCEvents.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ApiResponse } from './ApiResponses';
import config from '../config/config.json';

const SCEVENTS_API_URL = 'http://localhost:8002';
const SCEVENTS_API_URL = config.SCEvents?.BASE_URL || '/api/scevents';
export async function getAllSCEvents() {
const status = new ApiResponse();
try {
Expand Down
29 changes: 13 additions & 16 deletions src/Components/Navbar/AdminNavbar.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import { useSCE } from '../context/SceContext';
import config from '../../config/config.json';
import { membershipState } from '../../Enums';

export default function UserNavBar(props) {
Expand Down Expand Up @@ -44,27 +43,25 @@ export default function UserNavBar(props) {
];

const sceventsAdminNavLinks = [];
if (config.SCEvents?.ENABLED) {
sceventsAdminNavLinks.push({
title: 'Events',
route: '/events',
icon: (
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor" className="w-6 h-6">
<path strokeLinecap="round" strokeLinejoin="round" d="M6.75 3v2.25M17.25 3v2.25M3 18.75V7.5a2.25 2.25 0 0 1 2.25-2.25h13.5A2.25 2.25 0 0 1 21 7.5v11.25m-18 0A2.25 2.25 0 0 0 5.25 21h13.5a2.25 2.25 0 0 0 2.25-2.25m-18 0v-7.5A2.25 2.25 0 0 1 5.25 9h13.5a2.25 2.25 0 0 1 2.25 2.25v7.5" />
</svg>
),
});
if (user?.accessLevel >= membershipState.OFFICER) {
sceventsAdminNavLinks.push({
title: 'Events',
route: '/events',
title: 'Create event',
route: '/events/create',
icon: (
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor" className="w-6 h-6">
<path strokeLinecap="round" strokeLinejoin="round" d="M6.75 3v2.25M17.25 3v2.25M3 18.75V7.5a2.25 2.25 0 0 1 2.25-2.25h13.5A2.25 2.25 0 0 1 21 7.5v11.25m-18 0A2.25 2.25 0 0 0 5.25 21h13.5a2.25 2.25 0 0 0 2.25-2.25m-18 0v-7.5A2.25 2.25 0 0 1 5.25 9h13.5a2.25 2.25 0 0 1 2.25 2.25v7.5" />
<path strokeLinecap="round" strokeLinejoin="round" d="M12 4.5v15m7.5-7.5h-15" />
</svg>
),
});
if (user?.accessLevel >= membershipState.OFFICER) {
sceventsAdminNavLinks.push({
title: 'Create event',
route: '/events/create',
icon: (
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor" className="w-6 h-6">
<path strokeLinecap="round" strokeLinejoin="round" d="M12 4.5v15m7.5-7.5h-15" />
</svg>
),
});
}
}

const adminLinks = [
Expand Down
3 changes: 0 additions & 3 deletions src/Components/Navbar/UserNavbar.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useState, useEffect, useRef } from 'react';
import { membershipState } from '../../Enums';
import { useSCE } from '../context/SceContext';
import config from '../../config/config.json';

export default function UserNavbar(props) {
const { user, authenticated } = useSCE();
Expand All @@ -15,14 +14,12 @@ export default function UserNavbar(props) {
{ title: 'About', route: '/about' },
{ title: 'Projects', route: '/projects' },
{ title: 'Summer Internship', route: '/s/internship', newTab: true },
...(config.SCEvents?.ENABLED ? [{ title: 'Events', route: '/events' }] : []),
];

const authedRoutes = [
{ title: 'Printing', route: '/2DPrinting' },
{ title: 'Chat', route: '/messaging' },
{ title: 'LED Sign', route: '/led-sign' },
...(config.SCEvents?.ENABLED ? [{ title: 'Events', route: '/events' }] : []),
];

const authentication = [
Expand Down
8 changes: 1 addition & 7 deletions src/Pages/Events/CreateEventPage.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/* eslint-disable camelcase -- mirrors SCEvents JSON field names in state and payloads */
import React, { useMemo, useState } from 'react';
import { Link, useHistory, Redirect } from 'react-router-dom';
import { Link, useHistory } from 'react-router-dom';
import { useSCE } from '../../Components/context/SceContext.js';
import { createSCEvent } from '../../APIFunctions/SCEvents.js';
import CreateEventFormQuestionBlock from './CreateEventFormQuestionBlock.js';
import { membershipState } from '../../Enums';
import config from '../../config/config.json';

/** Matches SCEvents `max_attendees` when there is no cap. */
const UNLIMITED_ATTENDEES = -1;
Expand Down Expand Up @@ -71,7 +70,6 @@ function toApiRegistrationForm(questions) {
export default function CreateEventPage() {
const { user } = useSCE();
const history = useHistory();
const isSCEventsEnabled = config.SCEvents?.ENABLED;

const [eventId] = useState(() => crypto.randomUUID());
const [eventName, setEventName] = useState('');
Expand Down Expand Up @@ -234,10 +232,6 @@ export default function CreateEventPage() {
history.push('/events');
}

if (!isSCEventsEnabled) {
return <Redirect to="/notfound" />;
}

if (!isOfficerOrAdmin) {
return (
<div className="m-10">
Expand Down
14 changes: 2 additions & 12 deletions src/Pages/Events/EditEventPage.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/* eslint-disable camelcase -- mirrors SCEvents JSON field names in state and payloads */
import React, { useMemo, useState, useEffect } from 'react';
import { Link, useHistory, useParams, Redirect } from 'react-router-dom';
import { Link, useHistory, useParams } from 'react-router-dom';
import { useSCE } from '../../Components/context/SceContext.js';
import { getEventByID, updateSCEvent } from '../../APIFunctions/SCEvents.js';
import CreateEventFormQuestionBlock from './CreateEventFormQuestionBlock.js';
import { membershipState } from '../../Enums';
import config from '../../config/config.json';

/** Matches SCEvents `max_attendees` when there is no cap. */
const UNLIMITED_ATTENDEES = -1;
Expand Down Expand Up @@ -46,7 +45,6 @@ export default function EditEventPage() {
const { id } = useParams();
const { user } = useSCE();
const history = useHistory();
const isSCEventsEnabled = config.SCEvents?.ENABLED;

const [isLoading, setIsLoading] = useState(true);
const [fetchError, setFetchError] = useState('');
Expand Down Expand Up @@ -96,12 +94,8 @@ export default function EditEventPage() {
setEventAdmins(evt.admins || []);
}

if (!isSCEventsEnabled) {
return;
}

loadEvent();
}, [id, isSCEventsEnabled]);
}, [id]);

function addQuestion() {
setQuestions((prev) => [...prev, newQuestionTemplate()]);
Expand Down Expand Up @@ -229,10 +223,6 @@ export default function EditEventPage() {
history.push('/events');
}

if (!isSCEventsEnabled) {
return <Redirect to="/notfound" />;
}

if (!isOfficerOrAdmin) {
return (
<div className="m-10">
Expand Down
12 changes: 2 additions & 10 deletions src/Pages/Events/Events.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useEffect, useState } from 'react';
import config from '../../config/config.json';
import { Link, Redirect } from 'react-router-dom';
import { Link } from 'react-router-dom';
import { getAllSCEvents, getEventAttendanceSummary } from '../../APIFunctions/SCEvents';
import { useSCE } from '../../Components/context/SceContext';
import { membershipState } from '../../Enums';
Expand Down Expand Up @@ -281,14 +280,11 @@ export default function EventsPage() {
const [isLoading, setIsLoading] = useState(true);
const [hasError, setHasError] = useState(false);

const isSCEventsEnabled = config.SCEvents?.ENABLED;
const canCreateEvent = user?.accessLevel >= membershipState.OFFICER;
const visibleEvents = events.filter((event) => canUserSeeEvent(event, user));
const isAdminView = canCreateEvent;

useEffect(() => {
if (!isSCEventsEnabled) return;

async function fetchEvents() {
setIsLoading(true);
setHasError(false);
Expand All @@ -305,11 +301,7 @@ export default function EventsPage() {
}

fetchEvents();
}, [isSCEventsEnabled]);

if (!isSCEventsEnabled) {
return <Redirect to="/notfound" />;
}
}, []);

return (
<div className="relative min-h-screen overflow-hidden bg-gradient-to-r from-gray-800 to-gray-600 text-white">
Expand Down
18 changes: 4 additions & 14 deletions src/Pages/Events/EventsRegistation.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable camelcase -- mirrors SCEvents JSON field names in state and payloads */
import React, { useState, useEffect } from 'react';
import { useParams, useHistory, Redirect } from 'react-router-dom';
import config from '../../config/config.json';
import { useParams, useHistory } from 'react-router-dom';
import { useSCE } from '../../Components/context/SceContext';
import { getEventByID, getEventAttendanceSummary, registerForSCEvent } from '../../APIFunctions/SCEvents';

Expand All @@ -24,7 +23,6 @@ export default function EventRegistration() {
const { user } = useSCE();
const { id } = useParams();
const history = useHistory();
const isSCEventsEnabled = Boolean(config.SCEvents?.ENABLED);
const [event, setEvent] = useState(null);
const [formData, setFormData] = useState({});
const [isLoading, setIsLoading] = useState(true);
Expand All @@ -36,10 +34,6 @@ export default function EventRegistration() {
const [attendanceLoading, setAttendanceLoading] = useState(false);

useEffect(() => {
if (!isSCEventsEnabled) {
return;
}

async function fetchEvent() {
setIsLoading(true);
setHasError(false);
Expand All @@ -58,10 +52,10 @@ export default function EventRegistration() {
setIsLoading(false);
}
fetchEvent();
}, [id, isSCEventsEnabled]);
}, [id]);

useEffect(() => {
if (!isSCEventsEnabled || !id) {
if (!id) {
return;
}
let isCurrent = true;
Expand All @@ -86,11 +80,7 @@ export default function EventRegistration() {
return () => {
isCurrent = false;
};
}, [id, isSCEventsEnabled]);

if (!isSCEventsEnabled) {
return <Redirect to="/notfound" />;
}
}, [id]);

const handleInputChange = (fieldId, value, type) => {
if (type === 'checkbox') {
Expand Down
13 changes: 8 additions & 5 deletions src/Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ export const officerOrAdminRoutes = [
redirect: '/',
inAdminNavbar: false
},
{
Component: EventsPage,
path: '/events',
pageName: 'Events',
allowedIf: allowedIf.OFFICER_OR_ADMIN,
redirect: '/',
inAdminNavbar: true
},
...memberRoutes,
];

Expand Down Expand Up @@ -217,11 +225,6 @@ export const signedOutRoutes = [
path: '/projects',
pageName: 'Projects'
},
{
Component: EventsPage,
path: '/events',
pageName: 'Events'
},
{
Component: EventRegistration,
path: '/events/:id/register',
Expand Down
2 changes: 1 addition & 1 deletion src/config/config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"TINYMCE_API_KEY": "XXXXXXXXXXXXXXXXXXXXX",
"GOOGLE_API_CLIENT_ID": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com",
"SCEvents": {
"ENABLED": false
"BASE_URL": "/api/scevents"
}
}
Loading