From e58229b09f332d736adda921b24eb3d85b9a7b94 Mon Sep 17 00:00:00 2001 From: Ryan Lepinski Date: Thu, 23 Mar 2023 16:56:45 -0700 Subject: [PATCH] [MOBILE-3571] Send up an empty form response (#2705) --- Airship/AirshipCore/Source/FormState.swift | 5 +---- .../Source/ThomasEnvironment.swift | 19 +++++++++---------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/Airship/AirshipCore/Source/FormState.swift b/Airship/AirshipCore/Source/FormState.swift index 75af8a02a..2fd49925c 100644 --- a/Airship/AirshipCore/Source/FormState.swift +++ b/Airship/AirshipCore/Source/FormState.swift @@ -193,6 +193,7 @@ public struct FormInputData { guard let value = value else { return nil } + return [ FormInputData.typeKey: "text_input", FormInputData.valueKey: value @@ -211,10 +212,6 @@ public struct FormInputData { childrenMap[value.identifier] = value.getData() } - guard !childrenMap.isEmpty else { - return nil - } - switch formType { case .form: return [ diff --git a/Airship/AirshipCore/Source/ThomasEnvironment.swift b/Airship/AirshipCore/Source/ThomasEnvironment.swift index 4703f0eac..acc56e158 100644 --- a/Airship/AirshipCore/Source/ThomasEnvironment.swift +++ b/Airship/AirshipCore/Source/ThomasEnvironment.swift @@ -48,10 +48,10 @@ class ThomasEnvironment : ObservableObject { return } - if let formResult = formState.toFormResult() { - self.delegate.onFormSubmitted(formResult: formResult, - layoutContext: layoutState.toLayoutContext()) - } + self.delegate.onFormSubmitted( + formResult: formState.toFormResult(), + layoutContext: layoutState.toLayoutContext() + ) let channelEditor = Airship.channel.editAttributes() let contactEditor = Airship.contact.editAttributes() @@ -209,12 +209,11 @@ private extension FormState { } } - func toFormResult() -> ThomasFormResult? { - if let data = self.data.toPayload() { - return ThomasFormResult(identifier: self.identifier, - formData: data) - } - return nil + func toFormResult() -> ThomasFormResult { + return ThomasFormResult( + identifier: self.identifier, + formData: self.data.toPayload() ?? [:] + ) } }