From 47c2b406ee59a36dfe7b93a7333ac40c241bf5a1 Mon Sep 17 00:00:00 2001 From: Emma Mansell <73774046+7emansell@users.noreply.github.com> Date: Mon, 16 Dec 2024 14:30:04 -0500 Subject: [PATCH] Pulling out type = notification --- .../MyAccount/Settings/SettingsSelectForm.tsx | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/components/MyAccount/Settings/SettingsSelectForm.tsx b/src/components/MyAccount/Settings/SettingsSelectForm.tsx index 40316052..e8283b52 100644 --- a/src/components/MyAccount/Settings/SettingsSelectForm.tsx +++ b/src/components/MyAccount/Settings/SettingsSelectForm.tsx @@ -37,6 +37,7 @@ const SettingsSelectForm = ({ const patronHasNonePref = patronData.notificationPreference === "-" const patronHasPhone = patronData.phones.length > 0 const patronHasEmail = patronData.emails.length > 0 + const isNotification = type === "notification" const notificationPreferenceMap = patronHasNonePref ? [ @@ -74,8 +75,7 @@ const SettingsSelectForm = ({ selectorId: "update-home-library-selector", } - const formUtils = - type === "notification" ? notificationFormUtils : libraryFormUtils + const formUtils = isNotification ? notificationFormUtils : libraryFormUtils const [selection, setSelection] = useState(formUtils.initialState) @@ -104,18 +104,16 @@ const SettingsSelectForm = ({ setIsLoading(true) setIsEditing(false) setStatus("") - const code = - type === "notification" - ? notificationPreferenceMap.find((pref) => pref.name === tempSelection) - ?.code - : pickupLocations.find((loc) => loc.name === tempSelection)?.code - - const body = - type === "notification" - ? { - fixedFields: { "268": { label: "Notice Preference", value: code } }, - } - : { homeLibraryCode: `${code}` } + const code = isNotification + ? notificationPreferenceMap.find((pref) => pref.name === tempSelection) + ?.code + : pickupLocations.find((loc) => loc.name === tempSelection)?.code + + const body = isNotification + ? { + fixedFields: { "268": { label: "Notice Preference", value: code } }, + } + : { homeLibraryCode: `${code}` } try { const response = await fetch( @@ -203,7 +201,7 @@ const SettingsSelectForm = ({ > {selection} - {type === "notification" && + {isNotification && patronHasNonePref && !patronHasPhone && !patronHasEmail && ( @@ -219,7 +217,7 @@ const SettingsSelectForm = ({ {editingField === "" && (