Skip to content

Commit

Permalink
Merge pull request #420 from NYPL/SCC-4389/my-account-2.0-qa
Browse files Browse the repository at this point in the history
Pulling out type = notification
  • Loading branch information
7emansell authored Dec 16, 2024
2 parents 11aceac + 47c2b40 commit eba37fa
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions src/components/MyAccount/Settings/SettingsSelectForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
? [
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -203,7 +201,7 @@ const SettingsSelectForm = ({
>
{selection}
</Text>
{type === "notification" &&
{isNotification &&
patronHasNonePref &&
!patronHasPhone &&
!patronHasEmail && (
Expand All @@ -219,7 +217,7 @@ const SettingsSelectForm = ({
{editingField === "" && (
<EditButton
isDisabled={
type === "notification" &&
isNotification &&
patronHasNonePref &&
!patronHasPhone &&
!patronHasEmail
Expand Down

0 comments on commit eba37fa

Please sign in to comment.