From 11caacd5a01b76218cae054e698079dc2c6d50f1 Mon Sep 17 00:00:00 2001
From: Andreas Ellewsen <ae@uio.no>
Date: Fri, 4 Feb 2022 15:09:51 +0100
Subject: [PATCH] Stop posting consents the guest did not answer

Before this commit, an optional consent that was not answered was posted
with the choice value set to null. This was rejected by the backend,
making it impossible to not answer an optional consent. It is now
possible.

Resolves: GREG-187
---
 frontend/src/routes/guest/register/steps/consent.tsx | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/frontend/src/routes/guest/register/steps/consent.tsx b/frontend/src/routes/guest/register/steps/consent.tsx
index 8e0aba7c..e6761163 100644
--- a/frontend/src/routes/guest/register/steps/consent.tsx
+++ b/frontend/src/routes/guest/register/steps/consent.tsx
@@ -38,9 +38,12 @@ const GuestConsentStep = forwardRef(
     useFieldArray({ control, name: 'consents' })
 
     const submit: SubmitHandler<GuestConsentData> = (data) => {
-      console.log('consent submit', data)
-
-      nextHandler(data)
+      // Exclude consents the guest did not accept an answer for
+      const submitdata: GuestConsentData = {
+        consents: data.consents?.filter((cons) => cons.choice !== null),
+      }
+      console.log('consent submit', submitdata)
+      nextHandler(submitdata)
     }
 
     const onSubmit = handleSubmit<GuestConsentData>(submit)
-- 
GitLab