fix mapping screen crash when office/resource is unknown

This commit is contained in:
Bilal Catic
2019-11-20 13:45:54 +01:00
parent fcb71a3f00
commit eff96f9e5e

View File

@@ -76,67 +76,71 @@ class SingleMapping extends Component {
}; };
render() { render() {
const { singleMapping: { officeSlug, resourceSlug } } = this.props; try {
const { officeId, resourceId, officeOptions, allResourceOptions, pendingMappings } = this.props; const {singleMapping: {officeSlug, resourceSlug}} = this.props;
const { showDeletePrompt, newOfficeId, newResourceId } = this.state; const {officeId, resourceId, officeOptions, allResourceOptions, pendingMappings} = this.props;
const {showDeletePrompt, newOfficeId, newResourceId} = this.state;
const selectedOfficeId = newOfficeId ? newOfficeId : officeId; const selectedOfficeId = newOfficeId ? newOfficeId : officeId;
const selectedResourceId = newResourceId ? newResourceId : resourceId; const selectedResourceId = newResourceId ? newResourceId : resourceId;
const resourceOptions = allResourceOptions && officeId ? allResourceOptions[selectedOfficeId].roomOptions : []; const resourceOptions = allResourceOptions && officeId ? allResourceOptions[selectedOfficeId].roomOptions : [];
const enableActions = !pendingMappings; const enableActions = !pendingMappings;
const enableSave = enableActions && ((newOfficeId !== null) || (newResourceId !== null)); const enableSave = enableActions && ((newOfficeId !== null) || (newResourceId !== null));
const saveIconColor = enableSave ? 'green' : null; const saveIconColor = enableSave ? 'green' : null;
return ( return (
<Table.Row> <Table.Row>
<PromptMessage <PromptMessage
onClose={this.onPromptClose} onClose={this.onPromptClose}
onActionNo={this.onPromptClose} onActionNo={this.onPromptClose}
onActionYes={this.onPromptYes} onActionYes={this.onPromptYes}
title={'Delete mapping'} title={'Delete mapping'}
message={'Do you want to delete this mapping ?'} message={'Do you want to delete this mapping ?'}
show={showDeletePrompt} 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>
<Table.Cell> <Label size={'big'}>{`[${officeSlug}-${resourceSlug}]`}</Label>
<Dropdown </Table.Cell>
options={resourceOptions} <Table.Cell>
value={selectedResourceId} <Dropdown
onChange={this.onResourceChange} options={officeOptions}
/> defaultValue={officeId}
</Table.Cell> onChange={this.onOfficeChange}
<Table.Cell> />
<Icon </Table.Cell>
circular <Table.Cell>
name={'check'} <Dropdown
size={'large'} options={resourceOptions}
disabled={!enableSave} value={selectedResourceId}
link={enableSave || null} onChange={this.onResourceChange}
color={saveIconColor} />
onClick={this.onMappingUpdate} </Table.Cell>
/> <Table.Cell>
<Icon <Icon
circular circular
name={'trash'} name={'check'}
size={'large'} size={'large'}
disabled={!enableActions} disabled={!enableSave}
link={enableActions || null} link={enableSave || null}
onClick={this.deleteMapping} color={saveIconColor}
/> onClick={this.onMappingUpdate}
</Table.Cell> />
</Table.Row> <Icon
); circular
name={'trash'}
size={'large'}
disabled={!enableActions}
link={enableActions || null}
onClick={this.deleteMapping}
/>
</Table.Cell>
</Table.Row>
);
}catch (e) {
return null;
}
} }
} }