-
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.
- Loading branch information
1 parent
57ffb1b
commit 45063b8
Showing
2 changed files
with
113 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
'use client'; | ||
|
||
import * as React from 'react'; | ||
import Button from '@mui/material/Button'; | ||
import Card from '@mui/material/Card'; | ||
import CardActions from '@mui/material/CardActions'; | ||
import CardContent from '@mui/material/CardContent'; | ||
import CardHeader from '@mui/material/CardHeader'; | ||
import Divider from '@mui/material/Divider'; | ||
import FormControl from '@mui/material/FormControl'; | ||
import InputLabel from '@mui/material/InputLabel'; | ||
// import MenuItem from '@mui/material/MenuItem'; | ||
import OutlinedInput from '@mui/material/OutlinedInput'; | ||
// import Select from '@mui/material/Select'; | ||
import Grid from '@mui/material/Unstable_Grid2'; | ||
// import type {AxiosResponse} from "axios"; | ||
import type {WooclapUser} from "@/types/wooclap-user"; | ||
import apiService from "@/api/api-service"; | ||
import {authClient} from "@/lib/auth/client"; | ||
import {logger} from "@/lib/default-logger"; | ||
|
||
// const roles = [ | ||
// { value: 'student', label: 'Student' }, | ||
// { value: 'instructor', label: 'Instructor' }, | ||
// { value: 'admin', label: 'Admin' }, | ||
// ] as const; | ||
|
||
export function WooclapUserForm(): React.JSX.Element { | ||
const [email, setEmail] = React.useState(''); | ||
const [username, setUsername] = React.useState(''); | ||
const [firstName, setFirstName] = React.useState(''); | ||
const [lastName, setLastName] = React.useState(''); | ||
|
||
const handleSubmit = async (event: React.FormEvent<HTMLFormElement>): Promise<void> => { | ||
event.preventDefault(); | ||
|
||
const newUser: Partial<WooclapUser> = { | ||
email, | ||
username, | ||
first_name: firstName, | ||
last_name: lastName, | ||
}; | ||
|
||
try { | ||
await apiService.post('/api/WooclapUser/', newUser); | ||
logger.debug('User added successfully'); | ||
} catch (error: unknown) { | ||
await authClient.signInWithMsal(); | ||
logger.error(error); | ||
} | ||
}; | ||
return ( | ||
<form onSubmit={handleSubmit}> | ||
<Card> | ||
<CardHeader subheader="Add new user to the database" title="New User" /> | ||
<Divider /> | ||
<CardContent> | ||
<Grid container spacing={3}> | ||
<Grid md={3} xs={6}> | ||
<FormControl fullWidth required> | ||
<InputLabel>Email</InputLabel> | ||
<OutlinedInput defaultValue="" label="Email" name="email" onChange={e => { setEmail(e.target.value); }} /> | ||
</FormControl> | ||
</Grid> | ||
<Grid md={3} xs={6}> | ||
<FormControl fullWidth required> | ||
<InputLabel>Username</InputLabel> | ||
<OutlinedInput defaultValue="" label="Username" name="username" onChange={e => { setUsername(e.target.value); }} /> | ||
</FormControl> | ||
</Grid> | ||
<Grid md={3} xs={6}> | ||
<FormControl fullWidth required> | ||
<InputLabel>First Name</InputLabel> | ||
<OutlinedInput defaultValue="" label="First Name" name="first_name" onChange={e => { setFirstName(e.target.value); }} /> | ||
</FormControl> | ||
</Grid> | ||
<Grid md={3} xs={6}> | ||
<FormControl fullWidth required> | ||
<InputLabel>Last Name</InputLabel> | ||
<OutlinedInput defaultValue="" label="Last Name" name="last_name" onChange={e => { setLastName(e.target.value); }} /> | ||
</FormControl> | ||
</Grid> | ||
{/*<Grid md={3} xs={6}>*/} | ||
{/* <FormControl fullWidth>*/} | ||
{/* <InputLabel>Role</InputLabel>*/} | ||
{/* <Select defaultValue="New York" label="State" name="state" variant="outlined">*/} | ||
{/* {roles.map((option) => (*/} | ||
{/* <MenuItem key={option.value} value={option.value}>*/} | ||
{/* {option.label}*/} | ||
{/* </MenuItem>*/} | ||
{/* ))}*/} | ||
{/* </Select>*/} | ||
{/* </FormControl>*/} | ||
{/*</Grid>*/} | ||
</Grid> | ||
</CardContent> | ||
<CardActions sx={{ justifyContent: 'flex-end' }}> | ||
<Button type="submit" variant="contained">Add</Button> | ||
</CardActions> | ||
</Card> | ||
</form> | ||
); | ||
} |