Skip to content

Commit

Permalink
Merge pull request #878 from episphere/stage
Browse files Browse the repository at this point in the history
Stage -> Prod Sync (December 2024)
  • Loading branch information
we-ai authored Dec 20, 2024
2 parents c6614cc + aac13a9 commit 589c5b9
Show file tree
Hide file tree
Showing 83 changed files with 7,138 additions and 2,154 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"eslint:recommended"
],
"globals": {
"bootstrap": "readonly",
"firebase": "readonly",
"firebaseui": "readonly",
"google":"readonly",
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ temp
.DS_Store
.hintrc
.eslintrc.js
eslint.config.mjs
connectApp-translation
node_modules/
local-dev/
local-dev/
npm-debug.log*
package.json
package-lock.json
142 changes: 84 additions & 58 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getParameters, validateToken, userLoggedIn, getMyData, hasUserData, getMyCollections, showAnimation, hideAnimation, storeResponse, isBrowserCompatible, inactivityTime, urls, appState, processAuthWithFirebaseAdmin, successResponse, logDDRumError, translateHTML, translateText, languageAcronyms } from "./js/shared.js";
import { userNavBar, homeNavBar, languageSelector } from "./js/components/navbar.js";
import { getParameters, validateToken, userLoggedIn, getMyData, hasUserData, getMyCollections, showAnimation, hideAnimation, storeResponse, isBrowserCompatible, inactivityTime, urls, appState, processAuthWithFirebaseAdmin, successResponse, logDDRumError, translateHTML, translateText, languageAcronyms, toggleNavbarMobileView } from "./js/shared.js";
import { userNavBar, homeNavBar, languageSelector, signOutNavBarTemplate } from "./js/components/navbar.js";
import { homePage, joinNowBtn, whereAmIInDashboard, renderHomeAboutPage, renderHomeExpectationsPage, renderHomePrivacyPage } from "./js/pages/homePage.js";
import { addEventPinAutoUpperCase, addEventRequestPINForm, addEventRetrieveNotifications, toggleCurrentPage, toggleCurrentPageNoUser, addEventToggleSubmit, addEventLanguageSelection } from "./js/event.js";
import { addEventPinAutoUpperCase, addEventRequestPINForm, addEventRetrieveNotifications, toggleCurrentPage, toggleCurrentPageNoUser, addEventToggleSubmit, addEventLanguageSelection, environmentWarningModal } from "./js/event.js";
import { requestPINTemplate, duplicateAccountReminderRender } from "./js/pages/healthCareProvider.js";
import { myToDoList } from "./js/pages/myToDoList.js";
import {renderNotificationsPage} from "./js/pages/notifications.js"
Expand All @@ -10,38 +10,40 @@ import { renderSettingsPage } from "./js/pages/settings.js";
import { renderSupportPage } from "./js/pages/support.js";
import { renderPaymentPage } from "./js/pages/payment.js";
import { renderSamplesPage } from "./js/pages/samples.js";
import { footerTemplate } from "./js/pages/footer.js";
import { renderVerifiedPage } from "./js/pages/verifiedPage.js";
import { firebaseConfig as devFirebaseConfig } from "./dev/config.js";
import { firebaseConfig as stageFirebaseConfig } from "./stage/config.js";
import { firebaseConfig as prodFirebaseConfig } from "./prod/config.js";
// When doing local development, uncomment this.
// Get the API key file from Box or the DevOps team
// Do not accept PRs with the localDevFirebaseConfig import uncommented
// import { firebaseConfig as localDevFirebaseConfig} from "./local-dev/config.js";
import conceptIdMap from "./js/fieldToConceptIdMapping.js";

if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("./serviceWorker.js").catch((error) => {
console.error("Service worker registration failed.", error);
return;
});

navigator.serviceWorker
.register("./serviceWorker.js")
.then((registration) => {
registration.onupdatefound = () => {
const sw = registration.installing;
if (sw) {
sw.onstatechange = () => sw.state === "activated" && sw.postMessage({ action: "getAppVersion" });
}
};
})
.catch((err) => {
console.error("Service worker registration failed.", err);
});

navigator.serviceWorker.ready.then(() => {
if (navigator.serviceWorker.controller) {
navigator.serviceWorker.controller.postMessage({ action: "getAppVersion" });
}
const sw = navigator.serviceWorker.controller;
sw && sw.postMessage({ action: "getAppVersion" });
});

navigator.serviceWorker.addEventListener("message", (event) => {
if (event.data.action === "sendAppVersion") {
if (event.data.action === "sendAppVersion") {
document.getElementById("appVersion").textContent = event.data.payload;
}
}
});
}
}

