Ship Novya PWA with backend for deployable production use.

Fix production TypeScript builds and add DEPLOY.md so the app can be hosted from this repo.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
ar.badiei
2026-09-03 21:01:52 +03:30
co-authored by Cursor
parent aa9236fb92
commit 370ac15471
193 changed files with 25997 additions and 1991 deletions
+209 -104
View File
@@ -1,125 +1,230 @@
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
import type { ReactNode } from 'react';
import { useAuth } from '@/hooks/useAuth';
import { useNavigate } from 'react-router-dom';
import { LogOut, User as UserIcon, Mail, Phone } from 'lucide-react';
import { useToast } from '@/components/ui/use-toast';
import { useLearningJourney } from '@/hooks/useLearningJourney';
import { useCurrentSession } from '@/hooks/useCurrentSession';
import { PROGRAM_SESSION_COUNT } from '@/data/program/sessions';
import { getProgramProgress } from '@/services/programService';
import { Progress } from '@/components/ui/progress';
import { Navigate, useNavigate } from 'react-router-dom';
import { Check, ChevronLeft, Loader2, Lock } from 'lucide-react';
import { cn } from '@/lib/utils';
import { StaggeredList, StaggerItem, AnimationWrapper } from '@/components/motion';
import { motion } from 'framer-motion';
import { fastTransition } from '@/lib/motion';
type StepState = 'open' | 'locked' | 'done';
/**
* Course Status surface (profile menu → وضعیت دوره).
* Journey status only — no settings, scores, or assessment results.
*/
export default function AccountPage() {
const { user, signOut } = useAuth();
const { effectiveUserId, isGuest, guestSessionHydrated } = useAuth();
const { progress, loading, permissions } = useLearningJourney(effectiveUserId ?? undefined);
const { currentSession, isProgramComplete, programProgress } = useCurrentSession(effectiveUserId);
const navigate = useNavigate();
const { toast } = useToast();
const handleSignOut = async () => {
try {
await signOut();
toast({
title: 'خروج موفق',
description: 'با موفقیت خارج شدید'
});
navigate('/');
} catch (error) {
toast({
title: 'خطا',
description: 'خطا در خروج از حساب کاربری',
variant: 'destructive'
});
}
};
if (!guestSessionHydrated || loading) {
return (
<div className="flex min-h-[50vh] items-center justify-center">
<Loader2 className="h-8 w-8 animate-spin text-neon-cyan" />
</div>
);
}
const getUserInitials = () => {
if (user?.email) {
return user.email.substring(0, 2).toUpperCase();
}
if (user?.phone) {
return user.phone.slice(-2);
}
return 'U';
};
if (!effectiveUserId) {
return <Navigate to="/login" replace />;
}
const cachedProgress = getProgramProgress(effectiveUserId);
const effectiveProgramProgress = programProgress ?? cachedProgress;
const completedSessions = effectiveProgramProgress.completedSessions.length;
const programDone =
isProgramComplete ||
Boolean(effectiveProgramProgress.completedAt) ||
completedSessions >= PROGRAM_SESSION_COUNT;
const progressPercent = programDone
? 100
: Math.round((completedSessions / PROGRAM_SESSION_COUNT) * 100);
const preDone = Boolean(progress?.pre_test_completed_at);
const trainingDone = Boolean(progress?.training_completed_at) || programDone;
const postDone = Boolean(progress?.post_test_completed_at);
const displaySessionOrder =
currentSession?.order ??
(programDone ? PROGRAM_SESSION_COUNT : Math.max(effectiveProgramProgress.currentSessionOrder, 1));
const preState: StepState = preDone ? 'done' : 'open';
const trainingState: StepState = !permissions.canOpenTraining
? 'locked'
: trainingDone
? 'done'
: 'open';
const postState: StepState = postDone
? 'done'
: permissions.canTakePostTest || (trainingDone && preDone && !postDone)
? 'open'
: 'locked';
return (
<div className="min-h-screen bg-gradient-to-br from-background to-muted p-4 pb-20">
<div className="mx-auto max-w-sm">
<div className="mb-4">
<h1 className="text-2xl font-bold mb-2">حساب کاربری</h1>
<p className="text-sm text-muted-foreground">مدیریت اطلاعات و تنظیمات حساب کاربری</p>
</div>
<div className="h-full min-h-0 flex-1 overflow-y-auto px-4 py-6">
<div className="mx-auto w-full max-w-md space-y-4">
<AnimationWrapper immediate className="space-y-1 pb-2">
<h1 className="text-2xl font-bold tracking-tight text-foreground">وضعیت دوره</h1>
{isGuest && <p className="text-sm text-body">جلسه مهمان</p>}
</AnimationWrapper>
<Card>
<CardHeader>
<CardTitle>اطلاعات کاربری</CardTitle>
<CardDescription>جزئیات حساب کاربری شما</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div className="flex items-center gap-4">
<Avatar className="h-16 w-16">
<AvatarImage src={user?.user_metadata?.avatar_url} alt={user?.email || 'User'} />
<AvatarFallback className="text-lg">{getUserInitials()}</AvatarFallback>
</Avatar>
<div className="flex-1 min-w-0">
<h3 className="text-lg font-semibold mb-2 truncate">
{user?.user_metadata?.full_name || user?.email || user?.phone || 'کاربر'}
</h3>
<div className="space-y-2 text-sm text-muted-foreground">
{user?.email && (
<div className="flex items-center gap-2">
<Mail className="h-4 w-4 flex-shrink-0" />
<span className="truncate">{user.email}</span>
</div>
)}
{user?.phone && (
<div className="flex items-center gap-2">
<Phone className="h-4 w-4 flex-shrink-0" />
<span className="truncate">{user.phone}</span>
</div>
)}
</div>
</div>
</div>
<StaggeredList itemCount={3} className="space-y-3" role="region" aria-label="وضعیت دوره">
<StaggerItem>
<StatusRow
title="پیش‌آزمون"
state={preState}
onOpen={() => navigate('/assessment/pre')}
lockedHint={preDone ? 'انجام شده — قابل تکرار نیست' : undefined}
>
{preDone ? (
<StatusDone label="انجام شده" />
) : (
<p className="text-sm text-body">برای شروع مسیر، پیش‌آزمون را انجام دهید</p>
)}
</StatusRow>
</StaggerItem>
<div className="border-t pt-6">
<div className="space-y-4">
<div className="flex items-center justify-between">
<div>
<div className="font-medium">شناسه کاربری</div>
<div className="text-sm text-muted-foreground font-mono">
{user?.id?.substring(0, 8)}...
</div>
<StaggerItem>
<StatusRow
title="دوره آموزشی"
state={trainingState}
onOpen={() => navigate('/chat')}
lockedHint={
trainingDone ? 'دوره تکمیل شده' : 'پس از انجام پیش‌آزمون فعال می‌شود'
}
>
{trainingDone ? (
<StatusDone label="دوره تکمیل شده" />
) : !permissions.canOpenTraining ? (
<p className="flex items-start gap-2 text-sm text-body">
<Lock className="mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground" aria-hidden />
<span>پس از انجام پیش‌آزمون فعال می‌شود</span>
</p>
) : (
<div className="space-y-2">
<p className="text-sm font-medium text-foreground">
جلسه {displaySessionOrder} از {PROGRAM_SESSION_COUNT}
</p>
<div className="flex items-center gap-3">
<Progress value={progressPercent} className="h-2.5 flex-1" />
<span className="min-w-[2.5rem] text-left text-sm tabular-nums text-body">
{progressPercent}٪
</span>
</div>
<UserIcon className="h-5 w-5 text-muted-foreground" />
</div>
)}
</StatusRow>
</StaggerItem>
{user?.created_at && (
<div className="flex items-center justify-between">
<div>
<div className="font-medium">تاریخ عضویت</div>
<div className="text-sm text-muted-foreground">
{new Date(user.created_at).toLocaleDateString('fa-IR')}
</div>
</div>
</div>
)}
</div>
</div>
<div className="border-t pt-6">
<Button
variant="destructive"
className="w-full"
onClick={handleSignOut}
>
<LogOut className="ml-2 h-4 w-4" />
خروج از حساب کاربری
</Button>
</div>
</CardContent>
</Card>
<StaggerItem>
<StatusRow
title="پس‌آزمون"
state={postState}
onOpen={() => navigate('/assessment/post')}
lockedHint={
postDone
? 'انجام شده — قابل تکرار نیست'
: 'پس از پایان دوره آموزشی فعال می‌شود'
}
>
{postState === 'done' && <StatusDone label="انجام شده" />}
{postState === 'open' && (
<p className="flex items-center gap-2 text-sm font-medium text-foreground">
<span
className="inline-block h-2 w-2 shrink-0 rounded-full bg-neon-teal shadow-[0_0_8px_rgba(52,184,150,0.7)]"
aria-hidden
/>
آماده انجام
</p>
)}
{postState === 'locked' && (
<p className="flex items-start gap-2 text-sm text-body">
<Lock className="mt-0.5 h-4 w-4 shrink-0 text-muted-foreground" aria-hidden />
<span>پس از پایان دوره فعال می‌شود</span>
</p>
)}
</StatusRow>
</StaggerItem>
</StaggeredList>
</div>
</div>
);
}
function StatusRow({
title,
children,
state,
onOpen,
lockedHint,
}: {
title: string;
children: ReactNode;
state: StepState;
onOpen: () => void;
lockedHint?: string;
}) {
const isInteractive = state === 'open';
const content = (
<div className="flex items-start justify-between gap-3">
<div className="min-w-0 flex-1 space-y-2 text-right">
<h2 className="text-sm font-semibold text-foreground">{title}</h2>
{children}
</div>
{isInteractive ? (
<ChevronLeft className="mt-0.5 h-5 w-5 shrink-0 text-neon-cyan" aria-hidden />
) : (
<Lock
className={cn(
'mt-0.5 h-4 w-4 shrink-0',
state === 'done' ? 'text-neon-emerald/70' : 'text-muted-foreground'
)}
aria-hidden
/>
)}
</div>
);
if (isInteractive) {
return (
<motion.button
type="button"
onClick={onOpen}
whileHover={{ scale: 1.02 }}
whileTap={{ scale: 0.98 }}
transition={fastTransition}
className="glass-panel w-full px-4 py-4 text-right transition-colors duration-200 hover:border-neon-cyan/55 hover:shadow-[0_0_18px_rgba(72,180,200,0.22)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-neon-cyan/50"
aria-label={`${title} — باز کردن`}
>
{content}
</motion.button>
);
}
return (
<div
className="glass-panel w-full px-4 py-4 opacity-90"
aria-disabled="true"
title={lockedHint}
>
{content}
</div>
);
}
function StatusDone({ label }: { label: string }) {
return (
<p className="flex items-center gap-2 text-sm font-medium text-foreground">
<Check className="h-4 w-4 shrink-0 text-neon-emerald" aria-hidden />
{label}
</p>
);
}