import { Meteor } from 'meteor/meteor';
import React, { useState, useEffect } from 'react';
import { useTracker } from 'meteor/react-meteor-data';
import _ from 'lodash';
// import queryString from 'query-string'
import {Link, useSearchParams} from "react-router-dom";
const RenderUsage = ({data}) => {
return (
<>
{data.map((next, i) => (
-
{next.person && (
<>
User: {next.person.firstName} {next.person.lastName} {next.person.grade ? "~ " + next.person.grade : ""} ({next.email})
>
)}
Device ID: {next.deviceId}
Serial: {next.serial}
{next.asset && (
<>
Asset ID: {next.asset.assetId}
>
)}
{new Date(next.startTime).toLocaleDateString("en-US") + "-" + new Date(next.endTime).toLocaleDateString("en-US")}
{next.assetType && (
<>
Asset Type: {next.assetType.name}
>
)}
{next.assignedTo && (
<>
Currently assigned to: {next.assignedTo.firstName} {next.assignedTo.lastName} {next.assignedTo.grade ? "~ " + next.assignedTo.grade : ""} ({next.assignedTo.email})
>
)}
))}
>
)
}
const RenderAssignments = ({data}) => {
return (
<>
{data.map((next, i) => (
-
{next.assignee && (
<>
User: {next.assignee.firstName} {next.assignee.lastName} {next.assignee.grade ? "~ " + next.assignee.grade : ""} ({next.assignee.email})
>
)}
Serial: {next.serial}
{next.asset && (
<>
Asset ID: {next.asset.assetId}
>
)}
{next.assetType && (
<>
Asset Type: {next.assetType.name}
>
)}
{new Date(next.startDate).toLocaleDateString("en-US") + "-" + new Date(next.endDate).toLocaleDateString("en-US")}
Comment: {next.comment}
Start Condition: {next.startCondition}
Details: {next.startConditionDetails}
End Condition: {next.endCondition}
Details: {next.endConditionDetails}
))}
>
)
}
export default () => {
// const query = queryString.parse(search)
const [data, setData] = useState([])
const [search, setSearch] = useSearchParams()
useEffect(() => {
let args;
if(search.get('resultType') === 'usage') {
if(search.get('studentId')) {
args = {studentId: search.get('studentId')}
}
else if(search.get('staffId')) {
args = {staffId: search.get('staffId')}
}
else if(search.get('email')) {
args = {email: search.get('email')}
}
else if(search.get('deviceId')) {
args = {deviceId: search.get('deviceId')}
}
else if(search.get('serial')) {
args = {serial: search.get('serial')}
}
else if(search.get('assetId')) {
args = {assetId: search.get('assetId')}
}
Meteor.call('DataCollection.chromebookData', args, (err, result) => {
if (err) console.error(err)
else setData(result)
})
}
else {
if(search.get('studentId')) {
args = {studentId: search.get('studentId')}
}
else if(search.get('staffId')) {
args = {staffId: search.get('staffId')}
}
else if(search.get('serial')) {
args = {serial: search.get('serial')}
}
else if(search.get('assetId')) {
args = {assetId: search.get('assetId')}
}
Meteor.call('AssetAssignmentHistory.get', args, (err, result) => {
if (err) console.error(err)
else setData(result)
})
}
}, [search])
return (search.get('resultType') === 'usage' ? : )
}