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

feat: delete classroom button on classroom cards #459

Merged
merged 5 commits into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions backend/graphql/resolvers/classResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ const classResolvers = {
): Promise<ClassResponseDTO> => {
return classService.createStudent(student, classId);
},
deleteClass: (_req: undefined, { classId }: { classId: string }) =>
classService.deleteClass(classId),
},
ClassResponseDTO: {
teacher: async (parent: ClassResponseDTO) => {
Expand Down
1 change: 1 addition & 0 deletions backend/graphql/types/classType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const classType = gql`
extend type Mutation {
createClass(classObj: ClassRequestDTO!): ClassResponseDTO!
createStudent(student: StudentRequestDTO!, classId: ID!): ClassResponseDTO!
deleteClass(classId: ID!): ID
}
`;

Expand Down
6 changes: 6 additions & 0 deletions frontend/src/APIClients/mutations/ClassMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ export const CREATE_STUDENT = gql`
}
}
`;

export const DELETE_CLASS = gql`
mutation DeleteClass($classId: ID!) {
deleteClass(classId: $classId)
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const ClassroomCard = ({
{name}
</Text>
</LinkOverlay>
<ClassroomPopover />
<ClassroomPopover classId={id} />
</HStack>
{classroomCardBody.map(({ icon, text }, i) => {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,42 @@
import React from "react";
import React, { useContext } from "react";
import { useMutation } from "@apollo/client";
import { Divider, useDisclosure, VStack } from "@chakra-ui/react";

import { DELETE_CLASS } from "../../../../APIClients/mutations/ClassMutations";
import { GET_CLASSES_BY_TEACHER } from "../../../../APIClients/queries/ClassQueries";
import AuthContext from "../../../../contexts/AuthContext";
import Popover from "../../../common/popover/Popover";
import PopoverButton from "../../../common/popover/PopoverButton";

const ClassroomPopover = (): React.ReactElement => {
interface ClassroomPopoverProps {
classId: string;
}

const ClassroomPopover = ({
classId,
}: ClassroomPopoverProps): React.ReactElement => {
const {
isOpen: isPopoverOpen,
onOpen: onPopoverOpen,
onClose: onPopoverClose,
} = useDisclosure();
const { authenticatedUser } = useContext(AuthContext);

const { id: teacherId } = authenticatedUser ?? {};

const [deleteClass] = useMutation<{ deleteClass: string }>(DELETE_CLASS, {
variables: { classId },
refetchQueries: [
{
query: GET_CLASSES_BY_TEACHER,
variables: { teacherId },
},
],
});

const handleDeleteClass = async () => {
await deleteClass({ variables: { classId } });
};

return (
<Popover
Expand All @@ -20,7 +47,12 @@ const ClassroomPopover = (): React.ReactElement => {
<VStack spacing={0}>
<PopoverButton name="Edit" onClick={() => {}} />
<Divider />
<PopoverButton name="Delete" onClick={() => {}} />
<PopoverButton
name="Delete"
onClick={() => {
handleDeleteClass();
}}
/>
</VStack>
</Popover>
);
Expand Down
Loading