Room Office Mapping / Home screen now functional / Bugfixes
This commit is contained in:
@@ -5,7 +5,7 @@ import { Menu } from 'semantic-ui-react';
|
||||
import { mainMenuItems } from '../../constants/menuItems';
|
||||
|
||||
const MainMenu = () =>
|
||||
(<Menu>
|
||||
(<Menu size={'huge'}>
|
||||
{
|
||||
mainMenuItems.map(mainMenuItem => {
|
||||
if (!mainMenuItem.showInMenu){
|
||||
|
||||
35
client/src/components/PromptMessage/index.js
Normal file
35
client/src/components/PromptMessage/index.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import React, { Component } from 'react';
|
||||
import {Button, Modal} from "semantic-ui-react";
|
||||
|
||||
|
||||
class PromptMessage extends Component {
|
||||
render() {
|
||||
const {
|
||||
show = false,
|
||||
size = 'tiny',
|
||||
title = '',
|
||||
message = '',
|
||||
noActionLabel = 'No',
|
||||
yesActionLabel = 'Yes',
|
||||
yesActionIconName = 'checkmark',
|
||||
onClose = null,
|
||||
onActionNo = null,
|
||||
onActionYes = null,
|
||||
} = this.props;
|
||||
|
||||
return (
|
||||
<Modal size={size} open={show} onClose={onClose}>
|
||||
<Modal.Header>{title}</Modal.Header>
|
||||
<Modal.Content>
|
||||
<p>{message}</p>
|
||||
</Modal.Content>
|
||||
<Modal.Actions>
|
||||
<Button negative onClick={onActionNo}>{noActionLabel}</Button>
|
||||
<Button positive icon={yesActionIconName} onClick={onActionYes} labelPosition='right' content={yesActionLabel} />
|
||||
</Modal.Actions>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default PromptMessage;
|
||||
@@ -3,11 +3,13 @@ import Home from '../scenes/Home';
|
||||
import IncidentsReport from '../scenes/IncidentsReport';
|
||||
import SpecificMemberIncidentsReport from '../scenes/SpecificMemberIncidentsReport';
|
||||
import MemberPracticeSummaryReport from '../scenes/MemberPracticeSummaryReport';
|
||||
import RoomOfficeNameMapping from '../scenes/RoomOfficeNameMapping';
|
||||
|
||||
export const mainMenuItems = [
|
||||
{
|
||||
id: 'home',
|
||||
showInMenu: true,
|
||||
showOnHomePage: false,
|
||||
title: 'Home',
|
||||
url: '/',
|
||||
component: Home,
|
||||
@@ -15,35 +17,53 @@ export const mainMenuItems = [
|
||||
{
|
||||
id: 'memberPracticeSummaryReport',
|
||||
showInMenu: true,
|
||||
showOnHomePage: true,
|
||||
title: 'Member Practice Summary Report',
|
||||
url: '/member-practice-summary-report',
|
||||
component: MemberPracticeSummaryReport,
|
||||
description: 'Generate a report for a year, for all members',
|
||||
},
|
||||
{
|
||||
id: 'specificMemberIncidentsReport',
|
||||
showInMenu: true,
|
||||
showOnHomePage: true,
|
||||
title: 'Member Incidents Report',
|
||||
url: '/specific-member-incidents-report',
|
||||
component: SpecificMemberIncidentsReport,
|
||||
description: 'Displays all incidents with a total charge amount in a selected month for a selected member. It is also possible to send displayed fees to the ORD',
|
||||
},
|
||||
{
|
||||
id: 'specificMemberIncidentsReportWithMemberId',
|
||||
showInMenu: false,
|
||||
showOnHomePage: false,
|
||||
url: '/specific-member-incidents-report/:memberId',
|
||||
component: SpecificMemberIncidentsReport,
|
||||
},
|
||||
{
|
||||
id: 'report',
|
||||
showInMenu: true,
|
||||
showOnHomePage: true,
|
||||
title: 'Incidents Report',
|
||||
url: '/incidents-report',
|
||||
component: IncidentsReport,
|
||||
description: 'Display all incidents in a selected month for all members. It is also possible to send displayed fees to the ORD',
|
||||
},
|
||||
{
|
||||
id: 'uploadDLockData',
|
||||
showInMenu: true,
|
||||
showOnHomePage: true,
|
||||
title: 'DLock',
|
||||
url: '/dlock',
|
||||
component: UploadDLockData,
|
||||
description: 'Upload DLock files to the system',
|
||||
},
|
||||
{
|
||||
id: 'roomOfficeNameMapping',
|
||||
showInMenu: true,
|
||||
showOnHomePage: true,
|
||||
title: 'Room Office Mapping',
|
||||
url: '/room-office-name-mapping',
|
||||
component: RoomOfficeNameMapping,
|
||||
description: 'Edit / delete existing office-room mappings',
|
||||
}
|
||||
];
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import React, { Component } from 'react';
|
||||
|
||||
import { Container, Form } from 'semantic-ui-react';
|
||||
import { Container, Message } from 'semantic-ui-react';
|
||||
|
||||
import MainMenu from '../../components/MainMenu';
|
||||
import { mainMenuItems } from '../../constants/menuItems';
|
||||
|
||||
class Home extends Component {
|
||||
|
||||
@@ -10,25 +11,23 @@ class Home extends Component {
|
||||
return (
|
||||
<Container>
|
||||
<MainMenu/>
|
||||
<h3>Report</h3>
|
||||
<h3>SIMA SPACE </h3>
|
||||
<hr/>
|
||||
<Form>
|
||||
<Form.Group widths="equal">
|
||||
<Form.Input
|
||||
fluid
|
||||
required
|
||||
label="Start date"
|
||||
type="date"
|
||||
/>
|
||||
<Form.Input
|
||||
fluid
|
||||
required
|
||||
label="End date"
|
||||
type="date"
|
||||
/>
|
||||
</Form.Group>
|
||||
<Form.Button>Show report</Form.Button>
|
||||
</Form>
|
||||
{
|
||||
mainMenuItems.map((menuItem) => {
|
||||
const { showOnHomePage, title, description, url} = menuItem;
|
||||
if (showOnHomePage){
|
||||
|
||||
return (
|
||||
<Message size={'large'}>
|
||||
<a href={url}><Message.Header>{title}</Message.Header></a>
|
||||
<br/>
|
||||
{description}
|
||||
</Message>
|
||||
);
|
||||
}
|
||||
})
|
||||
}
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
import React, { Component } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
import { Table, Label, Icon, Dropdown } from 'semantic-ui-react';
|
||||
import PromptMessage from '../../../components/PromptMessage';
|
||||
import { deleteMapping, updateMapping } from '../../../store/actions';
|
||||
|
||||
class SingleMapping extends Component {
|
||||
state = {showDeletePrompt: false, newOfficeId: null, newResourceId: null};
|
||||
|
||||
deleteMapping = () => {
|
||||
this.setState({showDeletePrompt: true});
|
||||
};
|
||||
|
||||
onPromptClose = () => {
|
||||
this.setState({showDeletePrompt: false});
|
||||
};
|
||||
|
||||
onPromptYes = () => {
|
||||
const { singleMapping: { id }, deleteMapping } = this.props;
|
||||
if (parseInt(id)){
|
||||
deleteMapping(id);
|
||||
}
|
||||
this.onPromptClose();
|
||||
};
|
||||
|
||||
onOfficeChange = (event, data) => {
|
||||
const newOfficeId = data.value;
|
||||
const { allResourceOptions, officeId: oldOfficeId } = this.props;
|
||||
|
||||
if (oldOfficeId !== newOfficeId){
|
||||
let newResourceId = null;
|
||||
const roomOptionsForOffice = allResourceOptions[newOfficeId] && allResourceOptions[newOfficeId].roomOptions ?
|
||||
allResourceOptions[newOfficeId].roomOptions : [];
|
||||
|
||||
if (roomOptionsForOffice.length > 0){
|
||||
newResourceId = roomOptionsForOffice[0].value;
|
||||
}
|
||||
|
||||
this.setState({newOfficeId, newResourceId});
|
||||
}else{
|
||||
this.setState({newOfficeId: null, newResourceId: null});
|
||||
}
|
||||
};
|
||||
|
||||
onResourceChange = (event, data) => {
|
||||
const newResourceId = data.value;
|
||||
const oldResourceId = this.props.resourceId;
|
||||
|
||||
if (oldResourceId !== newResourceId){
|
||||
this.setState({newResourceId});
|
||||
}else{
|
||||
this.setState({newResourceId: null});
|
||||
}
|
||||
};
|
||||
|
||||
onMappingUpdate = () => {
|
||||
const { singleMapping: { id, officeSlug, resourceSlug }, updateMapping, officeId, resourceId } = this.props;
|
||||
const { newOfficeId, newResourceId } = this.state;
|
||||
|
||||
const selectedOfficeId = newOfficeId ? newOfficeId : officeId;
|
||||
const selectedResourceId = newResourceId ? newResourceId : resourceId;
|
||||
|
||||
if (parseInt(id)){
|
||||
|
||||
const modifiedMapping = {
|
||||
officeSlug,
|
||||
resourceSlug,
|
||||
officeId: selectedOfficeId,
|
||||
resourceId: selectedResourceId,
|
||||
};
|
||||
|
||||
updateMapping(id, modifiedMapping);
|
||||
this.setState({newOfficeId: null, newResourceId: null});
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
const { singleMapping: { officeSlug, resourceSlug } } = this.props;
|
||||
const { officeId, resourceId, officeOptions, allResourceOptions, pendingMappings } = this.props;
|
||||
const { showDeletePrompt, newOfficeId, newResourceId } = this.state;
|
||||
|
||||
const selectedOfficeId = newOfficeId ? newOfficeId : officeId;
|
||||
const selectedResourceId = newResourceId ? newResourceId : resourceId;
|
||||
|
||||
const resourceOptions = allResourceOptions && officeId ? allResourceOptions[selectedOfficeId].roomOptions : [];
|
||||
|
||||
const enableActions = !pendingMappings;
|
||||
const enableSave = enableActions && ((newOfficeId !== null) || (newResourceId !== null));
|
||||
const saveIconColor = enableSave ? 'green' : null;
|
||||
|
||||
return (
|
||||
<Table.Row>
|
||||
<PromptMessage
|
||||
onClose={this.onPromptClose}
|
||||
onActionNo={this.onPromptClose}
|
||||
onActionYes={this.onPromptYes}
|
||||
title={'Delete mapping'}
|
||||
message={'Do you want to delete this mapping ?'}
|
||||
show={showDeletePrompt}
|
||||
/>
|
||||
<Table.Cell>
|
||||
<Label size={'big'}>{`[${officeSlug}-${resourceSlug}]`}</Label>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<Dropdown
|
||||
options={officeOptions}
|
||||
defaultValue={officeId}
|
||||
onChange={this.onOfficeChange}
|
||||
/>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<Dropdown
|
||||
options={resourceOptions}
|
||||
value={selectedResourceId}
|
||||
onChange={this.onResourceChange}
|
||||
/>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<Icon
|
||||
circular
|
||||
name={'check'}
|
||||
size={'large'}
|
||||
disabled={!enableSave}
|
||||
link={enableSave || null}
|
||||
color={saveIconColor}
|
||||
onClick={this.onMappingUpdate}
|
||||
/>
|
||||
<Icon
|
||||
circular
|
||||
name={'trash'}
|
||||
size={'large'}
|
||||
disabled={!enableActions}
|
||||
link={enableActions || null}
|
||||
onClick={this.deleteMapping}
|
||||
/>
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
pendingMappings: state.mappingsData.pending,
|
||||
});
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
deleteMapping: (id) => deleteMapping(dispatch, id),
|
||||
updateMapping: (id, mapping) => updateMapping(dispatch, id, mapping),
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(SingleMapping);
|
||||
99
client/src/scenes/RoomOfficeNameMapping/index.js
Normal file
99
client/src/scenes/RoomOfficeNameMapping/index.js
Normal file
@@ -0,0 +1,99 @@
|
||||
import React, { Component } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { Container, Message, Loader, Table } from 'semantic-ui-react';
|
||||
|
||||
import MainMenu from '../../components/MainMenu';
|
||||
import { fetchMappings } from '../../store/actions';
|
||||
import SingleMapping from './components/SingleMapping';
|
||||
|
||||
class RoomOfficeNameMapping extends Component {
|
||||
|
||||
componentDidMount() {
|
||||
const { fetchMappings } = this.props;
|
||||
|
||||
fetchMappings();
|
||||
}
|
||||
|
||||
render () {
|
||||
const { pendingMappings, mappings } = this.props;
|
||||
const existingMappings = mappings && mappings.existingMappings ? mappings.existingMappings : [];
|
||||
const offices = mappings && mappings.offices ? mappings.offices : [];
|
||||
const resources = mappings && mappings.resources ? mappings.resources : [];
|
||||
|
||||
const officeDropdownOptions = offices.map((office) => {
|
||||
const { officeId, officeName } = office;
|
||||
return {
|
||||
key: officeId,
|
||||
value: officeId,
|
||||
text: officeName,
|
||||
}
|
||||
});
|
||||
|
||||
const allResourceOptions = {};
|
||||
resources.forEach((resource) => {
|
||||
const { resourceId, resourceName, officeId } = resource;
|
||||
|
||||
if (!allResourceOptions[officeId]){
|
||||
allResourceOptions[officeId] = {
|
||||
roomOptions: []
|
||||
}
|
||||
}
|
||||
|
||||
allResourceOptions[officeId].roomOptions.push({
|
||||
key: resourceId,
|
||||
value: resourceId,
|
||||
text: resourceName,
|
||||
});
|
||||
});
|
||||
|
||||
return (
|
||||
<Container>
|
||||
<Loader active={pendingMappings} />
|
||||
<MainMenu/>
|
||||
<h3>Room Office Mapping</h3>
|
||||
<hr/>
|
||||
<br/>
|
||||
<Table singleLine unstackable>
|
||||
<Table.Header>
|
||||
<Table.Row>
|
||||
<Table.HeaderCell>File name</Table.HeaderCell>
|
||||
<Table.HeaderCell>Office</Table.HeaderCell>
|
||||
<Table.HeaderCell>Resource</Table.HeaderCell>
|
||||
<Table.HeaderCell>Actions</Table.HeaderCell>
|
||||
</Table.Row>
|
||||
</Table.Header>
|
||||
<Table.Body>
|
||||
{
|
||||
existingMappings.map((singleMapping) => {
|
||||
const { officeId, resourceId } = singleMapping;
|
||||
return <SingleMapping
|
||||
key={singleMapping.id}
|
||||
singleMapping={singleMapping}
|
||||
officeId={officeId}
|
||||
resourceId={resourceId}
|
||||
officeOptions={officeDropdownOptions}
|
||||
allResourceOptions={allResourceOptions}
|
||||
/>
|
||||
})
|
||||
}
|
||||
</Table.Body>
|
||||
</Table>
|
||||
<br/>
|
||||
<Message>
|
||||
<h4>To add the mapping, upload new DL lock files and you will be prompted with new mapping options if the file name contains the unknown location</h4>
|
||||
</Message>
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
pendingMappings: state.mappingsData.pending,
|
||||
mappings: state.mappingsData.result,
|
||||
});
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
fetchMappings: () => fetchMappings(dispatch),
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(RoomOfficeNameMapping);
|
||||
@@ -38,6 +38,30 @@ export const fetchMappings = (dispatch) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteMapping = (dispatch, mappingId) => {
|
||||
dispatch({type: FETCH_MAPPINGS_PENDING});
|
||||
API.delete(`integration/mappings/${mappingId}`)
|
||||
.then(response => {
|
||||
dispatch({type: FETCH_MAPPINGS_SUCCESS, payload: response.data});
|
||||
})
|
||||
.catch(error => {
|
||||
dispatch({type: FETCH_MAPPINGS_FAILED, payload: error.response});
|
||||
});
|
||||
};
|
||||
|
||||
export const updateMapping = (dispatch, id, mapping) => {
|
||||
dispatch({type: FETCH_MAPPINGS_PENDING});
|
||||
API.put(`integration/mappings/${id}`, {
|
||||
mapping
|
||||
})
|
||||
.then(response => {
|
||||
dispatch({type: FETCH_MAPPINGS_SUCCESS, payload: response.data});
|
||||
})
|
||||
.catch(error => {
|
||||
dispatch({type: FETCH_MAPPINGS_FAILED, payload: error.response});
|
||||
});
|
||||
};
|
||||
|
||||
export const addNewMapping = (dispatch, mapping) => {
|
||||
dispatch({type: ADD_NEW_MAPPING_PENDING});
|
||||
API.post('integration/mappings', {
|
||||
|
||||
Reference in New Issue
Block a user