Skip to content

Feat/add classroom #376

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

Open
wants to merge 18 commits into
base: development
Choose a base branch
from
Open
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
Prev Previous commit
Next Next commit
feat: add social login
  • Loading branch information
mariopesch committed Nov 25, 2024
commit 82d1333b8f316bc150e470b4c5f1f688c98a99ef
8 changes: 4 additions & 4 deletions src/actions/adminActions.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

import axios from 'axios';
import { GET_USERS_SUCCESS, GET_USERS_FAIL, UPDATE_USER_ROLE_SUCCESS, UPDATE_USER_ROLE_FAIL } from './types';
import api from '../utils/axiosConfig';


// Fetch all users
export const getUsers = () => async (dispatch) => {
try {
const res = await axios.get(`${process.env.REACT_APP_BLOCKLY_API}/user/users`)
const res = await api.get(`${process.env.REACT_APP_BLOCKLY_API}/user/users`)
dispatch({
type: GET_USERS_SUCCESS,
payload: res.data
Expand All @@ -26,7 +26,7 @@ export const updateUserRole = (userId, role) => async (dispatch) => {
};

try {
const res = await axios.put(`${process.env.REACT_APP_BLOCKLY_API}/user/role`, body); // API endpoint to update user role
const res = await api.put(`${process.env.REACT_APP_BLOCKLY_API}/user/role`, body); // API endpoint to update user role
dispatch({
type: UPDATE_USER_ROLE_SUCCESS,
payload: { userId, role: res.data.newRole } // Assuming response contains updated role
Expand Down
19 changes: 9 additions & 10 deletions src/actions/classroomActions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { GET_CLASSROOMS, GET_CLASSROOM, ADD_STUDENT_SUCCESS, CREATE_CLASSROOM, DELETE_STUDENT_SUCCESS, DELETE_STUDENT_FAIL, GET_CLASSROOM_PROJECTS_SUCCESS, GET_CLASSROOM_PROJECT_SUCCESS } from './types';

import axios from 'axios';
import { returnErrors, returnSuccess } from './messageActions';
import api from '../utils/axiosConfig';

Expand All @@ -18,7 +16,7 @@ export const createClassroom = (classroom) => (dispatch) => {
}
}
};
axios.post(`${process.env.REACT_APP_BLOCKLY_API}/classroom`, classroom, config)
api.post(`${process.env.REACT_APP_BLOCKLY_API}/classroom`, classroom, config)
.then(res => {
res.config.success(res);
})
Expand All @@ -38,7 +36,7 @@ export const deleteClassroom = (id) => (dispatch) => {
}
}
};
axios.delete(`${process.env.REACT_APP_BLOCKLY_API}/classroom/${id}`, config)
api.delete(`${process.env.REACT_APP_BLOCKLY_API}/classroom/${id}`, config)
.then(res => {
res.config.success(res);
})
Expand Down Expand Up @@ -66,7 +64,7 @@ export const addStudent = (classroomId, student) => (dispatch) => {
}
}
};
axios.post(`${process.env.REACT_APP_BLOCKLY_API}/classroom/${classroomId}/adduser`, body, config)
api.post(`${process.env.REACT_APP_BLOCKLY_API}/classroom/${classroomId}/adduser`, body, config)
.then(res => {
res.config.success(res);
})
Expand All @@ -81,7 +79,7 @@ export const deleteStudent = (classroomId, studentId) => (dispatch) => {
};
console.log(body);

axios.delete(`${process.env.REACT_APP_BLOCKLY_API}/classroom/${classroomId}/user`, { data: body })
api.delete(`${process.env.REACT_APP_BLOCKLY_API}/classroom/${classroomId}/user`, { data: body })
.then(res => {
dispatch({
type: DELETE_STUDENT_SUCCESS,
Expand Down Expand Up @@ -114,7 +112,7 @@ export const getClassrooms = () => (dispatch) => {
}
}
};
axios.get(`${process.env.REACT_APP_BLOCKLY_API}/classroom`, config)
api.get(`${process.env.REACT_APP_BLOCKLY_API}/classroom`, config)
.then(res => {
res.config.success(res);
})
Expand All @@ -125,7 +123,8 @@ export const getClassrooms = () => (dispatch) => {


export const getClassroom = (id) => (dispatch ) => {
axios
console.log('Fetching classroom:', id);
api
.get(`${process.env.REACT_APP_BLOCKLY_API}/classroom/${id}`)
.then((res) => {
var classroom = res.data.classroom;
Expand Down Expand Up @@ -195,7 +194,7 @@ export const getClassrooms = () => (dispatch) => {
}
}
};
axios.post(`${process.env.REACT_APP_BLOCKLY_API}/classroom/${classroomId}/projects`, body, config)
api.post(`${process.env.REACT_APP_BLOCKLY_API}/classroom/${classroomId}/projects`, body, config)
.then(res => {
res.config.success(res);
})
Expand All @@ -215,7 +214,7 @@ export const postClassroomProject = (classroomId, body) => (dispatch) => {
}
}
};
axios.post(`${process.env.REACT_APP_BLOCKLY_API}/classroom/${classroomId}/project`, body, config)
api.post(`${process.env.REACT_APP_BLOCKLY_API}/classroom/${classroomId}/project`, body, config)
.then(res => {
res.config.success(res);
})
Expand Down
3 changes: 3 additions & 0 deletions src/actions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ export const GET_PROJECT = "GET_PROJECT";
export const GET_PROJECTS = "GET_PROJECTS";
export const PROJECT_TYPE = "PROJECT_TYPE";
export const PROJECT_DESCRIPTION = "PROJECT_DESCRIPTION";
export const PROJECT_EMPTY = "PROJECT_EMPTY";
export const GET_PROJECT_FAIL = "GET_PROJECT_FAIL";
export const GET_PROJECTS_FAIL = "GET_PROJECTS_FAIL";

//board
export const BOARD = "BOARD";
Expand Down
13 changes: 6 additions & 7 deletions src/components/Classroom/Classroom.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,14 @@ class Classroom extends Component {
};

componentDidMount() {
// console.log(this.props.location.pathname.slice(11));
const classroomId = this.props.location.pathname.slice(11);
console.log('Fetching classroom with ID:', classroomId); // Add logging for debugging
this.props.getClassroom(classroomId);

// if (!this.props.progress) {
// console.log(this.props);
// this.props.getClassrooms();
// console.log(this.props.classrooms);
// this.props.getClassroom(this.props.location.pathname.slice(11));
if (!this.props.progress) {
console.log(this.props);
this.props.getClassroom(this.props.location.pathname.slice(11));
}
// }
}

componentDidUpdate(prevProps) {
Expand Down
22 changes: 15 additions & 7 deletions src/components/Project/Project.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import CircularProgress from '@mui/material/CircularProgress';
class Project extends Component {

componentDidMount() {
console.log('Props in Project:', this.props);
console.log('Component did mount. Calling getProject()');
this.props.resetProject();
this.getProject();
}
Expand Down Expand Up @@ -58,16 +60,20 @@ class Project extends Component {
getProject = () => {
const id = this.props.location.pathname.replace(/\/[a-z]{1,}\//, '');
const param = this.props.location.pathname.replace(`/${id}`, '').replace('/', '');
if (this.props.user && !this.props.classroomUser) {
this.props.getProject(param, id);
} else if (this.props.classroomUser) {
this.props.getClassroomProject(this.props.classroomUser.classroomId, id);
}
console.log(param, id);
this.props.getProject(param, id);

// if (this.props.user && !this.props.classroomUser) {
// this.props.getProject(param, id);
// } else if (this.props.classroomUser) {
// this.props.getClassroomProject(this.props.classroomUser.classroomId, id);
// }
}

render() {
const data = this.props.type === 'project' ? 'Projekte' : 'Galerie';
const { progress, project, type, classroomProject } = this.props;


return (
progress ?
Expand Down Expand Up @@ -105,8 +111,10 @@ Project.propTypes = {
};

const mapStateToProps = state => ({
project: state.project.projects[0],
classroomProject: state.classroomAuth.classroomUser.projects[0],
project: Array.isArray(state.project.projects) && state.project.projects.length > 0 ? state.project.projects[0] : null,
classroomProject: state.classroomAuth.classroomUser && Array.isArray(state.classroomAuth.classroomUser.projects)
? state.classroomAuth.classroomUser.projects[0]
: null,
progress: state.project.progress,
type: state.project.type,
message: state.message,
Expand Down
13 changes: 13 additions & 0 deletions src/components/Project/ProjectHome.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class ProjectHome extends Component {
this.props.getProjects(type);
} else if (type === "gallery") {
this.props.getProjects(type);

}
this.handleMessages(this.props.message, type);
}
Expand All @@ -57,6 +58,7 @@ class ProjectHome extends Component {
if (prevProps.message !== this.props.message) {
this.handleMessages(this.props.message, this.props.location.pathname.replace("/", ""));
}
console.log(this.props.projects);
}

componentWillUnmount() {
Expand Down Expand Up @@ -131,6 +133,17 @@ class ProjectHome extends Component {
</Backdrop>
) : (
<div>
{projects.length > 0 && !classroomUser && !user &&(
<div>
<Typography style={{ marginBottom: "10px" }}>
Hier findest du eine Übersicht aller frei verfügbaren Programme.
</Typography>
<Grid container spacing={2}>
{this.renderProjects(projects, data)}
</Grid>
</div>
)}

{!classroomUser && user && projects.length > 0 && (
<Grid container spacing={2}>
{this.renderProjects(projects, data)}
Expand Down
46 changes: 16 additions & 30 deletions src/components/Route/PrivateRoute.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,27 @@
import React, { Component } from "react";
import React from "react";
import { Route, Redirect } from "react-router-dom";
import PropTypes from "prop-types";
import { connect } from "react-redux";

import { Route, Redirect, withRouter } from "react-router-dom";

class PrivateRoute extends Component {
render() {
return !this.props.progress ? (
<Route
{...this.props.exact}
render={({ location }) =>
this.props.isAuthenticated
? this.props.children
: (() => {
return (
<Redirect
to={{
pathname: "/user/login",
state: { from: location },
}}
/>
);
})()
}
/>
) : null;
}
}
const PrivateRoute = ({ component: Component, isAuthenticated, ...rest }) => (
<Route
{...rest}
render={(props) =>
isAuthenticated ? (
<Component {...props} />
) : (
<Redirect to="/user/login" />
)
}
/>
);

PrivateRoute.propTypes = {
isAuthenticated: PropTypes.bool,
progress: PropTypes.bool.isRequired,
isAuthenticated: PropTypes.bool.isRequired,
};

const mapStateToProps = (state) => ({
isAuthenticated: state.auth.isAuthenticated,
progress: state.auth.progress,
});

export default connect(mapStateToProps, null)(withRouter(PrivateRoute));
export default connect(mapStateToProps)(PrivateRoute);
Loading