diff --git a/apps/web/src/app/(app)/layout.tsx b/apps/web/src/app/(app)/layout.tsx index eac1d1ad50..aae2e8bdac 100644 --- a/apps/web/src/app/(app)/layout.tsx +++ b/apps/web/src/app/(app)/layout.tsx @@ -9,6 +9,7 @@ import { AdminOmnibox } from '@/components/admin-omnibox'; import { AppShellSkipLink } from '@/components/AppShellSkipLink'; import { PrefetchedOrganizations } from './components/PrefetchedOrganizations'; import { PlatformPresenceMount } from './components/PlatformPresenceMount'; +import { CustomerSourceSurvey } from '@/components/CustomerSourceSurvey'; export default function AppLayout({ children }: { children: React.ReactNode }) { return ( @@ -31,6 +32,7 @@ export default function AppLayout({ children }: { children: React.ReactNode }) { + diff --git a/apps/web/src/app/customer-source-survey/page.tsx b/apps/web/src/app/customer-source-survey/page.tsx index 020280eab0..1223f94b05 100644 --- a/apps/web/src/app/customer-source-survey/page.tsx +++ b/apps/web/src/app/customer-source-survey/page.tsx @@ -1,28 +1,16 @@ import { redirect } from 'next/navigation'; import { getUserFromAuthOrRedirect } from '@/lib/user/server'; -import { KiloCardLayout } from '@/components/KiloCardLayout'; import { isValidCallbackPath } from '@/lib/getSignInCallbackUrl'; -import { CustomerSourceSurvey } from '@/components/CustomerSourceSurvey'; export default async function CustomerSourceSurveyPage({ searchParams }: AppPageProps) { - const user = await getUserFromAuthOrRedirect('/users/sign_in'); + await getUserFromAuthOrRedirect('/users/sign_in'); const params = await searchParams; - // Determine where to go after survey const callbackParam = params.callbackPath; const redirectPath = callbackParam && typeof callbackParam === 'string' && isValidCallbackPath(callbackParam) ? callbackParam : '/get-started'; - // If already answered, skip past - if (user.customer_source !== null) { - redirect(redirectPath); - } - - return ( - - - - ); + redirect(redirectPath); } diff --git a/apps/web/src/components/CustomerSourceSurvey.tsx b/apps/web/src/components/CustomerSourceSurvey.tsx index ba3c49ecb4..f9c9b66b56 100644 --- a/apps/web/src/components/CustomerSourceSurvey.tsx +++ b/apps/web/src/components/CustomerSourceSurvey.tsx @@ -1,72 +1,72 @@ 'use client'; import { useState } from 'react'; -import { useRouter } from 'next/navigation'; import { useMutation } from '@tanstack/react-query'; import { useTRPC } from '@/lib/trpc/utils'; +import { useUser } from '@/hooks/useUser'; import { Button } from '@/components/ui/button'; -import { Textarea } from '@/components/ui/textarea'; +import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; +import { Input } from '@/components/ui/input'; +import { Label } from '@/components/ui/label'; -type CustomerSourceSurveyProps = { - redirectPath: string; -}; - -export function CustomerSourceSurvey({ redirectPath }: CustomerSourceSurveyProps) { +export function CustomerSourceSurvey() { const [source, setSource] = useState(''); - const [skipped, setSkipped] = useState(false); - const router = useRouter(); + const [dismissed, setDismissed] = useState(false); + const { data: user } = useUser(); const trpc = useTRPC(); - const { mutate: submitSource, isPending } = useMutation( + const submitSource = useMutation( trpc.user.submitCustomerSource.mutationOptions({ - onSuccess: () => { - router.push(redirectPath); - }, + onSuccess: () => setDismissed(true), }) ); - const { mutate: skipSource } = useMutation( + const skipSource = useMutation( trpc.user.skipCustomerSource.mutationOptions({ - onSuccess: () => { - router.push(redirectPath); - }, - onError: () => { - setSkipped(false); - }, + onSuccess: () => setDismissed(true), }) ); - function handleSkip() { - setSkipped(true); - skipSource(); + if (dismissed || user?.customer_source !== null) { + return null; } return ( -
-