feat: Add demo users and trial logic uniformity
This commit is contained in:
@@ -275,7 +275,7 @@ export default function DashboardLayout({ children }: { children: ReactNode }) {
|
||||
</Link>
|
||||
{isDemoUser(userId) && (
|
||||
<button
|
||||
onClick={() => switchUser(DEMO_USERS.NEHA.id)}
|
||||
onClick={() => switchUser(DEMO_USERS.AICOACH_JEE.id)}
|
||||
className="w-full text-left flex items-center gap-2 px-3 py-2 text-sm text-foreground hover:bg-secondary rounded-lg transition-colors"
|
||||
>
|
||||
Reset Demo
|
||||
@@ -357,10 +357,10 @@ export default function DashboardLayout({ children }: { children: ReactNode }) {
|
||||
onChange={(e) => switchUser(e.target.value)}
|
||||
className="bg-secondary border border-border text-foreground px-2.5 py-1.5 rounded-xl text-xs font-bold focus:ring-2 focus:ring-[var(--cyan-ai)] outline-none cursor-pointer hover:bg-secondary/80 transition-colors disabled:opacity-50 disabled:cursor-wait"
|
||||
>
|
||||
<option value={DEMO_USERS.NEHA.id}>Neha Verma (AI Coach)</option>
|
||||
<option value={DEMO_USERS.AI_COACH.id}>Rahul (AI Coach)</option>
|
||||
<option value={DEMO_USERS.PRO.id}>Priya (Pro Plan)</option>
|
||||
<option value={DEMO_USERS.FREE.id}>Amit (Free Plan)</option>
|
||||
<option value={DEMO_USERS.AICOACH_JEE.id}>{DEMO_USERS.AICOACH_JEE.label}</option>
|
||||
<option value={DEMO_USERS.AICOACH_NEET.id}>{DEMO_USERS.AICOACH_NEET.label}</option>
|
||||
<option value={DEMO_USERS.AICOACH_JEE_NEET.id}>{DEMO_USERS.AICOACH_JEE_NEET.label}</option>
|
||||
<option value={DEMO_USERS.FREE_JEE.id}>{DEMO_USERS.FREE_JEE.label}</option>
|
||||
</select>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -22,13 +22,13 @@ export interface UserProfile {
|
||||
trial_end?: string;
|
||||
}
|
||||
|
||||
export const DEFAULT_USER_ID = "b0e17378-864d-439e-8806-708dc48a891b"; // AI Coach
|
||||
export const DEFAULT_USER_ID = "11111111-1111-1111-1111-111111111111"; // AI Coach - JEE
|
||||
|
||||
export const DEMO_USERS = {
|
||||
FREE: { id: "11111111-1111-1111-1111-111111111111", label: "Amit Kumar (Free Tier)" },
|
||||
PRO: { id: "22222222-2222-2222-2222-222222222222", label: "Priya Singh (Pro Tier)" },
|
||||
NEHA: { id: "33333333-3333-3333-3333-333333333333", label: "Neha Verma (AI Coach)" },
|
||||
AI_COACH: { id: DEFAULT_USER_ID, label: "Rahul Sharma (AI Coach)" },
|
||||
AICOACH_JEE: { id: "11111111-1111-1111-1111-111111111111", label: "Aarav (AI Coach - JEE)" },
|
||||
AICOACH_NEET: { id: "22222222-2222-2222-2222-222222222222", label: "Neha (AI Coach - NEET)" },
|
||||
AICOACH_JEE_NEET: { id: "33333333-3333-3333-3333-333333333333", label: "Rohan (AI Coach - JEE+NEET)" },
|
||||
FREE_JEE: { id: "44444444-4444-4444-4444-444444444444", label: "Amit (Free - JEE)" },
|
||||
};
|
||||
|
||||
// IDs considered "demo" accounts — demo switcher only shows for these
|
||||
@@ -69,25 +69,33 @@ export function computeTrialInfo(user: UserProfile | null, globalSettings: any):
|
||||
return defaultResult;
|
||||
}
|
||||
|
||||
// Compute from created_at
|
||||
// Compute from trial_end instead of created_at
|
||||
const trialEnd = user.trial_end ? new Date(user.trial_end) : null;
|
||||
const createdAt = user.created_at ? new Date(user.created_at) : null;
|
||||
if (!createdAt) {
|
||||
// If no created_at, assume trial is just starting (Day 1)
|
||||
return {
|
||||
isTrialActive: true,
|
||||
trialDayNumber: 1,
|
||||
trialDaysRemaining: trialDays,
|
||||
trialTotalDays: trialDays,
|
||||
effectiveTier: (globalSettings.trial_tier as "Pro" | "Al_Coach") ?? "Al_Coach",
|
||||
};
|
||||
|
||||
if (!trialEnd) {
|
||||
// If no trial_end is set in the DB, they don't have a trial active.
|
||||
return defaultResult;
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
const msPerDay = 1000 * 60 * 60 * 24;
|
||||
const daysSinceCreation = Math.floor((now.getTime() - createdAt.getTime()) / msPerDay);
|
||||
const trialDayNumber = Math.max(1, daysSinceCreation + 1); // 1-indexed
|
||||
const trialDaysRemaining = Math.max(0, trialDays - daysSinceCreation);
|
||||
const isTrialActive = trialDaysRemaining > 0;
|
||||
|
||||
const isTrialActive = now.getTime() < trialEnd.getTime();
|
||||
|
||||
// Calculate trial days remaining
|
||||
const trialDaysRemaining = isTrialActive
|
||||
? Math.max(0, Math.ceil((trialEnd.getTime() - now.getTime()) / msPerDay))
|
||||
: 0;
|
||||
|
||||
// Calculate day number based on created_at and today
|
||||
let trialDayNumber = 0;
|
||||
if (isTrialActive && createdAt) {
|
||||
const daysSinceCreation = Math.floor((now.getTime() - createdAt.getTime()) / msPerDay);
|
||||
trialDayNumber = Math.max(1, daysSinceCreation + 1); // 1-indexed
|
||||
} else if (isTrialActive) {
|
||||
trialDayNumber = 1;
|
||||
}
|
||||
|
||||
return {
|
||||
isTrialActive,
|
||||
|
||||
Reference in New Issue
Block a user