import React, { Component } from 'react'; import { Breadcrumb, Button, Container, Dropdown, Header, Icon, Image, Item, Label, Menu, Segment, Table, Input } from 'semantic-ui-react' import { Link } from 'react-router-dom'; class Tool extends Component { decodeStatus = status => { if (status === null) { return { msg: 'Unknown! Connection error?', canArm: false, canDisarm: false, }; } else if (!status.armed && !status.on) { return { msg: 'Off', canArm: true, canDisarm: false, }; } else if (status.armed && !status.on) { return { msg: 'Armed', canArm: false, canDisarm: true, }; } else if (status.armed && status.on) { return { msg: 'On', canArm: false, canDisarm: true, }; } else if (!status.armed && status.on) { return { msg: 'Error: Impossible state!', canArm: false, canDisarm: false, }; } } render() { const data = this.props.data; const user = this.props.user; const match = this.props.match; const toolStatus = this.props.toolStatus || []; const requestInterlock = this.props.requestInterlock; const category = data.categories.find(x => x.slug === match.params.category ); const tool = category.tools.find(x => x.id.toString() === match.params.id ); const status = toolStatus.find(x => x.id.toString() === match.params.id ) || null; const decodedStatus = this.decodeStatus(status); console.log(decodedStatus); const approved = user.authorizedTools.includes(tool.id); return (
Status: {decodedStatus.msg}
{tool.notes}