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

Calendar functionality #18

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
fff6863
Fixed
anantduggal Jun 21, 2024
4152184
Add calendar add and delete functionality
VJagiasi Jun 29, 2024
eda1d99
Add input form for absence details
VJagiasi Jul 5, 2024
443742a
Add Absence.ts
VJagiasi Jul 5, 2024
d1da6f8
Update calendar with database functionality
VJagiasi Jul 5, 2024
bc159f4
Fix build errors
VJagiasi Jul 6, 2024
c5977c1
Fix build error
VJagiasi Jul 7, 2024
3c84f7c
Add SubjectId and remove Subject
VJagiasi Jul 14, 2024
0359732
Fix double absence adding issue + rename event to absence
VJagiasi Jul 14, 2024
478f207
Rename event to absence
VJagiasi Jul 14, 2024
66db4f2
Add error message for invalid input
VJagiasi Jul 20, 2024
f24cb39
Fix form accepting invalid inputs issue
VJagiasi Jul 20, 2024
735e888
Fix package-lock.json
VJagiasi Jul 20, 2024
22e635d
Fix formatting
VJagiasi Jul 20, 2024
2777cc3
update package-lock.json
VJagiasi Jul 20, 2024
fd35487
Added DB Connect
ludavidca Jul 27, 2024
650e164
Deleted pnpm file
ludavidca Jul 27, 2024
e2a2b99
Completed package.json for vercel deploy
ludavidca Jul 27, 2024
9e47fed
Removed Console Log
ludavidca Jul 27, 2024
43fd605
Revert back to original tsconfig + auth.ts
VJagiasi Jul 27, 2024
5000e48
final changes
VJagiasi Oct 2, 2024
f63fdd5
Merge branch 'main' into vihaan-anant/calendar-functionality
VJagiasi Oct 2, 2024
da61aab
linting issues
VJagiasi Oct 2, 2024
c871bae
Merge branch 'vihaan-anant/calendar-functionality' of https://github.…
VJagiasi Oct 2, 2024
bb2abeb
Update eslintrc.json
VJagiasi Oct 5, 2024
c48a239
Fix linting errors
VJagiasi Oct 5, 2024
5064736
Fix nested button error by changing button to Box Layout
VJagiasi Oct 12, 2024
b92573a
fix colour scheme ChakraUI console errors
VJagiasi Oct 12, 2024
80adcbc
Remove size from button
VJagiasi Oct 12, 2024
e01e3c2
Update Dockerfile from main branch
VJagiasi Oct 12, 2024
d9a03bc
Add DayView, TileContent, WeekView components
VJagiasi Oct 12, 2024
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
2 changes: 1 addition & 1 deletion app/api/auth/[...nextauth]/route.ts
VJagiasi marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { handlers } from 'auth';
import { handlers } from '../../../../auth';
export const { GET, POST } = handlers;
2 changes: 1 addition & 1 deletion docker-compose.yml
VJagiasi marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ services:
- ./db-init:/docker-entrypoint-initdb.d

volumes:
postgres_data:
postgres_data:
2,090 changes: 539 additions & 1,551 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions package.json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert changes here

Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
"@chakra-ui/icons": "^2.0.2",
"@chakra-ui/react": "^2.2.1",
"@chakra-ui/theme-tools": "^2.0.2",
"@emotion/react": "^11.9.0",
"@emotion/styled": "^11.9.0",
"@prisma/client": "^5.15.0",
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.5",
"@mui/material": "^5.15.20",
"@mui/system": "^5.15.20",
"@prisma/client": "^5.16.0",
"framer-motion": "^6.3.0",
"next": "^14.2.3",
"next-auth": "^5.0.0-beta.19",
"pnpm": "^9.4.0",
"prisma": "^5.15.0",
"prisma": "^5.16.0",
"react": "^18.2.0",
"react-calendar": "^5.0.0",
"react-dom": "^18.2.0"
Expand Down
144 changes: 144 additions & 0 deletions src/components/InputForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import { useState } from 'react';
import {
Box,
Button,
Input,
FormControl,
FormLabel,
Text,
} from '@chakra-ui/react';

interface Absence {
id?: number;
lessonDate: Date;
lessonPlan: string | null;
reasonOfAbsence: string;
absentTeacherId: number;
substituteTeacherId: number | null;
locationId: number;
subjectId: number;
}

interface InputFormProps {
initialDate: Date;
onClose: () => void;
onAddAbsence: (newAbsence: Absence) => Promise<boolean>;
}

