Skip to content

Commit

Permalink
PM-367: moving reset method into costo-promo.js
Browse files Browse the repository at this point in the history
  • Loading branch information
pgilmore-phi committed Nov 20, 2024
1 parent a9c6134 commit cb7239f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
9 changes: 8 additions & 1 deletion blocks/plans-quote/costco-promo.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ const costcoFigoService = await getConfigValue('costco-figo-proxy');
const costcoFigoStoredData = localStorage.getItem(LS_KEY_FIGO_COSTCO);
const costcoFigoStoredValues = costcoFigoStoredData ? JSON.parse(costcoFigoStoredData) : {};
const costcoFigosubId = COSTCO_FIGO_PROMO_ITEMS.subId;
const hasCostcoFigoStored = costcoFigoStoredData !== null;

export const getIsMultiPet = costcoFigoStoredValues.multiPet ?? true;
export const isCostcoFigo = costcoFigoStoredValues.isEligible ?? false;
export const getSavedCouponCode = costcoFigoStoredValues.couponCode ?? null;
export const getSavedPolicyId = costcoFigoStoredValues.policyId ?? null;
export const hasCostcoFigoStored = costcoFigoStoredData !== null;

// is costco figo flow
function isCostcoFigoFlow(policyId) {
Expand Down Expand Up @@ -129,3 +129,10 @@ export async function checkCostcoFigoPromo(policyId, countryCode) {
}
return costcoFigoCouponData;
}

// remove storage data
export async function resetCostcoFigoData() {
if (hasCostcoFigoStored) {
localStorage.removeItem(LS_KEY_FIGO_COSTCO);
}
}
12 changes: 3 additions & 9 deletions blocks/plans-quote/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import APIClient, { getAPIBaseUrl } from '../../scripts/24petwatch-api.js';
import {
COOKIE_NAME_SAVED_OWNER_ID,
SS_KEY_FORM_ENTRY_URL,
LS_KEY_FIGO_COSTCO,
CURRENCY_CANADA,
CURRENCY_US,
EMAIL_REGEX,
Expand All @@ -31,7 +30,7 @@ import {
COSTCO_FIGO_PROMO_ITEMS,
getSavedCouponCode,
getIsMultiPet,
hasCostcoFigoStored,
resetCostcoFigoData,
} from './costco-promo.js';

const US_LEGAL_HEADER = '';
Expand Down Expand Up @@ -917,13 +916,6 @@ export default function formDecoration(block) {
return breedName;
}

async function resetCostcoFigoData() {
if (hasCostcoFigoStored) {
localStorage.removeItem(LS_KEY_FIGO_COSTCO);
isMultiPet = true;
}
}

async function executeCostcoFigoPromoCheck() {
// Check if we have a costco figo promo policy id from query string
if (costcoFigoPolicyId) {
Expand All @@ -948,10 +940,12 @@ export default function formDecoration(block) {
} else {
// we don't have a valid code and have stored policy data
await resetCostcoFigoData();
isMultiPet = true;
}
} else {
// no policy Id parameter, reset any promo data
await resetCostcoFigoData();
isMultiPet = true;
}
}

Expand Down

0 comments on commit cb7239f

Please sign in to comment.