Finished core functionality.

This commit is contained in:
2022-09-12 18:19:57 -07:00
parent bbff674b62
commit 6fe980ae6e
11 changed files with 608 additions and 194 deletions

View File

@@ -30,9 +30,9 @@ import SearchIcon from "@mui/icons-material/Search";
export default () => {
const navigate = useNavigate()
const [resultType, setResultType] = useState("usage")
const [searchType, setSearchType] = useState("email")
const [value, setValue] = useState("")
const search = () => {
if(searchType === 'email' || searchType === 'firstName' || searchType === 'lastName') {
if (value && value.length > 1) {
@@ -45,18 +45,18 @@ export default () => {
setPeopleToPickFrom(all)
setOpenPickPersonDialog(true)
} else if (all.length === 1) {
navigate("/history/search?resultType=" + encodeURIComponent(resultType) + "&" + (students.length ? "studentId" : 'staffId') + "=" + encodeURIComponent(all[0]._id));
navigate("/search?" + (students.length ? "studentId" : 'staffId') + "=" + encodeURIComponent(all[0]._id));
}
}
}
else if(searchType === 'assetID' || searchType === 'serial') {
let asset = Assets.findOne(searchType === 'assetID' ? {assetId: value} : {serial : value});
else if(searchType === 'assetId' || searchType === 'serial') {
let asset = Assets.findOne(searchType === 'assetId' ? {assetId: value.toUpperCase()} : {serial : value});
console.log(asset)
if(asset) {
if(searchType === 'assetID')
navigate("/history/search?resultType=" + encodeURIComponent(resultType) + "&assetId=" + encodeURIComponent(asset.assetId))
if(searchType === 'assetId')
navigate("/search?assetId=" + encodeURIComponent(asset.assetId.toUpperCase()))
else
navigate("/history/search?resultType=" + encodeURIComponent(resultType) + "&serial=" + encodeURIComponent(asset.serial))
navigate("/search?serial=" + encodeURIComponent(asset.serial))
}
}
}
@@ -71,7 +71,13 @@ export default () => {
if(openPickPersonDialog) setOpenPickPersonDialog(false)
if(person && person._id) {
navigate("/history/search?resultType=" + encodeURIComponent(resultType) + "&" + (person.grade ? "studentId" : 'staffId') + "=" + encodeURIComponent(person._id));
navigate("/search?" + (person.grade ? "studentId" : 'staffId') + "=" + encodeURIComponent(person._id));
}
}
const inputKeyPress = (e) => {
if(e.key === 'Enter' && value.length > 0) {
search()
}
}
@@ -95,14 +101,14 @@ export default () => {
</DialogActions>
</Dialog>
<div style={{display: "flex", flexDirection: "column"}} sx={{ p: '2px 4px', display: 'flex', alignItems: 'center', width: 400 }}>
<Paper componet='form'>
<div style={{marginBottom: "1rem", marginTop: "2rem"}}>
<ToggleButtonGroup color="primary" value={resultType} exclusive onChange={(e, type)=>setResultType(type)} aria-label="Result Type">
<ToggleButton value="usage">Usage History</ToggleButton>
<ToggleButton value="assignment">Assignment History</ToggleButton>
</ToggleButtonGroup>
</div>
<div style={{display: "flex", flexDirection: "column", marginTop: "1rem"}} sx={{ p: '2px 4px', display: 'flex', alignItems: 'center', width: 400 }}>
{/*<Paper componet='form'>*/}
{/* <div style={{marginBottom: "1rem", marginTop: "2rem"}}>*/}
{/* <ToggleButtonGroup color="primary" value={resultType} exclusive onChange={(e, type)=>setResultType(type)} aria-label="Result Type">*/}
{/* <ToggleButton value="usage">Usage History</ToggleButton>*/}
{/* <ToggleButton value="assignment">Assignment History</ToggleButton>*/}
{/* </ToggleButtonGroup>*/}
{/* </div>*/}
<div style={{marginBottom: "1rem"}}>
<ToggleButtonGroup color="primary" value={searchType} exclusive onChange={(e, type)=>setSearchType(type)} aria-label="Search Type">
<ToggleButton value="email">Email</ToggleButton>
@@ -113,12 +119,12 @@ export default () => {
</ToggleButtonGroup>
</div>
<div>
<InputBase value={value} onChange={(e) => {setValue(e.target.value)}} sx={{ ml: 1, flex: 1 }} placeholder="Value" inputProps={{ 'aria-label': 'Search Value' }}/>
<InputBase value={value} onKeyPress={inputKeyPress} onChange={(e) => {setValue(e.target.value)}} sx={{ ml: 1, flex: 1 }} placeholder="Value" inputProps={{ 'aria-label': 'Search Value' }}/>
<IconButton type="button" sx={{ p: '10px' }} aria-label="search" onClick={search}>
<SearchIcon />
</IconButton>
</div>
</Paper>
{/*</Paper>*/}
</div>
</>
)