Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev -> Stage Sync (September 2024) #17

Merged
merged 21 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
72 changes: 4 additions & 68 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,72 +1,8 @@
# remove hidden mac files
.DS_Store

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.hintrc
.env

# next.js build output
.next

.vscode

# ignore scratch & scratch.js
scratch
scratch.js
.eslintrc.json
.hintrc
node_modules/
temp
config/local-dev/
17 changes: 17 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,23 @@ window.onload = async () => {
!firebase.apps.length ? firebase.initializeApp(stageFirebaseConfig) : firebase.app();
window.DD_RUM && window.DD_RUM.init({ ...datadogConfig, env: 'stage' });
}
else if (isLocalDev) {
let localDevFirebaseConfig = null;
let hasError = false;
try {
const localDevConfig = await import("./config/local-dev/config.js");
localDevFirebaseConfig = localDevConfig.firebaseConfig;
if (!localDevFirebaseConfig) hasError = true;
} catch (error) {
hasError = true;
}

if (hasError) {
console.error("Local development requires firebaseConfig defined in src/local-dev/config.js.");
return;
}
!firebase.apps.length ? firebase.initializeApp(localDevFirebaseConfig) : firebase.app();
}
else {
!firebase.apps.length ? firebase.initializeApp(devFirebaseConfig) : firebase.app();
!isLocalDev && window.DD_RUM && window.DD_RUM.init({ ...datadogConfig, env: 'dev' });
Expand Down
48 changes: 46 additions & 2 deletions src/participantDetails.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { dashboardNavBarLinks, removeActiveClass } from './navigationBar.js';
import { attachUpdateLoginMethodListeners, allStates, closeModal, getFieldValues, getImportantRows, getModalLabel, hideUneditableButtons, renderReturnSearchResults, resetChanges, saveResponses, showSaveNoteInModal, submitClickHandler, suffixList, languageList, viewParticipantSummary, } from './participantDetailsHelpers.js';
import { attachUpdateLoginMethodListeners, allStates, closeModal, getFieldValues, getImportantRows, getModalLabel, hideUneditableButtons, renderReturnSearchResults, resetChanges, saveResponses, showSaveNoteInModal, submitClickHandler, resetClickHandlers, suffixList, languageList, viewParticipantSummary, } from './participantDetailsHelpers.js';
import fieldMapping from './fieldToConceptIdMapping.js';
import { renderParticipantHeader } from './participantHeader.js';
import { getDataAttributes } from './utils.js';
import { getDataAttributes, urls } from './utils.js';
import { appState } from './stateManager.js';

appState.setState({unsavedChangesTrack:{saveFlag: false, counter: 0}});
Expand Down Expand Up @@ -38,6 +38,7 @@ export const renderParticipantDetails = (participant, changedOption) => {
hideUneditableButtons(participant, changedOption);
localStorage.setItem("participant", JSON.stringify(participant));
changeParticipantDetail(participant, changedOption, originalHTML);
resetParticipantConfirm();
editAltContact(participant);
viewParticipantSummary(participant);
renderReturnSearchResults();
Expand All @@ -63,6 +64,7 @@ export const render = (participant, changedOption) => {
${renderParticipantHeader(participant)}
${renderBackToSearchDivAndButton()}
${renderCancelChangesAndSaveChangesButtons()}
${renderResetUserButton(participant?.state?.uid)}
${renderDetailsTableHeader()}
`;

Expand Down Expand Up @@ -107,6 +109,30 @@ export const render = (participant, changedOption) => {
return template;
}

const resetParticipantConfirm = () => {
const openResetDialogBtn = document.getElementById('openResetDialog');
if(openResetDialogBtn) {
let data = getDataAttributes(openResetDialogBtn);
openResetDialogBtn.addEventListener('click', () => {
const header = document.getElementById('modalHeader');
const body = document.getElementById('modalBody');
const uid = data.participantuid;
header.innerHTML = `
<h5>Confirm Participant Reset</h5>
<button type="button" class="modal-close-btn" id="closeModal" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>`
body.innerHTML = `<div>
Are you sure you want to reset this participant to a just-verified state? This cannot be undone.
<div style="display:inline-block;">
<button type="submit" class="btn btn-danger" data-dismiss="modal" target="_blank">Cancel</button>
&nbsp;
<button type="button" class="btn btn-primary" id="resetUserBtn">Confirm</button>
</div>
</div>`
resetClickHandlers(uid);
});
}
}

const changeParticipantDetail = (participant, changedOption, originalHTML) => {
const detailedRow = Array.from(document.getElementsByClassName('detailedRow'));
if (detailedRow) {
Expand Down Expand Up @@ -282,6 +308,24 @@ const renderBackToSearchDivAndButton = () => {
`;
};

const renderResetUserButton = (participantUid) => {
if(location.hostname === 'localhost' || location.hostname === '127.0.0.1' || location.host === urls.dev) {
return `
<a
data-toggle="modal"
data-target="#modalShowMoreData"
name="modalResetParticipant"
id="openResetDialog"
data-participantuid="${participantUid}"
>
<button type="button" class="btn btn-danger">Reset User</button>
</a>
`
} else {
return '';
}
}

const renderDetailsTableHeader = () => {
return `
<table class="table detailsTable"> <h4 style="text-align: center;"> Participant Details </h4>
Expand Down
78 changes: 78 additions & 0 deletions src/participantDetailsHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,37 @@ const showAuthUpdateAPIError = (bodyId, message) => {
return false;
}

export const refreshParticipantAfterReset = async (participant) => {
showAnimation();
localStorage.setItem('participant', JSON.stringify(participant));
renderParticipantDetails(participant, {});
appState.setState({unsavedChangesTrack:{saveFlag: false, counter: 0}})
let alertList = document.getElementById('alert_placeholder');
let template = '';
template += `<div class="alert alert-warning alert-dismissible fade show" role="alert">
Success! Participant Reset.
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>`
hideAnimation();
alertList.innerHTML = template;
}

export const participantRefreshError = async (errorMsg) => {
showAnimation();
let alertList = document.getElementById('alert_placeholder');
let template = '';
template += `<div class="alert alert-danger alert-dismissible fade show" role="alert">
Error resetting participant: ${errorMsg}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>`
hideAnimation();
alertList.innerHTML = template;
}

export const refreshParticipantAfterUpdate = async (participant) => {
showAnimation();
localStorage.setItem('participant', JSON.stringify(participant));
Expand Down Expand Up @@ -1206,6 +1237,29 @@ export const submitClickHandler = async (participant, changedOption) => {
}
};

export const resetClickHandlers = async (participantUid) => {
const resetButton = document.getElementById('resetUserBtn');
if(!resetButton) {
return;
}
resetButton.addEventListener('click', async () => {
try {
const json = await postResetUserData(participantUid);
closeModal();
if(json.code === 200) {
refreshParticipantAfterReset(json.data.data);
} else if (json.code === 404) {
participantRefreshError('Unable to find participant.');
} else {
participantRefreshError(json.data);
}
} catch(error) {
console.error('error', error);
participantRefreshError('Unknown error.');
}
});
}

/**
* Handle the query.frstName and query.lastName fields.
* Check changedUserDataForProfile the participant profile for all name types. If a name is in changedUserDataForProfile, Add it to the queryNameArray.
Expand Down Expand Up @@ -1490,3 +1544,27 @@ export const postUserDataUpdate = async (changedUserData) => {
throw error;
}
}

export const postResetUserData = async (uid) => {
try {
const idToken = await getIdToken();
const response = await fetch(`${baseAPI}/dashboard?api=resetUser`, {
method: "POST",
headers:{
Authorization: "Bearer " + idToken,
"Content-Type": "application/json"
},
body: JSON.stringify({uid, saveToDb: 'true'})
});

if (!response.ok) {
const error = (response.status + ": " + (await response.json()).message);
throw new Error(error);
}

return await response.json();
} catch (error) {
console.error('Error in postResetUserData:', error);
throw error;
}
}
Loading