Swap functionality: PDF only in Pro DPPs, CBT only in AI Coach PrepPilot AI

This commit is contained in:
2026-09-25 16:13:59 +05:30
parent 6599ff02c9
commit 196238ddd0
2 changed files with 41 additions and 41 deletions

View File

@@ -26,9 +26,22 @@ export default function DPPPage() {
try {
const pattern = user.target_exam || "JEE_Main";
// Also fetch from the correct Next.js proxied route instead of localhost:8000
const res = await fetchWithAuth(`/api/tests?type=DPS&exam_pattern=${pattern}`);
const res = await fetchWithAuth(`/api/tests?type=DPS`);
if (res.ok) {
const data = await res.json()
let data = await res.json()
// Filter by subject based on target exam
const target = user.target_exam || "JEE_Main";
data = data.filter((dpp: any) => {
const title = dpp.title.toLowerCase();
const isMath = title.includes("math");
const isBio = title.includes("bio") || title.includes("botany") || title.includes("zoology");
if (target === "NEET" && isMath) return false;
if (target.startsWith("JEE") && target !== "JEE_NEET" && isBio) return false;
return true;
});
setDpps(data)
}
@@ -68,15 +81,14 @@ export default function DPPPage() {
}, {} as Record<string, any>);
const filteredDpps = dpps.filter(dpp => {
// Only show CBT DPPs here (no PDF)
if (dpp.pdf_url) return false;
if (dateFilter) {
if (!dpp.scheduled_date) return false;
const scheduledDate = new Date(dpp.scheduled_date).toISOString().split('T')[0];
if (scheduledDate !== dateFilter) return false;
}
const isNeet = user?.target_exam === "NEET";
const title = dpp.title.toLowerCase();
if (isNeet && (title.includes("math") || title.includes("mth"))) return false;
if (!isNeet && title.includes("bio")) return false;
return true;
});
@@ -219,15 +231,27 @@ export default function DPPPage() {
<Button variant="outline" size="sm" className="font-bold border-border">Result</Button>
</Link>
{!isExpired && (
<Button onClick={() => setSelectedPdfDpp(dpp)} variant="secondary" size="sm" className="font-bold bg-[var(--cyan-ai-10)] text-[var(--cyan-ai)] hover:bg-[var(--cyan-ai-20)] gap-2">
<Eye size={14} /> Read PDF
hasAccessTo('AI_COACH') ? (
<Link href={`/cbt/${dpp.id}`}>
<Button variant="secondary" size="sm" className="font-bold bg-[var(--cyan-ai-10)] text-[var(--cyan-ai)] hover:bg-[var(--cyan-ai-20)] gap-2">
<Play size={14} className="fill-current" /> Retake Test
</Button>
</Link>
) : (
<Button variant="outline" size="sm" className="opacity-50" disabled><Lock size={14} className="mr-2"/> Retake</Button>
)
)}
</>
) : (
<Button onClick={() => setSelectedPdfDpp(dpp)} variant="secondary" className="rounded-xl bg-primary/10 text-primary hover:bg-primary/20 font-bold gap-2 text-xs">
<Eye size={14} /> Open PDF
hasAccessTo('AI_COACH') ? (
<Link href={`/cbt/${dpp.id}`}>
<Button variant="secondary" size="sm" className="rounded-xl bg-[var(--cyan-ai)] text-black hover:bg-[var(--cyan-ai-80)] font-extrabold gap-2 text-xs shadow-[0_0_12px_rgba(12,96,96,0.2)]">
<Play size={14} className="fill-black" /> Launch Practice Test
</Button>
</Link>
) : (
<Button variant="outline" size="sm" className="opacity-50" disabled><Lock size={14} className="mr-2"/> Launch Practice Test</Button>
)
)}
</div>
</CardContent>

View File

@@ -82,6 +82,9 @@ export default function AIDailyPracticePage() {
}, {} as Record<string, any>);
const filteredDpps = dpps.filter(dpp => {
// Only show PDF DPPs here
if (!dpp.pdf_url) return false;
if (dateFilter) {
if (!dpp.scheduled_date) return false;
const scheduledDate = new Date(dpp.scheduled_date).toISOString().split('T')[0];
@@ -210,9 +213,9 @@ export default function AIDailyPracticePage() {
<div className="flex flex-col sm:flex-row gap-2 shrink-0 md:self-center">
{isUpcoming ? (
<Button disabled variant="outline" size="sm" className="font-bold">Starts Soon</Button>
) : isExpired && !isAttempted && !dpp.pdf_url ? (
) : isExpired && !isAttempted ? (
<Button disabled variant="outline" size="sm" className="font-bold bg-secondary/50">Expired</Button>
) : dpp.pdf_url ? (
) : (
hasAccessTo('PRO') ? (
<Button onClick={() => setSelectedPdfDpp(dpp)} variant="secondary" size="sm" className="rounded-xl bg-[var(--cyan-ai)] text-black hover:bg-[var(--cyan-ai-80)] font-extrabold gap-2 text-xs shadow-[0_0_12px_rgba(12,96,96,0.2)]">
<FileText size={14} className="text-black" /> View PDF
@@ -220,33 +223,6 @@ export default function AIDailyPracticePage() {
) : (
<Button variant="outline" size="sm" className="opacity-50" disabled><Lock size={14} className="mr-2"/> View PDF</Button>
)
) : isAttempted ? (
<>
<Link href={`/cbt/${dpp.id}/result`}>
<Button variant="outline" size="sm" className="font-bold border-border">Result</Button>
</Link>
{!isExpired && (
hasAccessTo('AI_COACH') ? (
<Link href={`/cbt/${dpp.id}`}>
<Button variant="secondary" size="sm" className="font-bold bg-[var(--cyan-ai-10)] text-[var(--cyan-ai)] hover:bg-[var(--cyan-ai-20)] gap-2">
<Play size={14} className="fill-current" /> Retake Test
</Button>
</Link>
) : (
<Button variant="outline" size="sm" className="opacity-50" disabled><Lock size={14} className="mr-2"/> Retake</Button>
)
)}
</>
) : (
hasAccessTo('AI_COACH') ? (
<Link href={`/cbt/${dpp.id}`}>
<Button variant="secondary" size="sm" className="rounded-xl bg-[var(--cyan-ai)] text-black hover:bg-[var(--cyan-ai-80)] font-extrabold gap-2 text-xs shadow-[0_0_12px_rgba(12,96,96,0.2)]">
<Play size={14} className="fill-black" /> Launch Practice Test
</Button>
</Link>
) : (
<Button variant="outline" size="sm" className="opacity-50" disabled><Lock size={14} className="mr-2"/> Launch Practice Test</Button>
)
)}
</div>
</CardContent>