diff --git a/components/committee/CommitteApplicants.tsx b/components/committee/CommitteApplicants.tsx index 2a4cd078..18bd65ef 100644 --- a/components/committee/CommitteApplicants.tsx +++ b/components/committee/CommitteApplicants.tsx @@ -30,10 +30,6 @@ const CommitteeApplicants: NextPage = ({ routeString }) => { filteredPeriods.map((period: periodType) => { return { name: period.name, - preparation: - formatDate(period.preparationPeriod.start) + - " til " + - formatDate(period.preparationPeriod.end), application: formatDate(period.applicationPeriod.start) + " til " + @@ -58,7 +54,6 @@ const CommitteeApplicants: NextPage = ({ routeString }) => { const periodsColumns = [ { label: "Navn", field: "name" }, - { label: "Forberedelse", field: "preparation" }, { label: "Søknad", field: "application" }, { label: "Intervju", field: "interview" }, ]; diff --git a/lib/mongo/periods.ts b/lib/mongo/periods.ts index 2be006e2..d677a4d0 100644 --- a/lib/mongo/periods.ts +++ b/lib/mongo/periods.ts @@ -63,11 +63,6 @@ export const getCurrentPeriods = async () => { const filter = { $or: [ - { - // Check if current ISO date string is within the preparation period - "preparationPeriod.start": { $lte: currentDate }, - "preparationPeriod.end": { $gte: currentDate }, - }, { // Check if current ISO date string is within the application period "applicationPeriod.start": { $lte: currentDate }, diff --git a/lib/types/types.ts b/lib/types/types.ts index f1e28104..79807105 100644 --- a/lib/types/types.ts +++ b/lib/types/types.ts @@ -66,10 +66,6 @@ export type periodType = { _id: ObjectId; name: string; description: string; - preparationPeriod: { - start: Date; - end: Date; - }; applicationPeriod: { start: Date; end: Date; diff --git a/lib/utils/PeriodValidator.ts b/lib/utils/PeriodValidator.ts index 7d4e43d3..2f343b90 100644 --- a/lib/utils/PeriodValidator.ts +++ b/lib/utils/PeriodValidator.ts @@ -4,8 +4,6 @@ import { DeepPartial, periodType } from "../types/types"; export const validatePeriod = ( periodData: DeepPartial ): boolean => { - const prepStart = periodData.preparationPeriod?.start; - const prepEnd = periodData.preparationPeriod?.end; const appStart = periodData.applicationPeriod?.start; const appEnd = periodData.applicationPeriod?.end; const intStart = periodData.interviewPeriod?.start; @@ -14,32 +12,18 @@ export const validatePeriod = ( const optionalCommittees = periodData.optionalCommittees; // Check for undefined or empty fields - if ( - !periodData.name || - !prepStart || - !prepEnd || - !appStart || - !appEnd || - !intStart || - !intEnd - ) { + if (!periodData.name || !appStart || !appEnd || !intStart || !intEnd) { toast.error("Alle feltene må fylles ut."); return false; } - // Check date sequence and overlaps - if (prepEnd > appStart) { - toast.error("Forberedelsesperioden må slutte før søknadsperioden starter."); - return false; - } - if (appEnd > intStart) { toast.error("Søknadsperioden må slutte før intervju perioden starter."); return false; } // Check for overlapping dates within the same period - if (prepStart > prepEnd || appStart > appEnd || intStart > intEnd) { + if (appStart > appEnd || intStart > intEnd) { toast.error("Startdatoer må være før sluttdatoer."); return false; } diff --git a/lib/utils/validators.ts b/lib/utils/validators.ts index eaf1d6c3..845ff253 100644 --- a/lib/utils/validators.ts +++ b/lib/utils/validators.ts @@ -84,15 +84,12 @@ export const isPeriodType = (data: any): data is periodType => { }; const arePeriodsValid = ( - preparationPeriod: any, applicationPeriod: any, interviewPeriod: any ): boolean => { return ( - isChronological(preparationPeriod.start, preparationPeriod.end) && isChronological(applicationPeriod.start, applicationPeriod.end) && isChronological(interviewPeriod.start, interviewPeriod.end) && - new Date(preparationPeriod.end) <= new Date(applicationPeriod.start) && new Date(applicationPeriod.end) <= new Date(interviewPeriod.start) ); }; @@ -100,16 +97,11 @@ export const isPeriodType = (data: any): data is periodType => { const hasBasicFields = typeof data.name === "string" && typeof data.description === "string" && - isValidPeriod(data.preparationPeriod) && isValidPeriod(data.applicationPeriod) && isValidPeriod(data.interviewPeriod) && Array.isArray(data.committees) && data.committees.every((committee: any) => typeof committee === "string") && - arePeriodsValid( - data.preparationPeriod, - data.applicationPeriod, - data.interviewPeriod - ); + arePeriodsValid(data.applicationPeriod, data.interviewPeriod); return hasBasicFields; }; diff --git a/pages/admin/index.tsx b/pages/admin/index.tsx index e7836035..8d5160e5 100644 --- a/pages/admin/index.tsx +++ b/pages/admin/index.tsx @@ -22,10 +22,6 @@ const Admin = () => { return { id: period._id, name: period.name, - preparation: - formatDate(period.preparationPeriod.start) + - " til " + - formatDate(period.preparationPeriod.end), application: formatDate(period.applicationPeriod.start) + " til " + @@ -66,7 +62,6 @@ const Admin = () => { const periodsColumns = [ { label: "Navn", field: "name" }, - { label: "Forberedelse", field: "preparation" }, { label: "Søknad", field: "application" }, { label: "Intervju", field: "interview" }, { label: "Delete", field: "delete" }, diff --git a/pages/admin/new-period.tsx b/pages/admin/new-period.tsx index 768cd4f2..b465b8b7 100644 --- a/pages/admin/new-period.tsx +++ b/pages/admin/new-period.tsx @@ -18,10 +18,6 @@ const NewPeriod = () => { const [periodData, setPeriodData] = useState>({ name: "", description: "", - preparationPeriod: { - start: undefined, - end: undefined, - }, applicationPeriod: { start: undefined, end: undefined, @@ -34,22 +30,6 @@ const NewPeriod = () => { optionalCommittees: [], }); - const updatePreparationPeriodDates = ({ - start, - end, - }: { - start: string; - end: string; - }) => { - setPeriodData((prevData) => ({ - ...prevData, - preparationPeriod: { - start: start ? new Date(start) : undefined, - end: end ? new Date(end) : undefined, - }, - })); - }; - const updateApplicationPeriodDates = ({ start, end, @@ -159,7 +139,7 @@ const NewPeriod = () => { }) } /> -
+