const InputForm: React.FC<InputFormProps> = ({
initialDate,
onClose,
onAddAbsence,
}) => {
const [lessonPlan, setLessonPlan] = useState('');
const [reasonOfAbsence, setReasonOfAbsence] = useState('');
const [absentTeacherId, setAbsentTeacherId] = useState('');
const [substituteTeacherId, setSubstituteTeacherId] = useState('');
const [locationId, setLocationId] = useState('');
const [subjectId, setSubjectId] = useState('');
const [error, setError] = useState('');

const handleAddAbsence = async (e: React.FormEvent) => {
e.preventDefault();
const newAbsence: Absence = {
lessonDate: initialDate,
lessonPlan: lessonPlan || null,
reasonOfAbsence,
absentTeacherId: parseInt(absentTeacherId, 10),
substituteTeacherId: substituteTeacherId
? parseInt(substituteTeacherId, 10)
: null,
locationId: parseInt(locationId, 10),
subjectId: parseInt(subjectId, 10),
};
const success = await onAddAbsence(newAbsence);
if (success) {
setLessonPlan('');
setReasonOfAbsence('');
setAbsentTeacherId('');
setSubstituteTeacherId('');
setLocationId('');
setSubjectId('');
onClose();
} else {
setError('Invalid input. Please enter correct details.');
}
};

return (
<Box as="form" onSubmit={handleAddAbsence} p={4}>
<FormControl mb={3}>
<FormLabel>Lesson Plan</FormLabel>
<Input
type="text"
placeholder="Enter lesson plan"
value={lessonPlan}
onChange={(e) => setLessonPlan(e.target.value)}
color="black"
/>
</FormControl>
<FormControl mb={3}>
<FormLabel>Reason of Absence</FormLabel>
<Input
type="text"
placeholder="Enter reason of absence"
value={reasonOfAbsence}
onChange={(e) => setReasonOfAbsence(e.target.value)}
required
color="black"
/>
</FormControl>
<FormControl mb={3}>
<FormLabel>Absent Teacher ID</FormLabel>
<Input
type="number"
placeholder="Enter absent teacher ID"
value={absentTeacherId}
onChange={(e) => setAbsentTeacherId(e.target.value)}
required
color="black"
/>
</FormControl>
<FormControl mb={3}>
<FormLabel>Substitute Teacher ID</FormLabel>
<Input
type="number"
placeholder="Enter substitute teacher ID"
value={substituteTeacherId}
onChange={(e) => setSubstituteTeacherId(e.target.value)}
color="black"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this might not matter because this ticket is more about frontend than styling, but on these number inputs if you scroll on your trackpad the number changes which is annoying

Copy link
Collaborator Author

@VJagiasi VJagiasi Jul 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't seem to happen when I try to fill out the input form, do you mean it just starts changing as soon as you scroll?

/>
</FormControl>
<FormControl mb={3}>
<FormLabel>Location ID</FormLabel>
<Input
type="number"
placeholder="Enter location ID"
value={locationId}
onChange={(e) => setLocationId(e.target.value)}
required
color="black"
/>
</FormControl>
<FormControl mb={3}>
<FormLabel>Subject ID</FormLabel>
<Input
type="number"
placeholder="Enter subject ID"
value={subjectId}
onChange={(e) => setSubjectId(e.target.value)}
required
color="black"
/>
</FormControl>
{error && (
<Text color="red.500" mt={2}>
{error}
</Text>
)}
<Button type="submit">Add Absence</Button>
</Box>
);
};

export default InputForm;
63 changes: 63 additions & 0 deletions src/pages/api/absence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { PrismaClient } from '@prisma/client';
import type { NextApiRequest, NextApiResponse } from 'next';

const prisma = new PrismaClient();

export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
if (req.method === 'GET') {
try {
const absences = await prisma.absence.findMany();

res.status(200).json({ absences });
} catch (error) {
res
.status(500)
.json({ error: 'Failed to fetch absences', message: error.message });
}
} else if (req.method === 'POST') {
const {
lessonDate,
lessonPlan,
reasonOfAbsence,
absentTeacherId,
substituteTeacherId,
locationId,
subjectId,
} = req.body;
try {
const newAbsence = await prisma.absence.create({
data: {
lessonDate,
lessonPlan,
reasonOfAbsence,
absentTeacherId,
substituteTeacherId,
locationId,
subjectId,
},
});

res.status(200).json({ newAbsence });
} catch (error) {
res
.status(500)
.json({ error: 'Failed to add absence', message: error.message });
}
} else if (req.method === 'DELETE') {
const { id } = req.body;
try {
await prisma.absence.delete({
where: { id },
});
res.status(200).json({ message: 'Absence deleted' });
} catch (error) {
res.status(500).json({ error: 'Failed to delete absence' });
}
} else {
res.setHeader('Allow', ['GET', 'POST', 'DELETE']);
res.status(405).end(`Method ${req.method} Not Allowed`);
}
}
Loading
Loading