@@ -174,22 +202,11 @@ const Application: NextPage = () => {
color="white"
onClick={handleDeleteApplication}
/>
- {fetchedApplicationData?.application && (
-
- )}
- {applicationData.phone && (
-
- )}
+
)}
From 79f9ed63b12c46d1a13e7e08778e5ce963066488 Mon Sep 17 00:00:00 2001
From: fredrir
Date: Wed, 18 Dec 2024 22:21:08 +0100
Subject: [PATCH 08/11] Fix radiobutton
---
components/form/ApplicationForm.tsx | 23 ++++++++++++++++++-----
components/form/CheckboxInput.tsx | 2 +-
components/form/EditApplicationModal.tsx | 5 +++--
pages/apply/[period-id].tsx | 2 --
4 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/components/form/ApplicationForm.tsx b/components/form/ApplicationForm.tsx
index dcd5180f..a50d5e9f 100644
--- a/components/form/ApplicationForm.tsx
+++ b/components/form/ApplicationForm.tsx
@@ -18,6 +18,7 @@ interface Props {
setApplicationData: Function;
availableCommittees: string[];
optionalCommittees: string[];
+ isEditing?: boolean;
}
export const ApplicationForm = (props: Props) => {
@@ -202,9 +203,17 @@ export const ApplicationForm = (props: Props) => {
["Nei", "nei"],
["Usikker (gjerne spør om mer info på intervjuet)", "kanskje"],
]}
- defaultValue={props.applicationData.bankom ? "ja" : "nei"}
+ defaultValue={
+ props.isEditing
+ ? props.applicationData.bankom === "ja"
+ ? "ja"
+ : props.applicationData.bankom === "nei"
+ ? "nei"
+ : "kanskje"
+ : undefined
+ }
label="Er du interessert i å være økonomiansvarlig i komiteen (tilleggsverv i Bankom)?"
- updateInputValues={(value: boolean) =>
+ updateInputValues={(value: string) =>
props.setApplicationData({
...props.applicationData,
bankom: value,
@@ -215,9 +224,13 @@ export const ApplicationForm = (props: Props) => {
void;
}
@@ -21,7 +20,6 @@ const ApplicationEditModal = ({
optionalCommittees,
periodId,
originalApplicationData,
- isEditing,
setIsEditing,
}: Props) => {
const queryClient = useQueryClient();
@@ -35,6 +33,8 @@ const ApplicationEditModal = ({
phone: originalApplicationData.phone,
grade: originalApplicationData.grade,
about: originalApplicationData.about,
+ bankom: originalApplicationData.bankom,
+
optionalCommittees: originalApplicationData.optionalCommittees,
preferences: originalApplicationData.preferences,
selectedTimes: originalApplicationData.selectedTimes,
@@ -83,6 +83,7 @@ const ApplicationEditModal = ({
setApplicationData={setApplicationData}
availableCommittees={availableCommittees}
optionalCommittees={optionalCommittees}
+ isEditing={true}
/>
diff --git a/pages/apply/[period-id].tsx b/pages/apply/[period-id].tsx
index 2026d85b..c8dbe007 100644
--- a/pages/apply/[period-id].tsx
+++ b/pages/apply/[period-id].tsx
@@ -161,7 +161,6 @@ const Application: NextPage = () => {
optionalCommittees={period?.optionalCommittees || []}
originalApplicationData={fetchedApplicationData.application}
periodId={periodId}
- isEditing={isEditing}
setIsEditing={setIsEditing}
/>
)}
@@ -171,7 +170,6 @@ const Application: NextPage = () => {
optionalCommittees={period?.optionalCommittees || []}
originalApplicationData={applicationData as applicantType}
periodId={periodId}
- isEditing={isEditing}
setIsEditing={setIsEditing}
/>
)}
From 2af45d700860932f17a130036b0b624320cfe752 Mon Sep 17 00:00:00 2001
From: fredrir
Date: Wed, 18 Dec 2024 22:37:19 +0100
Subject: [PATCH 09/11] fix PUT method
---
pages/api/applicants/[period-id]/[id].ts | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/pages/api/applicants/[period-id]/[id].ts b/pages/api/applicants/[period-id]/[id].ts
index c36cbdff..601623ad 100644
--- a/pages/api/applicants/[period-id]/[id].ts
+++ b/pages/api/applicants/[period-id]/[id].ts
@@ -53,16 +53,22 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
if (error) throw new Error(error);
return res.status(204).end();
} else if (req.method === "PUT") {
+ const { application } = req.body;
+
+ if (!application) {
+ return res.status(400).json({ error: "Missing application data" });
+ }
+
const { period } = await getPeriodById(periodId);
if (!period) {
return res.status(400).json({ error: "Invalid period id" });
}
- const requestBody: applicantType = req.body;
- requestBody.periodId = periodId;
+ application.periodId = periodId;
+ application.date = new Date(new Date().getTime() + 60 * 60 * 2000); // add date with norwegain time (GMT+2)
- if (!isApplicantType(requestBody, period)) {
+ if (!isApplicantType(application, period)) {
return res.status(400).json({ error: "Invalid data format" });
}
@@ -70,17 +76,19 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const applicationStart = period.applicationPeriod.start;
const applicationEnd = period.applicationPeriod.end;
+ console.log(now < applicationStart || now > applicationEnd);
+
if (now < applicationStart || now > applicationEnd) {
return res
.status(400)
.json({ error: "Not within the application period" });
}
- if (!isApplicantType(requestBody, period)) {
+ if (!isApplicantType(application, period)) {
return res.status(400).json({ error: "Invalid data format" });
}
- const { error } = await editApplication(id, periodId, requestBody);
+ const { error } = await editApplication(id, periodId, application);
if (error) throw new Error(error);
return res
.status(200)
From b855de57e3c6d709d6e7df1ed162a351fa823d46 Mon Sep 17 00:00:00 2001
From: fredrir
Date: Wed, 18 Dec 2024 22:40:24 +0100
Subject: [PATCH 10/11] fix visual bug
---
pages/apply/[period-id].tsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pages/apply/[period-id].tsx b/pages/apply/[period-id].tsx
index c8dbe007..9e77da0c 100644
--- a/pages/apply/[period-id].tsx
+++ b/pages/apply/[period-id].tsx
@@ -217,7 +217,7 @@ const Application: NextPage = () => {
)}
- {applicationData.phone && (
+ {applicationData.phone && !fetchedApplicationData.application && (
Date: Wed, 18 Dec 2024 22:47:40 +0100
Subject: [PATCH 11/11] add Schedule to edit application
---
components/form/EditApplicationModal.tsx | 71 ++++++++++++++++++++----
pages/api/applicants/[period-id]/[id].ts | 2 -
pages/apply/[period-id].tsx | 8 +--
3 files changed, 63 insertions(+), 18 deletions(-)
diff --git a/components/form/EditApplicationModal.tsx b/components/form/EditApplicationModal.tsx
index 0a2ff59d..d003bafb 100644
--- a/components/form/EditApplicationModal.tsx
+++ b/components/form/EditApplicationModal.tsx
@@ -6,10 +6,14 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
import { editApplicant } from "../../lib/api/applicantApi";
import toast from "react-hot-toast";
import { validateApplication } from "../../lib/utils/validateApplication";
+import { Tabs } from "../Tabs";
+import CheckBoxIcon from "../icons/icons/CheckBoxIcon";
+import { CalendarIcon } from "@heroicons/react/24/outline";
+import Schedule from "../committee/Schedule";
interface Props {
originalApplicationData: applicantType;
- periodId: string;
+ period: periodType;
availableCommittees: string[];
optionalCommittees: string[];
setIsEditing: (isEditing: boolean) => void;
@@ -18,12 +22,12 @@ interface Props {
const ApplicationEditModal = ({
availableCommittees,
optionalCommittees,
- periodId,
+ period,
originalApplicationData,
setIsEditing,
}: Props) => {
const queryClient = useQueryClient();
-
+ const [activeTab, setActiveTab] = useState(0);
const [applicationData, setApplicationData] = useState<
DeepPartial
>({
@@ -45,7 +49,7 @@ const ApplicationEditModal = ({
editApplicationMutation.mutate({
applicant: applicationData as applicantType,
- periodId,
+ periodId: period._id.toString(),
owId: originalApplicationData.owId,
});
};
@@ -54,7 +58,11 @@ const ApplicationEditModal = ({
mutationFn: editApplicant,
onSuccess: () => {
queryClient.invalidateQueries({
- queryKey: ["applicant", periodId, originalApplicationData.owId],
+ queryKey: [
+ "applicant",
+ period._id.toString(),
+ originalApplicationData.owId,
+ ],
});
toast.success("Søknad oppdatert successfully");
setIsEditing(false);
@@ -77,13 +85,52 @@ const ApplicationEditModal = ({