import { storeActions } from "@/constants/store-actions"; import store from "@/store"; 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, pageName } ) { if (isPhoneContactMethod(contactMethod)) { await dispatchStoreAction( storeActions.SAVE_PHONE_NUMBER, normalizePhoneNumberForStore(userInput), false ); await dispatchStoreAction(storeActions.SAVE_IS_SMS_OPT_IN, smsConsent.transactional, false); const existingPageData = store.getters.pageData(pageName) ?? {}; await dispatchStoreAction( storeActions.SAVE_PAGE_DATA, { page: pageName, data: { ...existingPageData, saveProgressSmsConsent: { ...smsConsent }, }, }, false ); return; } await dispatchStoreAction(storeActions.SAVE_EMAIL, userInput, false); }