mirror of
https://github.com/openmhz/trunk-server.git
synced 2026-11-12 08:47:40 -05:00
cleaned up the routing
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@lagunovsky/redux-react-router": "^4.3.0",
|
||||
"@visx/axis": "3.0.1",
|
||||
"@visx/curve": "3.0.0",
|
||||
"@visx/glyph": "3.0.0",
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// in src/restricted.js
|
||||
//import React, { Component } from 'react';
|
||||
import React, { useEffect} from "react";
|
||||
import { useSelector, useDispatch } from 'react-redux'
|
||||
import { authenticateUser } from "../features/user/userSlice";
|
||||
@@ -7,7 +6,6 @@ import { authenticateUser } from "../features/user/userSlice";
|
||||
* Higher-order component (HOC) to wrap restricted pages
|
||||
*/
|
||||
|
||||
|
||||
const Restricted = ({children }) => {
|
||||
const { authenticated, hasAuthenticated } = useSelector((state) => state.user);
|
||||
const dispatch = useDispatch();
|
||||
@@ -16,12 +14,6 @@ const Restricted = ({children }) => {
|
||||
dispatch(authenticateUser({}));
|
||||
},[]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!authenticated) {
|
||||
console.log("I loaded things and it is not good")
|
||||
}
|
||||
}, [hasAuthenticated])
|
||||
|
||||
if (authenticated) {
|
||||
return children;;
|
||||
}
|
||||
@@ -29,51 +21,4 @@ const Restricted = ({children }) => {
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
const restricted = (BaseComponent, store) => {
|
||||
|
||||
class Restricted extends Component {
|
||||
componentDidMount() {
|
||||
this.checkAuthentication(this.props);
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
if (prevProps.location !== this.props.location) {
|
||||
this.checkAuthentication(this.props);
|
||||
}
|
||||
}
|
||||
|
||||
checkAuthentication(params) {
|
||||
const authenticated = store.getState().user.authenticated;
|
||||
if (!authenticated) {
|
||||
axios
|
||||
.get(process.env.REACT_APP_ACCOUNT_SERVER + "/authenticated", { withCredentials: true })
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
const user = response.data.user
|
||||
store.dispatch({
|
||||
type: types.LOGIN_SUCCESS_USER,
|
||||
data: user
|
||||
});
|
||||
} else {
|
||||
window.location = process.env.REACT_APP_ACCOUNT_SERVER + "/login?nextLocation=admin";
|
||||
}
|
||||
})
|
||||
.catch(response => {
|
||||
if (response instanceof Error) {
|
||||
window.location = process.env.REACT_APP_ACCOUNT_SERVER + "/login?nextLocation=admin";
|
||||
// Something happened during logout that triggered an Error
|
||||
console.log("Error", response.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
render() {
|
||||
return <BaseComponent {...this.props} />;
|
||||
}
|
||||
}
|
||||
return withRouter(Restricted);
|
||||
}
|
||||
*/
|
||||
|
||||
export default Restricted
|
||||
@@ -1,148 +0,0 @@
|
||||
import React, { Component } from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import {
|
||||
Container,
|
||||
Checkbox,
|
||||
Header,
|
||||
Form,
|
||||
Grid,
|
||||
Modal,
|
||||
Rail,
|
||||
Segment,
|
||||
List,
|
||||
Input,
|
||||
Button,
|
||||
Message,
|
||||
Icon,
|
||||
Table
|
||||
} from "semantic-ui-react";
|
||||
|
||||
// ----------------------------------------------------
|
||||
const requestMessageStyle = {
|
||||
color: "red"
|
||||
};
|
||||
|
||||
// ----------------------------------------------------
|
||||
class AddPermissionModal extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.handleSubmit = this.handleSubmit.bind(this);
|
||||
this.handleClose = this.handleClose.bind(this);
|
||||
this.handleChange = this.handleChange.bind(this);
|
||||
// Set initial state
|
||||
this.state = {
|
||||
role: 5,
|
||||
email: "",
|
||||
error: ""
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
handleInputChange = (e, { name, value }) => this.setState({ [name]: value });
|
||||
handleChange = (e, { newRole }) => this.setState({ newRole })
|
||||
|
||||
|
||||
|
||||
|
||||
handleClose = () => {
|
||||
this.setState({
|
||||
error: ""
|
||||
});
|
||||
this.props.onClose(false);
|
||||
}
|
||||
handleSubmit() {
|
||||
//if (this.props.updatePermissionId) {
|
||||
const data = {email: this.state.email, shortName: this.props.shortName, role: this.state.role }
|
||||
|
||||
this.props.permissionActions.addPermission(data).then(requestMessage => {
|
||||
if (requestMessage) {
|
||||
// report to the user is there was a problem during registration
|
||||
this.setState({
|
||||
error: requestMessage
|
||||
});
|
||||
//this.props.onClose(false);
|
||||
} else {
|
||||
this.setState({
|
||||
error: ""
|
||||
});
|
||||
this.props.onClose(true);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//}
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
const railStyle = {
|
||||
top: "15px",
|
||||
minHeight: "200px"
|
||||
};
|
||||
var errorMessage = "";
|
||||
|
||||
if (this.state.error) {
|
||||
errorMessage = (
|
||||
<Message negative>
|
||||
<Message.Header>That didn't work...</Message.Header>
|
||||
<p>{this.state.error}</p>
|
||||
</Message>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal size='tiny' open={this.props.open} onClose={this.handleClose} centered={false}>
|
||||
<Modal.Header>Select Role</Modal.Header>
|
||||
<Modal.Content >
|
||||
<Modal.Description>
|
||||
<Form>
|
||||
<Form.Field>
|
||||
Add User Access to System: {this.props.shortName}
|
||||
</Form.Field>
|
||||
<Form.Field>
|
||||
<Input label="User's email" placeholder='user@domain.com' name='email' onChange={this.handleInputChange} />
|
||||
</Form.Field>
|
||||
<Form.Field>
|
||||
<Checkbox
|
||||
radio
|
||||
label='User'
|
||||
name='role'
|
||||
value={5}
|
||||
checked={(this.state.role >= 0) && (this.state.role < 10)}
|
||||
onChange={this.handleInputChange}
|
||||
/>
|
||||
</Form.Field>
|
||||
<Form.Field>
|
||||
<Checkbox
|
||||
radio
|
||||
label='Admin'
|
||||
name='role'
|
||||
value={15}
|
||||
checked={(this.state.role >= 10) && (this.state.role < 20)}
|
||||
onChange={this.handleInputChange}
|
||||
/>
|
||||
</Form.Field>
|
||||
</Form>
|
||||
{errorMessage}
|
||||
</Modal.Description>
|
||||
</Modal.Content>
|
||||
<Modal.Actions>
|
||||
<Button onClick={this.handleClose} >
|
||||
<Icon name='remove' /> Cancel
|
||||
</Button>
|
||||
<Button onClick={this.handleSubmit} >
|
||||
<Icon name='plus' /> Add
|
||||
</Button>
|
||||
</Modal.Actions>
|
||||
</Modal>
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default AddPermissionModal;
|
||||
@@ -1,23 +0,0 @@
|
||||
import { connect } from "react-redux"
|
||||
import * as permissionActionCreators from "./permission-actions"
|
||||
import { bindActionCreators } from 'redux'
|
||||
import AddPermissionModal from "./AddPermissionModal"
|
||||
|
||||
//groups: state.group.items[props.match.params.shortName],
|
||||
function mapStateToProps(state,props) {
|
||||
return {
|
||||
permissions: state.permission.items,
|
||||
shortName: props.shortName
|
||||
}
|
||||
}
|
||||
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
permissionActions: bindActionCreators(permissionActionCreators,dispatch)
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(AddPermissionModal)
|
||||
@@ -1,76 +0,0 @@
|
||||
import React, { Component } from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import { Link } from 'react-router-dom'
|
||||
import {
|
||||
Container,
|
||||
Header,
|
||||
Form,
|
||||
Grid,
|
||||
Segment,
|
||||
Input,
|
||||
Button,
|
||||
Message,
|
||||
Icon,
|
||||
Table
|
||||
} from "semantic-ui-react";
|
||||
|
||||
// ----------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------
|
||||
class ListPermissions extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//https://stackoverflow.com/questions/36559661/how-can-i-dispatch-from-child-components-in-react-redux
|
||||
//https://stackoverflow.com/questions/42597602/react-onclick-pass-event-with-parameter
|
||||
render() {
|
||||
const permissions = this.props.permissions;
|
||||
if (permissions) {
|
||||
return (
|
||||
|
||||
<Table >
|
||||
<Table.Header>
|
||||
<Table.Row>
|
||||
<Table.HeaderCell>Name</Table.HeaderCell>
|
||||
<Table.HeaderCell>Email</Table.HeaderCell>
|
||||
<Table.HeaderCell>Role</Table.HeaderCell>
|
||||
<Table.HeaderCell></Table.HeaderCell>
|
||||
</Table.Row>
|
||||
</Table.Header>
|
||||
<Table.Body>
|
||||
{permissions.map((permission, i) => (
|
||||
<Table.Row key={ "Group-" + i}>
|
||||
<Table.Cell>{permission.firstName} {permission.lastName}</Table.Cell>
|
||||
<Table.Cell>{permission.email}</Table.Cell>
|
||||
<Table.Cell>{permission.role}</Table.Cell>
|
||||
<Table.Cell><Icon
|
||||
name="pencil alternate"
|
||||
link={true}
|
||||
onClick={e => this.props.updatePermission(permission._id)}
|
||||
/>
|
||||
<Icon
|
||||
name="remove"
|
||||
link={true}
|
||||
onClick={e => this.props.deletePermission(permission)}
|
||||
/>
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
))}
|
||||
</Table.Body>
|
||||
</Table>
|
||||
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<div/>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default ListPermissions;
|
||||
@@ -1,134 +0,0 @@
|
||||
import React, { Component } from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import {
|
||||
Container,
|
||||
Checkbox,
|
||||
Header,
|
||||
Form,
|
||||
Grid,
|
||||
Modal,
|
||||
Rail,
|
||||
Segment,
|
||||
List,
|
||||
Input,
|
||||
Button,
|
||||
Message,
|
||||
Icon,
|
||||
Table
|
||||
} from "semantic-ui-react";
|
||||
|
||||
// ----------------------------------------------------
|
||||
const requestMessageStyle = {
|
||||
color: "red"
|
||||
};
|
||||
|
||||
// ----------------------------------------------------
|
||||
class UpdatePermissionModal extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.handleSubmit = this.handleSubmit.bind(this);
|
||||
this.handleClose = this.handleClose.bind(this);
|
||||
this.handleChange = this.handleChange.bind(this);
|
||||
// Set initial state
|
||||
this.state = {
|
||||
newRole: false,
|
||||
permission: false
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
|
||||
if (nextProps.permissions && nextProps.updatePermissionId) {
|
||||
var updatePermission = nextProps.permissions.find(permission=> permission._id === nextProps.updatePermissionId);
|
||||
|
||||
if (updatePermission) {
|
||||
this.setState({permission: updatePermission, newRole: updatePermission.role});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handleChange = (e, { name, value }) => this.setState({ newRole: value })
|
||||
|
||||
|
||||
|
||||
|
||||
handleClose = () => this.props.onClose(false);
|
||||
handleSubmit() {
|
||||
if (this.props.updatePermissionId) {
|
||||
const data = {permissionId: this.props.updatePermissionId, shortName: this.props.shortName, role: this.state.newRole }
|
||||
|
||||
this.props.permissionActions.update(data).then(requestMessage => {
|
||||
if (requestMessage) {
|
||||
// report to the user is there was a problem during registration
|
||||
this.setState({
|
||||
requestMessage
|
||||
});
|
||||
this.props.onClose(false);
|
||||
} else {
|
||||
this.props.onClose(true);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
const railStyle = {
|
||||
top: "15px",
|
||||
minHeight: "200px"
|
||||
};
|
||||
var user = ""
|
||||
if (this.state.permission) {
|
||||
user = this.state.permission.email
|
||||
}
|
||||
return (
|
||||
<Modal size='tiny' open={this.props.open} onClose={this.handleClose} centered={false}>
|
||||
<Modal.Header>Select Role</Modal.Header>
|
||||
<Modal.Content >
|
||||
<Modal.Description>
|
||||
<Form>
|
||||
<Form.Field>
|
||||
Set role for <b>{user}</b>:
|
||||
</Form.Field>
|
||||
<Form.Field>
|
||||
<Checkbox
|
||||
radio
|
||||
label='User'
|
||||
name='checkboxRadioGroup'
|
||||
value={5}
|
||||
checked={(this.state.newRole >= 0) && (this.state.newRole < 10)}
|
||||
onChange={this.handleChange}
|
||||
/>
|
||||
</Form.Field>
|
||||
<Form.Field>
|
||||
<Checkbox
|
||||
radio
|
||||
label='Admin'
|
||||
name='checkboxRadioGroup'
|
||||
value={15}
|
||||
checked={(this.state.newRole >= 10) && (this.state.newRole < 20)}
|
||||
onChange={this.handleChange}
|
||||
/>
|
||||
</Form.Field>
|
||||
</Form>
|
||||
|
||||
</Modal.Description>
|
||||
</Modal.Content>
|
||||
<Modal.Actions>
|
||||
<Button onClick={this.handleSubmit} >
|
||||
<Icon name='checkmark' /> Update
|
||||
</Button>
|
||||
</Modal.Actions>
|
||||
</Modal>
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default UpdatePermissionModal;
|
||||
@@ -1,23 +0,0 @@
|
||||
import { connect } from "react-redux"
|
||||
import * as permissionActionCreators from "./permission-actions"
|
||||
import { bindActionCreators } from 'redux'
|
||||
import UpdatePermissionModal from "./UpdatePermissionModal"
|
||||
|
||||
//groups: state.group.items[props.match.params.shortName],
|
||||
function mapStateToProps(state,props) {
|
||||
return {
|
||||
permissions: state.permission.items,
|
||||
shortName: props.shortName
|
||||
}
|
||||
}
|
||||
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
permissionActions: bindActionCreators(permissionActionCreators,dispatch)
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(UpdatePermissionModal)
|
||||
@@ -1,166 +0,0 @@
|
||||
import axios from "axios";
|
||||
//import { browserHistory } from "react-router"
|
||||
import * as types from "./permission-constants";
|
||||
|
||||
function beginAddPermission() {
|
||||
return { type: types.ADD_PERMISSION };
|
||||
}
|
||||
|
||||
function addPermissionSuccess(data) {
|
||||
return { type: types.ADD_PERMISSION_SUCCESS, data };
|
||||
}
|
||||
|
||||
function addPermissionError() {
|
||||
return { type: types.ADD_PERMISSION_ERROR };
|
||||
}
|
||||
|
||||
function beginDeletePermission() {
|
||||
return { type: types.DELETE_PERMISSION };
|
||||
}
|
||||
|
||||
function deletePermissionSuccess(data) {
|
||||
return { type: types.DELETE_PERMISSION_SUCCESS, data };
|
||||
}
|
||||
|
||||
function deletePermissionError() {
|
||||
return { type: types.DELETE_PERMISSION_ERROR };
|
||||
}
|
||||
|
||||
|
||||
function beginUpdateRole() {
|
||||
return { type: types.UPDATE_ROLE };
|
||||
}
|
||||
|
||||
function updateRoleSuccess(data) {
|
||||
return { type: types.UPDATE_ROLE_SUCCESS, data };
|
||||
}
|
||||
|
||||
function updateRoleError() {
|
||||
return { type: types.UPDATE_ROLE_ERROR };
|
||||
}
|
||||
|
||||
// "Log In" action creators
|
||||
function beginFetchPermission() {
|
||||
return { type: types.FETCH_PERMISSION };
|
||||
}
|
||||
|
||||
function fetchPermissionError(data) {
|
||||
return { type: types.FETCH_ERROR_PERMISSION,
|
||||
data };
|
||||
}
|
||||
|
||||
function fetchPermissionSuccess(data) {
|
||||
return { type: types.FETCH_SUCCESS_PERMISSION,
|
||||
data };
|
||||
}
|
||||
|
||||
function shouldFetch(state) {
|
||||
if ((!state.permission.items) || (state.permission.items.length <1)) {
|
||||
return true
|
||||
} else if (state.permission.isWaiting) {
|
||||
return false
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export function fetch(shortName) {
|
||||
return (dispatch, getState) => {
|
||||
if (shouldFetch(getState())) {
|
||||
dispatch(beginFetchPermission());
|
||||
|
||||
return axios
|
||||
.get(process.env.REACT_APP_ADMIN_SERVER + "/permissions/"+shortName, {withCredentials: true})
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
dispatch(fetchPermissionSuccess(response.data.permissions));
|
||||
} else {
|
||||
dispatch(fetchPermissionError());
|
||||
let registerMessage = response.data.message;
|
||||
return registerMessage;
|
||||
}
|
||||
})
|
||||
.catch(response => {
|
||||
if (response instanceof Error) {
|
||||
// Something happened in setting up the request that triggered an Error
|
||||
console.log("Error", response.message);
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export function update(data) {
|
||||
return (dispatch, getState) => {
|
||||
|
||||
dispatch(beginUpdateRole());
|
||||
var url = process.env.REACT_APP_ADMIN_SERVER + "/permissions/" + data.shortName + "/" + data.permissionId;
|
||||
return axios.post( url, data, {withCredentials: true})
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
dispatch(updateRoleSuccess(response.data.permission));
|
||||
} else {
|
||||
dispatch(updateRoleError());
|
||||
let registerMessage = response.data.message;
|
||||
return registerMessage;
|
||||
}
|
||||
})
|
||||
.catch(response => {
|
||||
if (response instanceof Error) {
|
||||
// Something happened in setting up the request that triggered an Error
|
||||
console.log("Error", response.message);
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
export function addPermission(data) {
|
||||
return (dispatch, getState) => {
|
||||
dispatch(beginAddPermission());
|
||||
var url = process.env.REACT_APP_ADMIN_SERVER + "/permissions/" + data.shortName;
|
||||
return axios.post( url, data, {withCredentials: true})
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
dispatch(addPermissionSuccess(response.data.permission));
|
||||
} else {
|
||||
dispatch(addPermissionError());
|
||||
let registerMessage = response.data.message;
|
||||
return registerMessage;
|
||||
}
|
||||
})
|
||||
.catch(response => {
|
||||
if (response instanceof Error) {
|
||||
// Something happened in setting up the request that triggered an Error
|
||||
console.log("Error", response.message);
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export function deletePermission(data) {
|
||||
return (dispatch, getState) => {
|
||||
|
||||
dispatch(beginDeletePermission());
|
||||
var url = process.env.REACT_APP_ADMIN_SERVER + "/permissions/" + data.shortName + "/" + data.permissionId;
|
||||
return axios.delete( url, {withCredentials: true})
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
dispatch(deletePermissionSuccess(data.permissionId));
|
||||
} else {
|
||||
dispatch(deletePermissionError());
|
||||
let registerMessage = response.data.message;
|
||||
return registerMessage;
|
||||
}
|
||||
})
|
||||
.catch(response => {
|
||||
if (response instanceof Error) {
|
||||
// Something happened in setting up the request that triggered an Error
|
||||
console.log("Error", response.message);
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
export const ADD_PERMISSION = "ADD_PERMISSION"
|
||||
export const ADD_PERMISSION_ERROR = "ADD_PERMISSION_ERROR"
|
||||
export const ADD_PERMISSION_SUCCESS = "ADD_PERMISSION_SUCCESS"
|
||||
export const FETCH_PERMISSION = "FETCH_PERMISSION"
|
||||
export const FETCH_ERROR_PERMISSION = "FETCH_ERROR_PERMISSION"
|
||||
export const FETCH_SUCCESS_PERMISSION = "FETCH_SUCCESS_PERMISSION"
|
||||
export const UPDATE_ROLE = "UPDATE_ROLE"
|
||||
export const UPDATE_ROLE_ERROR = "UPDATE_ROLE_ERROR"
|
||||
export const UPDATE_ROLE_SUCCESS = "UPDATE_ROLE SUCCESS"
|
||||
export const DELETE_PERMISSION = "DELETE_PERMISSION"
|
||||
export const DELETE_PERMISSION_ERROR = "DELETE_PERMISSION_ERROR"
|
||||
export const DELETE_PERMISSION_SUCCESS = "DELETE_PERMISSION_SUCCESS"
|
||||
@@ -1,87 +0,0 @@
|
||||
import {
|
||||
ADD_PERMISSION,
|
||||
ADD_PERMISSION_SUCCESS,
|
||||
ADD_PERMISSION_ERROR,
|
||||
DELETE_PERMISSION,
|
||||
DELETE_PERMISSION_SUCCESS,
|
||||
DELETE_PERMISSION_ERROR,
|
||||
FETCH_PERMISSION,
|
||||
FETCH_SUCCESS_PERMISSION,
|
||||
FETCH_ERROR_PERMISSION,
|
||||
UPDATE_ROLE,
|
||||
UPDATE_ROLE_ERROR,
|
||||
UPDATE_ROLE_SUCCESS
|
||||
} from "./permission-constants";
|
||||
|
||||
function updateRoleInArray(array, updatedItem) {
|
||||
const updatedItems = array.map(item => {
|
||||
if(item._id !== updatedItem._id) {
|
||||
// Since we only want to update one item, preserve all others as they are now
|
||||
return item;
|
||||
}
|
||||
item.role = updatedItem.role;
|
||||
return item;
|
||||
});
|
||||
|
||||
return updatedItems;
|
||||
}
|
||||
|
||||
function deleteItemInArray(array, _id) {
|
||||
const updatedItems = array.filter(function (item) {
|
||||
return item._id !== _id;
|
||||
});
|
||||
|
||||
return updatedItems;
|
||||
}
|
||||
|
||||
const permission = (
|
||||
state = {
|
||||
isWaiting: false,
|
||||
items: []
|
||||
},
|
||||
action
|
||||
) => {
|
||||
switch (action.type) {
|
||||
|
||||
|
||||
case ADD_PERMISSION_SUCCESS:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false,
|
||||
items: [...state.items, action.data]
|
||||
});
|
||||
case DELETE_PERMISSION_SUCCESS:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false,
|
||||
items: deleteItemInArray(state.items, action.data)
|
||||
});
|
||||
case UPDATE_ROLE_SUCCESS:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false,
|
||||
items: updateRoleInArray(state.items, action.data)
|
||||
});
|
||||
case FETCH_SUCCESS_PERMISSION:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false,
|
||||
items: action.data
|
||||
});
|
||||
|
||||
case DELETE_PERMISSION_ERROR:
|
||||
case ADD_PERMISSION_ERROR:
|
||||
case UPDATE_ROLE_ERROR:
|
||||
case FETCH_ERROR_PERMISSION:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false
|
||||
});
|
||||
|
||||
case DELETE_PERMISSION:
|
||||
case ADD_PERMISSION:
|
||||
case UPDATE_ROLE:
|
||||
case FETCH_PERMISSION:
|
||||
return Object.assign({}, state, { isWaiting: true});
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default permission;
|
||||
@@ -76,8 +76,6 @@ constructor(props) {
|
||||
<AxisLeft scale={yScale} />
|
||||
<LinePath
|
||||
data={callTotals}
|
||||
xScale={xScale}
|
||||
yScale={yScale}
|
||||
x={x}
|
||||
y={y}
|
||||
strokeWidth={2}
|
||||
@@ -85,8 +83,6 @@ constructor(props) {
|
||||
/>
|
||||
<LinePath
|
||||
data={errorTotals}
|
||||
xScale={xScale}
|
||||
yScale={yScale}
|
||||
x={x}
|
||||
y={y}
|
||||
strokeWidth={2}
|
||||
|
||||
@@ -1,27 +1,23 @@
|
||||
import React, { Component } from "react"
|
||||
import React, { Component } from "react"
|
||||
import CallChart from "./CallChart"
|
||||
import { ParentSize } from "@visx/responsive";
|
||||
|
||||
class ResponsiveCallChart extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
const ResponsiveCallChart = (props) => {
|
||||
|
||||
render() {
|
||||
return(
|
||||
<ParentSize className="graph-container">
|
||||
{({ width: w, height: h }) => {
|
||||
return (
|
||||
<CallChart
|
||||
width={w}
|
||||
height={h}
|
||||
data={this.props.data}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
</ParentSize>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<ParentSize className="graph-container">
|
||||
{({ width: w, height: h }) => {
|
||||
return (
|
||||
<CallChart
|
||||
width={w}
|
||||
height={h}
|
||||
data={props.data}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
</ParentSize>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
export default ResponsiveCallChart
|
||||
|
||||
@@ -1,27 +1,22 @@
|
||||
import React, { Component } from "react"
|
||||
import React, { Component } from "react"
|
||||
import ErrorChart from "./ErrorChart"
|
||||
import { ParentSize } from "@visx/responsive";
|
||||
|
||||
class ResponsiveErrorChart extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
const ResponsiveErrorChart = (props) => {
|
||||
|
||||
render() {
|
||||
return(
|
||||
<ParentSize className="graph-container">
|
||||
{({ width: w, height: h }) => {
|
||||
return (
|
||||
<ErrorChart
|
||||
width={w}
|
||||
height={h}
|
||||
data={this.props.data}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
</ParentSize>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<ParentSize className="graph-container">
|
||||
{({ width: w, height: h }) => {
|
||||
return (
|
||||
<ErrorChart
|
||||
width={w}
|
||||
height={h}
|
||||
data={props.data}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
</ParentSize>
|
||||
)
|
||||
}
|
||||
|
||||
export default ResponsiveErrorChart
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
const groupSlice = createSlice({
|
||||
name: 'group',
|
||||
initialState: {
|
||||
orderChange: false,
|
||||
isWaiting: false,
|
||||
items: {}
|
||||
},
|
||||
reducers: {
|
||||
},
|
||||
})
|
||||
|
||||
// Extract the action creators object and the reducer
|
||||
const { actions, reducer } = groupSlice
|
||||
// Export the reducer, either as a default or named export
|
||||
export default reducer
|
||||
@@ -2,12 +2,12 @@ import React from 'react';
|
||||
import { Provider } from 'react-redux'
|
||||
import { createRoot } from 'react-dom/client';
|
||||
import { BrowserRouter } from "react-router-dom";
|
||||
import configureStore, { history } from './redux-router/configureStore'
|
||||
import setupStore from './redux-router/configureStore'
|
||||
import 'semantic-ui-css/semantic.min.css'
|
||||
import App from "./App/App"
|
||||
|
||||
|
||||
const store = configureStore(/* provide initial state if any */)
|
||||
const store = setupStore(/* provide initial state if any */)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,31 +1,20 @@
|
||||
// https://github.com/supasate/connected-react-router
|
||||
// configureStore.js
|
||||
import { configureStore } from '@reduxjs/toolkit'
|
||||
import { userReducer } from '../features/user/userSlice'
|
||||
import { apiSlice } from "../features/api/apiSlice"
|
||||
|
||||
import { createBrowserHistory } from 'history'
|
||||
import { applyMiddleware, compose, createStore } from 'redux'
|
||||
import { createRouterMiddleware } from '@lagunovsky/redux-react-router'
|
||||
import createRootReducer from './reducers'
|
||||
import thunk from 'redux-thunk';
|
||||
import { apiSlice } from '../features/api/apiSlice'
|
||||
import { composeWithDevTools } from 'redux-devtools-extension'
|
||||
|
||||
//const composedEnhancers = composeWithDevTools(...enhancers)
|
||||
export const history = createBrowserHistory()
|
||||
|
||||
export default function configureStore(preloadedState) {
|
||||
const store = createStore(
|
||||
createRootReducer(history), // root reducer with router state
|
||||
const setupStore = (preloadedState) => {
|
||||
const store = configureStore({
|
||||
reducer: {
|
||||
user: userReducer,
|
||||
[apiSlice.reducerPath]: apiSlice.reducer,
|
||||
},
|
||||
middleware: (getDefaultMiddleware) =>
|
||||
// adding the api middleware enables caching, invalidation, polling and other features of `rtk-query`
|
||||
getDefaultMiddleware().concat(apiSlice.middleware),
|
||||
preloadedState,
|
||||
composeWithDevTools(
|
||||
applyMiddleware(
|
||||
createRouterMiddleware(history), // for dispatching history actions
|
||||
thunk,
|
||||
apiSlice.middleware,
|
||||
// ... other middlewares ...
|
||||
),
|
||||
),
|
||||
)
|
||||
})
|
||||
|
||||
return store
|
||||
}
|
||||
|
||||
export default setupStore;
|
||||
@@ -1,16 +0,0 @@
|
||||
|
||||
// from https://github.com/supasate/connected-react-router
|
||||
import { combineReducers } from 'redux'
|
||||
import { createRouterReducer } from '@lagunovsky/redux-react-router'
|
||||
import { userSlice, userReducer } from '../features/user/userSlice'
|
||||
import {apiSlice} from "../features/api/apiSlice"
|
||||
|
||||
const createRootReducer = (history) => combineReducers({
|
||||
router: createRouterReducer (history),
|
||||
user: userReducer,
|
||||
[apiSlice.reducerPath]: apiSlice.reducer,
|
||||
|
||||
})
|
||||
export default createRootReducer
|
||||
|
||||
|
||||
@@ -1546,11 +1546,6 @@
|
||||
"@jridgewell/resolve-uri" "3.1.0"
|
||||
"@jridgewell/sourcemap-codec" "1.4.14"
|
||||
|
||||
"@lagunovsky/redux-react-router@^4.3.0":
|
||||
version "4.3.0"
|
||||
resolved "https://registry.npmjs.org/@lagunovsky/redux-react-router/-/redux-react-router-4.3.0.tgz"
|
||||
integrity sha512-zjjIu0xiX4cAE6O0ttLwo/Fk2zF3oeDfP3nC9YPUFSMnK7QumxS4xQIaH8x+amIIrg3klvPAk64L1bZLvDHl5w==
|
||||
|
||||
"@leichtgewicht/ip-codec@^2.0.1":
|
||||
version "2.0.4"
|
||||
resolved "https://registry.npmjs.org/@leichtgewicht/ip-codec/-/ip-codec-2.0.4.tgz"
|
||||
|
||||
@@ -2,11 +2,11 @@ import React from 'react';
|
||||
import { createRoot } from 'react-dom/client';
|
||||
import { BrowserRouter } from "react-router-dom";
|
||||
import { Provider } from 'react-redux'
|
||||
import configureStore from './redux-router/configureStore'
|
||||
import setupStore from './redux-router/configureStore'
|
||||
|
||||
import App from "./app"
|
||||
|
||||
const store = configureStore(/* provide initial state if any */)
|
||||
const store = setupStore(/* provide initial state if any */)
|
||||
|
||||
const container = document.getElementById('root');
|
||||
const root = createRoot(container);
|
||||
|
||||
@@ -1,31 +1,22 @@
|
||||
// https://github.com/supasate/connected-react-router
|
||||
// configureStore.js
|
||||
import { configureStore } from '@reduxjs/toolkit'
|
||||
import { apiSlice } from "../features/api/apiSlice"
|
||||
import callPlayerSlice from "../features/callPlayer/callPlayerSlice"
|
||||
import { callsReducer } from "../features/calls/callsSlice"
|
||||
|
||||
import { createBrowserHistory } from 'history'
|
||||
import { applyMiddleware, compose, createStore } from 'redux'
|
||||
import { createRouterMiddleware } from '@lagunovsky/redux-react-router'
|
||||
//import { routerMiddleware } from 'connected-react-router'
|
||||
import createRootReducer from './reducers'
|
||||
import { apiSlice } from '../features/api/apiSlice'
|
||||
const setupStore = (preloadedState) => {
|
||||
const store = configureStore({
|
||||
reducer: {
|
||||
callPlayer: callPlayerSlice,
|
||||
calls: callsReducer,
|
||||
[apiSlice.reducerPath]: apiSlice.reducer,
|
||||
},
|
||||
middleware: (getDefaultMiddleware) =>
|
||||
// adding the api middleware enables caching, invalidation, polling and other features of `rtk-query`
|
||||
getDefaultMiddleware().concat(apiSlice.middleware),
|
||||
preloadedState,
|
||||
})
|
||||
|
||||
import thunk from 'redux-thunk';
|
||||
|
||||
export const history = createBrowserHistory()
|
||||
|
||||
export default function configureStore(preloadedState) {
|
||||
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
|
||||
const store = createStore(
|
||||
createRootReducer(history), // root reducer with router state
|
||||
preloadedState,
|
||||
composeEnhancers(
|
||||
applyMiddleware(
|
||||
createRouterMiddleware(history), // for dispatching history actions
|
||||
thunk,
|
||||
apiSlice.middleware,
|
||||
// ... other middlewares ...
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
return store
|
||||
}
|
||||
}
|
||||
|
||||
export default setupStore;
|
||||
@@ -1,15 +0,0 @@
|
||||
|
||||
// from https://github.com/supasate/connected-react-router
|
||||
import { combineReducers } from 'redux'
|
||||
//import { connectRouter } from 'connected-react-router'
|
||||
import { createRouterReducer } from '@lagunovsky/redux-react-router'
|
||||
import {apiSlice} from "../features/api/apiSlice"
|
||||
import callPlayerSlice from "../features/callPlayer/callPlayerSlice"
|
||||
import { callsReducer } from "../features/calls/callsSlice"
|
||||
|
||||
export default (history) => combineReducers({
|
||||
router: createRouterReducer(history),
|
||||
callPlayer: callPlayerSlice,
|
||||
calls: callsReducer,
|
||||
[apiSlice.reducerPath]: apiSlice.reducer,
|
||||
})
|
||||
Reference in New Issue
Block a user