Merge pull request #20371 from overleaf/mf-us-gov-banner

[web] Add US gov banner based on inclusion and exclusion criteria

GitOrigin-RevId: c45ed280c8ef2dbdf9f3b84488e767c06fcc1ae1
This commit is contained in:
M Fahru
2024-10-03 10:01:32 -07:00
committed by Copybot
parent f3cb79c12f
commit 16ba4b0ddf
12 changed files with 211 additions and 11 deletions

View File

@@ -8,11 +8,26 @@ const POSTPONE_DURATION_MS = 24 * 60 * 60 * 1000 // 1 day
* @param {string} userId
* @param {string} tutorialKey
* @param {'completed' | 'postponed'} state
* @param {Date} [postponedUntil] - The date until which the tutorial is postponed
*/
async function setTutorialState(userId, tutorialKey, state) {
async function setTutorialState(
userId,
tutorialKey,
state,
postponedUntil = null
) {
const updateData = {
state,
updatedAt: new Date(),
}
if (state === 'postponed' && postponedUntil) {
updateData.postponedUntil = postponedUntil
}
await UserUpdater.promises.updateUser(userId, {
$set: {
[`completedTutorials.${tutorialKey}`]: { state, updatedAt: new Date() },
[`completedTutorials.${tutorialKey}`]: updateData,
},
})
}
@@ -29,9 +44,11 @@ function getInactiveTutorials(user, tutorialKey) {
// Legacy format: single date means the tutorial was completed
inactiveTutorials.push(key)
} else if (record.state === 'postponed') {
const postponedUntil = new Date(
const defaultPostponedUntil = new Date(
record.updatedAt.getTime() + POSTPONE_DURATION_MS
)
const postponedUntil = record.postponedUntil ?? defaultPostponedUntil
if (new Date() < postponedUntil) {
inactiveTutorials.push(key)
}