-
Notifications
You must be signed in to change notification settings - Fork 8
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
Member role add (fixes: #405) #406
base: main
Are you sure you want to change the base?
Conversation
@@ -85,7 +85,7 @@ const getAllMembers = async (req, res) => { | |||
const data = await db.CommunityUser.findAll( | |||
{ | |||
where: { communityId: req.params.id, active: true }, | |||
attributes: ['userId'], | |||
attributes: ['userId', "role"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
linting issue
api/src/models/communityUserModel.js
Outdated
}, | ||
role: { | ||
type: DataTypes.STRING, | ||
defaultValue: 'manager' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default value between model and migration seems to have conflict
src/App.jsx
Outdated
@@ -51,6 +51,7 @@ import UserVerification from './screens/verification/UserVerification' | |||
import AddTest from './screens/addTest/AddTest' | |||
import LogoutUser from './screens/logoutUser/LogoutUser' | |||
import PageNotFound from './screens/pageNotFound/PageNotFound' | |||
import ComMemberAdmin from './screens/admin/ComMemberAdmin' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try to put full name so its easier to understand
src/screens/admin/ComMemberAdmin.jsx
Outdated
? JSON.parse(localStorage.getItem('currentCommunity')) | ||
: null | ||
const dispatch = useDispatch(); | ||
const config = configFunc() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not required to be used instead create general putApi request
src/screens/admin/ComMemberAdmin.jsx
Outdated
<div className="com-member-container"> | ||
<div className="com-member-header"> | ||
{ | ||
["firstName", "lastName", "email", "phone", "dateOfBirth", "role", "options"].map(el => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not using table component created for admin panel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Table component is in another branch(admin-category-page), so it will be replaced after the branch is merged.
api/src/middleware/memberPermit.js
Outdated
@@ -0,0 +1,15 @@ | |||
const db = require("../models") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this to permission file so that we don't have lot of permission files
<div className="com-member-container"> | ||
<div className="com-member-header"> | ||
{ | ||
["firstName", "lastName", "email", "phone", "dateOfBirth", "role", "options"].map(el => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do manual lint fix
whole file needs to fix linting seems like its using 4 spaces instead of 2
import React, { useEffect, useState } from 'react' | ||
import { useDispatch } from 'react-redux' | ||
import DashboardLayout from '../../layout/dashboardLayout/DashboardLayout' | ||
import { getApi, getCommunity, putApi } from '../../utils/apiFunc' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there was already another function to get current community
} | ||
</div> | ||
{ | ||
data.map(item => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use table.jsx from main branch
// @route GET /api/community-users/community/:id/details | ||
// @access Public | ||
|
||
const getAllMemberDetails = async (req, res) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like getAllMemberDetails, getAllMembers, getCommunityUsers can be single function
// flattening the array to show only one object | ||
const newArray = data.map(item => { | ||
const { userId, role, id } = item.dataValues | ||
const { ...rest } = item.user |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line is not required can be used directly below in place of rest.datavalues
) | ||
|
||
// flattening the array to show only one object | ||
const newArray = data.map(item => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it could just be nested to after findall
setData(data.results) | ||
} | ||
|
||
const allowAccess = async (id) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be able to switch between roles not always make manager
[ | ||
{ | ||
img: '/img/edit-icon.svg', | ||
action: allowAccess |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should be list of roles for now lets take [manager, member, coach] and should show list which is not current role of member as dropdown
`${process.env.REACT_APP_API_BASE_URL}/api/communities-users/${id}/community/${currentCommunity.id}`, | ||
{ role: 'manager' } | ||
) | ||
setSuccess(data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is also not reloading table so have to manually do refresh
Fixes #405
Description
added role to the community member
protect route based on the role of comunity member
community member admin page is made
community manager can grant access to the other member
drop down added in table
made one route: getAllMemberDetails, getAllMembers, getCommunityUsers can be single function
rerenders the table while changing role
Screenshots
Links and Curls
route:
http://localhost:3000/admin/community-members
file added:
src/middleware/memberPermit.js ( changed to : api/src/middleware/permission.js)
src/migrations/20210728085949-alter_community_user.js
../src/screens/admin/
src/components/dropDown/
file modified:
src/controllers/communityUserController.js
src/models/communityUserModel.js
src/routes/communityUserRouter.js
../src/App.jsx
src/actions/memberActions.js
src/components/table/Table.jsx
src/constants/memberConstants.js
src/reducers/memberReducers.js
src/screens/admin/CommunityMemberAdmin.jsx
src/store.js
src/screens/communityMembers/CommunityMembers.jsx
src/components/cardImage/CardImage.jsx