Skip to content

Commit

Permalink
improved error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ARADDCC002 committed Dec 18, 2024
1 parent 3360beb commit 1be12a2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion frontend/src/MuiForms/TagSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@ interface TagSelectorProps {
label: string
formContext?: FormContextType
required?: boolean
rawErrors?: string[]
}

export default function TagSelector({ onChange, value, label, formContext, required }: TagSelectorProps) {
const theme = useTheme()

const [newTag, setNewTag] = useState('')
const [errorText, setErrorText] = useState('')

const handleNewTagSubmit = () => {
setErrorText('')
if (value.includes(newTag)) {
setErrorText('You cannot add duplicate tags')
return
}
const updatedArray = value
updatedArray.push(newTag)
onChange(updatedArray)
Expand Down Expand Up @@ -50,6 +55,9 @@ export default function TagSelector({ onChange, value, label, formContext, requi
))}
</Stack>
</Box>
<Typography variant='caption' color={theme.palette.error.main}>
{errorText}
</Typography>
</Stack>
)}
{formContext && !formContext.editMode && (
Expand Down

0 comments on commit 1be12a2

Please sign in to comment.