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
6 changes: 4 additions & 2 deletions backend/models/user.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ const userSchema = mongoose.Schema({
isHflaGithubMember: { type: Boolean }, // pull from API once github handle in place?
githubPublic2FA: { type: Boolean }, // does the user have 2FA enabled on their github and membership set to public?
availability: { type: String }, // availability to meet outside of hacknight times; string for now, more structured in future
managedProjects: [{ type: String}] // Which projects managed by user.
managedProjects: [{ type: String}], // Which projects managed by user.
//currentProject: { type: String } // no longer need this as we can get it from Project Team Member table
// password: { type: String, required: true }
isActive: { type: Boolean, default: true }
});

userSchema.methods.serialize = function () {
Expand Down Expand Up @@ -65,7 +66,8 @@ userSchema.methods.serialize = function () {
isHflaGithubMember: this.isHflaGithubMember,
githubPublic2FA: this.githubPublic2FA,
availability: this.availability,
managedProjects: this.managedProjects
managedProjects: this.managedProjects,
isActive: this.isActive
};
};

Expand Down
16 changes: 16 additions & 0 deletions client/src/api/UserApiService.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ class UserApiService {
}
return undefined;
}

async updateUserDbIsActive(userToEdit, isActive) {
const url = `${this.baseUserUrl}${userToEdit._id}`;
const requestOptions = {
method: 'PATCH',
headers: this.headers,
body: JSON.stringify({ isActive })
}

try {
return await fetch(url, requestOptions);
} catch (err) {
console.error('update is-active error', err)
alert('server not responding. Please try again.');
}
}
}

export default UserApiService;
18 changes: 17 additions & 1 deletion client/src/components/user-admin/EditUsers.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React, { useEffect, useState } from 'react';
import '../../sass/UserAdmin.scss';
import { FormGroup, FormControlLabel, Switch } from '@mui/material'

// child of UserAdmin. Displays form to update users.
const EditUsers = ({ userToEdit, backToSearch, updateUserDb, projects }) => {
const EditUsers = ({ userToEdit, backToSearch, updateUserDb, projects, updateUserActiveStatus }) => {
const [userManagedProjects, setUserManagedProjects] = useState([]); // The projects that the selected user is assigned
const [projectValue, setProjectValue] = useState(''); // State and handler for form in EditUsers
const [isActive, setIsActive] = useState(userToEdit.isActive);

// Prepare data for display
const userName = `${userToEdit.name?.firstName} ${userToEdit.name?.lastName}`;
Expand Down Expand Up @@ -57,6 +59,11 @@ const EditUsers = ({ userToEdit, backToSearch, updateUserDb, projects }) => {
}
};

const handleSetIsActive = () => {
setIsActive(!isActive)
updateUserActiveStatus(userToEdit, !isActive)
}

return (
<div className="edit-users">
<div className="ua-row">
Expand All @@ -67,6 +74,15 @@ const EditUsers = ({ userToEdit, backToSearch, updateUserDb, projects }) => {
<div className="user-display-column-left">Email:</div>
<div className="user-display-column-right">{userEmail}</div>
</div>
<div className="ua-row is-active-flex">
<div className="user-is-active-column-left">Is Active:</div>
<div className="is-active-flex">
<span className="active-status">{isActive.toString()}</span>
<FormGroup>
<FormControlLabel control={<Switch checked={isActive} />} onClick={() => handleSetIsActive()} />
</FormGroup>
</div>
</div>
<div className="ua-row">
<div className="user-display-column-left">Projects:</div>
<div className="user-display-column-right">
Expand Down
8 changes: 8 additions & 0 deletions client/src/pages/UserAdmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ const UserAdmin = () => {
[userApiService, fetchUsers]
);

const updateUserActiveStatus = useCallback(
async (user, isActive) => {
await userApiService.updateUserDbIsActive(user, isActive);
fetchUsers()
}, [userApiService, fetchUsers]
)

const fetchProjects = useCallback(async () => {
const projectRes = await projectApiService.fetchProjects();
setProjects(projectRes);
Expand Down Expand Up @@ -57,6 +64,7 @@ const UserAdmin = () => {
projects={projects}
updateUserDb={updateUserDb}
backToSearch={backToSearch}
updateUserActiveStatus={updateUserActiveStatus}
/>
);
}
Expand Down
16 changes: 16 additions & 0 deletions client/src/sass/UserAdmin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@
margin-bottom: 8px;
}

.user-is-active-column-left {
display: flex;
flex-direction: column;
flex-basis: 15%;
}

.active-status {
margin-right: 15px;
width: 25px;
}

.is-active-flex {
display: flex;
align-items: center;
}

.button-remove {
width: 25%;
color: #fa114f;
Expand Down