-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #374 from bluewave-labs/20-creating-popup-js-code
20 creating popup js code
- Loading branch information
Showing
26 changed files
with
691 additions
and
374 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const showPopup = (popupData) => { | ||
if (!popupData || popupData.length === 0) { | ||
console.warn('No popup data available'); | ||
return; | ||
} | ||
|
||
popupData.forEach(popup => { | ||
// Create popup container | ||
const popupContainer = document.createElement('div'); | ||
Object.assign(popupContainer.style, { | ||
position: 'fixed', | ||
bottom: '20px', | ||
right: '20px', | ||
backgroundColor: popup.headerBg || '#FFFFFF', | ||
padding: '20px', | ||
border: '1px solid #000', | ||
zIndex: 1000, | ||
}); | ||
|
||
// Create header | ||
const header = document.createElement('h2'); | ||
header.textContent = popup.headerText; | ||
header.style.color = popup.headerTextColor || '#000'; | ||
popupContainer.appendChild(header); | ||
|
||
// Create content | ||
const content = document.createElement('div'); | ||
content.innerHTML = popup.contentHtml; | ||
Object.assign(content.style, { | ||
color: popup.fontColor || '#000', | ||
fontSize: popup.font || '14px', | ||
}); | ||
popupContainer.appendChild(content); | ||
|
||
// Create action button | ||
const actionButton = document.createElement('button'); | ||
actionButton.textContent = popup.actionButtonText || 'Close'; | ||
Object.assign(actionButton.style, { | ||
backgroundColor: popup.actionButtonColor || '#CCC', | ||
}); | ||
actionButton.addEventListener('click', () => { | ||
document.body.removeChild(popupContainer); // Remove popup when button is clicked | ||
}); | ||
popupContainer.appendChild(actionButton); | ||
|
||
// Append the popup to the document body | ||
document.body.appendChild(popupContainer); | ||
}); | ||
}; | ||
|
||
export default showPopup; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<!-- Client-side HTML/JS Snippet to be integrated into their website --> | ||
<script> | ||
(function() { | ||
const apiId = 'YOUR_CLIENT_API_ID'; | ||
const apiUrl = `https://onboarding-demo.bluewavelabs.ca/api/onboard`; | ||
|
||
fetch(apiUrl, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ userId: apiId }) | ||
}) | ||
.then(response => response.json()) | ||
.then(data => { | ||
const script = document.createElement('script'); | ||
script.src = `https://onboarding-demo.bluewavelabs.ca/api/scripts/popupRenderer.js?apiId=${apiId}`; | ||
script.type = 'module'; | ||
script.onload = () => { | ||
import(`https://onboarding-demo.bluewavelabs.ca/api/scripts/popupRenderer.js?apiId=${apiId}`) | ||
.then(module => { | ||
module.default(data.popupData); | ||
}); | ||
}; | ||
document.head.appendChild(script); | ||
}) | ||
.catch(error => console.error('Error fetching onboarding data:', error)); | ||
})(); | ||
</script> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const bannerService = require("../service/banner.service.js"); | ||
const getBannerData = async (req, res) => { | ||
try { | ||
const { userId } = req.body; | ||
const bannerData = await bannerService.getBannerData(userId); | ||
res.status(200).json(bannerData); | ||
} catch (error) { | ||
res.status(500).json({ error: error.message }); | ||
} | ||
}; | ||
|
||
module.exports = { getBannerData }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
// bannerData: require('./bannerData.controller'), | ||
popupData: require('./popupData.controller'), | ||
// tourData: require('./tourData.controller'), | ||
// hintData: require('./hintData.controller') | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const popupService = require('../../service/popup.service'); | ||
|
||
const getPopupData = async (req, res) => { | ||
try { | ||
const { userId } = req.body; | ||
const popupData = await popupService.getPopups(userId); | ||
res.status(200).json(popupData); | ||
} catch (error) { | ||
res.status(500).json({ error: error.message }); | ||
} | ||
}; | ||
|
||
module.exports = { getPopupData }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const tourService = require('../service/tour.service'); | ||
|
||
const getTourData = async (req, res) => { | ||
try { | ||
const { userId } = req.body; | ||
const tourData = await tourService.getTourData(userId); | ||
res.status(200).json(tourData); | ||
} catch (error) { | ||
res.status(500).json({ error: error.message }); | ||
} | ||
}; | ||
|
||
module.exports = { getTourData }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const db = require('../models'); | ||
const { v4: uuidv4 } = require('uuid'); | ||
|
||
// Middleware to validate API ID | ||
const validateApiId = async (req, res, next) => { | ||
const { apiId } = req.query; // Assume API ID is sent in query params | ||
if (!apiId) { | ||
return res.status(400).json({ error: "API ID is required." }); | ||
} | ||
|
||
try { | ||
const user = await db.User.findOne({ where: { apiId } }); // API ID must be in User model | ||
if (!user) { | ||
return res.status(403).json({ error: "Invalid API ID." }); | ||
} | ||
|
||
req.user = user; // Attach the user to the request for future use | ||
next(); | ||
} catch (error) { | ||
return res.status(500).json({ error: "API ID validation failed." }); | ||
} | ||
}; | ||
|
||
// Middleware to generate client ID for each session | ||
const generateClientId = (req, res, next) => { | ||
if (!req.session.clientId) { | ||
req.session.clientId = uuidv4(); // Generate new client ID and store in session | ||
} | ||
next(); | ||
}; | ||
|
||
module.exports = { | ||
validateApiId, | ||
generateClientId | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const express = require("express"); | ||
const { validateApiId, generateClientId } = require("../middleware/onboard.middleware"); | ||
const onboardControllers = require("../controllers/onboard"); | ||
|
||
const router = express.Router(); | ||
|
||
router.use(validateApiId); | ||
router.use(generateClientId); | ||
|
||
// router.get("/banner", onboardControllers.bannerData.getBannerData); | ||
router.get("/popup", onboardControllers.popupData.getPopupData); | ||
// router.get("/tour", onboardControllers.tourData.getTourData); | ||
// router.get("/hint", onboardControllers.hintData.getHintData); | ||
|
||
module.exports = router; |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.