Add read-only Noya admin panel with assignments and UX polish.
Ship admin auth, user overview, assessments, chats, assignment filters/export, security hardening, and a separate desktop admin shell with clearer assessment answers. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -22,11 +22,12 @@ type StepState = 'open' | 'locked' | 'done';
|
||||
export default function AccountPage() {
|
||||
const { effectiveUserId, isGuest, guestSessionHydrated, user } = useAuth();
|
||||
const { progress, loading, permissions } = useLearningJourney(effectiveUserId ?? undefined);
|
||||
const { currentSession, isProgramComplete, programProgress } = useCurrentSession(effectiveUserId);
|
||||
const { currentSession, isProgramComplete, programProgress, progressLoading } =
|
||||
useCurrentSession(effectiveUserId);
|
||||
const navigate = useNavigate();
|
||||
const usernameLabel = isGuest ? 'مهمان' : user?.email?.trim() || null;
|
||||
|
||||
if (!guestSessionHydrated || loading) {
|
||||
if (!guestSessionHydrated || loading || progressLoading) {
|
||||
return <CourseStatusSkeleton />;
|
||||
}
|
||||
|
||||
@@ -55,7 +56,9 @@ export default function AccountPage() {
|
||||
|
||||
const displaySessionOrder =
|
||||
currentSession?.order ??
|
||||
(programDone ? PROGRAM_SESSION_COUNT : Math.max(effectiveProgramProgress.currentSessionOrder, 1));
|
||||
(programDone
|
||||
? PROGRAM_SESSION_COUNT
|
||||
: Math.max(effectiveProgramProgress.currentSessionOrder || 1, 1));
|
||||
|
||||
const preState: StepState = preDone ? 'done' : 'open';
|
||||
const trainingState: StepState = !permissions.canOpenTraining
|
||||
@@ -70,7 +73,7 @@ export default function AccountPage() {
|
||||
: 'locked';
|
||||
|
||||
return (
|
||||
<div className="h-full min-h-0 flex-1 overflow-y-auto bg-slate-50 px-4 py-6 transition-colors duration-300 dark:bg-slate-900">
|
||||
<div className="h-full min-h-0 flex-1 overflow-x-hidden overflow-y-auto bg-slate-50 px-4 py-6 transition-colors duration-300 dark:bg-slate-900">
|
||||
<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>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,307 @@
|
||||
import { useCallback, useEffect, useState, startTransition } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import {
|
||||
AdminEmptyState,
|
||||
AdminErrorState,
|
||||
AdminLoadingBlock,
|
||||
AdminPageHeader,
|
||||
AdminPageShell,
|
||||
AdminPrimaryButton,
|
||||
AdminSecondaryButton,
|
||||
AdminSection,
|
||||
AdminStatsSkeleton,
|
||||
AdminStatusPill,
|
||||
formatAdminDate,
|
||||
getAdminErrorMessage,
|
||||
isAdminForbiddenError,
|
||||
} from '@/components/admin';
|
||||
import {
|
||||
fetchAdminStats,
|
||||
fetchAdminUsers,
|
||||
type AdminStats,
|
||||
type AdminUserListItem,
|
||||
type AdminUsersQuery,
|
||||
} from '@/services/adminService';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
const STEP_LABELS: Record<string, string> = {
|
||||
registered: 'ثبتنام',
|
||||
pre_test_done: 'پیشآزمون',
|
||||
training_in_progress: 'در حال آموزش',
|
||||
training_completed: 'پایان آموزش',
|
||||
post_test_done: 'پسآزمون',
|
||||
completed: 'تکمیل دوره',
|
||||
};
|
||||
|
||||
function StatCard({ label, value }: { label: string; value: number }) {
|
||||
return (
|
||||
<div className="rounded-xl border border-slate-200 bg-white px-4 py-3 dark:border-slate-700 dark:bg-slate-800">
|
||||
<p className="text-xs text-slate-500 dark:text-slate-400">{label}</p>
|
||||
<p className="mt-1 text-2xl font-semibold tabular-nums text-slate-900 dark:text-slate-50">
|
||||
{value.toLocaleString('fa-IR')}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function AdminUsersPage() {
|
||||
const [stats, setStats] = useState<AdminStats | null>(null);
|
||||
const [users, setUsers] = useState<AdminUserListItem[]>([]);
|
||||
const [page, setPage] = useState(1);
|
||||
const [pageSize] = useState(20);
|
||||
const [totalPages, setTotalPages] = useState(0);
|
||||
const [total, setTotal] = useState(0);
|
||||
const [searchInput, setSearchInput] = useState('');
|
||||
const [query, setQuery] = useState('');
|
||||
const [sortBy, setSortBy] = useState<AdminUsersQuery['sortBy']>('createdAt');
|
||||
const [sortDir, setSortDir] = useState<AdminUsersQuery['sortDir']>('desc');
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [forbidden, setForbidden] = useState(false);
|
||||
const [hasLoadedOnce, setHasLoadedOnce] = useState(false);
|
||||
|
||||
const load = useCallback(async () => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
setForbidden(false);
|
||||
try {
|
||||
const [nextStats, list] = await Promise.all([
|
||||
fetchAdminStats(),
|
||||
fetchAdminUsers({
|
||||
q: query || undefined,
|
||||
page,
|
||||
pageSize,
|
||||
sortBy,
|
||||
sortDir,
|
||||
}),
|
||||
]);
|
||||
startTransition(() => {
|
||||
setStats(nextStats);
|
||||
setUsers(list.items);
|
||||
setTotal(list.pagination.total);
|
||||
setTotalPages(list.pagination.totalPages);
|
||||
setHasLoadedOnce(true);
|
||||
});
|
||||
} catch (err) {
|
||||
setForbidden(isAdminForbiddenError(err));
|
||||
setError(getAdminErrorMessage(err, 'دریافت دادههای ادمین ناموفق بود.'));
|
||||
setStats(null);
|
||||
setUsers([]);
|
||||
setTotal(0);
|
||||
setTotalPages(0);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [page, pageSize, query, sortBy, sortDir]);
|
||||
|
||||
useEffect(() => {
|
||||
void load();
|
||||
}, [load]);
|
||||
|
||||
const submitSearch = (event: React.FormEvent) => {
|
||||
event.preventDefault();
|
||||
setPage(1);
|
||||
setQuery(searchInput.trim());
|
||||
};
|
||||
|
||||
const clearSearch = () => {
|
||||
setSearchInput('');
|
||||
setQuery('');
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
const hasActiveSearch = Boolean(query);
|
||||
|
||||
return (
|
||||
<AdminPageShell>
|
||||
<AdminPageHeader
|
||||
title="پنل ادمین"
|
||||
subtitle="آمار کلی و فهرست کاربران آزمایشی"
|
||||
/>
|
||||
|
||||
{error ? (
|
||||
<AdminErrorState
|
||||
message={error}
|
||||
tone={forbidden ? 'warning' : 'error'}
|
||||
onRetry={() => void load()}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{loading && !hasLoadedOnce ? (
|
||||
<AdminStatsSkeleton />
|
||||
) : stats ? (
|
||||
<section className="grid grid-cols-2 gap-3 md:grid-cols-4" aria-label="آمار کلی">
|
||||
<StatCard label="کل کاربران" value={stats.totalUsers} />
|
||||
<StatCard label="پیشآزمون" value={stats.pretestCompletedUsers} />
|
||||
<StatCard label="پسآزمون" value={stats.posttestCompletedUsers} />
|
||||
<StatCard label="در حال آموزش" value={stats.trainingInProgressUsers} />
|
||||
<StatCard label="پایان آموزش" value={stats.trainingCompletedUsers} />
|
||||
<StatCard label="تکمیل دوره" value={stats.courseCompletedUsers} />
|
||||
<StatCard label="پاسخ آزمونها" value={stats.totalAssessmentAttempts} />
|
||||
<StatCard label="گفتگوها" value={stats.totalChatSessions} />
|
||||
</section>
|
||||
) : null}
|
||||
|
||||
<AdminSection title="فهرست کاربران">
|
||||
<div className="flex flex-col gap-3 md:flex-row md:items-end md:justify-between">
|
||||
<form onSubmit={submitSearch} className="flex min-w-0 flex-1 flex-col gap-2 sm:flex-row">
|
||||
<input
|
||||
value={searchInput}
|
||||
onChange={(e) => setSearchInput(e.target.value)}
|
||||
placeholder="جستوجو با ایمیل، کد پژوهشی یا نام"
|
||||
className="w-full min-w-0 rounded-lg border border-slate-200 bg-white px-3 py-2 text-sm dark:border-slate-600 dark:bg-slate-900"
|
||||
aria-label="جستوجوی کاربران"
|
||||
/>
|
||||
<div className="flex shrink-0 gap-2">
|
||||
<AdminPrimaryButton type="submit" disabled={loading} aria-busy={loading}>
|
||||
جستوجو
|
||||
</AdminPrimaryButton>
|
||||
{hasActiveSearch ? (
|
||||
<AdminSecondaryButton type="button" onClick={clearSearch} disabled={loading}>
|
||||
پاککردن جستوجو
|
||||
</AdminSecondaryButton>
|
||||
) : null}
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<select
|
||||
value={sortBy}
|
||||
onChange={(e) => {
|
||||
setPage(1);
|
||||
setSortBy(e.target.value as AdminUsersQuery['sortBy']);
|
||||
}}
|
||||
className="rounded-lg border border-slate-200 bg-white px-3 py-2 text-sm dark:border-slate-600 dark:bg-slate-900"
|
||||
aria-label="مرتبسازی بر اساس"
|
||||
>
|
||||
<option value="createdAt">تاریخ ثبتنام</option>
|
||||
<option value="lastActivityAt">آخرین فعالیت</option>
|
||||
<option value="role">نقش</option>
|
||||
<option value="externalId">کد پژوهشی</option>
|
||||
</select>
|
||||
<select
|
||||
value={sortDir}
|
||||
onChange={(e) => {
|
||||
setPage(1);
|
||||
setSortDir(e.target.value as AdminUsersQuery['sortDir']);
|
||||
}}
|
||||
className="rounded-lg border border-slate-200 bg-white px-3 py-2 text-sm dark:border-slate-600 dark:bg-slate-900"
|
||||
aria-label="جهت مرتبسازی"
|
||||
>
|
||||
<option value="desc">نزولی</option>
|
||||
<option value="asc">صعودی</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p className="text-xs text-slate-500" aria-live="polite">
|
||||
{loading
|
||||
? 'در حال بهروزرسانی فهرست…'
|
||||
: `${total.toLocaleString('fa-IR')} کاربر · صفحه ${page.toLocaleString('fa-IR')}${
|
||||
totalPages > 0 ? ` از ${totalPages.toLocaleString('fa-IR')}` : ''
|
||||
}`}
|
||||
</p>
|
||||
|
||||
{loading ? (
|
||||
<AdminLoadingBlock label="در حال بارگذاری کاربران…" rows={4} />
|
||||
) : users.length === 0 ? (
|
||||
<AdminEmptyState
|
||||
title={hasActiveSearch ? 'نتیجهای برای این جستوجو نیست' : 'کاربری ثبت نشده است'}
|
||||
description={
|
||||
hasActiveSearch
|
||||
? 'عبارت جستوجو را تغییر دهید یا فیلتر را پاک کنید.'
|
||||
: 'هنوز کاربری در سامانه ثبت نشده است.'
|
||||
}
|
||||
action={
|
||||
hasActiveSearch ? (
|
||||
<AdminSecondaryButton type="button" onClick={clearSearch}>
|
||||
پاککردن جستوجو
|
||||
</AdminSecondaryButton>
|
||||
) : undefined
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<ul className="divide-y divide-slate-100 dark:divide-slate-700">
|
||||
{users.map((user) => (
|
||||
<li key={user.id} className="space-y-2 py-4">
|
||||
<div className="flex flex-wrap items-start justify-between gap-2">
|
||||
<div className="min-w-0">
|
||||
<Link
|
||||
to={`/admin/users/${user.id}`}
|
||||
className="font-medium text-slate-900 underline-offset-2 hover:underline focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 dark:text-slate-50"
|
||||
>
|
||||
{user.name || user.email || 'بدون نام'}
|
||||
</Link>
|
||||
<p className="truncate text-xs text-slate-500" dir="ltr" title={user.id}>
|
||||
{user.email ?? '—'} · {user.id}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<div className="flex flex-wrap gap-1">
|
||||
<AdminStatusPill ok={user.role === 'admin'} label={user.role} />
|
||||
<AdminStatusPill
|
||||
ok={!user.isGuest}
|
||||
label={user.isGuest ? 'مهمان' : 'ثبتنامی'}
|
||||
/>
|
||||
<AdminStatusPill
|
||||
ok={user.profileComplete}
|
||||
label={user.profileComplete ? 'پروفایل کامل' : 'پروفایل ناقص'}
|
||||
/>
|
||||
</div>
|
||||
<Link
|
||||
to={`/admin/users/${user.id}`}
|
||||
className={cn(
|
||||
'rounded-lg border border-slate-200 px-2.5 py-1 text-xs text-slate-700 dark:border-slate-600 dark:text-slate-200',
|
||||
'focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2',
|
||||
)}
|
||||
>
|
||||
جزئیات
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap gap-1">
|
||||
<AdminStatusPill ok={user.pretestCompleted} label="پیشآزمون" />
|
||||
<AdminStatusPill ok={user.trainingCompleted} label="آموزش" />
|
||||
<AdminStatusPill ok={user.posttestCompleted} label="پسآزمون" />
|
||||
<AdminStatusPill ok={user.courseCompleted} label="دوره" />
|
||||
</div>
|
||||
|
||||
<p className="text-xs text-slate-500">
|
||||
وضعیت:{' '}
|
||||
{user.currentStep ? STEP_LABELS[user.currentStep] ?? user.currentStep : '—'}
|
||||
{' · '}
|
||||
جلسات: {user.completedSessionCount}/{user.programSessionCount}
|
||||
{user.age != null ? ` · سن: ${user.age}` : ''}
|
||||
{' · '}
|
||||
ثبتنام: {formatAdminDate(user.createdAt)}
|
||||
{' · '}
|
||||
فعالیت: {formatAdminDate(user.lastActivityAt)}
|
||||
</p>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
|
||||
<div className="flex items-center justify-between gap-2 pt-2">
|
||||
<AdminSecondaryButton
|
||||
type="button"
|
||||
disabled={page <= 1 || loading}
|
||||
onClick={() => setPage((p) => Math.max(1, p - 1))}
|
||||
aria-label="صفحه قبلی کاربران"
|
||||
>
|
||||
قبلی
|
||||
</AdminSecondaryButton>
|
||||
<AdminSecondaryButton
|
||||
type="button"
|
||||
disabled={totalPages === 0 || page >= totalPages || loading}
|
||||
onClick={() => setPage((p) => p + 1)}
|
||||
aria-label="صفحه بعدی کاربران"
|
||||
>
|
||||
بعدی
|
||||
</AdminSecondaryButton>
|
||||
</div>
|
||||
</AdminSection>
|
||||
</AdminPageShell>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useMemo, useState } from 'react';
|
||||
import { Navigate, useNavigate, useParams } from 'react-router-dom';
|
||||
import { Sparkles } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Progress } from '@/components/ui/progress';
|
||||
import { useAuth } from '@/hooks/useAuth';
|
||||
@@ -15,9 +16,13 @@ import { PCQ24_QUESTIONS, PCQ_LIKERT_OPTIONS } from '@/config/pcq24';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { AssessmentSkeleton } from '@/components/skeletons';
|
||||
import { LoadingOverlay } from '@/components/ui/loading-overlay';
|
||||
import { BrandLogo } from '@/components/BrandLogo';
|
||||
import { APP_NAME } from '@/utils/constants';
|
||||
|
||||
const FADE_MS = 220;
|
||||
|
||||
const PRE_INTRO_STEPS = 3;
|
||||
|
||||
export default function AssessmentPage() {
|
||||
const { phase } = useParams<{ phase: AttemptPhase }>();
|
||||
const navigate = useNavigate();
|
||||
@@ -32,6 +37,7 @@ export default function AssessmentPage() {
|
||||
const [successMessage, setSuccessMessage] = useState<string | null>(null);
|
||||
const [isRedirecting, setIsRedirecting] = useState(false);
|
||||
const [showIntro, setShowIntro] = useState(true);
|
||||
const [introStep, setIntroStep] = useState(0);
|
||||
const [contentVisible, setContentVisible] = useState(true);
|
||||
const [isAnimating, setIsAnimating] = useState(false);
|
||||
|
||||
@@ -215,62 +221,216 @@ export default function AssessmentPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const introTitle = isPreTest ? 'پیشآزمون' : 'پسآزمون';
|
||||
const introBody = isPreTest ? (
|
||||
<>
|
||||
<p>
|
||||
قبل از شروع مسیر یادگیری، لازم است وضعیت سرمایه روانشناختی شما را بسنجیم. این پرسشنامه کوتاه
|
||||
(PCQ-24) به ما کمک میکند آموزش را متناسب با شرایط شما پیش ببریم.
|
||||
</p>
|
||||
<p className="text-sm text-slate-300/90">
|
||||
پاسخ درست یا غلط وجود ندارد؛ گزینهای را انتخاب کنید که بیشتر با تجربه واقعی شما همخوانی دارد.
|
||||
</p>
|
||||
</>
|
||||
) : (
|
||||
<p>
|
||||
پس از پایان آموزش، پرسشنامه سرمایه روانشناختی (PCQ-24) را دوباره تکمیل کنید تا پیشرفت شما مشخص
|
||||
شود.
|
||||
</p>
|
||||
);
|
||||
const phaseLabel = isPreTest ? 'پیشآزمون' : 'پسآزمون';
|
||||
const isLastIntroStep = !isPreTest || introStep >= PRE_INTRO_STEPS - 1;
|
||||
|
||||
const goIntroNext = () => {
|
||||
if (isPreTest && introStep < PRE_INTRO_STEPS - 1) {
|
||||
setIntroStep((s) => s + 1);
|
||||
return;
|
||||
}
|
||||
setShowIntro(false);
|
||||
};
|
||||
|
||||
const goIntroBack = () => {
|
||||
if (introStep > 0) setIntroStep((s) => s - 1);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="relative h-full min-h-0 flex-1 overflow-hidden p-4">
|
||||
<div className="ambient-glow relative h-full min-h-0 flex-1 overflow-hidden p-4">
|
||||
<LoadingOverlay
|
||||
open={isRedirecting}
|
||||
message={successMessage ?? 'در حال انتقال…'}
|
||||
/>
|
||||
{/* Intro overlay — dark veil on text area; bottom almost visible */}
|
||||
|
||||
{showIntro && (
|
||||
<div
|
||||
className="absolute inset-0 z-40 flex flex-col p-5 pt-6"
|
||||
className="absolute inset-0 z-40 flex items-stretch justify-center p-3 sm:p-4"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="assessment-intro-title"
|
||||
>
|
||||
<div
|
||||
className="pointer-events-none absolute inset-0"
|
||||
style={{
|
||||
background:
|
||||
'linear-gradient(to bottom, rgba(0,0,0,0.97) 0%, rgba(0,0,0,0.95) 70%, rgba(0,0,0,0.88) 85%, rgba(0,0,0,0.35) 92%, rgba(0,0,0,0.08) 100%)',
|
||||
}}
|
||||
className="pointer-events-none absolute inset-0 bg-background/55 backdrop-blur-md dark:bg-background/60"
|
||||
aria-hidden
|
||||
/>
|
||||
<div className="animate-in fade-in relative z-10 flex w-full flex-col items-stretch gap-5 text-right duration-500">
|
||||
<h2
|
||||
id="assessment-intro-title"
|
||||
className="text-xl font-semibold text-white drop-shadow-lg"
|
||||
>
|
||||
{isPreTest ? 'راهنمای پیشآزمون' : 'راهنمای پسآزمون'}
|
||||
</h2>
|
||||
<div className="space-y-4 text-sm leading-7 text-slate-100">{introBody}</div>
|
||||
<Button
|
||||
type="button"
|
||||
variant="neon"
|
||||
className="mt-2 w-full"
|
||||
onClick={() => setShowIntro(false)}
|
||||
>
|
||||
متوجه شدم
|
||||
</Button>
|
||||
<div
|
||||
className="pointer-events-none absolute inset-0 ambient-glow opacity-70"
|
||||
aria-hidden
|
||||
/>
|
||||
|
||||
<div className="animate-in fade-in relative z-10 flex h-full w-full max-w-lg flex-col duration-500">
|
||||
<div className="glass-panel relative z-10 flex min-h-0 flex-1 flex-col overflow-hidden">
|
||||
<div className="relative z-10 flex shrink-0 flex-col items-center gap-2 px-5 pb-2 pt-5 text-center">
|
||||
<BrandLogo imgClassName="h-10" />
|
||||
<p className="text-xs font-medium text-cyan-800 dark:text-neon-cyan">
|
||||
{isPreTest ? `خوش آمدی به ${APP_NAME}` : 'پسآزمون'}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="relative z-10 min-h-0 flex-1 overflow-x-hidden overflow-y-auto px-5 pb-4 pt-1 text-right">
|
||||
{isPreTest ? (
|
||||
<>
|
||||
{introStep === 0 && (
|
||||
<div className="space-y-4">
|
||||
<h2
|
||||
id="assessment-intro-title"
|
||||
className="text-xl font-bold tracking-tight text-foreground"
|
||||
>
|
||||
سلام! 👋
|
||||
</h2>
|
||||
<div className="space-y-3 text-sm leading-7 text-body">
|
||||
<p>
|
||||
خوش اومدی به <span className="font-semibold text-foreground">{APP_NAME}</span>.
|
||||
</p>
|
||||
<p>
|
||||
قراره با هم یک مسیر جذاب و متفاوت رو شروع کنیم؛ مسیری که هم قراره چیزهای
|
||||
جدیدی یاد بگیری و هم فرصت داشته باشی خودت رو بهتر بشناسی.
|
||||
</p>
|
||||
<p>
|
||||
این مسیر خیلی طولانی نیست و فعالیتها و تمرینها کوتاه و متنوع طراحی شدن تا
|
||||
در کنارشون هم یاد بگیری و هم بهت خوش بگذره.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{introStep === 1 && (
|
||||
<div className="space-y-4">
|
||||
<h2
|
||||
id="assessment-intro-title"
|
||||
className="text-lg font-bold tracking-tight text-foreground"
|
||||
>
|
||||
توی این مسیر چه اتفاقی میافته؟
|
||||
</h2>
|
||||
<ol className="space-y-3.5 text-sm leading-7 text-body">
|
||||
<li className="rounded-xl border border-border/60 bg-background/40 px-3.5 py-3 dark:bg-slate-900/30">
|
||||
<p className="mb-1 font-semibold text-foreground">۱. پیشآزمون</p>
|
||||
<p>
|
||||
اول چند سؤال کوتاه ازت میپرسیم تا با تجربهها و شرایط فعلیت بیشتر آشنا
|
||||
بشیم. جواب درست یا غلطی وجود نداره؛ مهم اینه که پاسخهات تا جای ممکن به
|
||||
تجربه واقعی خودت نزدیک باشن.
|
||||
</p>
|
||||
</li>
|
||||
<li className="rounded-xl border border-border/60 bg-background/40 px-3.5 py-3 dark:bg-slate-900/30">
|
||||
<p className="mb-1 font-semibold text-foreground">۲. یادگیری و تمرین</p>
|
||||
<p>
|
||||
بعد وارد بخشهای مختلف مسیر میشی. هر بخش روی یک موضوع یا مهارت مشخص
|
||||
تمرکز داره و با محتوای آموزشی، فعالیتها و تمرینهای کوتاه پیش میره.
|
||||
</p>
|
||||
</li>
|
||||
<li className="rounded-xl border border-border/60 bg-background/40 px-3.5 py-3 dark:bg-slate-900/30">
|
||||
<p className="mb-1 font-semibold text-foreground">۳. تجربه و تمرین بیشتر</p>
|
||||
<p>
|
||||
در طول مسیر، با موقعیتها و فعالیتهای مختلف روبهرو میشی و میتونی
|
||||
چیزهایی که یاد گرفتی رو در عمل امتحان کنی.
|
||||
</p>
|
||||
</li>
|
||||
<li className="rounded-xl border border-border/60 bg-background/40 px-3.5 py-3 dark:bg-slate-900/30">
|
||||
<p className="mb-1 font-semibold text-foreground">۴. پسآزمون</p>
|
||||
<p>
|
||||
در پایان مسیر، دوباره چند سؤال رو پاسخ میدی تا ببینیم بعد از این تجربه،
|
||||
چه تغییری در پاسخها و نتایجت ایجاد شده.
|
||||
</p>
|
||||
</li>
|
||||
</ol>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{introStep === 2 && (
|
||||
<div className="space-y-4">
|
||||
<h2
|
||||
id="assessment-intro-title"
|
||||
className="text-lg font-bold tracking-tight text-foreground"
|
||||
>
|
||||
یک چیز دیگه...
|
||||
</h2>
|
||||
<div className="space-y-3 text-sm leading-7 text-body">
|
||||
<p>
|
||||
کار کردن تو با {APP_NAME} فقط برای خودت نیست. تجربه و بازخوردت به ما کمک
|
||||
میکنه بفهمیم کدوم بخشهای مسیر مفیدتر و جذابتر بودن و چطور میتونیم{' '}
|
||||
{APP_NAME} رو بهتر کنیم.
|
||||
</p>
|
||||
<p>
|
||||
پس با خیال راحت پیش برو، تجربه واقعی خودت رو با ما در میون بذار و از مسیر
|
||||
لذت ببر.
|
||||
</p>
|
||||
<p className="pt-1 text-base font-semibold text-foreground">
|
||||
آمادهای شروع کنیم؟ 🚀
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<div className="space-y-4">
|
||||
<h2
|
||||
id="assessment-intro-title"
|
||||
className="text-lg font-bold tracking-tight text-foreground"
|
||||
>
|
||||
راهنمای پسآزمون
|
||||
</h2>
|
||||
<div className="space-y-3 text-sm leading-7 text-body">
|
||||
<p>
|
||||
مسیر رو تموم کردی. حالا چند سؤال کوتاه دوباره ازت میپرسیم تا ببینیم بعد از
|
||||
این تجربه، چه تغییری در پاسخهات ایجاد شده.
|
||||
</p>
|
||||
<p>
|
||||
مثل قبل، جواب درست یا غلطی وجود نداره؛ مهم تجربه واقعی خودته.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="relative z-10 shrink-0 space-y-3 border-t border-white/25 px-5 py-4 dark:border-white/10">
|
||||
{isPreTest ? (
|
||||
<div className="flex items-center justify-center gap-1.5" aria-hidden>
|
||||
{Array.from({ length: PRE_INTRO_STEPS }).map((_, i) => (
|
||||
<span
|
||||
key={i}
|
||||
className={cn(
|
||||
'h-1.5 rounded-full transition-all duration-300',
|
||||
i === introStep
|
||||
? 'w-5 bg-neon-cyan'
|
||||
: 'w-1.5 bg-muted-foreground/35'
|
||||
)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div
|
||||
className={cn(
|
||||
'grid gap-2',
|
||||
isPreTest && introStep > 0 ? 'grid-cols-2' : 'grid-cols-1'
|
||||
)}
|
||||
>
|
||||
{isPreTest && introStep > 0 ? (
|
||||
<Button type="button" variant="glass" onClick={goIntroBack}>
|
||||
قبلی
|
||||
</Button>
|
||||
) : null}
|
||||
|
||||
{!isLastIntroStep ? (
|
||||
<Button type="button" variant="neon" className="w-full" onClick={goIntroNext}>
|
||||
بعدی
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
type="button"
|
||||
variant="neon"
|
||||
size="lg"
|
||||
className="w-full gap-2"
|
||||
onClick={goIntroNext}
|
||||
>
|
||||
<Sparkles className="h-5 w-5" />
|
||||
{`شروع ${phaseLabel}`}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
@@ -278,21 +438,21 @@ export default function AssessmentPage() {
|
||||
{/* Questions surface */}
|
||||
<div
|
||||
className={cn(
|
||||
'mx-auto flex h-full w-full max-w-lg flex-col gap-3',
|
||||
'relative z-10 mx-auto flex h-full w-full max-w-lg flex-col gap-3',
|
||||
showIntro && 'pointer-events-none'
|
||||
)}
|
||||
>
|
||||
<div className="shrink-0 space-y-2">
|
||||
<div className="flex items-center justify-between text-sm text-body">
|
||||
<span className="font-medium text-cyan-800 dark:text-neon-cyan">{introTitle}</span>
|
||||
<span className="font-medium text-cyan-800 dark:text-neon-cyan">{phaseLabel}</span>
|
||||
<span className="font-medium tabular-nums text-foreground">{`سوال ${currentIndex + 1} از ${totalQuestions}`}</span>
|
||||
</div>
|
||||
<Progress value={progressPercent} className="h-2" />
|
||||
</div>
|
||||
|
||||
<div className="glass-panel flex min-h-0 flex-1 flex-col overflow-hidden p-4">
|
||||
<div className="glass-panel relative z-10 flex min-h-0 flex-1 flex-col overflow-hidden p-4">
|
||||
{/* Fixed question zone — number + text stay pinned (no vertical reflow) */}
|
||||
<div className="relative h-[9.5rem] shrink-0 overflow-hidden pt-1">
|
||||
<div className="relative z-10 h-[9.5rem] shrink-0 overflow-hidden pt-1">
|
||||
<div
|
||||
className={cn(
|
||||
'absolute inset-x-0 top-0 transition-opacity duration-[220ms] ease-out',
|
||||
@@ -311,7 +471,7 @@ export default function AssessmentPage() {
|
||||
{/* Fixed answers grid — same slot for every question */}
|
||||
<div
|
||||
className={cn(
|
||||
'mt-3 grid shrink-0 grid-cols-1 gap-2 transition-opacity duration-[220ms] ease-out',
|
||||
'relative z-10 mt-3 grid shrink-0 grid-cols-1 gap-2 transition-opacity duration-[220ms] ease-out',
|
||||
contentVisible ? 'opacity-100' : 'opacity-0'
|
||||
)}
|
||||
>
|
||||
@@ -325,11 +485,11 @@ export default function AssessmentPage() {
|
||||
onClick={() => onSelect(currentQuestion.id, option.value)}
|
||||
className={cn(
|
||||
'flex h-11 w-full items-center justify-start rounded-xl border px-4 text-right text-sm transition-all duration-200',
|
||||
'shadow-[0_2px_4px_rgba(15,23,42,0.05)] focus-visible:outline-none',
|
||||
'shadow-[0_2px_4px_rgba(15,23,42,0.05)] focus-visible:outline-none backdrop-blur-md',
|
||||
'focus-visible:border-[#26d4ca] focus-visible:shadow-[0_0_0_1px_rgba(38,212,202,0.35),0_3px_8px_rgba(15,23,42,0.08)]',
|
||||
selected
|
||||
? 'border-[#26d4ca] bg-[rgb(38_212_202/0.12)] text-foreground shadow-[0_0_0_1px_rgba(38,212,202,0.25),0_3px_8px_rgba(15,23,42,0.08)] dark:border-neon-cyan dark:bg-neon-cyan/15 dark:text-white dark:shadow-glow-sm'
|
||||
: 'border-slate-200 bg-white/80 text-body hover:border-[#26d4ca]/70 hover:bg-white hover:text-foreground dark:border-neon-cyan/20 dark:bg-slate-900/35 dark:hover:border-neon-cyan/55 dark:hover:bg-slate-800/45 dark:hover:text-white'
|
||||
? 'border-[#26d4ca] bg-[rgb(38_212_202/0.18)] text-foreground shadow-[0_0_0_1px_rgba(38,212,202,0.25),0_3px_8px_rgba(15,23,42,0.08)] dark:border-neon-cyan dark:bg-neon-cyan/15 dark:text-white dark:shadow-glow-sm'
|
||||
: 'border-white/45 bg-white/35 text-body hover:border-[#26d4ca]/70 hover:bg-white/55 hover:text-foreground dark:border-white/12 dark:bg-slate-900/35 dark:hover:border-neon-cyan/55 dark:hover:bg-slate-800/45 dark:hover:text-white'
|
||||
)}
|
||||
>
|
||||
{option.label}
|
||||
@@ -339,7 +499,12 @@ export default function AssessmentPage() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid shrink-0 grid-cols-2 gap-2">
|
||||
<div
|
||||
className={cn(
|
||||
'grid shrink-0 gap-2',
|
||||
isLastQuestion ? 'grid-cols-2' : 'grid-cols-1'
|
||||
)}
|
||||
>
|
||||
<Button
|
||||
type="button"
|
||||
variant="glass"
|
||||
@@ -357,17 +522,7 @@ export default function AssessmentPage() {
|
||||
>
|
||||
{submitting ? 'در حال ثبت...' : 'ثبت آزمون'}
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
type="button"
|
||||
variant="neon"
|
||||
className="w-full"
|
||||
disabled={!selectedValue || isAnimating || submitting || isRedirecting || showIntro}
|
||||
onClick={() => advanceWithFade(1)}
|
||||
>
|
||||
سوال بعدی
|
||||
</Button>
|
||||
)}
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,460 @@
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { Link, Navigate, useNavigate, useParams } from 'react-router-dom';
|
||||
import { useAuth } from '@/hooks/useAuth';
|
||||
import { AssignmentFormFields } from '@/components/assignments/AssignmentFormFields';
|
||||
import {
|
||||
assignmentDayStatusLabel,
|
||||
assignmentStatusLabel,
|
||||
assignmentTypeLabel,
|
||||
createAssignmentEntry,
|
||||
fetchAssignment,
|
||||
isMultiDayAssignment,
|
||||
saveAssignmentDraft,
|
||||
startAssignment,
|
||||
submitAssignmentReport,
|
||||
updateAssignmentEntry,
|
||||
type AssignmentDayStatus,
|
||||
type AssignmentFormField,
|
||||
type AssignmentReportStatus,
|
||||
type UserAssignment,
|
||||
} from '@/services/assignmentService';
|
||||
import { useToast } from '@/components/ui/use-toast';
|
||||
import { getFetchErrorMessage } from '@/lib/fetchError';
|
||||
import { PageSkeleton } from '@/components/skeletons';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { ArrowRight, Check, Loader2 } from 'lucide-react';
|
||||
|
||||
function emptyDraftFromSchema(schema: AssignmentFormField[] | null): Record<string, unknown> {
|
||||
if (!schema) return { text: '' };
|
||||
const draft: Record<string, unknown> = {};
|
||||
for (const field of schema) {
|
||||
if (field.type === 'list') {
|
||||
draft[field.key] = [{}];
|
||||
} else if (field.type === 'checkbox') {
|
||||
draft[field.key] = false;
|
||||
} else {
|
||||
draft[field.key] = '';
|
||||
}
|
||||
}
|
||||
return draft;
|
||||
}
|
||||
|
||||
function progressLabel(assignment: UserAssignment): string | null {
|
||||
const target = assignment.definition.expectedDurationDays;
|
||||
if (!target) return `${assignment.doneDayCount} روز انجامشده`;
|
||||
return `${assignment.doneDayCount} روز از ${target} روز هدف`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assignment detail — one-time vs multi-day flows diverge deliberately.
|
||||
* Status is system-driven; experience notes are optional and soft.
|
||||
*/
|
||||
export default function AssignmentDetailPage() {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const { effectiveUserId, guestSessionHydrated, isGuest } = useAuth();
|
||||
const navigate = useNavigate();
|
||||
const { toast } = useToast();
|
||||
|
||||
const [assignment, setAssignment] = useState<UserAssignment | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [draft, setDraft] = useState<Record<string, unknown>>({});
|
||||
const [entryData, setEntryData] = useState<Record<string, unknown>>({});
|
||||
const [entryNote, setEntryNote] = useState('');
|
||||
const [dayStatus, setDayStatus] = useState<AssignmentDayStatus>('done');
|
||||
const [editingEntryId, setEditingEntryId] = useState<string | null>(null);
|
||||
const [experienceNote, setExperienceNote] = useState('');
|
||||
const [experienceStatus, setExperienceStatus] =
|
||||
useState<AssignmentReportStatus>('difficult');
|
||||
|
||||
const load = useCallback(async () => {
|
||||
if (!id) return;
|
||||
setLoading(true);
|
||||
try {
|
||||
const row = await fetchAssignment(id);
|
||||
setAssignment(row);
|
||||
const schema = row.definition.formSchema;
|
||||
setDraft(
|
||||
(row.draftData as Record<string, unknown> | null) ?? emptyDraftFromSchema(schema),
|
||||
);
|
||||
const today = row.serverToday;
|
||||
const todayEntry = row.dailyEntries?.find((e) => e.entryDate === today);
|
||||
if (todayEntry) {
|
||||
setEditingEntryId(todayEntry.id);
|
||||
setEntryData(todayEntry.responseData);
|
||||
setEntryNote(todayEntry.note ?? '');
|
||||
setDayStatus(todayEntry.dayStatus);
|
||||
} else {
|
||||
setEditingEntryId(null);
|
||||
setEntryData(emptyDraftFromSchema(schema));
|
||||
setEntryNote('');
|
||||
setDayStatus('done');
|
||||
}
|
||||
} catch (err) {
|
||||
toast({
|
||||
title: 'خطا',
|
||||
description: getFetchErrorMessage(err, 'بارگذاری تکلیف ناموفق بود'),
|
||||
variant: 'destructive',
|
||||
});
|
||||
navigate('/assignments', { replace: true });
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [id, navigate, toast]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!effectiveUserId || isGuest) return;
|
||||
void load();
|
||||
}, [effectiveUserId, isGuest, load]);
|
||||
|
||||
if (!guestSessionHydrated || loading) {
|
||||
return <PageSkeleton />;
|
||||
}
|
||||
|
||||
if (!effectiveUserId) {
|
||||
return <Navigate to="/login" replace />;
|
||||
}
|
||||
|
||||
if (isGuest || !assignment) {
|
||||
return <Navigate to="/assignments" replace />;
|
||||
}
|
||||
|
||||
const isMultiDay = isMultiDayAssignment(assignment.definition.assignmentType);
|
||||
const isOneTime = assignment.definition.assignmentType === 'ONE_TIME';
|
||||
const schema = assignment.definition.formSchema;
|
||||
const completed = assignment.status === 'COMPLETED';
|
||||
const serverToday = assignment.serverToday;
|
||||
|
||||
const updateDraftField = (key: string, value: unknown) => {
|
||||
setDraft((prev) => ({ ...prev, [key]: value }));
|
||||
};
|
||||
|
||||
const updateEntryField = (key: string, value: unknown) => {
|
||||
setEntryData((prev) => ({ ...prev, [key]: value }));
|
||||
};
|
||||
|
||||
const handleSaveDraft = async (completeIfValid: boolean) => {
|
||||
setSaving(true);
|
||||
try {
|
||||
await startAssignment(assignment.id);
|
||||
const updated = await saveAssignmentDraft(assignment.id, draft, { completeIfValid });
|
||||
setAssignment(updated);
|
||||
toast({
|
||||
title: updated.status === 'COMPLETED' ? 'پاسخ ثبت و تکلیف تکمیل شد' : 'پیشنویس ذخیره شد',
|
||||
description:
|
||||
updated.status === 'COMPLETED'
|
||||
? undefined
|
||||
: completeIfValid
|
||||
? undefined
|
||||
: 'برای تکمیل، فیلدهای الزامی را پر کن و «ثبت پاسخ» را بزن.',
|
||||
});
|
||||
} catch (err) {
|
||||
toast({
|
||||
title: 'خطا',
|
||||
description: getFetchErrorMessage(err, 'ذخیره پاسخ ناموفق بود'),
|
||||
variant: 'destructive',
|
||||
});
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSaveEntry = async () => {
|
||||
setSaving(true);
|
||||
try {
|
||||
await startAssignment(assignment.id);
|
||||
const payload = {
|
||||
dayStatus,
|
||||
responseData: dayStatus === 'done' ? entryData : {},
|
||||
note: entryNote || null,
|
||||
};
|
||||
if (editingEntryId) {
|
||||
await updateAssignmentEntry(assignment.id, editingEntryId, payload);
|
||||
} else {
|
||||
await createAssignmentEntry(assignment.id, {
|
||||
...payload,
|
||||
entryDate: serverToday,
|
||||
});
|
||||
}
|
||||
await load();
|
||||
toast({ title: 'ثبت امروز ذخیره شد' });
|
||||
} catch (err) {
|
||||
toast({
|
||||
title: 'خطا',
|
||||
description: getFetchErrorMessage(err, 'ثبت روزانه ناموفق بود'),
|
||||
variant: 'destructive',
|
||||
});
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleExperienceNote = async () => {
|
||||
const text = experienceNote.trim();
|
||||
if (text.length < 3) {
|
||||
toast({
|
||||
title: 'یادداشت کوتاه است',
|
||||
description: 'اگر میخواهی مانعی را ثبت کنی، چند کلمه بنویس.',
|
||||
variant: 'destructive',
|
||||
});
|
||||
return;
|
||||
}
|
||||
setSaving(true);
|
||||
try {
|
||||
const result = await submitAssignmentReport(assignment.id, text, experienceStatus);
|
||||
setAssignment(result.assignment);
|
||||
setExperienceNote('');
|
||||
toast({ title: 'یادداشت تجربه ثبت شد' });
|
||||
} catch (err) {
|
||||
toast({
|
||||
title: 'خطا',
|
||||
description: getFetchErrorMessage(err, 'ثبت یادداشت ناموفق بود'),
|
||||
variant: 'destructive',
|
||||
});
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const dayOptions: Array<{ value: AssignmentDayStatus; label: string }> = [
|
||||
{ value: 'done', label: 'بله، انجام دادم' },
|
||||
{ value: 'skipped', label: 'امروز انجام ندادم' },
|
||||
{ value: 'difficult', label: 'امروز برایم دشوار بود' },
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="h-full min-h-0 flex-1 overflow-x-hidden overflow-y-auto bg-slate-50 px-4 py-6 dark:bg-slate-900">
|
||||
<div className="mx-auto w-full max-w-md space-y-5">
|
||||
<div>
|
||||
<Link
|
||||
to="/assignments"
|
||||
className="mb-3 inline-flex items-center gap-1 text-sm text-sky-700 dark:text-sky-300"
|
||||
>
|
||||
<ArrowRight className="h-4 w-4" />
|
||||
بازگشت به تکالیف
|
||||
</Link>
|
||||
<p className="text-[11px] font-medium text-sky-700 dark:text-sky-300">
|
||||
جلسه {assignment.definition.sessionOrder}
|
||||
</p>
|
||||
<h1 className="text-xl font-bold text-foreground">{assignment.definition.title}</h1>
|
||||
<div className="mt-3 flex flex-wrap gap-2 text-[11px] text-muted-foreground">
|
||||
<span className="rounded-md bg-slate-100 px-2 py-0.5 dark:bg-slate-700">
|
||||
{assignmentTypeLabel(assignment.definition.assignmentType)}
|
||||
</span>
|
||||
<span className="rounded-md bg-sky-50 px-2 py-0.5 text-sky-800 dark:bg-sky-950 dark:text-sky-200">
|
||||
{assignmentStatusLabel(assignment.status)}
|
||||
</span>
|
||||
{isMultiDay && <span>{progressLabel(assignment)}</span>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<section className="rounded-xl border border-sky-200/80 bg-sky-50/70 p-4 dark:border-sky-900 dark:bg-sky-950/40">
|
||||
<h2 className="mb-2 text-sm font-semibold text-foreground">راهنمای تمرین</h2>
|
||||
<p className="whitespace-pre-wrap text-sm leading-7 text-body">
|
||||
{assignment.definition.instructions}
|
||||
</p>
|
||||
</section>
|
||||
|
||||
{completed && isOneTime && (
|
||||
<section className="space-y-3 rounded-xl border border-emerald-200 bg-emerald-50/60 p-4 dark:border-emerald-900 dark:bg-emerald-950/30">
|
||||
<h2 className="text-sm font-semibold text-foreground">پاسخ ثبتشده</h2>
|
||||
<AssignmentFormFields fields={schema} values={draft} onChange={() => {}} disabled />
|
||||
</section>
|
||||
)}
|
||||
|
||||
{isOneTime && !completed && (
|
||||
<section className="space-y-3 rounded-xl border border-slate-200 bg-white p-4 dark:border-slate-700 dark:bg-slate-800">
|
||||
<h2 className="text-sm font-semibold text-foreground">پاسخ تمرین</h2>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
فیلدهای ستارهدار لازماند. میتوانی پیشنویس ذخیره کنی و بعداً ادامه بدهی.
|
||||
</p>
|
||||
<AssignmentFormFields fields={schema} values={draft} onChange={updateDraftField} />
|
||||
<div className="grid grid-cols-1 gap-2 sm:grid-cols-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => void handleSaveDraft(false)}
|
||||
disabled={saving}
|
||||
className="w-full"
|
||||
>
|
||||
{saving ? <Loader2 className="h-4 w-4 animate-spin" /> : 'ذخیره پیشنویس'}
|
||||
</Button>
|
||||
<Button onClick={() => void handleSaveDraft(true)} disabled={saving} className="w-full">
|
||||
{saving ? <Loader2 className="h-4 w-4 animate-spin" /> : 'ثبت پاسخ و تکمیل'}
|
||||
</Button>
|
||||
</div>
|
||||
</section>
|
||||
)}
|
||||
|
||||
{isMultiDay && (
|
||||
<section className="space-y-3 rounded-xl border border-slate-200 bg-white p-4 dark:border-slate-700 dark:bg-slate-800">
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div>
|
||||
<h2 className="text-sm font-semibold text-foreground">پیشرفت کلی</h2>
|
||||
<p className="mt-1 text-xs text-muted-foreground">{progressLabel(assignment)}</p>
|
||||
</div>
|
||||
{assignment.definition.minValidDays != null ? (
|
||||
<p className="text-[11px] text-muted-foreground">
|
||||
تکمیل پس از {assignment.definition.minValidDays} روز انجامشده
|
||||
</p>
|
||||
) : (
|
||||
<p className="max-w-[12rem] text-left text-[11px] leading-4 text-muted-foreground">
|
||||
تکمیل خودکار فعلاً فعال نیست
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
{assignment.completionBlockReason && !completed ? (
|
||||
<p className="text-xs text-amber-800 dark:text-amber-200">
|
||||
{assignment.completionBlockReason}
|
||||
</p>
|
||||
) : null}
|
||||
{completed ? (
|
||||
<p className="text-sm text-emerald-700 dark:text-emerald-300">این تمرین تکمیل شده است.</p>
|
||||
) : null}
|
||||
</section>
|
||||
)}
|
||||
|
||||
{isMultiDay && !completed && (
|
||||
<section className="space-y-3 rounded-xl border border-slate-200 bg-white p-4 dark:border-slate-700 dark:bg-slate-800">
|
||||
<h2 className="text-sm font-semibold text-foreground">
|
||||
ثبت امروز ({serverToday})
|
||||
{editingEntryId ? ' — ویرایش' : ''}
|
||||
</h2>
|
||||
<p className="text-xs text-muted-foreground">آیا امروز این تمرین را انجام دادی؟</p>
|
||||
<div className="grid grid-cols-1 gap-2">
|
||||
{dayOptions.map((opt) => (
|
||||
<button
|
||||
key={opt.value}
|
||||
type="button"
|
||||
onClick={() => setDayStatus(opt.value)}
|
||||
className={cn(
|
||||
'flex items-center gap-2 rounded-lg border px-3 py-2 text-right text-sm transition-colors',
|
||||
dayStatus === opt.value
|
||||
? 'border-sky-500 bg-sky-50 dark:border-sky-400 dark:bg-sky-950'
|
||||
: 'border-slate-200 dark:border-slate-600',
|
||||
)}
|
||||
>
|
||||
<span
|
||||
className={cn(
|
||||
'inline-flex h-4 w-4 items-center justify-center rounded border',
|
||||
dayStatus === opt.value
|
||||
? 'border-sky-600 bg-sky-600 text-white'
|
||||
: 'border-slate-300 dark:border-slate-500',
|
||||
)}
|
||||
>
|
||||
{dayStatus === opt.value ? <Check className="h-2.5 w-2.5" /> : null}
|
||||
</span>
|
||||
{opt.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{dayStatus === 'done' ? (
|
||||
<>
|
||||
<AssignmentFormFields
|
||||
fields={schema}
|
||||
values={entryData}
|
||||
onChange={updateEntryField}
|
||||
/>
|
||||
<textarea
|
||||
className="w-full rounded-xl border border-slate-200 bg-white px-3 py-2 text-sm dark:border-slate-600 dark:bg-slate-900"
|
||||
rows={2}
|
||||
dir="rtl"
|
||||
placeholder="یادداشت روزانه (اختیاری)"
|
||||
value={entryNote}
|
||||
onChange={(e) => setEntryNote(e.target.value)}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<textarea
|
||||
className="w-full rounded-xl border border-slate-200 bg-white px-3 py-2 text-sm dark:border-slate-600 dark:bg-slate-900"
|
||||
rows={2}
|
||||
dir="rtl"
|
||||
placeholder="اگر مایلید، دلیل یا مانع را کوتاه بنویسید (اختیاری)"
|
||||
value={entryNote}
|
||||
onChange={(e) => setEntryNote(e.target.value)}
|
||||
/>
|
||||
)}
|
||||
|
||||
<Button onClick={() => void handleSaveEntry()} disabled={saving} className="w-full">
|
||||
{saving ? <Loader2 className="h-4 w-4 animate-spin" /> : 'ذخیره ثبت امروز'}
|
||||
</Button>
|
||||
|
||||
{(assignment.dailyEntries?.length ?? 0) > 0 && (
|
||||
<div className="space-y-2 border-t border-slate-100 pt-3 dark:border-slate-700">
|
||||
<h3 className="text-xs font-medium text-muted-foreground">تاریخچه روزها</h3>
|
||||
{assignment.dailyEntries?.map((entry) => (
|
||||
<button
|
||||
key={entry.id}
|
||||
type="button"
|
||||
className="block w-full rounded-lg border border-slate-100 px-3 py-2 text-right text-xs hover:bg-slate-50 dark:border-slate-700 dark:hover:bg-slate-900"
|
||||
onClick={() => {
|
||||
setEditingEntryId(entry.id);
|
||||
setEntryData(entry.responseData);
|
||||
setEntryNote(entry.note ?? '');
|
||||
setDayStatus(entry.dayStatus);
|
||||
}}
|
||||
>
|
||||
<span className="font-medium text-foreground">{entry.entryDate}</span>
|
||||
<span className="mt-0.5 block text-muted-foreground">
|
||||
{assignmentDayStatusLabel(entry.dayStatus)}
|
||||
{entry.note ? ` · ${entry.note}` : ''}
|
||||
</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
)}
|
||||
|
||||
{!completed && (
|
||||
<section className="space-y-3 rounded-xl border border-dashed border-slate-200 bg-white/70 p-4 dark:border-slate-700 dark:bg-slate-800/60">
|
||||
<h2 className="text-sm font-semibold text-foreground">یادداشت تجربه (اختیاری)</h2>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
اگر انجام تمرین برایت دشوار بود یا میخواهی مانعی را ثبت کنی — جدا از پاسخ اصلی تمرین.
|
||||
</p>
|
||||
<div className="grid grid-cols-1 gap-2">
|
||||
{(
|
||||
[
|
||||
{ value: 'difficult' as const, label: 'انجام آن برایم دشوار بود' },
|
||||
{ value: 'in_progress' as const, label: 'هنوز درگیر تمرین هستم' },
|
||||
{ value: 'not_started' as const, label: 'هنوز شروع نکردهام' },
|
||||
] as const
|
||||
).map((opt) => (
|
||||
<button
|
||||
key={opt.value}
|
||||
type="button"
|
||||
onClick={() => setExperienceStatus(opt.value)}
|
||||
className={cn(
|
||||
'rounded-lg border px-3 py-2 text-right text-sm',
|
||||
experienceStatus === opt.value
|
||||
? 'border-slate-400 bg-slate-50 dark:border-slate-500 dark:bg-slate-900'
|
||||
: 'border-slate-200 dark:border-slate-600',
|
||||
)}
|
||||
>
|
||||
{opt.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<textarea
|
||||
className="w-full rounded-xl border border-slate-200 bg-white px-3 py-2 text-sm dark:border-slate-600 dark:bg-slate-900"
|
||||
rows={2}
|
||||
dir="rtl"
|
||||
value={experienceNote}
|
||||
onChange={(e) => setExperienceNote(e.target.value)}
|
||||
placeholder="توضیح کوتاه (اختیاری اما توصیهشده)"
|
||||
/>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => void handleExperienceNote()}
|
||||
disabled={saving}
|
||||
className="w-full"
|
||||
>
|
||||
ثبت یادداشت تجربه
|
||||
</Button>
|
||||
</section>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { Link, Navigate, useNavigate } from 'react-router-dom';
|
||||
import { useAuth } from '@/hooks/useAuth';
|
||||
import {
|
||||
assignmentStatusLabel,
|
||||
assignmentTypeLabel,
|
||||
ASSIGNMENTS_REFRESH_EVENT,
|
||||
fetchAssignmentCatalog,
|
||||
type AssignmentCatalogItem,
|
||||
} from '@/services/assignmentService';
|
||||
import { AnimationWrapper, StaggerItem, StaggeredList } from '@/components/motion';
|
||||
import { PageSkeleton } from '@/components/skeletons';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { Check, ChevronLeft, Lock, NotebookPen } from 'lucide-react';
|
||||
|
||||
function formatActivity(iso: string | null | undefined): string {
|
||||
if (!iso) return '—';
|
||||
try {
|
||||
return new Date(iso).toLocaleDateString('fa-IR');
|
||||
} catch {
|
||||
return '—';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* «تکالیف من» — ۹ تکلیف جلسهای؛ با زدن هر کدام به صفحه همان تمرین میروی.
|
||||
*/
|
||||
export default function AssignmentsPage() {
|
||||
const { effectiveUserId, guestSessionHydrated, isGuest } = useAuth();
|
||||
const navigate = useNavigate();
|
||||
const [items, setItems] = useState<AssignmentCatalogItem[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const load = useCallback(async () => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const rows = await fetchAssignmentCatalog();
|
||||
setItems(rows);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'بارگذاری تکالیف ناموفق بود');
|
||||
setItems([]);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!effectiveUserId || isGuest) return;
|
||||
void load();
|
||||
}, [effectiveUserId, isGuest, load]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!effectiveUserId || isGuest) return;
|
||||
const onRefresh = () => {
|
||||
void load();
|
||||
};
|
||||
window.addEventListener(ASSIGNMENTS_REFRESH_EVENT, onRefresh);
|
||||
return () => window.removeEventListener(ASSIGNMENTS_REFRESH_EVENT, onRefresh);
|
||||
}, [effectiveUserId, isGuest, load]);
|
||||
|
||||
const unlockedCount = useMemo(() => items.filter((i) => i.unlocked).length, [items]);
|
||||
|
||||
if (!guestSessionHydrated) {
|
||||
return <PageSkeleton />;
|
||||
}
|
||||
|
||||
if (!effectiveUserId) {
|
||||
return <Navigate to="/login" replace />;
|
||||
}
|
||||
|
||||
if (isGuest) {
|
||||
return (
|
||||
<div className="flex h-full flex-1 flex-col items-center justify-center px-4 text-center">
|
||||
<p className="mb-3 text-sm text-muted-foreground">
|
||||
برای ذخیره و پیگیری تکالیف باید وارد حساب کاربری شوید.
|
||||
</p>
|
||||
<Button onClick={() => navigate('/login')}>ورود</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="h-full min-h-0 flex-1 overflow-x-hidden overflow-y-auto bg-slate-50 px-4 py-6 transition-colors duration-300 dark:bg-slate-900">
|
||||
<div className="mx-auto w-full max-w-md space-y-4">
|
||||
<AnimationWrapper immediate className="space-y-1 pb-1">
|
||||
<div className="flex items-center gap-2">
|
||||
<NotebookPen className="h-5 w-5 text-sky-600 dark:text-sky-400" />
|
||||
<h1 className="text-2xl font-bold tracking-tight text-foreground">تکالیف من</h1>
|
||||
</div>
|
||||
<p className="text-sm leading-6 text-body">
|
||||
برای هر جلسه یک بخش جداگانه هست. روی تکلیف بزن تا دستورالعمل را ببینی و فیلدهای گزارش
|
||||
را پر کنی.
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{unlockedCount} از {items.length || 9} تکلیف باز شده
|
||||
</p>
|
||||
</AnimationWrapper>
|
||||
|
||||
{loading ? (
|
||||
<PageSkeleton />
|
||||
) : error ? (
|
||||
<div className="rounded-xl border border-red-200 bg-red-50 p-4 text-sm text-red-700 dark:border-red-900 dark:bg-red-950/40 dark:text-red-300">
|
||||
{error}
|
||||
<Button variant="link" className="mt-1 px-0" onClick={() => void load()}>
|
||||
تلاش مجدد
|
||||
</Button>
|
||||
</div>
|
||||
) : items.length === 0 ? (
|
||||
<p className="rounded-xl border border-dashed border-slate-300 p-6 text-center text-sm text-muted-foreground dark:border-slate-600">
|
||||
هنوز تکلیفی تعریف نشده است.
|
||||
</p>
|
||||
) : (
|
||||
<StaggeredList itemCount={items.length} className="space-y-3">
|
||||
{items.map((item) => {
|
||||
const ua = item.userAssignment;
|
||||
const unlocked = item.unlocked && ua;
|
||||
const completed = ua?.status === 'COMPLETED';
|
||||
|
||||
const content = (
|
||||
<>
|
||||
<div className="mb-2 flex items-start justify-between gap-2">
|
||||
<div className="min-w-0 space-y-1">
|
||||
<p className="text-[11px] font-medium text-sky-700 dark:text-sky-300">
|
||||
جلسه {item.definition.sessionOrder}
|
||||
</p>
|
||||
<h2 className="text-base font-semibold text-foreground">
|
||||
{item.definition.title}
|
||||
</h2>
|
||||
</div>
|
||||
{unlocked ? (
|
||||
<ChevronLeft className="mt-1 h-4 w-4 shrink-0 text-muted-foreground" />
|
||||
) : (
|
||||
<Lock className="mt-1 h-4 w-4 shrink-0 text-muted-foreground" />
|
||||
)}
|
||||
</div>
|
||||
<p className="mb-3 line-clamp-2 text-xs leading-5 text-muted-foreground">
|
||||
{item.definition.instructions}
|
||||
</p>
|
||||
<div className="flex flex-wrap gap-2 text-[11px] text-muted-foreground">
|
||||
<span className="rounded-md bg-slate-100 px-2 py-0.5 dark:bg-slate-700">
|
||||
{assignmentTypeLabel(item.definition.assignmentType)}
|
||||
</span>
|
||||
{unlocked && ua ? (
|
||||
<>
|
||||
<span
|
||||
className={cn(
|
||||
'inline-flex items-center gap-1 rounded-md px-2 py-0.5',
|
||||
completed
|
||||
? 'bg-emerald-50 text-emerald-800 dark:bg-emerald-950 dark:text-emerald-200'
|
||||
: 'bg-sky-50 text-sky-800 dark:bg-sky-950 dark:text-sky-200',
|
||||
)}
|
||||
>
|
||||
{completed ? <Check className="h-3 w-3" /> : null}
|
||||
{assignmentStatusLabel(ua.status)}
|
||||
</span>
|
||||
<span>آخرین فعالیت: {formatActivity(ua.lastActivityAt)}</span>
|
||||
</>
|
||||
) : (
|
||||
<span className="rounded-md bg-slate-100 px-2 py-0.5 dark:bg-slate-700">
|
||||
{item.lockReason ?? 'پس از پایان جلسه مربوطه باز میشود'}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
|
||||
return (
|
||||
<StaggerItem key={item.definition.id}>
|
||||
{unlocked ? (
|
||||
<Link
|
||||
to={`/assignments/${ua.id}`}
|
||||
className="block rounded-xl border border-slate-200/80 bg-white p-4 shadow-sm transition hover:border-sky-300 dark:border-slate-700 dark:bg-slate-800 dark:hover:border-sky-600"
|
||||
>
|
||||
{content}
|
||||
</Link>
|
||||
) : (
|
||||
<div className="rounded-xl border border-dashed border-slate-200 bg-slate-50/80 p-4 opacity-80 dark:border-slate-700 dark:bg-slate-800/50">
|
||||
{content}
|
||||
</div>
|
||||
)}
|
||||
</StaggerItem>
|
||||
);
|
||||
})}
|
||||
</StaggeredList>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -96,7 +96,7 @@ export default function LoginPage() {
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="app-auth-screen ambient-glow relative flex h-full min-h-0 items-center justify-center overflow-y-auto p-4">
|
||||
<div className="app-auth-screen ambient-glow relative flex h-full min-h-0 items-center justify-center overflow-x-hidden overflow-y-auto p-4">
|
||||
<button
|
||||
type="button"
|
||||
onClick={toggleTheme}
|
||||
@@ -107,20 +107,20 @@ export default function LoginPage() {
|
||||
</button>
|
||||
|
||||
<AnimationWrapper immediate interactive={false} className="relative z-10 w-full max-w-sm">
|
||||
<Card className="relative w-full overflow-hidden">
|
||||
<div
|
||||
className="pointer-events-none absolute inset-x-0 top-0 h-32 bg-gradient-to-b from-neon-blue/20 via-neon-cyan/5 to-transparent"
|
||||
aria-hidden
|
||||
/>
|
||||
<CardHeader className="relative space-y-3">
|
||||
<Card className="relative z-10 w-full overflow-hidden">
|
||||
<CardHeader className="relative z-10 space-y-3">
|
||||
<div className="mb-1 flex justify-center">
|
||||
<BrandLogo imgClassName="h-12" />
|
||||
</div>
|
||||
<CardTitle className="text-center text-2xl font-bold tracking-tight text-foreground">ورود</CardTitle>
|
||||
<CardDescription className="text-center text-body">وارد شوید</CardDescription>
|
||||
<CardTitle className="text-center text-2xl font-bold tracking-tight text-foreground">
|
||||
خوش اومدی!
|
||||
</CardTitle>
|
||||
<CardDescription className="text-center text-body">
|
||||
وارد حسابت شو و ادامه مسیرت رو دنبال کن.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
|
||||
<CardContent className="relative space-y-4">
|
||||
<CardContent className="relative z-10 space-y-4">
|
||||
<form onSubmit={handleEmailLogin} className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="email" className="text-body">
|
||||
@@ -182,11 +182,14 @@ export default function LoginPage() {
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
<div className="text-center text-sm text-body">
|
||||
حساب کاربری ندارید؟{' '}
|
||||
<Link to="/signup" className="text-neon-cyan hover:text-neon-teal hover:underline">
|
||||
ثبت نام
|
||||
</Link>
|
||||
<div className="space-y-1 text-center text-sm text-body">
|
||||
<p>هنوز حساب نداری؟</p>
|
||||
<p>
|
||||
<Link to="/signup" className="text-neon-cyan hover:text-neon-teal hover:underline">
|
||||
حسابت رو بساز
|
||||
</Link>{' '}
|
||||
و مسیرت رو با نویا شروع کن.
|
||||
</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
@@ -9,7 +9,6 @@ import { useTheme } from '@/hooks/useTheme';
|
||||
import { useToast } from '@/components/ui/use-toast';
|
||||
import { getBackendErrorMessage } from '@/lib/backendError';
|
||||
import { Loader2, Moon, Sun, Eye, EyeOff } from 'lucide-react';
|
||||
import { APP_NAME, APP_DESCRIPTION } from '@/utils/constants';
|
||||
import { BrandLogo } from '@/components/BrandLogo';
|
||||
|
||||
export default function SignupPage() {
|
||||
@@ -71,7 +70,7 @@ export default function SignupPage() {
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="app-auth-screen ambient-glow relative flex h-full min-h-0 items-center justify-center overflow-y-auto p-4">
|
||||
<div className="app-auth-screen ambient-glow relative flex h-full min-h-0 items-center justify-center overflow-x-hidden overflow-y-auto p-4">
|
||||
<button
|
||||
type="button"
|
||||
onClick={toggleTheme}
|
||||
@@ -82,21 +81,19 @@ export default function SignupPage() {
|
||||
</button>
|
||||
|
||||
<Card className="relative z-10 w-full max-w-sm overflow-hidden">
|
||||
<div
|
||||
className="pointer-events-none absolute inset-x-0 top-0 h-32 bg-gradient-to-b from-neon-blue/20 via-neon-cyan/5 to-transparent"
|
||||
aria-hidden
|
||||
/>
|
||||
<CardHeader className="relative space-y-3">
|
||||
<CardHeader className="relative z-10 space-y-3">
|
||||
<div className="mb-1 flex justify-center">
|
||||
<BrandLogo imgClassName="h-12" />
|
||||
</div>
|
||||
<CardTitle className="text-center text-2xl font-bold tracking-tight text-foreground">ثبت نام</CardTitle>
|
||||
<CardTitle className="text-center text-2xl font-bold tracking-tight text-foreground">
|
||||
بیا شروع کنیم!
|
||||
</CardTitle>
|
||||
<CardDescription className="text-center text-body">
|
||||
ایجاد حساب کاربری در {APP_NAME} — {APP_DESCRIPTION}
|
||||
حسابت رو بساز و وارد مسیر نویا شو.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
|
||||
<CardContent className="relative space-y-4">
|
||||
<CardContent className="relative z-10 space-y-4">
|
||||
<form onSubmit={handleSignup} className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="email" className="text-body">ایمیل</Label>
|
||||
@@ -164,19 +161,22 @@ export default function SignupPage() {
|
||||
{isLoading ? (
|
||||
<>
|
||||
<Loader2 className="ml-2 h-4 w-4 animate-spin" />
|
||||
در حال ثبت نام...
|
||||
در حال ثبتنام...
|
||||
</>
|
||||
) : (
|
||||
'ثبت نام'
|
||||
'ثبتنام'
|
||||
)}
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
<div className="text-center text-sm text-body">
|
||||
حساب کاربری دارید؟{' '}
|
||||
<Link to="/login" className="text-neon-cyan hover:text-neon-teal hover:underline">
|
||||
ورود
|
||||
</Link>
|
||||
<div className="space-y-1 text-center text-sm text-body">
|
||||
<p>قبلاً ثبتنام کردی؟</p>
|
||||
<p>
|
||||
<Link to="/login" className="text-neon-cyan hover:text-neon-teal hover:underline">
|
||||
وارد شو
|
||||
</Link>{' '}
|
||||
و ادامه مسیرت رو دنبال کن.
|
||||
</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
@@ -106,9 +106,18 @@ export default function ChatPage() {
|
||||
return;
|
||||
}
|
||||
|
||||
const unlockedHomework = updated.unlockedAssignments?.filter((a) => a.unlocked) ?? [];
|
||||
const waiting = Boolean(updated.nextSessionUnlocksAt && updated.waitingForSessionOrder);
|
||||
const homeworkHint =
|
||||
unlockedHomework.length > 0
|
||||
? `تکلیف جلسه ${payload.sessionOrder} الان در «تکالیف من» باز شد.`
|
||||
: null;
|
||||
|
||||
toast({
|
||||
title: 'جلسه تکمیل شد',
|
||||
description: 'جلسه بعدی برای شما باز شد.',
|
||||
description: waiting
|
||||
? [homeworkHint, 'جلسه بعدی پس از بازهٔ انتظار باز میشود.'].filter(Boolean).join(' ')
|
||||
: [homeworkHint, 'میتوانی به جلسه بعدی بروی.'].filter(Boolean).join(' '),
|
||||
});
|
||||
},
|
||||
[effectiveUserId, markTrainingDone, navigate, refreshCurrentSession, reloadProgress, toast]
|
||||
|
||||
@@ -21,7 +21,7 @@ export default function FinishedPage() {
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="h-full min-h-0 flex-1 overflow-y-auto px-4 py-10">
|
||||
<div className="h-full min-h-0 flex-1 overflow-x-hidden overflow-y-auto px-4 py-10">
|
||||
<div className="mx-auto flex w-full max-w-md flex-col items-center gap-8 text-center">
|
||||
<div className="avatar-glow">
|
||||
<div className="flex h-16 w-16 items-center justify-center rounded-full bg-white text-emerald-600 shadow-sm dark:bg-navy dark:text-neon-emerald dark:shadow-none">
|
||||
|
||||
@@ -14,6 +14,7 @@ import { ROUTES } from '@/utils/constants';
|
||||
import { BrandLogo } from '@/components/BrandLogo';
|
||||
|
||||
const NAME_MAX_LENGTH = 100;
|
||||
const PROFILE_AGE_MIN = 12;
|
||||
|
||||
const toAsciiDigits = (value: string) =>
|
||||
value.replace(/[۰-۹٠-٩]/g, (digit) => {
|
||||
@@ -64,6 +65,8 @@ export default function ProfileCompletionPage() {
|
||||
|
||||
if (parsedAge === null) {
|
||||
nextErrors.age = 'سن باید یک عدد صحیح باشد';
|
||||
} else if (parsedAge < PROFILE_AGE_MIN) {
|
||||
nextErrors.age = `حداقل سن ${PROFILE_AGE_MIN} سال است`;
|
||||
}
|
||||
|
||||
setFieldError(nextErrors);
|
||||
@@ -93,14 +96,10 @@ export default function ProfileCompletionPage() {
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="app-auth-screen ambient-glow relative flex h-full min-h-0 items-center justify-center overflow-y-auto p-4">
|
||||
<div className="app-auth-screen ambient-glow relative flex h-full min-h-0 items-center justify-center overflow-x-hidden overflow-y-auto p-4">
|
||||
<AnimationWrapper immediate interactive={false} className="relative z-10 w-full max-w-sm">
|
||||
<Card className="relative w-full overflow-hidden">
|
||||
<div
|
||||
className="pointer-events-none absolute inset-x-0 top-0 h-32 bg-gradient-to-b from-neon-blue/20 via-neon-cyan/5 to-transparent"
|
||||
aria-hidden
|
||||
/>
|
||||
<CardHeader className="relative space-y-3">
|
||||
<Card className="relative z-10 w-full overflow-hidden">
|
||||
<CardHeader className="relative z-10 space-y-3">
|
||||
<div className="mb-1 flex justify-center">
|
||||
<BrandLogo imgClassName="h-12" />
|
||||
</div>
|
||||
@@ -112,7 +111,7 @@ export default function ProfileCompletionPage() {
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
|
||||
<CardContent className="relative space-y-4">
|
||||
<CardContent className="relative z-10 space-y-4">
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="profile-name" className="text-body">
|
||||
|
||||
Reference in New Issue
Block a user