AI Resource Pro / website · airesourcepro.com / src / app / roadmap / about-you / about-you.tsx
| 1 | "use client"; |
| 2 | |
| 3 | import { useEffect, useState } from "react"; |
| 4 | import { useRouter } from "next/navigation"; |
| 5 | import { accountRequest } from "@/lib/account-client"; |
| 6 | import type { AiSurvey } from "@/lib/ai-survey"; |
| 7 | import { useUser } from "@/lib/use-user"; |
| 8 | import { AiSurveySteps } from "../start/ai-survey-steps"; |
| 9 | |
| 10 | // The AI-use questions on their own, for answering or editing them from the account page |
| 11 | export function AboutYou() { |
| 12 | const { user, loading } = useUser(); |
| 13 | const router = useRouter(); |
| 14 | const [survey, setSurvey] = useState<AiSurvey | null | undefined>(undefined); |
| 15 | |
| 16 | useEffect(() => { |
| 17 | if (!loading && !user) router.replace("/login?next=/roadmap/about-you"); |
| 18 | }, [loading, user, router]); |
| 19 | |
| 20 | useEffect(() => { |
| 21 | if (!user?.id) return; |
| 22 | let active = true; |
| 23 | accountRequest<AiSurvey | null>("survey").then(({ data, error }) => { |
| 24 | if (!active) return; |
| 25 | if (error) console.error("Failed to load AI survey:", error); |
| 26 | setSurvey(data ?? null); |
| 27 | }); |
| 28 | return () => { active = false; }; |
| 29 | }, [user?.id]); |
| 30 | |
| 31 | if (!user || survey === undefined) return <div className="min-h-[60vh]" />; |
| 32 | return <AiSurveySteps initial={survey} onDone={() => router.push("/account#ai-use")} />; |
| 33 | } |