Skip to content

Commit

Permalink
Merge branch 'hacked-branch' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
sindremil authored Sep 22, 2024
2 parents 48b9fc1 + e04ef50 commit acd0fa6
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 95 deletions.
16 changes: 8 additions & 8 deletions lib/mongo/applicants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ export const createApplicant = async (applicantData: applicantType) => {
try {
if (!applicants) await init();

const existingApplicant = await applicants.findOne({
owId: applicantData.owId,
periodId: applicantData.periodId,
});

if (existingApplicant) {
return { error: "409 Application already exists for this period" };
}
// const existingApplicant = await applicants.findOne({
// owId: applicantData.owId,
// periodId: applicantData.periodId,
// });

// if (existingApplicant) {
// return { error: "409 Application already exists for this period" };
// }

const result = await applicants.insertOne(applicantData);
if (result.insertedId) {
Expand Down
88 changes: 44 additions & 44 deletions pages/api/applicants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,50 +65,50 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
optionalCommitteesString = "Ingen";
}

const emailData: emailDataType = {
name: applicant.name,
emails: [applicant.email],
phone: applicant.phone,
grade: applicant.grade,
about: applicant.about.replace(/\n/g, "<br>"),
firstChoice: "Tom",
secondChoice: "Tom",
thirdChoice: "Tom",
bankom:
applicant.bankom == "ja"
? "Ja"
: applicant.bankom == "nei"
? "Nei"
: "Kanskje",
optionalCommittees: optionalCommitteesString,
};

//Type guard
if (!Array.isArray(applicant.preferences)) {
emailData.firstChoice =
applicant.preferences.first == "onlineil"
? "Online IL"
: capitalizeFirstLetter(applicant.preferences.first);
emailData.secondChoice =
applicant.preferences.second == "onlineil"
? "Online IL"
: capitalizeFirstLetter(applicant.preferences.second);
emailData.thirdChoice =
applicant.preferences.third == "onlineil"
? "Online IL"
: capitalizeFirstLetter(applicant.preferences.third);
}

try {
await sendEmail({
toEmails: emailData.emails,
subject: "Vi har mottatt din søknad!",
htmlContent: generateApplicantEmail(emailData),
});
} catch (error) {
console.error("Error sending email: ", error);
throw error;
}
// const emailData: emailDataType = {
// name: applicant.name,
// emails: [applicant.email],
// phone: applicant.phone,
// grade: applicant.grade,
// about: applicant.about.replace(/\n/g, "<br>"),
// firstChoice: "Tom",
// secondChoice: "Tom",
// thirdChoice: "Tom",
// bankom:
// applicant.bankom == "ja"
// ? "Ja"
// : applicant.bankom == "nei"
// ? "Nei"
// : "Kanskje",
// optionalCommittees: optionalCommitteesString,
// };

// //Type guard
// if (!Array.isArray(applicant.preferences)) {
// emailData.firstChoice =
// applicant.preferences.first == "onlineil"
// ? "Online IL"
// : capitalizeFirstLetter(applicant.preferences.first);
// emailData.secondChoice =
// applicant.preferences.second == "onlineil"
// ? "Online IL"
// : capitalizeFirstLetter(applicant.preferences.second);
// emailData.thirdChoice =
// applicant.preferences.third == "onlineil"
// ? "Online IL"
// : capitalizeFirstLetter(applicant.preferences.third);
// }

// try {
// await sendEmail({
// toEmails: emailData.emails,
// subject: "Vi har mottatt din søknad!",
// htmlContent: generateApplicantEmail(emailData),
// });
// } catch (error) {
// console.error("Error sending email: ", error);
// throw error;
// }
}

return res.status(201).json({ applicant });
Expand Down
22 changes: 19 additions & 3 deletions pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,25 @@ export const authOptions: NextAuthOptions = {
email: userInfo.email,
//phone: userInfo.phone_number,
//grade: userInfo.year,
committees: committeeData.results.map((committee: any) =>
committee.name_short.toLowerCase()
),
committees: [
"appkom",
"arrkom",
"backlog",
"bankom",
"bedkom",
"debug",
"dotkom",
"ekskom",
"fagkom",
"feminit",
"jubkom",
"online-il",
"output",
"prokom",
"kjelleren",
"trikom",
"velkom",
],
isCommittee: userInfo.is_committee,
};
},
Expand Down
80 changes: 40 additions & 40 deletions pages/apply/[period-id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,47 +150,47 @@ const Application: NextPage = () => {
if (!periodData?.exists)
return <SimpleTitle title="Opptaket finnes ikke" size="large" />;

if (fetchedApplicationData?.exists)
return (
<div className="flex flex-col items-center justify-center h-full gap-5 px-5 py-10 md:px-40 lg:px-80 dark:text-white">
<WellDoneIllustration className="h-32" />
<p className="max-w-md text-lg text-center">
Vi har mottatt din søknad og sendt deg en bekreftelse på e-post!
</p>
<p className="max-w-md text-lg text-center">
Du vil få enda en e-post med intervjutider når søknadsperioden er over
(rundt {formatDateNorwegian(period?.applicationPeriod?.end)}).
</p>
<p className="max-w-md text-center text-gray-500">
(Hvis du ikke finner e-posten din, sjekk søppelpost- eller
spam-mappen.)
</p>
{!isApplicationPeriodOver && (
<Button
title="Trekk tilbake søknad"
color="white"
onClick={handleDeleteApplication}
/>
)}
{fetchedApplicationData?.application && (
<div className="w-full max-w-md">
<ApplicantCard
applicant={fetchedApplicationData.application}
includePreferences={true}
/>
</div>
)}
// if (fetchedApplicationData?.exists)
// return (
// <div className="flex flex-col items-center justify-center h-full gap-5 px-5 py-10 md:px-40 lg:px-80 dark:text-white">
// <WellDoneIllustration className="h-32" />
// <p className="max-w-md text-lg text-center">
// Vi har mottatt din søknad og sendt deg en bekreftelse på e-post!
// </p>
// <p className="max-w-md text-lg text-center">
// Du vil få enda en e-post med intervjutider når søknadsperioden er over
// (rundt {formatDateNorwegian(period?.applicationPeriod?.end)}).
// </p>
// <p className="max-w-md text-center text-gray-500">
// (Hvis du ikke finner e-posten din, sjekk søppelpost- eller
// spam-mappen.)
// </p>
// {!isApplicationPeriodOver && (
// <Button
// title="Trekk tilbake søknad"
// color="white"
// onClick={handleDeleteApplication}
// />
// )}
// {fetchedApplicationData?.application && (
// <div className="w-full max-w-md">
// <ApplicantCard
// applicant={fetchedApplicationData.application}
// includePreferences={true}
// />
// </div>
// )}

{applicationData.phone && (
<div className="w-full max-w-md">
<ApplicantCard
applicant={applicationData as applicantType}
includePreferences={true}
/>
</div>
)}
</div>
);
// {applicationData.phone && (
// <div className="w-full max-w-md">
// <ApplicantCard
// applicant={applicationData as applicantType}
// includePreferences={true}
// />
// </div>
// )}
// </div>
// );

return (
<div>
Expand Down

0 comments on commit acd0fa6

Please sign in to comment.