Skip to content
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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

Member role add (fixes: #405) #406

wants to merge 16 commits into from

Conversation

SujalLama
Copy link
Contributor

@SujalLama SujalLama commented Jul 28, 2021

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

mem

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

@SujalLama SujalLama requested review from dogi and lmmrssa July 28, 2021 12:32
@SujalLama SujalLama self-assigned this Jul 28, 2021
@@ -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"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linting issue

},
role: {
type: DataTypes.STRING,
defaultValue: 'manager'
Copy link
Member

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'
Copy link
Member

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

? JSON.parse(localStorage.getItem('currentCommunity'))
: null
const dispatch = useDispatch();
const config = configFunc()
Copy link
Member

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

<div className="com-member-container">
<div className="com-member-header">
{
["firstName", "lastName", "email", "phone", "dateOfBirth", "role", "options"].map(el => {
Copy link
Member

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

Copy link
Contributor Author

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.

@SujalLama SujalLama requested a review from lmmrssa July 29, 2021 04:30
@@ -0,0 +1,15 @@
const db = require("../models")
Copy link
Member

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 => {
Copy link
Member

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'
Copy link
Member

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 => {
Copy link
Member

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

@SujalLama SujalLama added the WIP label Aug 2, 2021
@SujalLama SujalLama removed the WIP label Aug 2, 2021
@SujalLama SujalLama requested a review from lmmrssa August 2, 2021 08:31
// @route GET /api/community-users/community/:id/details
// @access Public

const getAllMemberDetails = async (req, res) => {
Copy link
Member

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
Copy link
Member

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 => {
Copy link
Member

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) => {
Copy link
Member

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
Copy link
Member

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)
Copy link
Member

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

@SujalLama SujalLama added the WIP label Aug 3, 2021
@SujalLama SujalLama removed the WIP label Aug 4, 2021
@SujalLama SujalLama requested a review from lmmrssa August 4, 2021 12:11
@lmmrssa lmmrssa added the WIP label Aug 9, 2021
@SujalLama SujalLama added WIP and removed WIP labels Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add role in the community_users tbl
2 participants