Add Snackbar component for displaying error messages in SignupView and ChoreView

This commit is contained in:
Mo Tarbin 2024-08-10 02:29:17 -04:00
parent e974568374
commit ea4783ff39
2 changed files with 66 additions and 17 deletions

View file

@ -7,6 +7,7 @@ import {
FormHelperText, FormHelperText,
Input, Input,
Sheet, Sheet,
Snackbar,
Typography, Typography,
} from '@mui/joy' } from '@mui/joy'
import React from 'react' import React from 'react'
@ -25,6 +26,8 @@ const SignupView = () => {
const [emailError, setEmailError] = React.useState('') const [emailError, setEmailError] = React.useState('')
const [displayNameError, setDisplayNameError] = React.useState('') const [displayNameError, setDisplayNameError] = React.useState('')
const [error, setError] = React.useState(null) const [error, setError] = React.useState(null)
const [snackbarOpen, setSnackbarOpen] = React.useState(false)
const [snackbarMessage, setSnackbarMessage] = React.useState('')
const handleLogin = (username, password) => { const handleLogin = (username, password) => {
login(username, password).then(response => { login(username, password).then(response => {
if (response.status === 200) { if (response.status === 200) {
@ -39,6 +42,7 @@ const SignupView = () => {
}) })
} else { } else {
console.log('Login failed', response) console.log('Login failed', response)
// Navigate('/login') // Navigate('/login')
} }
}) })
@ -101,7 +105,10 @@ const SignupView = () => {
handleLogin(username, password) handleLogin(username, password)
} else { } else {
console.log('Signup failed') console.log('Signup failed')
setError('Signup failed') response.json().then(res => {
setError(res.error)
}
)
} }
}) })
} }
@ -256,6 +263,14 @@ const SignupView = () => {
</Button> </Button>
</Sheet> </Sheet>
</Box> </Box>
<Snackbar
open={error !== null}
onClose={() => setError(null)}
autoHideDuration={5000}
message={error}
>
{error}
</Snackbar>
</Container> </Container>
) )
} }

View file

@ -3,6 +3,7 @@ import {
CancelScheduleSend, CancelScheduleSend,
Check, Check,
Checklist, Checklist,
Edit,
History, History,
PeopleAlt, PeopleAlt,
Person, Person,
@ -258,7 +259,7 @@ const ChoreView = () => {
> >
<Grid container spacing={1}> <Grid container spacing={1}>
{infoCards.map((detail, index) => ( {infoCards.map((detail, index) => (
<Grid item xs={4} key={index}> <Grid item xs={6} key={index}>
{/* divider between the list items: */} {/* divider between the list items: */}
<ListItem key={index}> <ListItem key={index}>
@ -411,20 +412,7 @@ const ChoreView = () => {
}} }}
/> />
)} )}
<Box
<Button
fullWidth
size='lg'
onClick={handleTaskCompletion}
disabled={isPendingCompletion}
color={isPendingCompletion ? 'danger' : 'success'}
startDecorator={<Check />}
>
<Box>Mark as done</Box>
</Button>
<Divider sx={{ my: 0.5 }}>or</Divider>
<Box
sx={{ sx={{
display: 'flex', display: 'flex',
flexDirection: 'row', flexDirection: 'row',
@ -433,6 +421,22 @@ const ChoreView = () => {
justifyContent: 'center', justifyContent: 'center',
}} }}
> >
<Button
fullWidth
size='lg'
onClick={handleTaskCompletion}
disabled={isPendingCompletion}
color={isPendingCompletion ? 'danger' : 'success'}
startDecorator={<Check />}
sx={
{
flex: 4,
}
}
>
<Box>Mark as done</Box>
</Button>
<Button <Button
fullWidth fullWidth
size='lg' size='lg'
@ -454,9 +458,26 @@ const ChoreView = () => {
}) })
}} }}
startDecorator={<SwitchAccessShortcut />} startDecorator={<SwitchAccessShortcut />}
sx={
{
flex: 1,
}
}
> >
<Box>Skip</Box> <Box>Skip</Box>
</Button> </Button>
</Box>
<Divider sx={{ my: 0.5 }}>More</Divider>
<Box
sx={{
display: 'flex',
flexDirection: 'row',
gap: 1,
alignContent: 'center',
justifyContent: 'center',
}}
>
<Button <Button
startDecorator={<History />} startDecorator={<History />}
size='lg' size='lg'
@ -469,8 +490,21 @@ const ChoreView = () => {
> >
History History
</Button> </Button>
</Box>
<Button
startDecorator={<Edit />}
size='lg'
color='primary'
variant='outlined'
fullWidth
onClick={() => {
navigate(`/chores/${choreId}/edit`)
}}
>
Edit
</Button>
</Box>
<Snackbar <Snackbar
open={isPendingCompletion} open={isPendingCompletion}
endDecorator={ endDecorator={