Skip to content

Commit

Permalink
divide event attendee list into attendees and ppl on waitlist
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikskog committed Sep 22, 2023
1 parent 9bc9494 commit d6bacd4
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .env.localow4
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
OW4_SSO_CLIENT_ID='837461'
OW4_ADDRESS='http://localhost:8000
8 changes: 8 additions & 0 deletions src/events/api/publicAttendee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ import { IPublicAttendee } from 'events/models/Attendee';
import { getUser } from 'authentication/api';

const getPublicAttendeesUrl = (eventId: number) => `/api/v1/event/attendance-events/${eventId}/public-attendees/`;
const getPublicUsersOnWaitlistUrl = (eventId: number) =>
`/api/v1/event/attendance-events/${eventId}/public-on-waitlist/`;

export const getPublicAttendeesForEvent = async (eventId: number) => {
const user = await getUser();
const attendees = await get<IPublicAttendee[]>(getPublicAttendeesUrl(eventId), { format: 'json' }, { user });
return attendees;
};

export const getPublicUsersOnWaitlistForEvent = async (eventId: number) => {
const user = await getUser();
const attendees = await get<IPublicAttendee[]>(getPublicUsersOnWaitlistUrl(eventId), { format: 'json' }, { user });
return attendees;
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,20 @@ interface IAttendeeListProps {

const AttendeeList: FC<IAttendeeListProps> = ({ attendees }) => (
<div className={style.grid}>
{attendees.map((attendee, index) => (
<Attendee key={attendee.id} attendee={attendee} count={index + 1} />
))}
<hr />
Påmeldt
{attendees
.filter((att) => !att.waitlist)
.map((attendee, index) => (
<Attendee key={attendee.id} attendee={attendee} count={index + 1} />
))}
<hr />
På venteliste
{attendees
.filter((att) => att.waitlist)
.map((attendee, index) => (
<Attendee key={attendee.id} attendee={attendee} count={index + 1} />
))}
</div>
);

Expand Down
1 change: 1 addition & 0 deletions src/events/models/Attendee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ export interface IPublicAttendee {
full_name: string;
year_of_study: number;
field_of_study: string;
waitlist: boolean;
}
9 changes: 7 additions & 2 deletions src/events/slices/publicAttendees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createAsyncThunk, createEntityAdapter, createSlice, SerializedError } f

import { State } from 'core/redux/Store';
import { IPublicAttendee } from 'events/models/Attendee';
import { getPublicAttendeesForEvent } from 'events/api/publicAttendee';
import { getPublicAttendeesForEvent, getPublicUsersOnWaitlistForEvent } from 'events/api/publicAttendee';

const publicAttendeesAdapter = createEntityAdapter<IPublicAttendee>({
sortComparer: (attendeeA, attendeeB) => {
Expand All @@ -16,7 +16,12 @@ export const fetchPublicAttendeesByEventId = createAsyncThunk(
'publicAttendees/fetchByEventId',
async (eventId: number) => {
const attendees = await getPublicAttendeesForEvent(eventId);
return attendees;
const onWaitlist = await getPublicUsersOnWaitlistForEvent(eventId);

// merge the two arrays, using waitlist true or false
const mergedAttendees = attendees.map((attendee) => ({ ...attendee, waitlist: false }));
const mergedOnWaitlist = onWaitlist.map((attendee) => ({ ...attendee, waitlist: true }));
return [...mergedAttendees, ...mergedOnWaitlist];
}
);

Expand Down

1 comment on commit d6bacd4

@vercel
Copy link

@vercel vercel bot commented on d6bacd4 Sep 22, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.