Skip to content
Open
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
9 changes: 9 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
VITE_INITIAL_COMPILER_URL=https://compiler.sensebox.de

VITE_BOARD=sensebox-mcu
VITE_BLOCKLY_API=http://localhost:8080

GENERATE_SOURCEMAP=false

# in days
VITE_SHARE_LINK_EXPIRES=30
1 change: 1 addition & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const theme = createTheme({
class App extends Component {
componentDidMount() {
store.dispatch(loadUser());

// set initial compiler
console.log("compiler", import.meta.env.VITE_INITIAL_COMPILER_URL);
store.dispatch(setCompiler(import.meta.env.VITE_INITIAL_COMPILER_URL));
Expand Down
47 changes: 47 additions & 0 deletions src/actions/adminActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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 api.get(`${import.meta.env.VITE_BLOCKLY_API}/user/users`);
dispatch({
type: GET_USERS_SUCCESS,
payload: res.data,
});
} catch (err) {
dispatch({
type: GET_USERS_FAIL,
payload: err.response.data,
});
}
};

// Update user role
export const updateUserRole = (userId, role) => async (dispatch) => {
const body = {
_id: userId,
newRole: role,
};

try {
const res = await api.put(
`${import.meta.env.VITE_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
});
} catch (err) {
dispatch({
type: UPDATE_USER_ROLE_FAIL,
payload: err.response ? err.response.data : "Error updating role",
});
}
};
Loading