Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vihaan anant/ calendar functionality #11

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .prettierignore 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.next
.out
7 changes: 7 additions & 0 deletions .prettierrc 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"semi": true,
"singleQuote": true,
"trailingComma": "es5",
"printWidth": 80,
"tabWidth": 2
}
120 changes: 120 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

109 changes: 109 additions & 0 deletions src/components/InputForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { useState } from 'react';

interface Event {
title: string;
date: Date;
lessonPlan: string;
reasonOfAbsence: string;
numberOfStudents: number;
absentTeacherId: number;
substituteTeacherId: number | null;
locationId: number;
}

interface InputFormProps {
initialDate: Date;
onClose: () => void;
onAddEvent: (newEvent: Event) => void;
}

function InputForm({ initialDate, onClose, onAddEvent }: InputFormProps) {
const [title, setTitle] = useState('');
const [lessonPlan, setLessonPlan] = useState('');
const [reasonOfAbsence, setReasonOfAbsence] = useState('');
const [numberOfStudents, setNumberOfStudents] = useState(0);
const [absentTeacherId, setAbsentTeacherId] = useState('');
const [substituteTeacherId, setSubstituteTeacherId] = useState('');
const [locationId, setLocationId] = useState('');

const handleAddEvent = (e: React.FormEvent) => {
e.preventDefault();
const newEvent: Event = {
title,
date: initialDate,
lessonPlan,
reasonOfAbsence,
numberOfStudents: parseInt(numberOfStudents.toString()),
absentTeacherId: parseInt(absentTeacherId.toString()),
substituteTeacherId: substituteTeacherId ? parseInt(substituteTeacherId.toString()) : null,
locationId: parseInt(locationId.toString()),
};
onAddEvent(newEvent);
setTitle('');
setLessonPlan('');
setReasonOfAbsence('');
setNumberOfStudents(0);
setAbsentTeacherId('');
setSubstituteTeacherId('');
setLocationId('');
};

return (
<div className="form-container">
<form onSubmit={handleAddEvent}>
<input
type="text"
placeholder="Subject"
value={title}
onChange={(e) => setTitle(e.target.value)}
required
/>
<input
type="text"
placeholder="Lesson Plan"
value={lessonPlan}
onChange={(e) => setLessonPlan(e.target.value)}
/>

<input
type="text"
placeholder="Reason of Absence"
value={reasonOfAbsence}
onChange={(e) => setReasonOfAbsence(e.target.value)}
required
/>
<input
type="number"
placeholder="Number of Students"
value={numberOfStudents}
onChange={(e) => setNumberOfStudents(e.target.value)}
required
/>
<input
type="number"
placeholder="Absent Teacher ID"
value={absentTeacherId}
onChange={(e) => setAbsentTeacherId(e.target.value)}
required
/>
<input
type="number"
placeholder="Substitute Teacher ID"
value={substituteTeacherId}
onChange={(e) => setSubstituteTeacherId(e.target.value)}
/>
<input
type="number"
placeholder="Location ID"
value={locationId}
onChange={(e) => setLocationId(e.target.value)}
required
/>
<button type="button">Upload Lesson Plan</button>
<button type="submit">Add Event</button>
</form>
</div>
);
}

export default InputForm;
Loading
Loading