DigitalConsumer.FixMyGlass/src/helpers/save-progress-popup-contact-helper.js

41 lines
1.1 KiB
JavaScript

import { storeActions } from "@/constants/store-actions";
export const saveProgressPopupContactMethods = {
PHONE: "PhoneAnswer",
EMAIL: "EmailAnswer",
};
export function isPhoneContactMethod(contactMethod) {
return contactMethod === saveProgressPopupContactMethods.PHONE;
}
export function normalizePhoneNumberForStore(phoneNumber) {
if (!phoneNumber) {
return phoneNumber;
}
return String(phoneNumber).replace(/\D/g, "");
}
export async function saveProgressPopupContactToStore(
dispatchStoreAction,
{ contactMethod, userInput, smsConsent }
) {
if (isPhoneContactMethod(contactMethod)) {
await dispatchStoreAction(
storeActions.SAVE_PHONE_NUMBER,
normalizePhoneNumberForStore(userInput),
false
);
await dispatchStoreAction(storeActions.SAVE_IS_SMS_OPT_IN, smsConsent.transactional, false);
await dispatchStoreAction(
storeActions.SAVE_IS_SMS_MARKETING_OPT_IN,
smsConsent.marketing,
false
);
return;
}
await dispatchStoreAction(storeActions.SAVE_EMAIL, userInput, false);
}