Skip to content

Commit

Permalink
USAGOV-2014-Display-Call-Times: change to replace div
Browse files Browse the repository at this point in the history
  • Loading branch information
IsabelLaurenceau committed Oct 30, 2024
1 parent fac257b commit 0cd04bb
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions web/themes/custom/usagov/scripts/callCenterWaitTimeLookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ jQuery(document).ready(async function () {
function checkPagePath() {
if (
window.location.pathname === "/phone" ||
window.location.pathname === "/es/llamenos"
window.location.pathname === "/es/llamenos" ||
window.location.pathname === "/chat" ||
window.location.pathname === "/es/chat"
) {
return true;
}
}

function getCallCenterWaitTime() {
var jsonSeconds;
var jsonTimestamp;
let jsonSeconds;
let jsonTimestamp;
jQuery.ajax({
"url": "https://s3-us-gov-west-1.amazonaws.com/cg-4d6fb302-315f-403e-a96e-a7563ccddd3d/1.0/waittime.json",
"type": "GET",
Expand All @@ -27,7 +29,7 @@ jQuery(document).ready(async function () {
else if (window.location.pathname === "/chat") {
jsonSeconds = response.chat.estimatedWaitTimeSeconds.en;
}
else (window.location.pathname === "/es/chat") {
else if (window.location.pathname === "/es/chat") {
jsonSeconds = response.chat.estimatedWaitTimeSeconds.sp;
}

Expand All @@ -41,7 +43,7 @@ jQuery(document).ready(async function () {
}

function checkTimeStamp(timestamp) {
var timeOfEstimate = timestamp ? timestamp : 0;
let timeOfEstimate = timestamp ? timestamp : 0;
if (Date.now() / 1000 - timeOfEstimate < 600) {
return true;
}
Expand All @@ -50,7 +52,7 @@ jQuery(document).ready(async function () {
function createDisplayWaitTime(actualSeconds, timestamp) {
// If the estimated time was captured over 10 minutes ago, remain silent.
if (checkTimeStamp(timestamp)) {
var displayTime;
let displayTime;
if (actualSeconds !== -1) {
if (actualSeconds < 60) {
displayTime = 1;
Expand All @@ -64,18 +66,18 @@ jQuery(document).ready(async function () {
}

function displayWaitTime(displayTime) {
var docLang = [document.documentElement.lang];
let docLang = [document.documentElement.lang];

var plural = displayTime > 1;
let plural = displayTime > 1;
const plurals = plural ? "s" : "";

const displayText =
docLang[0] === "es"
? `El tiempo aproximado de espera es <strong>${displayTime} minuto${plurals}</strong>.`
: `The current estimated wait time is <strong>${displayTime} minute${plurals}</strong>.`;

jQuery("#block-usagov-content").append(
`<div class="paragraph paragraph--type--uswds-alert paragraph--view-mode--embed paragraph--id--2485 usa-alert usa-alert--slim usa-alert--no-icon"><div class="usa-alert__body"> <div class="field field--name-field-alert-body field--type-text field--label-hidden field__item">${displayText}</div> </div> </div>`
jQuery('div[data-call-wait="showTime"]').replaceWith(
`<div class="paragraph paragraph--type--uswds-alert paragraph--view-mode--embed paragraph--id--2485 usa-alert usa-alert--slim usa-alert--no-icon" data-call-wait='showTime'><div class="usa-alert__body"> <div class="field field--name-field-alert-body field--type-text field--label-hidden field__item">${displayText}</div> </div> </div>`
);
}

Expand Down

0 comments on commit 0cd04bb

Please sign in to comment.