Skip to content

Commit

Permalink
addchangesubjectpage: save knop redirect juist nu en je kan geen vak …
Browse files Browse the repository at this point in the history
…opslaan als het geen naam heeft
  • Loading branch information
gusvanpoucke committed May 21, 2024
1 parent 2649c96 commit cf1d58a
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions frontend/frontend/src/pages/subjectsPage/AddChangeSubjectPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export interface User {
email: string
}

interface errorChecks {
title: boolean
}

// This function takes a list of users and will render it.
// It can be used for both the teachers and the students.
function UserList(
Expand Down Expand Up @@ -252,6 +256,20 @@ export function AddChangeSubjectPage() {
const [saveConfirmation, setSaveConfirmation] = useState(false)
const [cancelConfirmation, setCancelConfirmation] = useState(false)

const [assignmentErrors, setAssignmentErrors] = useState<errorChecks>({
title: false,
})

const handleSubmit = () => {
setAssignmentErrors({
title: title === '',
})
if (title === '') {
return
}
setSaveConfirmation(true)
}

const closeSaveConfirmation = () => {
setSaveConfirmation(false)
}
Expand Down Expand Up @@ -484,11 +502,11 @@ export function AddChangeSubjectPage() {
})
.then((res) => {
setVakID(res.data.vak_id)
navigate(`/course/${res.data.vak_id}`)
})
.catch((err) => {
console.log(err)
})
navigate(`/course/${vakID}`)
} else {
instance
.put('vakken/' + vakID + '/', {
Expand Down Expand Up @@ -658,7 +676,17 @@ export function AddChangeSubjectPage() {
<TextField
type="text"
value={title}
error={
assignmentErrors.title
}
placeholder={t('name')}
helperText={
assignmentErrors.title
? t('name') +
' ' +
t('is_required')
: ''
}
onChange={(event) =>
setTitle(
event.target.value
Expand All @@ -685,9 +713,7 @@ export function AddChangeSubjectPage() {

<Button
/* This is the large save button on the top of the page */
onClick={() =>
setSaveConfirmation(true)
}
onClick={handleSubmit}
>
{t('save')}
</Button>
Expand Down

0 comments on commit cf1d58a

Please sign in to comment.