Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
greg
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
it-bott-integrasjoner
greg
Commits
3a95df62
Commit
3a95df62
authored
2 years ago
by
lass
Browse files
Options
Downloads
Patches
Plain Diff
Fix backend-error handling
parent
8f155ee6
No related branches found
No related tags found
1 merge request
!398
Greg 342 roledate error
Pipeline
#187867
passed
2 years ago
Stage: venv update
Stage: tests and linting
Changes
2
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
frontend/package-lock.json
+908
-500
908 additions, 500 deletions
frontend/package-lock.json
frontend/src/routes/sponsor/guest/newGuestRole/index.tsx
+45
-41
45 additions, 41 deletions
frontend/src/routes/sponsor/guest/newGuestRole/index.tsx
with
953 additions
and
541 deletions
frontend/package-lock.json
+
908
−
500
View file @
3a95df62
This diff is collapsed.
Click to expand it.
frontend/src/routes/sponsor/guest/newGuestRole/index.tsx
+
45
−
41
View file @
3a95df62
import
{
useEffect
,
useState
}
from
'
react
'
import
{
useState
}
from
'
react
'
import
{
Controller
,
useForm
}
from
'
react-hook-form
'
import
{
useTranslation
}
from
'
react-i18next
'
import
{
Link
,
useNavigate
,
useParams
}
from
'
react-router-dom
'
...
...
@@ -63,9 +63,7 @@ interface NewGuestRoleProps {
reloadGuestInfo
:
()
=>
void
}
function
NewGuestRole
({
guest
,
reloadGuestInfo
}:
NewGuestRoleProps
)
{
const
[
submitState
,
setSubmitState
]
=
useState
(
SubmitState
.
NotSubmitted
)
const
{
...
...
@@ -85,15 +83,6 @@ function NewGuestRole({ guest, reloadGuestInfo }: NewGuestRoleProps) {
return
<></>
}
const
navigate
=
useNavigate
()
const
onSubmit
=
handleSubmit
(
async
()
=>
{
await
postRole
(
getValues
(),
pid
)
reloadGuestInfo
()
if
(
submitState
==
SubmitState
.
SubmitSuccess
)
{
navigate
(
`/sponsor/guest/
${
pid
}
`
)
}
})
const
{
ous
}
=
useOus
()
const
roleTypes
=
useRoleTypes
()
...
...
@@ -159,35 +148,7 @@ function NewGuestRole({ guest, reloadGuestInfo }: NewGuestRoleProps) {
</
MenuItem
>
)
}
const
postRole
=
async
(
formData
:
AddRoleFormData
,
pid
:
string
)
=>
{
const
payload
:
AddRolePayload
=
{
orgunit
:
formData
.
orgunit
,
person
:
pid
,
type
:
formData
.
type
,
end_date
:
format
(
formData
.
end_date
as
Date
,
'
yyyy-MM-dd
'
),
}
if
(
formData
.
start_date
)
{
payload
.
start_date
=
format
(
formData
.
start_date
as
Date
,
'
yyyy-MM-dd
'
)
}
if
(
formData
.
contact_person_unit
)
{
payload
.
contact_person_unit
=
formData
.
contact_person_unit
}
if
(
formData
.
comments
)
{
payload
.
comments
=
formData
.
comments
}
if
(
availableInSearchEnabled
&&
formData
.
available_in_search
)
{
payload
.
available_in_search
=
formData
.
available_in_search
}
fetch
(
'
/api/ui/v1/role
'
,
submitJsonOpts
(
'
POST
'
,
payload
))
.
then
((
res
)
=>
{
if
(
!
res
.
ok
)
{
handleSubmitErrorResponse
(
res
)
}
else
{
setSubmitState
(
SubmitState
.
SubmitSuccess
)
}
})
}
function
handleSubmitErrorResponse
(
res
:
Response
)
{
// Try to extract data from body of error message
res
...
...
@@ -221,6 +182,44 @@ function NewGuestRole({ guest, reloadGuestInfo }: NewGuestRoleProps) {
setSubmitState
(
SubmitState
.
SubmitFailure
)
})
}
const
postRole
=
async
(
formData
:
AddRoleFormData
)
=>
{
const
payload
:
AddRolePayload
=
{
orgunit
:
formData
.
orgunit
,
person
:
pid
,
type
:
formData
.
type
,
end_date
:
format
(
formData
.
end_date
as
Date
,
'
yyyy-MM-dd
'
),
}
if
(
formData
.
start_date
)
{
payload
.
start_date
=
format
(
formData
.
start_date
as
Date
,
'
yyyy-MM-dd
'
)
}
if
(
formData
.
contact_person_unit
)
{
payload
.
contact_person_unit
=
formData
.
contact_person_unit
}
if
(
formData
.
comments
)
{
payload
.
comments
=
formData
.
comments
}
if
(
availableInSearchEnabled
&&
formData
.
available_in_search
)
{
payload
.
available_in_search
=
formData
.
available_in_search
}
fetch
(
'
/api/ui/v1/role
'
,
submitJsonOpts
(
'
POST
'
,
payload
))
.
then
((
res
)
=>
{
reloadGuestInfo
()
if
(
!
res
.
ok
)
{
handleSubmitErrorResponse
(
res
)
}
else
{
setSubmitState
(
SubmitState
.
SubmitSuccess
)
navigate
(
`/sponsor/guest/
${
pid
}
`
)
}
})
.
catch
(()
=>
{
setSubmitState
(
SubmitState
.
SubmitFailure
)
})
}
const
onSubmit
=
handleSubmit
(
async
()
=>
{
postRole
(
getValues
())
})
const
hasRoleTypeError
=
errors
&&
errors
.
type
&&
errors
.
type
.
type
===
'
required
'
const
hasOuChoiceError
=
...
...
@@ -400,7 +399,12 @@ function NewGuestRole({ guest, reloadGuestInfo }: NewGuestRoleProps) {
label
=
{
t
(
'
input.searchable
'
)
}
/>
)
}
<
Button
variant
=
"contained"
color
=
"secondary"
type
=
"submit"
>
<
Button
onClick
=
{
onSubmit
}
variant
=
"contained"
color
=
"secondary"
type
=
"submit"
>
{
t
(
'
button.save
'
)
}
</
Button
>
<
Button
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment