mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-22 20:46:42 +02:00
feat(shared-auth-ui): add GuestRegistrationNudge + complete feature texts + improve seed data
- Add GuestRegistrationNudge component: shows a floating banner after X minutes of guest usage to encourage sign-up (bottom-center, dismissible) - Add guestNudge.ts utilities (session tracking, delay, dismiss via localStorage) - Add feature texts for all 16 missing apps in GuestWelcomeModal - Integrate nudge in Todo app as reference implementation (3min delay) - Improve SkillTree seed: 3 skills across branches, 6 activities, 1 achievement - Improve Zitare seed: 5 favorites, 2 themed lists instead of 1 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
4d0e9a6a3f
commit
1570cc0bb4
8 changed files with 439 additions and 20 deletions
69
packages/shared-auth-ui/src/utils/guestNudge.ts
Normal file
69
packages/shared-auth-ui/src/utils/guestNudge.ts
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
/**
|
||||
* Utility functions for managing guest registration nudge state.
|
||||
* Shows a nudge after X minutes of guest usage to encourage sign-up.
|
||||
*/
|
||||
|
||||
const SESSION_PREFIX = 'guest-nudge-session';
|
||||
const DISMISSED_PREFIX = 'guest-nudge-dismissed';
|
||||
|
||||
/**
|
||||
* Record the start of a guest session for an app (call once on mount).
|
||||
* Only sets the timestamp if one doesn't already exist.
|
||||
*/
|
||||
export function startGuestSession(appId: string): void {
|
||||
if (typeof localStorage === 'undefined') return;
|
||||
const key = `${SESSION_PREFIX}-${appId}`;
|
||||
if (!localStorage.getItem(key)) {
|
||||
localStorage.setItem(key, Date.now().toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if enough time has passed to show the registration nudge.
|
||||
* Returns false if already dismissed or not enough time elapsed.
|
||||
*/
|
||||
export function shouldShowGuestNudge(appId: string, delayMinutes = 5): boolean {
|
||||
if (typeof localStorage === 'undefined') return false;
|
||||
|
||||
// Already dismissed?
|
||||
if (localStorage.getItem(`${DISMISSED_PREFIX}-${appId}`) === 'true') return false;
|
||||
|
||||
// Check elapsed time
|
||||
const sessionStart = localStorage.getItem(`${SESSION_PREFIX}-${appId}`);
|
||||
if (!sessionStart) return false;
|
||||
|
||||
const elapsed = Date.now() - parseInt(sessionStart, 10);
|
||||
return elapsed >= delayMinutes * 60 * 1000;
|
||||
}
|
||||
|
||||
/**
|
||||
* Permanently dismiss the nudge for an app.
|
||||
*/
|
||||
export function dismissGuestNudge(appId: string): void {
|
||||
if (typeof localStorage === 'undefined') return;
|
||||
localStorage.setItem(`${DISMISSED_PREFIX}-${appId}`, 'true');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset nudge state for an app (will show again after delay).
|
||||
*/
|
||||
export function resetGuestNudge(appId: string): void {
|
||||
if (typeof localStorage === 'undefined') return;
|
||||
localStorage.removeItem(`${SESSION_PREFIX}-${appId}`);
|
||||
localStorage.removeItem(`${DISMISSED_PREFIX}-${appId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset nudge state for all apps.
|
||||
*/
|
||||
export function resetAllGuestNudges(): void {
|
||||
if (typeof localStorage === 'undefined') return;
|
||||
const keysToRemove: string[] = [];
|
||||
for (let i = 0; i < localStorage.length; i++) {
|
||||
const key = localStorage.key(i);
|
||||
if (key?.startsWith(SESSION_PREFIX) || key?.startsWith(DISMISSED_PREFIX)) {
|
||||
keysToRemove.push(key);
|
||||
}
|
||||
}
|
||||
keysToRemove.forEach((key) => localStorage.removeItem(key));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue