-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added logic so that operating initials can be assigned from the matrix.
- Loading branch information
1 parent
4611ceb
commit f5b71a7
Showing
4 changed files
with
107 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
components/OperatingInitials/OperatingInitialAssignmentItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
'use client'; | ||
import { updateOperatingInitials } from "@/actions/user"; | ||
import { getRating } from "@/lib/vatsim"; | ||
import { Autocomplete, Box, Button, Dialog, DialogActions, DialogContent, DialogTitle, TextField, Typography } from "@mui/material"; | ||
|
||
import { Grid2 } from "@mui/material"; | ||
import { User } from "next-auth"; | ||
import { useState } from "react"; | ||
import { toast } from "react-toastify"; | ||
|
||
export default function OperatingInitialAssignmentItem({ initials, allControllers, }: { initials: string, allControllers: User[], }) { | ||
|
||
const [open, setOpen] = useState(false); | ||
const [user, setUser] = useState<string>(''); | ||
|
||
const handleSubmit = async () => { | ||
|
||
const u = allControllers.find((u) => u.id === user); | ||
|
||
if (!u) return; | ||
|
||
const error = await updateOperatingInitials(u, initials); | ||
|
||
if (error) { | ||
toast.error(error); | ||
return; | ||
} | ||
|
||
toast.success(`Successfully assigned ${initials} to ${u.firstName} ${u.lastName}`); | ||
setOpen(false); | ||
} | ||
|
||
return ( | ||
<> | ||
<Grid2 | ||
key={initials} | ||
size={{ | ||
xs: 4, | ||
sm: 3, | ||
md: 2, | ||
xl: 1 | ||
}}> | ||
<Box sx={{border: 2, borderRadius: 2, cursor: 'pointer', }}> | ||
<div onClick={() => setOpen(true)}> | ||
<Typography textAlign="center" variant="body2">{initials}</Typography> | ||
</div> | ||
</Box> | ||
</Grid2> | ||
<Dialog open={open} onClose={() => setOpen(false)}> | ||
<DialogTitle>Assign Operating Initials - {initials}</DialogTitle> | ||
<DialogContent> | ||
<Autocomplete | ||
options={allControllers} | ||
getOptionLabel={(option) => `${option.firstName} ${option.lastName} - ${getRating(option.rating)} (${option.cid})`} | ||
value={allControllers.find((u) => u.id === user) || null} | ||
onChange={(event, newValue) => { | ||
setUser(newValue ? newValue.id : ''); | ||
}} | ||
renderInput={(params) => <TextField {...params} label="Controller"/>} /> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button onClick={() => setOpen(false)}>Cancel</Button> | ||
<Button onClick={handleSubmit} variant="contained">Assign</Button> | ||
</DialogActions> | ||
</Dialog> | ||
</> | ||
); | ||
} |