|
|
@ -18,8 +18,8 @@ import QuestionCard from "@/components/Componentes/question-card"; |
|
|
import RequiredStepsCard from "@/components/Componentes/required-steps-card"; |
|
|
import RequiredStepsCard from "@/components/Componentes/required-steps-card"; |
|
|
import type { MarriageField } from "@/hooks/marriage/types"; |
|
|
import type { MarriageField } from "@/hooks/marriage/types"; |
|
|
import { marriageQueryKeys } from "@/hooks/marriage/query-keys"; |
|
|
import { marriageQueryKeys } from "@/hooks/marriage/query-keys"; |
|
|
import { getCattellQuestions } from "@/hooks/marriage/use-cattell"; |
|
|
|
|
|
import { getGlasserQuestions } from "@/hooks/marriage/use-glasser"; |
|
|
|
|
|
|
|
|
import { getCattellQuestions, useCattellResultQuery } from "@/hooks/marriage/use-cattell"; |
|
|
|
|
|
import { getGlasserQuestions, useGlasserResultQuery } from "@/hooks/marriage/use-glasser"; |
|
|
import { |
|
|
import { |
|
|
getFormSection, |
|
|
getFormSection, |
|
|
useFormOverviewQuery, |
|
|
useFormOverviewQuery, |
|
|
@ -97,6 +97,14 @@ export default function QuestionsListClient() { |
|
|
"profile", |
|
|
"profile", |
|
|
locale, |
|
|
locale, |
|
|
); |
|
|
); |
|
|
|
|
|
const { data: glasserResult } = useGlasserResultQuery(locale, { |
|
|
|
|
|
enabled: Boolean(profile?.id), |
|
|
|
|
|
retry: false, |
|
|
|
|
|
}); |
|
|
|
|
|
const { data: cattellResult } = useCattellResultQuery(locale, { |
|
|
|
|
|
enabled: Boolean(profile?.id), |
|
|
|
|
|
retry: false, |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
const isSectionsLoading = false; |
|
|
const isSectionsLoading = false; |
|
|
|
|
|
|
|
|
@ -205,11 +213,46 @@ export default function QuestionsListClient() { |
|
|
const profileId = profile?.id; |
|
|
const profileId = profile?.id; |
|
|
for (const slug of ["personality_test", "glasser_5_needs_test"]) { |
|
|
for (const slug of ["personality_test", "glasser_5_needs_test"]) { |
|
|
try { |
|
|
try { |
|
|
|
|
|
// 1. Check backend test results
|
|
|
|
|
|
if ( |
|
|
|
|
|
(slug === "glasser_5_needs_test" && Boolean(glasserResult)) || |
|
|
|
|
|
(slug === "personality_test" && Boolean(cattellResult)) |
|
|
|
|
|
) { |
|
|
|
|
|
next.set(slug, 100); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 2. Check local completion flag
|
|
|
|
|
|
if (typeof window !== "undefined") { |
|
|
|
|
|
const completionKeys = [ |
|
|
|
|
|
profileId ? `marriage:user:${profileId}:sections:${slug}:completed` : null, |
|
|
|
|
|
`marriage:sections:${slug}:completed`, |
|
|
|
|
|
`marriage:sections:${slug}:answers`, |
|
|
|
|
|
].filter(Boolean) as string[]; |
|
|
|
|
|
|
|
|
|
|
|
let isLocalCompleted = false; |
|
|
|
|
|
for (const key of completionKeys) { |
|
|
|
|
|
const raw = window.localStorage.getItem(key); |
|
|
|
|
|
if (raw) { |
|
|
|
|
|
try { |
|
|
|
|
|
const parsed = JSON.parse(raw); |
|
|
|
|
|
if (parsed?.completed === true) { |
|
|
|
|
|
next.set(slug, 100); |
|
|
|
|
|
isLocalCompleted = true; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} catch {} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (isLocalCompleted) continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 3. If not completed, read draft progress
|
|
|
let draft: any = null; |
|
|
let draft: any = null; |
|
|
if (profileId) { |
|
|
if (profileId) { |
|
|
draft = readScopedAssessmentDraft(profileId, slug); |
|
|
draft = readScopedAssessmentDraft(profileId, slug); |
|
|
} |
|
|
} |
|
|
if (!draft) { |
|
|
|
|
|
|
|
|
if (!draft && typeof window !== "undefined") { |
|
|
const raw = window.localStorage.getItem(`marriage:tests:${slug}:draft`); |
|
|
const raw = window.localStorage.getItem(`marriage:tests:${slug}:draft`); |
|
|
draft = raw ? JSON.parse(raw) : null; |
|
|
draft = raw ? JSON.parse(raw) : null; |
|
|
} |
|
|
} |
|
|
@ -220,7 +263,7 @@ export default function QuestionsListClient() { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
setLocalAssessmentProgress(next); |
|
|
setLocalAssessmentProgress(next); |
|
|
}, [overview, profile?.id]); |
|
|
|
|
|
|
|
|
}, [overview, profile?.id, glasserResult, cattellResult]); |
|
|
|
|
|
|
|
|
const sectionProgressBySlug = useMemo(() => { |
|
|
const sectionProgressBySlug = useMemo(() => { |
|
|
const progressBySlug = new Map<string, number>(); |
|
|
const progressBySlug = new Map<string, number>(); |
|
|
@ -236,7 +279,6 @@ export default function QuestionsListClient() { |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
localAssessmentProgress.forEach((progress, slug) => { |
|
|
localAssessmentProgress.forEach((progress, slug) => { |
|
|
if ((progressBySlug.get(slug) ?? 0) < 100) |
|
|
|
|
|
progressBySlug.set(slug, progress); |
|
|
progressBySlug.set(slug, progress); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|