fleet/website/api/controllers/account/update-start-cta-visibility.js
Eric bf239ecc78
Website: Add site-wide CTA to bring users back to the /start questionnaire (#19393)
Closes: #18530

Changes: 
- Added a collapsable sitewide CTA to bring users who have not completed
the get started questionnaire back to the /start page.
- Added a new action (`account/updateStartCtaVisibility`) to set a
timestamp of when the CTA will be visible (not collapsed) in a user's
session when they close the CTA

---------

Co-authored-by: Mike Thomas <[email protected]>
2024-05-31 18:44:13 -05:00

37 lines
747 B
JavaScript
Vendored

module.exports = {
friendlyName: 'Update start CTA visibility',
description: 'Sets a timestamp to determine when we should show the user the start CTA after they have dismissed it.',
inputs: {
},
exits: {
},
fn: async function () {
if(!this.req.session){
throw new Error('Consistency violation. When a user sent a request to the update start CTA visibility endpoint, a session is missing.');
}
if(this.req.session.expandCtaAt) {
// Expand the CTA.
this.req.session.expandCtaAt = 0;
} else {
// collapse CTA for 24 hours.
let nowAt = Date.now();
let tomorrowAt = nowAt + (24 * 60 * 60 * 1000);
this.req.session.expandCtaAt = tomorrowAt;
}
return;
}
};