fix mapping screen crash when office/resource is unknown
This commit is contained in:
@@ -76,67 +76,71 @@ class SingleMapping extends Component {
|
||||
};
|
||||
|
||||
render() {
|
||||
const { singleMapping: { officeSlug, resourceSlug } } = this.props;
|
||||
const { officeId, resourceId, officeOptions, allResourceOptions, pendingMappings } = this.props;
|
||||
const { showDeletePrompt, newOfficeId, newResourceId } = this.state;
|
||||
try {
|
||||
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 selectedOfficeId = newOfficeId ? newOfficeId : officeId;
|
||||
const selectedResourceId = newResourceId ? newResourceId : resourceId;
|
||||
|
||||
const resourceOptions = allResourceOptions && officeId ? allResourceOptions[selectedOfficeId].roomOptions : [];
|
||||
const resourceOptions = allResourceOptions && officeId ? allResourceOptions[selectedOfficeId].roomOptions : [];
|
||||
|
||||
const enableActions = !pendingMappings;
|
||||
const enableSave = enableActions && ((newOfficeId !== null) || (newResourceId !== null));
|
||||
const saveIconColor = enableSave ? 'green' : null;
|
||||
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}
|
||||
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>
|
||||
<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>
|
||||
);
|
||||
<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>
|
||||
);
|
||||
}catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user