feat(usage): prompt existing admins once for usage reporting after an update
An admin who already had PicPeak installed before the opt-in reporting feature existed never gets asked — the setup wizard only runs once, on a brand-new instance. Adds a one-time modal, shown on the admin's next dashboard visit after updating, offering the same choice the wizard gives a new install. - New `product_usage_state.prompt_shown` column (migration 211) and UsageService.markPromptShown(), set on either outcome (enable or decline) from both this modal and the wizard step, so an installation is never asked twice regardless of which path it took. - New POST /admin/usage/prompt-seen endpoint. - Extracted the wizard's three-point pitch (UsageReportingPitch.tsx) so the modal and the wizard step share identical copy instead of drifting apart. - The modal never shows once participation is already active, and never shows a second time after either the wizard or the modal has been through it once. Depends on #1360 (the setup wizard step this reuses).
This commit is contained in:
@@ -73,6 +73,13 @@ router.post(
|
||||
'/dismiss',
|
||||
wrap(async (_req, res) => res.json(await service.dismiss()))
|
||||
);
|
||||
// Acknowledges the one-time opt-in prompt (setup wizard or the post-update
|
||||
// modal) regardless of whether the admin enabled or declined — either way it
|
||||
// must not ask this installation again.
|
||||
router.post(
|
||||
'/prompt-seen',
|
||||
wrap(async (_req, res) => res.json(await service.markPromptShown()))
|
||||
);
|
||||
router.post(
|
||||
'/enable',
|
||||
wrap(async (req, res) =>
|
||||
|
||||
@@ -263,6 +263,7 @@ class UsageService {
|
||||
return {
|
||||
status: state.status,
|
||||
notice_dismissed: Boolean(state.notice_dismissed),
|
||||
prompt_shown: Boolean(state.prompt_shown),
|
||||
installation_id: state.installation_id,
|
||||
collector_url: collectorUrl,
|
||||
collector_error: collectorError,
|
||||
@@ -343,6 +344,18 @@ class UsageService {
|
||||
.update({ notice_dismissed: formatBoolean(true) });
|
||||
return this.status();
|
||||
}
|
||||
// The one-time opt-in prompt (setup wizard for a new install, a modal shown
|
||||
// once to an existing admin after an update) calls this on either outcome —
|
||||
// enable or decline — so it never asks the same installation twice. Kept
|
||||
// separate from `notice_dismissed`: that one only silences the persistent,
|
||||
// re-visitable dashboard banner and is unrelated to whether this one-time
|
||||
// prompt has already been shown.
|
||||
async markPromptShown() {
|
||||
await this.db('product_usage_state')
|
||||
.where({ id: 1 })
|
||||
.update({ prompt_shown: formatBoolean(true) });
|
||||
return this.status();
|
||||
}
|
||||
async enable(consent) {
|
||||
if (!Object.values(CONSENT_VERSIONS).includes(consent))
|
||||
throw new ValidationError('Explicit usage consent is required');
|
||||
@@ -382,6 +395,7 @@ class UsageService {
|
||||
status: 'activation_pending',
|
||||
consent_version: consent,
|
||||
notice_dismissed: formatBoolean(true),
|
||||
prompt_shown: formatBoolean(true),
|
||||
installation_id: identity.installation_id,
|
||||
public_key: identity.public_key,
|
||||
private_key_encrypted: this.encrypt(identity.private_key),
|
||||
|
||||
Reference in New Issue
Block a user