Skip to content
Merged
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: 2 additions & 1 deletion backend/hoagiehelp/api/study_group_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Meta:
"created_at",
"updated_at",
)
read_only_fields = ("id", "leader", "created_at", "updated_at")


class StudyGroupListView(APIView):
Expand All @@ -35,7 +36,7 @@ def post(self, request) -> Response:
"""Create a new study group."""
serializer = StudyGroupSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
serializer.save(leader=request.user)
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

Expand Down
1 change: 0 additions & 1 deletion frontend/api/studyGroupService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type StudyGroup = z.infer<typeof StudyGroupSchema>;
type StudyGroupPayload = {
title: string;
description: string;
leader: number;
meeting_datetime: string;
max_spots: number;
members: number[];
Expand Down
14 changes: 11 additions & 3 deletions frontend/components/StudyGroupForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, { useState } from 'react';

import { Pane, Textarea, Button, majorScale, minorScale } from 'evergreen-ui';

import { createNewStudyGroup } from '@/api/studyGroupService';
interface FormState {
title: string;
category: string;
Expand All @@ -22,7 +23,7 @@ const initialFormState: FormState = {
date: '',
time: '',
location: '',
maxParticipants: 0,
maxParticipants: 5,
description: '',
};

Expand All @@ -39,10 +40,17 @@ export default function StudyGroupForm(): React.ReactElement {
}));
};

const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
setSubmitted(true);
setCanceled(false);
await createNewStudyGroup({
title: form.title,
description: form.description,
meeting_datetime: form.date + ' ' + form.time,
max_spots: form.maxParticipants,
members: [],
});
setForm(initialFormState);
};

Expand Down Expand Up @@ -179,7 +187,7 @@ export default function StudyGroupForm(): React.ReactElement {
</div>
</form>
{submitted && (
<Pane marginTop={minorScale(2)}>Sutdy Group created successfully!</Pane>
<Pane marginTop={minorScale(2)}>Study Group created successfully!</Pane>
)}
{canceled && <Pane marginTop={minorScale(2)}>Edit canceled.</Pane>}
</Pane>
Expand Down
Loading