From 9244787bc6c6e8726babce68312e5e96e7750718 Mon Sep 17 00:00:00 2001
From: Tore Brede <Tore.Brede@uib.no>
Date: Fri, 21 Jan 2022 13:40:01 +0100
Subject: [PATCH] GREG-160: Using nullish coalescing operator

---
 frontend/src/routes/sponsor/guest/newGuestRole/index.tsx | 6 ++----
 frontend/src/routes/sponsor/register/stepPersonForm.tsx  | 7 ++-----
 frontend/src/routes/sponsor/register/stepSummary.tsx     | 6 ++----
 3 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/frontend/src/routes/sponsor/guest/newGuestRole/index.tsx b/frontend/src/routes/sponsor/guest/newGuestRole/index.tsx
index f90eec50..017cf9b5 100644
--- a/frontend/src/routes/sponsor/guest/newGuestRole/index.tsx
+++ b/frontend/src/routes/sponsor/guest/newGuestRole/index.tsx
@@ -112,10 +112,8 @@ function NewGuestRole({ guest, reloadGuestInfo }: NewGuestRoleProps) {
     history.push(`/sponsor/guest/${pid}`)
   })
 
-  const tempOus = useOus()
-  const ous = tempOus === undefined ? [] : tempOus
-  const tempRoleTypes = useRoleTypes()
-  const roleTypes = tempRoleTypes === undefined ? [] : tempRoleTypes
+  const ous = useOus() ?? []
+  const roleTypes = useRoleTypes() ?? []
   const [ouChoice, setOuChoice] = useState<string>('')
   const [roleTypeChoice, setRoleTypeChoice] = useState<string>('')
   const [t, i18n] = useTranslation('common')
diff --git a/frontend/src/routes/sponsor/register/stepPersonForm.tsx b/frontend/src/routes/sponsor/register/stepPersonForm.tsx
index ede38d42..fa1097cd 100644
--- a/frontend/src/routes/sponsor/register/stepPersonForm.tsx
+++ b/frontend/src/routes/sponsor/register/stepPersonForm.tsx
@@ -35,9 +35,7 @@ const StepPersonForm = forwardRef(
   (props: StepPersonFormProperties, ref: Ref<PersonFormMethods>) => {
     const { i18n, t } = useTranslation(['common'])
     const { nextHandler, formData } = props
-
-    const tempOus = useOus()
-    const ous = tempOus === undefined ? [] : tempOus
+    const ous = useOus() ?? []
 
     const [ouChoice, setOuChoice] = useState(
       formData.ou_id ? formData.ou_id : ''
@@ -47,8 +45,7 @@ const StepPersonForm = forwardRef(
     )
     const today = new Date()
     const [todayPlusMaxDays, setTodayPlusMaxDays] = useState(today)
-    const tempRoleTypes = useRoleTypes()
-    const roleTypes = tempRoleTypes === undefined ? [] : tempRoleTypes
+    const roleTypes = useRoleTypes() ?? []
     const { displayContactAtUnit, displayComment } = useContext(FeatureContext)
 
     const roleTypeSort = () => (a: RoleTypeData, b: RoleTypeData) => {
diff --git a/frontend/src/routes/sponsor/register/stepSummary.tsx b/frontend/src/routes/sponsor/register/stepSummary.tsx
index aa551a67..775b088c 100644
--- a/frontend/src/routes/sponsor/register/stepSummary.tsx
+++ b/frontend/src/routes/sponsor/register/stepSummary.tsx
@@ -23,10 +23,8 @@ interface StepSummaryProperties {
 function StepSummary(props: StepSummaryProperties) {
   const { t } = useTranslation(['common'])
   const { formData } = props
-  const tempOus = useOus()
-  const ous = tempOus === undefined ? [] : tempOus
-  const tempRoleTypes = useRoleTypes()
-  const roleTypes = tempRoleTypes === undefined ? [] : tempRoleTypes
+  const ous = useOus() ?? []
+  const roleTypes = useRoleTypes() ?? []
 
   const selectedOus = ous.find((value) => value.id === formData.ou_id)
   const ousName =
-- 
GitLab