Skip to content

Commit

Permalink
CHE-192 Basic validation that stops user from picking a future date w…
Browse files Browse the repository at this point in the history
…hen creating an application
  • Loading branch information
brok3turtl3 committed Jun 11, 2024
1 parent e80982e commit 3b5f0c2
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions client/src/pages/CreateApplicationPage/CreateApplicationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const CreateApplicationPage = () => {
const { status } = useAppSelector((state) => state.application);

const [statuses, setStatuses] = useState<IStatus[]>([]);
const [errorMessage, setErrorMessage] = useState<string | null>(null);
const [formData, setFormData] = useState<IApplicationFormData>({
title: '',
company: '',
Expand Down Expand Up @@ -40,6 +41,14 @@ const CreateApplicationPage = () => {

const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
const selectedDate = new Date(formData.date_applied);
const currentDate = new Date();

if (selectedDate > currentDate) {
setErrorMessage("Sean S says time travel isn't a thing.");
return;
}
setErrorMessage(null);
dispatch(createApplication(formData));
};

Expand Down Expand Up @@ -70,6 +79,9 @@ const CreateApplicationPage = () => {
<div className="pt-40 min-h-screen bg-gray-900 text-white flex flex-col items-center justify-center p-4">
<h1 className="text-4xl font-extrabold mb-4">Create Applications</h1>
<form className="w-full max-w-lg" onSubmit={handleSubmit}>
{errorMessage && (
<div className="bg-red-500 text-white p-2 rounded mb-4">{errorMessage}</div>
)}
<label className="block text-sm font-bold mb-2" htmlFor="title">
Job Title
<input
Expand Down

0 comments on commit 3b5f0c2

Please sign in to comment.