import clsx from 'clsx' import {QuestionWithStats} from 'common/api/types' import {debug} from 'common/logger' import {User} from 'common/user' import Link from 'next/link' import router from 'next/router' import {useEffect, useMemo, useState} from 'react' import toast from 'react-hot-toast' import {Button} from 'web/components/buttons/button' import {compareBySort, CompatibilitySort} from 'web/components/compatibility/sort-widget' import {Col} from 'web/components/layout/col' import {Modal, MODAL_CLASS, SCROLLABLE_MODAL_CLASS} from 'web/components/layout/modal' import {useT} from 'web/lib/locale' import {AnswerCompatibilityQuestionContent} from './answer-compatibility-question-content' export function AnswerCompatibilityQuestionButton(props: { user: User | null | undefined otherQuestions: QuestionWithStats[] refreshCompatibilityAll: () => void fromSignup?: boolean size?: 'sm' | 'md' }) { const {user, otherQuestions, refreshCompatibilityAll, fromSignup, size = 'md'} = props const [open, setOpen] = useState(fromSignup ?? false) const t = useT() const {isCore, questionsToAnswer} = useMemo(() => { const isCore = otherQuestions.some((q) => q.importance_score === 0) return { isCore, questionsToAnswer: isCore ? otherQuestions.filter((q) => q.importance_score === 0) : otherQuestions, } }, [otherQuestions]) if (!user) return null if (!fromSignup && questionsToAnswer.length === 0) return null return ( <> {size === 'md' ? ( ) : ( )} { if (fromSignup) router.push('/onboarding/soft-gate') }} /> ) } export function CompatibilityPageButton() { const t = useT() return ( {t('answers.answer.view_list', 'View List of Questions')} ) } export function AnswerSkippedCompatibilityQuestionsButton(props: { user: User | null | undefined skippedQuestions: QuestionWithStats[] refreshCompatibilityAll: () => void fromSignup?: boolean }) { const {user, skippedQuestions, refreshCompatibilityAll, fromSignup} = props const [open, setOpen] = useState(false) const t = useT() if (!user) return null return ( <> ) } function CompatibilityOnboardingScreen({onNext, onSkip}: {onNext: () => void; onSkip: () => void}) { const t = useT() return (

{t('compatibility.onboarding.title', "See who you'll actually align with")}

{t( 'compatibility.onboarding.body1', 'Answer a few short questions to calculate compatibility based on values and preferences — not photos or swipes.', )}

{t( 'compatibility.onboarding.body2', 'Your answers directly affect who matches with you and how strongly.', )}

{t( 'compatibility.onboarding.impact', 'Most people who answer at least 5 questions see far more relevant matches.', )}

) } function AnswerCompatibilityQuestionModal(props: { open: boolean setOpen: (open: boolean) => void user: User otherQuestions: QuestionWithStats[] refreshCompatibilityAll: () => void onClose?: () => void fromSignup?: boolean }) { const {open, setOpen, user, otherQuestions, refreshCompatibilityAll, onClose, fromSignup} = props const [questionIndex, setQuestionIndex] = useState(0) const [showOnboarding, setShowOnboarding] = useState(fromSignup ?? false) const [sort, setSort] = useState('random') useEffect(() => { refreshCompatibilityAll() setQuestionIndex(0) }, [sort]) const sortedQuestions = useMemo(() => { debug('Refreshing sorted questions') return [...otherQuestions].sort((a, b) => { return compareBySort(a, b, sort) }) as QuestionWithStats[] }, [otherQuestions, sort]) const handleStartQuestions = () => { if (otherQuestions.length === 0) { toast.error('No questions to answer') setOpen(false) return } setShowOnboarding(false) } const handleSkipOnboarding = () => { setShowOnboarding(false) setOpen(false) } return ( { refreshCompatibilityAll() setQuestionIndex(0) setShowOnboarding(fromSignup ?? false) onClose?.() }} > {showOnboarding ? ( ) : ( { setOpen(false) }} isLastQuestion={questionIndex === sortedQuestions.length - 1} onNext={() => { if (questionIndex === sortedQuestions.length - 1) { setOpen(false) } else { setQuestionIndex(questionIndex + 1) } }} sort={sort} setSort={setSort} /> )} ) }