Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions pages/wholesale/wholesale.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,21 +204,21 @@ export async function fetchStoreHours(store) {
return hours;
}

function shouldDisplayWholesale(operatingHours) {
async function shouldDisplayWholesale(wholesaleHoursKey) {
const normalizedWholesaleKey = `WHOLESALE_${wholesaleHoursKey.toUpperCase()}`
const operatingHours = await fetchStoreHours(normalizedWholesaleKey);

let shouldDisplay = false;
const days = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];

const { pathname } = window.location;
const isWholesaleTest = pathname.split('/').some((path) => path === 'wholesale-test');

const now = new Date();
const dayName = days[now.getDay()];

// eslint-disable-next-line prefer-const
let { open, close } = operatingHours[dayName];

const currentTime = now.getHours() * 60 + now.getMinutes();
shouldDisplay = isWholesaleTest ? true : shouldDisplayWholesaleForm(open, close, currentTime);
shouldDisplay = shouldDisplayWholesaleForm(open, close, currentTime);

return shouldDisplay;
}
Expand Down Expand Up @@ -392,10 +392,11 @@ async function buildWholesale(main, link) {
setWholesaleLocalStorage();
getOrderFormData();

// Fetch a list of store hours for wholesale
const wholesaleHours = await fetchStoreHours('WHOLESALE');
// determine if wholesale is open for orders
const displayWholesaleForm = await shouldDisplayWholesale(wholesaleHours);
const wholesaleKey = JSON.parse(sessionStorage.getItem('wholesaleKey'));

// Function call that fetches wholesale hours and assesses whether
// wholesale ordering should be displayed.
const displayWholesaleForm = await shouldDisplayWholesale(wholesaleKey);

const wholesaleFormContainer = main.querySelector('.wholesale-form');

Expand Down
Loading