import React, { useRef, useEffect } from 'react'; import superagent from 'superagent'; import { fromUnixTime, formatDistanceToNow } from "date-fns"; import { formatInTimeZone } from 'date-fns-tz'; import ClickableTableRow from "../Util/ClickableTableRow.jsx"; import * as ApiUtils from '../CloudApi/ApiUtils.js'; import constants, { DEFAULT_TIMEZONE } from '../CloudApi/Constants.js'; import WaxIdBitField from './WaxIdBitField.jsx'; import ToolPathDownloadButton from './ToolPathDownloadButton.jsx'; import { Header, Message, Icon, Button, Table, Label, Modal } from 'semantic-ui-react' export default class ScanRequestsTable extends React.Component { constructor(props) { super(props); this.state = { loading: false, revokeScanRequestModalOpen: false, }; } showRevokeScanRequestModal() {} openRevokeScanRequestModal(i, e) { this.setState({ revokeScanRequestModalOpen: true}); } closeRevokeScanRequestModal(i, e) { this.setState({ revokeScanRequestModalOpen: false}); } async onRevokeScanRequest(e) { e.preventDefault(); this.setState({ loading: true }); try { let res = await superagent.put(`/api/admin/fabricator/scan_request/${scanRequest.id}`).send({ scanRequestState: this.props.schemas.ScanRequestStates["Revoked"] }); window.location.reload(); } catch (e) { window.alert("Error sending scan request email: " + e.message); console.error(e); } this.setState({ loading: false, revokeScanRequestModalOpen: false}); } onClickScanRequest(scanRequest, e) { window.location.href = `/fabricator/scan_request/${scanRequest.id}`; } renderIpdLabel() { } renderScanRequestRow(scanRequest) { if (scanRequest.scanRequestState === this.props.schemas.ScanRequestStates["Revoked"]) { return ( Hiding revoked scan request {scanRequest.id} ); } let createdAtDateTime = fromUnixTime(scanRequest.createdAt / 1000); const createdAt = formatInTimeZone(createdAtDateTime, DEFAULT_TIMEZONE, 'PPPp z'); const fromNow = formatDistanceToNow(createdAtDateTime, { addSuffix: true }); const scanRequestState = Object.entries(this.props.schemas.ScanRequestStates).find(entry => entry[1] === scanRequest.scanRequestState)[0]; const stateLabelColor = (scanRequest.scanRequestState === this.props.schemas.ScanRequestStates["VerifiedAndReady"]) ? "green" : "grey"; let ipdLabel = ; if (scanRequest.ipd !== -1) { ipdLabel = } return ( {scanRequest.id}  {createdAt} ({fromNow}) {ipdLabel} {(scanRequest.jobIds && scanRequest.jobIds.length > 0) &&
{scanRequest.jobIds.map(jobId => )}
}
) } render() { if (this.props.loading) { return ( ); } else { return (
Scan Requests
ID Created At State IPD Jobs {this.props.scanRequests.map(scanRequest => this.renderScanRequestRow(scanRequest))}
Are you sure you want to revoke this scan request?
); } } }