Skip to content

Commit

Permalink
created modal to kick off course creation
Browse files Browse the repository at this point in the history
  • Loading branch information
NorthCountryEngineer committed Mar 29, 2024
1 parent bbc8f1e commit 2fcecbd
Show file tree
Hide file tree
Showing 34 changed files with 5,517 additions and 282 deletions.
70 changes: 1 addition & 69 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,72 +48,4 @@ Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md)

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.



{ allow: groups, groups: ["Students"], operations: [create, update, read, delete] }

type InstructorProfile @model
@auth(rules: [
{ allow: owner}
{ allow: groups, groups: ["Admins"], operations: [create, update, read, delete] }
{ allow: groups, groups: ["Students"], operations: [ read ] }
{ allow: groups, groups: ["Instructors"], operations: [ read ] }
]){
id: ID!
name: String!
email: AWSEmail!
biography: InstructorBiography!
contact: InstructorContact!
}

type InstructorContact @model
@auth(rules: [
{ allow: owner }
{ allow: groups, groups: ["Students"], operations: [ read ] }
{ allow: groups, groups: ["Instructors"], operations: [ read ] }
]){
id: ID!
phone: String
email: String
}

type InstructorBiography @model
@auth(rules: [
{ allow: owner }
{ allow: groups, groups: ["Students"], operations: [ read ] }
{ allow: groups, groups: ["Instructors"], operations: [ read ] }
]){
id: ID!
overview: String!
professionalExperience: [Experience] @hasMany
awards: [Award] @hasMany
}

type Experience @model
@auth(rules: [
{ allow: owner }
{ allow: groups, groups: ["Students"], operations: [ read ] }
{ allow: groups, groups: ["Instructors"], operations: [ read ] }
]){
id: ID!
startDate: String!
endDate: String
isCurrent: Boolean!
companyName: String!
jobTitle: String!
description: String!
}

type Award @model
@auth(rules: [
{ allow: owner }
{ allow: groups, groups: ["Students"], operations: [ read ] }
{ allow: groups, groups: ["Instructors"], operations: [ read ] }
]){
id: ID!
awardDate: String!
awardSource: String!
description: String!
}
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
67 changes: 67 additions & 0 deletions amplify/backend/api/nceed/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type StudentProfile
@auth(rules: [
{ allow: owner}
{ allow: groups, groups: ["Admins"], operations: [create, update, read, delete] }
{ allow: groups, groups: ["Students"], operations: [ read ] }
]){
id: ID!
name: String!
Expand Down Expand Up @@ -174,4 +175,70 @@ enum CourseSubject {
enum ExerciseType {
CODING
PROBLEM_SOLVING
}

# BEGIN INSTRUCTOR SCHEMA DEFINITIONS

type InstructorProfile @model
@auth(rules: [
{ allow: owner}
{ allow: groups, groups: ["Admins"], operations: [create, update, read, delete] }
{ allow: groups, groups: ["Students"], operations: [ read ] }
{ allow: groups, groups: ["Instructors"], operations: [ read ] }
]){
id: ID!
name: String!
email: AWSEmail!
biography: InstructorBiography!
contact: InstructorContact!
}

type InstructorContact @model
@auth(rules: [
{ allow: owner }
{ allow: groups, groups: ["Students"], operations: [ read ] }
{ allow: groups, groups: ["Instructors"], operations: [ read ] }
]){
id: ID!
phone: String
email: String
}

type InstructorBiography @model
@auth(rules: [
{ allow: owner }
{ allow: groups, groups: ["Students"], operations: [ read ] }
{ allow: groups, groups: ["Instructors"], operations: [ read ] }
]){
id: ID!
overview: String!
professionalExperience: [Experience] @hasMany
awards: [Award] @hasMany
}

type Experience @model
@auth(rules: [
{ allow: owner }
{ allow: groups, groups: ["Students"], operations: [ read ] }
{ allow: groups, groups: ["Instructors"], operations: [ read ] }
]){
id: ID!
startDate: String!
endDate: String
isCurrent: Boolean!
companyName: String!
jobTitle: String!
description: String!
}

type Award @model
@auth(rules: [
{ allow: owner }
{ allow: groups, groups: ["Students"], operations: [ read ] }
{ allow: groups, groups: ["Instructors"], operations: [ read ] }
]){
id: ID!
awardDate: String!
awardSource: String!
description: String!
}
80 changes: 7 additions & 73 deletions pages/Instructor/CourseManagement.tsx
Original file line number Diff line number Diff line change
@@ -1,91 +1,25 @@
import React, { useState } from 'react';
import { TextField, Button, FormControl, InputLabel, Select, MenuItem } from '@mui/material';
import { TextField, Button, FormControl, InputLabel, Select, MenuItem, Modal, Dialog, DialogContent, DialogTitle, useMediaQuery, useTheme } from '@mui/material';
import { amplifyApiClient } from '@/src/functions/AuthX';
import { createCourse } from '@/src/graphql/mutations';
import { CourseSubject } from '@/src/API';
import { DialogStyle } from '@/src/style/Components';
import CreateNewCourseDialog from '@/src/components/Instructor/Components';

const CourseManagement = ({ userData }) => {
const [title, setTitle] = useState('');
const [description, setDescription] = useState('');
const [subject, setSubject] = useState<CourseSubject | ''>('');
const [difficulty, setDifficulty] = useState('');

const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
const theme = useTheme()

// Ensure subject is not an empty string before proceeding
if (subject === '') {
alert('Please select a subject');
return;
}
const fullScreen = useMediaQuery(theme.breakpoints.down('md'));

const courseData = {
title,
description,
subject,
difficulty,
creator: userData.cognitoID, // Automatically populate creator field
};

try {
const response = await amplifyApiClient.graphql({
query: createCourse,
variables: { input: courseData }
});
console.log('Course creation response:', response);
} catch (error) {
console.error('Error creating course:', error);
}
};


return (
<form onSubmit={handleSubmit} style={{ display: 'flex', flexDirection: 'column', gap: '20px' }}>
<TextField
label="Title"
variant="outlined"
value={title}
onChange={(e) => setTitle(e.target.value)}
required
/>
<TextField
label="Description"
variant="outlined"
multiline
rows={4}
value={description}
onChange={(e) => setDescription(e.target.value)}
/>
<FormControl variant="outlined" required>
<InputLabel>Subject</InputLabel>
<Select
value={subject}
onChange={(e) => setSubject(e.target.value as CourseSubject)}
label="Subject"
>
{/* Dynamically generate menu items from CourseSubject enum */}
{Object.keys(CourseSubject).map((key) => (
<MenuItem key={key} value={CourseSubject[key]}>
{CourseSubject[key]}
</MenuItem>
))}
</Select>
</FormControl>
<TextField
label="Difficulty"
variant="outlined"
value={difficulty}
onChange={(e) => setDifficulty(e.target.value)}
/>
<TextField
label="Creator"
variant="outlined"
value={userData.email}
disabled
/>
<Button type="submit" variant="contained" color="primary">
Create Course
</Button>
</form>
<CreateNewCourseDialog userData={userData} />
);
};

Expand Down
Loading

0 comments on commit 2fcecbd

Please sign in to comment.