let auth = '';
// DataDog session management -> tie Connect_ID to DataDog sessions
let isDataDogUserSessionSet = false;

const datadogConfig = {
Expand Down Expand Up @@ -92,8 +94,9 @@ window.onload = async () => {
window.DD_RUM && window.DD_RUM.init({ ...datadogConfig, env: 'stage' });
}
else if (isLocalDev) {
if (typeof localDevFirebaseConfig === 'undefined') {
console.error('Local development requires a localDevFirebaseConfig function to be defined in ./local-dev/config.js.');
const { firebaseConfig: localDevFirebaseConfig } = await import("./local-dev/config.js");
if (!localDevFirebaseConfig) {
console.error('Local development requires a firebaseConfig variable defined in ./local-dev/config.js.');
return;
}
!firebase.apps.length ? firebase.initializeApp(localDevFirebaseConfig) : firebase.app();
Expand All @@ -108,33 +111,51 @@ window.onload = async () => {
document.body.appendChild(script)
auth = firebase.auth();

let inactivityCleanupFunction = null;

auth.onAuthStateChanged(async (user) => {
let idToken = '';
if (user) {
idToken = await user.getIdToken();
if (!user.isAnonymous) {
localforage.clear();
inactivityTime();
const firstSignInTime = new Date(user.metadata.creationTime).toISOString();
appState.setState({ participantData: { firstSignInTime } });
}
}
let idToken = '';
if (user) {
idToken = await user.getIdToken();
if (!user.isAnonymous) {
localforage.clear();
const firstSignInTime = new Date(user.metadata.creationTime).toISOString();
appState.setState({ participantData: { firstSignInTime } }); // TODO: potential issue with firstSignInTimestamp

// Reset to a clean activity state on auth update
localStorage.setItem('myConnectInactivityWarning', 'false');
localStorage.setItem('lastMyConnectActivityTimestamp', Date.now().toString());

// Clean up the old timer if it exists
if (inactivityCleanupFunction && typeof inactivityCleanupFunction === 'function') {
inactivityCleanupFunction();
}

appState.setState({ idToken });
// Start the inactivity timer and store the cleanup function
inactivityCleanupFunction = inactivityTime();
} else {
// User is anonymous or logged out, stop the timer if it exists
if (inactivityCleanupFunction && typeof inactivityCleanupFunction === 'function') {
inactivityCleanupFunction();
inactivityCleanupFunction = null;
}
localStorage.setItem('myConnectInactivityWarning', 'false');
}
} else {
// No user logged in (or user just logged out)
if (inactivityCleanupFunction && typeof inactivityCleanupFunction === 'function') {
inactivityCleanupFunction();
inactivityCleanupFunction = null;
}
localStorage.setItem('myConnectInactivityWarning', 'false');
}

appState.setState({ idToken });
});

const footer = document.getElementById('footer');
footer.innerHTML = footerTemplate();
// googleTranslateElementInit();

router();
await router();
}

// TODO: 'google is not defined' datadog error - inspect loading sequence/timing.
// const googleTranslateElementInit = () => {
// if(google) new google.translate.TranslateElement({pageLanguage: 'en'}, 'google_translate_element');
// }

const handleVerifyEmail = (auth, actionCode) => {
auth.applyActionCode(actionCode).then(function(resp) {
window.location.hash = '#verified';
Expand Down Expand Up @@ -198,8 +219,8 @@ const handleResetPassword = (auth, actionCode) => {
});
}

window.onhashchange = () => {
router();
window.onhashchange = async () => {
await router();
}

const router = async () => {
Expand Down Expand Up @@ -233,7 +254,7 @@ const router = async () => {
renderLanguageSelector();

if (route === '#') {
homePage();
await homePage();
} else if (route === '#about') {
renderHomeAboutPage();
} else if (route === '#expectations') {
Expand Down Expand Up @@ -270,7 +291,7 @@ const router = async () => {
if (route === '#') userProfile();
else if (route === '#dashboard') userProfile();
else if (route === '#messages') renderNotificationsPage();
else if (route === '#sign_out') signOut();
else if (route === '#sign_out') await signOut();
else if (route === '#forms') renderAgreements();
else if (route === '#myprofile') renderSettingsPage();
else if (route === '#support') renderSupportPage();
Expand All @@ -288,8 +309,8 @@ const renderLanguageSelector = () => {
//Add the language Selector Container
languageSelectorContainer = document.createElement('div');
languageSelectorContainer.id = 'languageSelectorContainer';
let navBarAlt = document.getElementById('navbarNavAltMarkup')
navBarAlt.parentNode.insertBefore(languageSelectorContainer, navBarAlt);
let userNavBar = document.getElementById('userNavBarContainer');
userNavBar.parentNode.insertBefore(languageSelectorContainer, userNavBar);
}

languageSelectorContainer.innerHTML = languageSelector();
Expand Down Expand Up @@ -406,7 +427,9 @@ const userProfile = () => {
});
}

const signOut = () => {
export const signOut = async () => {
toggleNavbarMobileView();

// Record a logout action and stop the DataDog session. This or 15 mins of inactivity will create a new session when the next action is taken.
if (!isLocalDev && window.DD_RUM) {
window.DD_RUM.addAction('user_logout', {
Expand All @@ -415,8 +438,10 @@ const signOut = () => {
window.DD_RUM.stopSession();
isDataDogUserSessionSet = false;
}
localforage.clear();

await firebase.auth().signOut();

firebase.auth().signOut();
window.location.hash = '#';
document.title = translateText('shared.homeTitle');
}
Expand All @@ -430,22 +455,23 @@ const toggleNavBar = (route, data) => {
auth.onAuthStateChanged(async user => {
if (user && !user.isAnonymous){
showAnimation();
document.getElementById('navbarNavAltMarkup').innerHTML = userNavBar(data);
document.getElementById('userNavBarContainer').innerHTML = userNavBar(data);
document.getElementById('signOutContainer').innerHTML = signOutNavBarTemplate();
document.getElementById('joinNow') ? document.getElementById('joinNow').innerHTML = joinNowBtn(false) : ``;
document.getElementById('signInWrapperDiv') ? document.getElementById('signInWrapperDiv').style.display = "none" :'';
document.getElementById('nextStepWarning') ? document.getElementById('nextStepWarning').innerHTML = await whereAmIInDashboard() : '';
document.getElementById('nextStepWarning') ? document.getElementById('nextStepWarning').style.display="block": '';
addEventRetrieveNotifications();
toggleCurrentPage(route);
await toggleCurrentPage(route);
hideAnimation();

}
else{
showAnimation();
document.getElementById('navbarNavAltMarkup').innerHTML = homeNavBar();
document.getElementById('userNavBarContainer').innerHTML = homeNavBar();
document.getElementById('signOutContainer').innerHTML = '';
document.getElementById('joinNow') ? document.getElementById('joinNow').innerHTML = joinNowBtn(true) : ``;
document.getElementById('nextStepWarning') ? document.getElementById('nextStepWarning').style.display="none": '';
toggleCurrentPageNoUser(route);
await toggleCurrentPageNoUser(route);
hideAnimation();
}
});
Expand Down Expand Up @@ -505,4 +531,4 @@ const updateFirebaseAuthPhoneTrigger = async (phone) => {
hideAnimation();
throw error;
}
};
};
62 changes: 45 additions & 17 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ a{
#root {
height: 100%;
margin-top:1px;
margin-left:15px;
margin-right:15px;
}

#footer {
Expand Down Expand Up @@ -1362,6 +1360,10 @@ button.connect-secondary {
font-family: Montserrat;
}

.site-info-italic {
font-style: italic;
}

.site-info-underline {
text-decoration: underline;
}
Expand All @@ -1387,6 +1389,10 @@ button.connect-secondary {
margin-bottom: 1rem;
}

#donateMySamplesTable tbody tr td {
padding: 0.5rem;
}

.messagesHeaderFont .samples-page-text {
font-size: 1.125rem;
color: #2E2E2E;
Expand Down Expand Up @@ -1471,33 +1477,55 @@ button.connect-secondary {
cursor: pointer;
}

.screen-reader-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0,0,0,0);
border: 0;
}

#languageSelectorContainer {
float: right;
line-height: .9rem;
line-height: 0.9rem;
font-weight: bold;
display: flex;
flex-direction: column;
}

#languageSelectorTitle {
margin: 2px 0;
font-weight: bold;
padding-bottom: 0.25rem;
text-align: center;
}

#languageSelector {
margin-bottom: 2px;
margin-bottom: 0.25rem;
}

@media (max-width: 991.98px) {
.navbar-collapse {
padding-top: 0.75rem;
}

.navbar-toggler {
margin: 0.5rem ;
}

/* Prevent language selector from moving when navbar expands */
.navbar-collapse.show~#languageSelectorContainer,
.navbar-collapse.collapsing~#languageSelectorContainer {
position: absolute;
right: 0.75rem;
top: 0.8rem;
}
}

#appVersion {
color: #fff;
font-size: 0.8rem;
}

.survey-main-body {
border: 1px solid #dee2e6;
padding: 20px;
border-radius: 0 10px 10px 10px;
}

@media (max-width: 768px) {
.survey-main-body {
padding: 10px;
border-width: 0.5px;
}
}
Loading

0 comments on commit 589c5b9

Please sign in to comment.