Skip to content
Snippets Groups Projects
Commit 7ec5112f authored by Albin Henriksson's avatar Albin Henriksson
Browse files

Add snackbar when duplicate team names and pre-select edited team's name

parent 6afcf518
No related branches found
No related tags found
1 merge request!151Add snackbar when duplicate team names and pre-select edited team's name
Pipeline #45697 passed with warnings
...@@ -8,10 +8,12 @@ import { ...@@ -8,10 +8,12 @@ import {
IconButton, IconButton,
ListItem, ListItem,
ListItemText, ListItemText,
Snackbar,
TextField, TextField,
} from '@material-ui/core' } from '@material-ui/core'
import CloseIcon from '@material-ui/icons/Close' import CloseIcon from '@material-ui/icons/Close'
import EditIcon from '@material-ui/icons/Edit' import EditIcon from '@material-ui/icons/Edit'
import { Alert } from '@material-ui/lab'
import axios from 'axios' import axios from 'axios'
import React, { useState } from 'react' import React, { useState } from 'react'
import { getEditorCompetition } from '../../../actions/editor' import { getEditorCompetition } from '../../../actions/editor'
...@@ -32,6 +34,7 @@ type TeamsProps = { ...@@ -32,6 +34,7 @@ type TeamsProps = {
const Teams = ({ competitionId }: TeamsProps) => { const Teams = ({ competitionId }: TeamsProps) => {
const dispatch = useAppDispatch() const dispatch = useAppDispatch()
const competition = useAppSelector((state) => state.editor.competition) const competition = useAppSelector((state) => state.editor.competition)
const [errorActive, setErrorActive] = React.useState(false)
const editTeam = async () => { const editTeam = async () => {
if (editTeamState.variant === 'Add') { if (editTeamState.variant === 'Add') {
await axios await axios
...@@ -46,7 +49,9 @@ const Teams = ({ competitionId }: TeamsProps) => { ...@@ -46,7 +49,9 @@ const Teams = ({ competitionId }: TeamsProps) => {
.then(() => { .then(() => {
dispatch(getEditorCompetition(competitionId)) dispatch(getEditorCompetition(competitionId))
}) })
.catch(console.log) .catch((response) => {
if (response?.response?.status === 409) setErrorActive(true)
})
} }
setEditTeamState({ open: false }) setEditTeamState({ open: false })
} }
...@@ -102,7 +107,14 @@ const Teams = ({ competitionId }: TeamsProps) => { ...@@ -102,7 +107,14 @@ const Teams = ({ competitionId }: TeamsProps) => {
<DialogContentText> <DialogContentText>
Skriv {editTeamState.variant === 'Edit' ? 'det nya' : ''} namnet på laget och klicka sedan på bekräfta. Skriv {editTeamState.variant === 'Edit' ? 'det nya' : ''} namnet på laget och klicka sedan på bekräfta.
</DialogContentText> </DialogContentText>
<TextField autoFocus margin="dense" label="Lagnamn" fullWidth onChange={updateSelectedTeamName} /> <TextField
autoFocus
margin="dense"
label="Lagnamn"
fullWidth
onChange={updateSelectedTeamName}
defaultValue={editTeamState.variant === 'Edit' ? editTeamState.team?.name : ''}
/>
</DialogContent> </DialogContent>
<DialogActions> <DialogActions>
<Button onClick={() => setEditTeamState({ open: false })} color="secondary"> <Button onClick={() => setEditTeamState({ open: false })} color="secondary">
...@@ -113,6 +125,9 @@ const Teams = ({ competitionId }: TeamsProps) => { ...@@ -113,6 +125,9 @@ const Teams = ({ competitionId }: TeamsProps) => {
</Button> </Button>
</DialogActions> </DialogActions>
</Dialog> </Dialog>
<Snackbar open={errorActive} autoHideDuration={4000} onClose={() => setErrorActive(false)}>
<Alert severity="error">{`Du kan inte välja det namnet eftersom ett annat lag har samma namn, välj ett annat namn och försök igen.`}</Alert>
</Snackbar>
</SettingsList> </SettingsList>
) )
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment