Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

divide event attendee list into attendees and ppl on waitlist #693

Merged
merged 1 commit into from
Sep 22, 2023
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
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