Skip to content

Commit

Permalink
Prevent submission of days in the future
Browse files Browse the repository at this point in the history
  • Loading branch information
ollieri3 committed Feb 6, 2024
1 parent 73551f2 commit c7d6b10
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/controllers/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export async function getCalendar(
dayjs(day.date).isSame(monthDate.date(i + 1)),
),
isToday: today.isSame(monthDate.date(i + 1), "day"),
isPast: monthDate.date(i + 1).isBefore(today, "day"),
isFuture: monthDate.date(i + 1).isAfter(today, "day"),
};
}),
};
Expand Down
9 changes: 9 additions & 0 deletions src/controllers/day.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ export async function submitDay(
return;
}

if (dayjs(req.body.date).isAfter(dayjs(), "day")) {
res.statusCode = 422;
res.json({
success: false,
message: "Date is in the future",
});
return;
}

if (await day.exists(req.body.date, (req.user as any).id)) {
res.statusCode = 500;
res.json({ success: false, message: "Date entry already exists" });
Expand Down
6 changes: 5 additions & 1 deletion src/public/calendar.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
background: #cfcfcf;
}

.day:disabled {
cursor: not-allowed;
}

.day:focus {
border: 0;
outline: 0;
Expand All @@ -47,7 +51,7 @@
box-shadow: 0 0 30px rgba(255, 1, 196, 0.7);
}

.day:hover {
.day:hover:not(:disabled) {
background: gold;
}

Expand Down
7 changes: 7 additions & 0 deletions src/views/calendar.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@
class="day today"
data-date="{{date}}"
>{{day}}</button>
{{else if isFuture}}
<button
id="{{date}}"
disabled
class="day"
data-date="{{date}}"
>{{day}}</button>
{{else}}
<button
id="{{date}}"
Expand Down

0 comments on commit c7d6b10

Please sign in to comment.