Skip to content

Commit

Permalink
Removed preparation period
Browse files Browse the repository at this point in the history
  • Loading branch information
julian-ao committed Jul 21, 2024
1 parent 78a2f47 commit 0765c77
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 71 deletions.
5 changes: 0 additions & 5 deletions components/committee/CommitteApplicants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ const CommitteeApplicants: NextPage<Props> = ({ 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 " +
Expand All @@ -58,7 +54,6 @@ const CommitteeApplicants: NextPage<Props> = ({ routeString }) => {

const periodsColumns = [
{ label: "Navn", field: "name" },
{ label: "Forberedelse", field: "preparation" },
{ label: "Søknad", field: "application" },
{ label: "Intervju", field: "interview" },
];
Expand Down
5 changes: 0 additions & 5 deletions lib/mongo/periods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
4 changes: 0 additions & 4 deletions lib/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ export type periodType = {
_id: ObjectId;
name: string;
description: string;
preparationPeriod: {
start: Date;
end: Date;
};
applicationPeriod: {
start: Date;
end: Date;
Expand Down
20 changes: 2 additions & 18 deletions lib/utils/PeriodValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { DeepPartial, periodType } from "../types/types";
export const validatePeriod = (
periodData: DeepPartial<periodType>
): 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;
Expand All @@ -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;
}
Expand Down
10 changes: 1 addition & 9 deletions lib/utils/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,32 +84,24 @@ 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)
);
};

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;
};
5 changes: 0 additions & 5 deletions pages/admin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 " +
Expand Down Expand Up @@ -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" },
Expand Down
26 changes: 1 addition & 25 deletions pages/admin/new-period.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ const NewPeriod = () => {
const [periodData, setPeriodData] = useState<DeepPartial<periodType>>({
name: "",
description: "",
preparationPeriod: {
start: undefined,
end: undefined,
},
applicationPeriod: {
start: undefined,
end: undefined,
Expand All @@ -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,
Expand Down Expand Up @@ -159,7 +139,7 @@ const NewPeriod = () => {
})
}
/>
<div className="max-w-xs w-full">
<div className="w-full max-w-xs">
<TextAreaInput
label="Beskrivelse"
placeholder="Flere komiteer søker nye medlemmer til suppleringsopptak. Har du det som trengs? Søk nå og bli en del av vårt fantastiske miljø!
Expand All @@ -173,10 +153,6 @@ const NewPeriod = () => {
/>
</div>

<DatePickerInput
label="Forberedelsesperiode"
updateDates={updatePreparationPeriodDates}
/>
<DatePickerInput
label="Søknadsperiode"
updateDates={updateApplicationPeriodDates}
Expand Down

0 comments on commit 0765c77

Please sign in to comment.