Skip to content

Commit

Permalink
Merge pull request #56 from devsoc-unsw/feature/event-management
Browse files Browse the repository at this point in the history
Feature/event management
  • Loading branch information
Gyoumi authored Dec 15, 2024
2 parents 812218e + a0b47cb commit 932f580
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 36 deletions.
4 changes: 2 additions & 2 deletions backend/src/config/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const uploadFile = async (
throw new Error(error.message);
}
console.log(data);
return data.path;
return (await getFileUrl(data.path)).publicUrl;
};

export const getFile = async (path: string) => {
Expand All @@ -62,7 +62,7 @@ export const getFileUrl = async (path: string) => {
throw new Error('Storage client not initialised.');
}

const { data } = await storageClient.from('images').getPublicUrl(path);
const { data } = storageClient.from('images').getPublicUrl(path);

return data;
};
9 changes: 1 addition & 8 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -745,15 +745,8 @@ app.put('/event', async (req: TypedRequest<UpdateEventBody>, res: Response) => {
description: req.body.description,
},
});
// we are choosing to send the image back as a url
let imageFile;
try {
imageFile = await getFileUrl(event.banner); // getFile(event.banner) if we wanted raw file
} catch (error) {
return res.status(400).json({ error: (error as Error).message });
}

return res.status(200).json({ ...event, banner: imageFile });
return res.status(200).json(eventRes);
} catch (e) {
return res.status(400).json({ message: 'Invalid event input' });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,47 @@ import { Link, useLocation } from 'react-router';
import Button from '../../../Button/Button';
import { ButtonIcons, ButtonVariants } from '../../../Button/ButtonTypes';
import { SettingsPage } from '../SettingsPage';
import { useEffect } from 'react';
import { useContext, useEffect, useState } from 'react';
import classes from './EventManagementPage.module.css';
import { UserContext } from '../../../UserContext/UserContext';

interface SocietyEvent {
banner: string,
description: string,
id: number,
startDateTime: Date,
endDateTime: Date,
location: string,
name: string,
societyId: number,
}

export function EventManagementPage() {
const location = useLocation();
const { creationSuccess } = location.state;
const { creationSuccess } = location.state ? location.state : { creationSuccess: false };
const { society } = useContext(UserContext);
const [events, setEvents] = useState<SocietyEvent[]>([]);

useEffect(() => {
const getEvents = async () => {
const events = await fetch(
'http://localhost:5180/society/events?' +
new URLSearchParams({
id: '1',
}),
{
method: 'GET',
credentials: 'include',
}
);

if (events.ok) {
const eventsJson = await events.json();
console.log(eventsJson);
}
};
getEvents();
}, []);
if(society) {
const getEvents = async () => {
const events = await fetch(
'http://localhost:5180/society/events?' +
new URLSearchParams({
id: String(society?.id),
}),
{
method: 'GET',
credentials: 'include',
}
);

const eventsJson: SocietyEvent[] = await events.json();
setEvents(eventsJson.map((event) => {return {...event, startDateTime: new Date(event.startDateTime), endDateTime: new Date(event.endDateTime)}}));
};
getEvents();
}
}, [society]);

return (
<SettingsPage
Expand Down Expand Up @@ -57,7 +71,15 @@ export function EventManagementPage() {
<th>Where</th>
</tr>
</thead>
<tbody></tbody>
<tbody>
{events && events.map((event) =>
<tr>
<td>{event.name}</td>
<td>{event.endDateTime.toLocaleDateString('en-GB')}</td>
<td>{event.location}</td>
</tr>
)}
</tbody>
</table>
</SettingsPage>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.dropdown {

}

.container {
position: absolute;
right: 0;
Expand Down

0 comments on commit 932f580

Please sign in to comment.