* Clarify intent * Increase email reminder period to once per day * Fallback * Snooze immediately after account creation, prevent showing right after signup * Fix e2e test exports * Remove redundant check * Better simple date generation * Replace in DateField * Use non-string comparison * Revert change to unrelated code * Also parse * Remove side effect
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import {simpleAreDatesEqual} from '#/lib/strings/time'
|
|
import {logger} from '#/logger'
|
|
import * as persisted from '#/state/persisted'
|
|
import {SessionAccount} from '../session'
|
|
import {isOnboardingActive} from './onboarding'
|
|
|
|
export function shouldRequestEmailConfirmation(account: SessionAccount) {
|
|
// ignore logged out
|
|
if (!account) return false
|
|
// ignore confirmed accounts, this is the success state of this reminder
|
|
if (account.emailConfirmed) return false
|
|
// wait for onboarding to complete
|
|
if (isOnboardingActive()) return false
|
|
|
|
const snoozedAt = persisted.get('reminders').lastEmailConfirm
|
|
const today = new Date()
|
|
|
|
logger.debug('Checking email confirmation reminder', {
|
|
today,
|
|
snoozedAt,
|
|
})
|
|
|
|
// never been snoozed, new account
|
|
if (!snoozedAt) {
|
|
return true
|
|
}
|
|
|
|
// already snoozed today
|
|
if (simpleAreDatesEqual(new Date(Date.parse(snoozedAt)), new Date())) {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
export function snoozeEmailConfirmationPrompt() {
|
|
const lastEmailConfirm = new Date().toISOString()
|
|
logger.debug('Snoozing email confirmation reminder', {
|
|
snoozedAt: lastEmailConfirm,
|
|
})
|
|
persisted.write('reminders', {
|
|
...persisted.get('reminders'),
|
|
lastEmailConfirm,
|
|
})
|
|
}
|