switched Role to Roles

This commit is contained in:
Sean Macfarlane
2020-11-27 20:34:29 -05:00
parent 0f463832a7
commit cca9fc3667
7 changed files with 33 additions and 33 deletions

View File

@@ -12,7 +12,7 @@ const GET_ALL_USERS = gql`
items {
id
email: username
role
roles
lastModifiedTimestamp
customerId
}
@@ -22,10 +22,10 @@ const GET_ALL_USERS = gql`
`;
const CREATE_USER = gql`
mutation CreateUser($username: String!, $password: String!, $role: String!, $customerId: ID!) {
createUser(username: $username, password: $password, role: $role, customerId: $customerId) {
mutation CreateUser($username: String!, $password: String!, $roles: [String], $customerId: ID!) {
createUser(username: $username, password: $password, roles: $roles, customerId: $customerId) {
username
role
roles
customerId
}
}
@@ -36,7 +36,7 @@ const UPDATE_USER = gql`
$id: ID!
$username: String!
$password: String!
$role: String!
$roles: [String]
$customerId: ID!
$lastModifiedTimestamp: String
) {
@@ -44,13 +44,13 @@ const UPDATE_USER = gql`
id: $id
username: $username
password: $password
role: $role
roles: $roles
customerId: $customerId
lastModifiedTimestamp: $lastModifiedTimestamp
) {
id
username
role
roles
customerId
lastModifiedTimestamp
}
@@ -95,12 +95,12 @@ const Accounts = () => {
}
};
const handleCreateUser = (email, password, role) => {
const handleCreateUser = (email, password, roles) => {
createUser({
variables: {
username: email,
password,
role,
roles: [roles],
customerId,
},
})
@@ -119,13 +119,13 @@ const Accounts = () => {
);
};
const handleEditUser = (id, email, password, role, lastModifiedTimestamp) => {
const handleEditUser = (id, email, password, roles, lastModifiedTimestamp) => {
updateUser({
variables: {
id,
username: email,
password,
role,
roles: [roles],
customerId,
lastModifiedTimestamp,
},

View File

@@ -42,7 +42,7 @@ const App = () => {
let initialUser = {};
if (token) {
const { userId, userName, userRole, customerId } = parseJwt(token.access_token);
initialUser = { id: userId, email: userName, role: userRole, customerId };
initialUser = { id: userId, email: userName, roles: userRole, customerId };
}
const [user, setUser] = useState(initialUser);
@@ -50,7 +50,7 @@ const App = () => {
setItem(AUTH_TOKEN, newToken);
if (newToken) {
const { userId, userName, userRole, customerId } = parseJwt(newToken.access_token);
setUser({ id: userId, email: userName, role: userRole, customerId });
setUser({ id: userId, email: userName, roles: userRole, customerId });
}
};
@@ -60,7 +60,7 @@ const App = () => {
<UserProvider
id={user.id}
email={user.email}
role={user.role}
roles={user.roles}
customerId={user.customerId}
updateUser={updateUser}
updateToken={updateToken}
@@ -87,7 +87,7 @@ const App = () => {
<ProtectedRouteWithLayout exact path={ROUTES.alarms} component={Alarms} />
<ProtectedRouteWithLayout exact path={ROUTES.account} component={EditAccount} />
{user.role === 'SuperUser' && (
{user?.roles?.[0] === 'SuperUser' && (
<ProtectedRouteWithLayout exact path={ROUTES.users} component={Accounts} />
)}
<ProtectedRouteWithLayout component={GenericNotFound} />

View File

@@ -10,7 +10,7 @@ const GET_USER = gql`
getUser(id: $id) {
id
username
role
roles
customerId
lastModifiedTimestamp
}
@@ -22,7 +22,7 @@ const UPDATE_USER = gql`
$id: ID!
$username: String!
$password: String!
$role: String!
$roles: [String]
$customerId: ID!
$lastModifiedTimestamp: String
) {
@@ -30,13 +30,13 @@ const UPDATE_USER = gql`
id: $id
username: $username
password: $password
role: $role
roles: $roles
customerId: $customerId
lastModifiedTimestamp: $lastModifiedTimestamp
) {
id
username
role
roles
customerId
lastModifiedTimestamp
}
@@ -49,14 +49,14 @@ const EditAccount = () => {
const [updateUser] = useMutation(UPDATE_USER);
const handleSubmit = newPassword => {
const { role, customerId, lastModifiedTimestamp } = data.getUser;
const { roles, customerId, lastModifiedTimestamp } = data.getUser;
updateUser({
variables: {
id,
username: email,
password: newPassword,
role,
roles,
customerId,
lastModifiedTimestamp,
},

View File

@@ -13,7 +13,7 @@ import { removeItem } from 'utils/localStorage';
import UserContext from 'contexts/UserContext';
const MasterLayout = ({ children }) => {
const { role, customerId } = useContext(UserContext);
const { roles, customerId } = useContext(UserContext);
const client = useApolloClient();
const location = useLocation();
@@ -70,7 +70,7 @@ const MasterLayout = ({ children }) => {
},
];
if (role === 'SuperUser') {
if (roles?.[0] === 'SuperUser') {
menuItems.push({
key: 'users',
path: ROUTES.users,

View File

@@ -3,8 +3,8 @@ import PropTypes from 'prop-types';
import UserContext from 'contexts/UserContext';
const UserProvider = ({ children, id, email, role, customerId, updateUser, updateToken }) => (
<UserContext.Provider value={{ id, email, role, customerId, updateUser, updateToken }}>
const UserProvider = ({ children, id, email, roles, customerId, updateUser, updateToken }) => (
<UserContext.Provider value={{ id, email, roles, customerId, updateUser, updateToken }}>
{children}
</UserContext.Provider>
);
@@ -15,14 +15,14 @@ UserProvider.propTypes = {
updateToken: PropTypes.func.isRequired,
id: PropTypes.number,
email: PropTypes.string,
role: PropTypes.string,
roles: PropTypes.instanceOf(Array),
customerId: PropTypes.number,
};
UserProvider.defaultProps = {
id: null,
email: null,
role: null,
roles: [],
customerId: null,
};

8
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "wlan-cloud-ui",
"version": "0.6.0",
"version": "0.7.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -1845,9 +1845,9 @@
}
},
"@tip-wlan/wlan-cloud-ui-library": {
"version": "0.5.1",
"resolved": "https://tip.jfrog.io/artifactory/api/npm/tip-wlan-cloud-npm-repo/@tip-wlan/wlan-cloud-ui-library/-/@tip-wlan/wlan-cloud-ui-library-0.5.1.tgz",
"integrity": "sha1-ZlZ1fpk3M9k5IaiXqciMrAkPY70="
"version": "0.6.0",
"resolved": "https://tip.jfrog.io/artifactory/api/npm/tip-wlan-cloud-npm-repo/@tip-wlan/wlan-cloud-ui-library/-/@tip-wlan/wlan-cloud-ui-library-0.6.0.tgz",
"integrity": "sha1-EQdON6Jmd3IuM60/qVyIrUEgUxk="
},
"@types/anymatch": {
"version": "1.3.1",

View File

@@ -1,6 +1,6 @@
{
"name": "wlan-cloud-ui",
"version": "0.6.0",
"version": "0.7.0",
"author": "ConnectUs",
"description": "React Portal",
"engines": {
@@ -21,7 +21,7 @@
"dependencies": {
"@ant-design/icons": "^4.2.1",
"@apollo/client": "^3.1.3",
"@tip-wlan/wlan-cloud-ui-library": "^0.5.1",
"@tip-wlan/wlan-cloud-ui-library": "^0.6.0",
"antd": "^4.5.2",
"apollo-upload-client": "^13.0.0",
"clean-webpack-plugin": "^3.0.0",