Skip to content

Commit 266e990

Browse files
committed
feat: enhance LicenseNag component logic for user tier and trial detection
- Updated the LicenseNag component to prevent display for users with paid tiers or active trials. - Added loading state check to avoid flashing for paid users. - Implemented auto-dismiss functionality for the LicenseNag when a paid tier or active trial is detected after opening.
1 parent 2eb59e3 commit 266e990

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

tauri-app/src/components/common/LicenseNag.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,17 @@ export function LicenseNag() {
3333
if (typeof window !== "undefined" && sessionStorage.getItem(SESSION_FLAG)) {
3434
return false; // already dismissed this session
3535
}
36+
// Wait for user state to be known to avoid flashing for paid users
37+
if (loading || user === null) {
38+
return false;
39+
}
3640
const tier = user?.tier?.toUpperCase();
37-
// Show only if tier is FREE or missing
38-
return !tier || tier === "FREE";
39-
}, [user?.tier]);
41+
const trialEndsAt = user?.trialEndsAt ? new Date(user.trialEndsAt) : null;
42+
const hasActiveTrial = Boolean(user?.trialActive && trialEndsAt && trialEndsAt.getTime() > Date.now());
43+
console.log('user has trial', hasActiveTrial, user)
44+
// Show only if tier is FREE or missing AND no active trial
45+
return (!tier || tier === "FREE") && !hasActiveTrial;
46+
}, [user, loading]);
4047

4148
// Fetch current user once on mount if unknown
4249
useEffect(() => {
@@ -67,6 +74,16 @@ export function LicenseNag() {
6774
load();
6875
}, [shouldShow]);
6976

77+
// Auto-dismiss if a paid tier (including LIFETIME/PRO/TEAM) is detected after opening
78+
useEffect(() => {
79+
const tier = user?.tier?.toUpperCase();
80+
const trialEndsAt = user?.trialEndsAt ? new Date(user.trialEndsAt) : null;
81+
const hasActiveTrial = Boolean(user?.trialActive && trialEndsAt && trialEndsAt.getTime() > Date.now());
82+
if (open && !loading && ((tier && tier !== "FREE") || hasActiveTrial)) {
83+
onDismiss();
84+
}
85+
}, [open, user?.tier, user?.trialActive, user?.trialEndsAt, loading]);
86+
7087
const onDismiss = () => {
7188
setOpen(false);
7289
try {

0 commit comments

Comments
 (0)