Skip to content
Snippets Groups Projects
Commit 8433f5b4 authored by Tore.Brede's avatar Tore.Brede
Browse files

Merge branch 'GREG-160_error_temporarily_showing' into 'master'

GREG-160: Error temporarily showing

See merge request !252
parents 64682558 a4f6df15
No related branches found
No related tags found
1 merge request!252GREG-160: Error temporarily showing
Pipeline #111885 passed
...@@ -7,13 +7,15 @@ type OuData = { ...@@ -7,13 +7,15 @@ type OuData = {
en: string en: string
} }
function useOus(): OuData[] { function useOus(): OuData[] | undefined {
const [ous, setOus] = useState<OuData[]>([]) const [ous, setOus] = useState<OuData[] | undefined>(undefined)
const getOptions = async () => { const getOptions = async () => {
const response = await fetch('/api/ui/v1/ous', fetchJsonOpts()) const response = await fetch('/api/ui/v1/ous', fetchJsonOpts())
if (response.ok) { if (response.ok) {
const ousJson = await response.json() const ousJson = await response.json()
setOus(ousJson) setOus(ousJson)
} else {
setOus([])
} }
} }
......
...@@ -9,8 +9,10 @@ type RoleTypeData = { ...@@ -9,8 +9,10 @@ type RoleTypeData = {
max_days: number max_days: number
} }
function useRoleTypes(): RoleTypeData[] { function useRoleTypes(): RoleTypeData[] | undefined {
const [roleTypes, setRoleTypes] = useState<RoleTypeData[]>([]) const [roleTypes, setRoleTypes] = useState<RoleTypeData[] | undefined>(
undefined
)
const fetchRoleTypes = async () => { const fetchRoleTypes = async () => {
const response = await fetch(`/api/ui/v1/roletypes/`, fetchJsonOpts()) const response = await fetch(`/api/ui/v1/roletypes/`, fetchJsonOpts())
...@@ -20,6 +22,7 @@ function useRoleTypes(): RoleTypeData[] { ...@@ -20,6 +22,7 @@ function useRoleTypes(): RoleTypeData[] {
const roleTypesJson = await response.json() const roleTypesJson = await response.json()
setRoleTypes(roleTypesJson) setRoleTypes(roleTypesJson)
} else { } else {
setRoleTypes([])
console.error(response) console.error(response)
} }
} }
......
...@@ -122,7 +122,10 @@ function NewGuestRole({ guest, reloadGuestInfo }: NewGuestRoleProps) { ...@@ -122,7 +122,10 @@ function NewGuestRole({ guest, reloadGuestInfo }: NewGuestRoleProps) {
const todayPlusMaxDays = (roleTypeId?: number) => { const todayPlusMaxDays = (roleTypeId?: number) => {
if (roleTypeId) { if (roleTypeId) {
const role = roleTypes.find((rt) => rt.id === roleTypeId) const role =
roleTypes === undefined
? undefined
: roleTypes.find((rt) => rt.id === roleTypeId)
if (role !== undefined) { if (role !== undefined) {
return addDays(role.max_days)(today) return addDays(role.max_days)(today)
} }
...@@ -191,7 +194,9 @@ function NewGuestRole({ guest, reloadGuestInfo }: NewGuestRoleProps) { ...@@ -191,7 +194,9 @@ function NewGuestRole({ guest, reloadGuestInfo }: NewGuestRoleProps) {
label={t('input.roleType')} label={t('input.roleType')}
onChange={handleRoleTypeChange} onChange={handleRoleTypeChange}
> >
{roleTypes.sort(roleTypeSort()).map((rt) => rolesToItem(rt))} {(roleTypes === undefined ? [] : roleTypes)
.sort(roleTypeSort())
.map((rt) => rolesToItem(rt))}
</Select> </Select>
</FormControl> </FormControl>
...@@ -205,7 +210,8 @@ function NewGuestRole({ guest, reloadGuestInfo }: NewGuestRoleProps) { ...@@ -205,7 +210,8 @@ function NewGuestRole({ guest, reloadGuestInfo }: NewGuestRoleProps) {
label={t('common:ou')} label={t('common:ou')}
onChange={handleOuChange} onChange={handleOuChange}
> >
{ous.length > 0 && {ous !== undefined &&
ous.length > 0 &&
ous ous
.sort(i18n.language === 'en' ? enSort : nbSort) .sort(i18n.language === 'en' ? enSort : nbSort)
.map((ou) => ouToItem(ou))} .map((ou) => ouToItem(ou))}
...@@ -310,4 +316,5 @@ function NewGuestRole({ guest, reloadGuestInfo }: NewGuestRoleProps) { ...@@ -310,4 +316,5 @@ function NewGuestRole({ guest, reloadGuestInfo }: NewGuestRoleProps) {
</Page> </Page>
) )
} }
export default NewGuestRole export default NewGuestRole
...@@ -36,6 +36,7 @@ const StepPersonForm = forwardRef( ...@@ -36,6 +36,7 @@ const StepPersonForm = forwardRef(
const { i18n, t } = useTranslation(['common']) const { i18n, t } = useTranslation(['common'])
const { nextHandler, formData } = props const { nextHandler, formData } = props
const ous = useOus() const ous = useOus()
const [ouChoice, setOuChoice] = useState( const [ouChoice, setOuChoice] = useState(
formData.ou_id ? formData.ou_id : '' formData.ou_id ? formData.ou_id : ''
) )
...@@ -91,7 +92,10 @@ const StepPersonForm = forwardRef( ...@@ -91,7 +92,10 @@ const StepPersonForm = forwardRef(
} }
function updateMaxDaysForRoleType(roleTypeId: any) { function updateMaxDaysForRoleType(roleTypeId: any) {
const selectedRoleTypeInfo = roleTypes.find((rt) => rt.id === roleTypeId) const selectedRoleTypeInfo =
roleTypes === undefined
? undefined
: roleTypes.find((rt) => rt.id === roleTypeId)
const maxDate = getMaxDateForRoleType(selectedRoleTypeInfo) const maxDate = getMaxDateForRoleType(selectedRoleTypeInfo)
setTodayPlusMaxDays(maxDate) setTodayPlusMaxDays(maxDate)
// Trigger revalidation of role end since the max end date is // Trigger revalidation of role end since the max end date is
...@@ -217,13 +221,15 @@ const StepPersonForm = forwardRef( ...@@ -217,13 +221,15 @@ const StepPersonForm = forwardRef(
label={t('input.roleType')} label={t('input.roleType')}
onChange={handleRoleTypeChange} onChange={handleRoleTypeChange}
> >
{roleTypes.sort(roleTypeSort()).map((roleType) => ( {(roleTypes === undefined ? [] : roleTypes)
<MenuItem key={roleType.id.toString()} value={roleType.id}> .sort(roleTypeSort())
{i18n.language === 'en' .map((roleType) => (
? roleType.name_en <MenuItem key={roleType.id.toString()} value={roleType.id}>
: roleType.name_nb} {i18n.language === 'en'
</MenuItem> ? roleType.name_en
))} : roleType.name_nb}
</MenuItem>
))}
</TextField> </TextField>
<TextField <TextField
...@@ -233,7 +239,7 @@ const StepPersonForm = forwardRef( ...@@ -233,7 +239,7 @@ const StepPersonForm = forwardRef(
label={t('common:ou')} label={t('common:ou')}
onChange={handleOuChange} onChange={handleOuChange}
> >
{ous {(ous === undefined ? [] : ous)
.sort(i18n.language === 'en' ? enSort : nbSort) .sort(i18n.language === 'en' ? enSort : nbSort)
.map((ou) => ( .map((ou) => (
<MenuItem key={ou.id.toString()} value={ou.id}> <MenuItem key={ou.id.toString()} value={ou.id}>
......
...@@ -182,6 +182,11 @@ export default function StepRegistration() { ...@@ -182,6 +182,11 @@ export default function StepRegistration() {
} }
useEffect(() => { useEffect(() => {
if (ous === undefined || roleTypes === undefined) {
// The organisational units or role types are still loading
return
}
if (ous.length === 0 || roleTypes.length === 0) { if (ous.length === 0 || roleTypes.length === 0) {
// These arrays should have values. There is no information // These arrays should have values. There is no information
// about the status code at this level, since the values come // about the status code at this level, since the values come
......
...@@ -26,7 +26,10 @@ function StepSummary(props: StepSummaryProperties) { ...@@ -26,7 +26,10 @@ function StepSummary(props: StepSummaryProperties) {
const ous = useOus() const ous = useOus()
const roleTypes = useRoleTypes() const roleTypes = useRoleTypes()
const selectedOus = ous.find((value) => value.id === formData.ou_id) const selectedOus =
ous === undefined
? undefined
: ous.find((value) => value.id === formData.ou_id)
const ousName = const ousName =
selectedOus === undefined selectedOus === undefined
? '' ? ''
...@@ -35,10 +38,14 @@ function StepSummary(props: StepSummaryProperties) { ...@@ -35,10 +38,14 @@ function StepSummary(props: StepSummaryProperties) {
})` })`
// TODO Fix this confusing mix between use of id and identifier // TODO Fix this confusing mix between use of id and identifier
const selectedRoleType = roleTypes.find( const selectedRoleType =
(value) => roleTypes === undefined
value.id === (formData.role_type === undefined ? -1 : formData.role_type) ? undefined
) : roleTypes.find(
(value) =>
value.id ===
(formData.role_type === undefined ? -1 : formData.role_type)
)
const roleTypeName = const roleTypeName =
selectedRoleType === undefined selectedRoleType === undefined
? '' ? ''
......
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