diff --git a/blocks/moredetailsaddress/moredetailsaddress.js b/blocks/moredetailsaddress/moredetailsaddress.js index de8012bab..a4bb1f0d9 100644 --- a/blocks/moredetailsaddress/moredetailsaddress.js +++ b/blocks/moredetailsaddress/moredetailsaddress.js @@ -114,16 +114,21 @@ async function getStateCity(lat, lng) { try { const response = await getStateName(lat, lng); const { results } = await response.json(); + let placeIDs = []; if (results[0]) { for (const result of results) { - if (result.place_id) { - const reviewRating = await getReviewRating(result.place_id); - if (reviewRating.result.reviews && reviewRating.result?.opening_hours?.weekday_text) { - setLocationObj.review = reviewRating.result.reviews; - setLocationObj.working = reviewRating.result.opening_hours.weekday_text; - break; - } - } + if (result.place_id) placeIDs.push(result.place_id); + /* const reviewRating = await getReviewRating(result.place_id); + if (reviewRating.result.reviews && reviewRating.result?.opening_hours?.weekday_text) { + setLocationObj.review = reviewRating.result.reviews; + setLocationObj.working = reviewRating.result.opening_hours.weekday_text; + break; + } */ + } + const reviewRating = await getReviewRating(placeIDs); + if(reviewRating.statusCode == 200){ + setLocationObj.review = reviewRating.result.reviews; + setLocationObj.working = reviewRating.result.opening_hours.weekday_text; } } } catch (err) { diff --git a/blocks/whatsappservice/otppopup.js b/blocks/whatsappservice/otppopup.js index 17428258c..219340d52 100644 --- a/blocks/whatsappservice/otppopup.js +++ b/blocks/whatsappservice/otppopup.js @@ -295,9 +295,9 @@ export function getWhatAPIAuth() { bot_id: '1', }, }; - return new Promise((resolve, reject) => { - fetchAPI('POST', getWhatAPIAuthURL, requestObj) + // fetchAPI('POST', getWhatAPIAuthURL, requestObj) + fetchAPI('GET', getWhatAPIAuthURL) .then((response) => { resolve(response.responseJson); }) diff --git a/scripts/scripts.js b/scripts/scripts.js index 03ebfb0b8..7d1df33e5 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -524,39 +524,8 @@ export function decorateViewMore(block) { export function decorateAnchorTag(main) { try { main.querySelectorAll('a').forEach((anchor) => { - if (anchor.innerHTML.includes('')) { - anchor.target = '_blank'; - } else if (anchor.href.includes('/modal-popup/')) { - const paths = anchor.href.split('/'); - const dataid = paths[paths.length - 1]; - anchor.dataset.modelId = dataid; - targetObject.modelId = dataid; - anchor.dataset.href = anchor.href; - anchor.href = 'javascript:void(0)'; - anchor.addEventListener('click', (e) => { - targetObject.models = document.querySelectorAll(`.${dataid}`); - targetObject.models?.forEach((eachModel) => { - eachModel.classList.add('dp-none'); - eachModel.remove(); - body.prepend(eachModel); - }); - e.preventDefault(); - body.style.overflow = 'hidden'; - - targetObject.models?.forEach((eachModel) => { - eachModel.classList.remove('dp-none'); - eachModel.classList.add('overlay'); - const crossIcon = eachModel.querySelector('em'); - if (crossIcon.innerHTML.includes(':cross-icon')) { - crossIcon.innerHTML = ''; - crossIcon.addEventListener('click', (e) => { - eachModel.classList.remove('overlay'); - eachModel.classList.add('dp-none'); - }); - } - }); - }); - } + const body = document.body; + processAnchor(anchor, body); }); } catch (error) { console.warn(error); @@ -1285,3 +1254,68 @@ export function groupAllKeys(array) { }, {}); } +// Helper functions +const handleRel = (anchor, hrefSplit) => { + if (hrefSplit.includes(',')) { + const rels = hrefSplit.split(','); + rels.forEach(function (eachRel) { + debugger + anchor.rel += `${eachRel.trim()}`; + }); + } else { + anchor.rel = hrefSplit; + } +}; +const handleModalPopup = (anchor, body) => { + const dataid = anchor.href.split('/').pop(); + // Set attributes + anchor.dataset.modelId = dataid; + targetObject.modelId = dataid; + anchor.dataset.href = anchor.href; + anchor.href = 'javascript:void(0)'; + anchor.addEventListener('click', (e) => { + e.preventDefault(); + const models = document.querySelectorAll(`.${dataid}`); + targetObject.models = models; + if (!models.length) return; + // Handle models + models.forEach(model => { + model.classList.add('dp-none'); + model.remove(); + body.prepend(model); + // Show modal + model.classList.remove('dp-none'); + model.classList.add('overlay'); + // Handle close button + const crossIcon = model.querySelector('em'); + if (crossIcon?.innerHTML.includes(':cross-icon')) { + crossIcon.innerHTML = ''; + crossIcon.addEventListener('click', () => { + model.classList.remove('overlay'); + model.classList.add('dp-none'); + }); + } + }); + body.style.overflow = 'hidden'; + }); +}; +// Main function +const processAnchor = (anchor, body) => { + // Handle rel attribute + if (anchor.href.includes('$')) { + const hrefSplit = anchor.href.split('$')[1]; + if (hrefSplit) { + handleRel(anchor, hrefSplit); + anchor.href = anchor.href.split('$')[0]; + } + } + // Handle target attribute + if (anchor.innerHTML.includes('')) { + anchor.target = '_blank'; + } + // Handle modal popup + if (anchor.href.includes('/modal-popup/')) { + handleModalPopup(anchor, body); + } +}; +