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
73 changes: 28 additions & 45 deletions src/actions/common-server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,68 +56,51 @@ export async function markPayment(
);
}

export type BasicRegistrationInfo = {
export type RegistrationInfo = {
eventId: number;
participant: ParticipantState;
comments: string | null;
additionalInfos?: FacultyDinnerInfo | HelloWorldInfo;
};

export type FacultyDinnerInfo = {
meal;
allergies;
plus_ones;
guest;
meal: number;
allergies: string;
plusOnes: number;
guest: boolean;
};

export type HelloWorldInfo = {
team;
team: string;
};

export type RegistrationInfo = BasicRegistrationInfo &
(FacultyDinnerInfo | HelloWorldInfo | {});

export async function sendRegistration(
{ eventId, participant, comments }: RegistrationInfo,
{ meal, allergies, plus_ones, guest }: FacultyDinnerInfo = {
meal: null,
allergies: null,
plus_ones: null,
guest: null,
},
{ team }: HelloWorldInfo = { team: null }
) {
const event = await directus().request(readItem('events', eventId));
export async function sendRegistration(info: RegistrationInfo) {
const event = await directus().request(readItem('events', info.eventId));

if (!event.opened) {
throw new Error('Not opened');
}

const eventRegistration = {
event: eventId,
email: participant.email.toLowerCase(),
first_name: participant.firstName,
family_name: participant.lastName,
year: participant.year,
section: participant.section,
comments,
// Faculty Dinner
meal,
allergies,
plusOnes: plus_ones,
guest,
// Hello World
team,
// ICBD
checked_in: false,
retreived_deposit: false,
can_retreive_deposit: false,
registration_complete: false,
// Clothes
order_complete: false,
};

const createdRegistration = await directus().request(
createItems('registrations', [eventRegistration])
createItems('registrations', [
{
event: info.eventId,
email: info.participant.email.toLowerCase(),
first_name: info.participant.firstName,
family_name: info.participant.lastName,
year: info.participant.year,
section: info.participant.section,
comments: info.comments,
// ICBD
checked_in: false,
retreived_deposit: false,
can_retreive_deposit: false,
registration_complete: false,
// Clothes
order_complete: false,
...(info.additionalInfos || {}),
},
])
);

return createdRegistration[0].id;
Expand Down
4 changes: 1 addition & 3 deletions src/app/[eventSlug]/guest/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ export default async function GuestForm({ params }) {

switch (event.type) {
case 'faculty_dinner':
return (
<FacultyDinnerForm event={event} guest={true} />
);
return <FacultyDinnerForm event={event} guest />;
default:
return notFound();
}
Expand Down
6 changes: 2 additions & 4 deletions src/app/[eventSlug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default async function Home({ params }) {
'background_color',
'icbd_event',
'location',
//@ts-expect-error
//@ts-expect-error
{ translations: ['*'] },
],
filter: {
Expand All @@ -54,9 +54,7 @@ export default async function Home({ params }) {
case 'icbd':
return <ICBD event={event}></ICBD>;
case 'faculty_dinner':
return (
<FacultyDinnerForm event={event} guest={false} />
);
return <FacultyDinnerForm event={event} guest={false} />;
case 'hello_world':
return <HelloWorldForm event={event} />;
case 'faculty_clothes_sale':
Expand Down
9 changes: 6 additions & 3 deletions src/components/forms/FacultyDinnerForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,13 @@ function Form({
section: guest ? 'Guest' : s.participant.section,
year: guest ? 'Guest' : s.participant.year,
},
meal: s.mealId,
comments: s.comments,
plus_ones: guest ? s.plus_ones : 0,
guest,
additionalInfos: {
meal: s.mealId,
allergies: s.comments,
plusOnes: guest ? s.plus_ones : 0,
guest,
},
});
setField('formState', FormStates.Confirmation);
} catch (error) {
Expand Down
4 changes: 3 additions & 1 deletion src/components/forms/HelloWorldForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,10 @@ function Form({
await sendRegistration({
eventId,
participant: member,
team: s.team,
comments: s.comments,
additionalInfos: {
team: s.team,
},
});
}
setField('formState', FormStates.Confirmation);
Expand Down
5 changes: 1 addition & 4 deletions src/components/forms/ICBDForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,7 @@ export default function ICBDForm({
interviews: { title: string; time: string; id: number }[];
}) {
// Info items
const infoItems: [ElementType, ReactNode][] = makeInfoItems(
event,
true
);
const infoItems: [ElementType, ReactNode][] = makeInfoItems(event, true);

// Define initial state
const initialState: State = {
Expand Down
4 changes: 1 addition & 3 deletions src/components/forms/PullFacForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ export default function FacultyClothesForm({
}) {
// Info items
// Skip the date, since this is just an order
const infoItems: [ElementType, ReactNode][] = makeInfoItems(
event,
).slice(1);
const infoItems: [ElementType, ReactNode][] = makeInfoItems(event).slice(1);

// Define initial state
const initialState: State = {
Expand Down
Loading