-
Notifications
You must be signed in to change notification settings - Fork 48
feat(web): make customer survey non-blocking #4482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Drixled
wants to merge
3
commits into
main
Choose a base branch
from
remove-customer-source-survey
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 ( | ||
| <KiloCardLayout title="Where did you hear about Kilo Code?" className="max-w-2xl"> | ||
| <CustomerSourceSurvey redirectPath={redirectPath} /> | ||
| </KiloCardLayout> | ||
| ); | ||
| redirect(redirectPath); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 ( | ||
| <div className="space-y-4 px-6 pb-6"> | ||
| <Textarea | ||
| autoFocus | ||
| placeholder="Example: A YouTube video from Theo" | ||
| value={source} | ||
| onChange={e => setSource(e.target.value)} | ||
| rows={3} | ||
| maxLength={1000} | ||
| /> | ||
| <div className="flex items-center justify-between"> | ||
| <button | ||
| type="button" | ||
| onClick={handleSkip} | ||
| disabled={skipped || isPending} | ||
| className="cursor-pointer text-muted-foreground text-sm hover:underline" | ||
| > | ||
| {skipped ? 'Skipping...' : 'Skip'} | ||
| </button> | ||
| <Button | ||
| onClick={() => submitSource({ source: source.trim() })} | ||
| disabled={isPending || skipped || source.trim().length === 0} | ||
| > | ||
| {isPending ? 'Submitting...' : 'Submit'} | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| <aside className="fixed right-4 bottom-20 z-40 w-[calc(100vw-2rem)] max-w-sm"> | ||
| <Card className="shadow-lg"> | ||
| <CardHeader className="p-4 pb-3"> | ||
| <CardTitle>Where did you hear about Kilo Code?</CardTitle> | ||
| <CardDescription>A short answer helps us understand what is working.</CardDescription> | ||
| </CardHeader> | ||
| <CardContent className="space-y-3 p-4 pt-0"> | ||
| <div className="space-y-1.5"> | ||
| <Label htmlFor="customer-source">Source</Label> | ||
| <Input | ||
| id="customer-source" | ||
| placeholder="GitHub, a teammate, YouTube..." | ||
| value={source} | ||
| onChange={event => setSource(event.target.value)} | ||
| maxLength={1000} | ||
| /> | ||
| </div> | ||
| <div className="flex items-center justify-between gap-2"> | ||
| <Button | ||
| type="button" | ||
| variant="ghost" | ||
| onClick={() => skipSource.mutate()} | ||
| disabled={skipSource.isPending || submitSource.isPending} | ||
| > | ||
| Dismiss | ||
| </Button> | ||
| <Button | ||
| onClick={() => submitSource.mutate({ source: source.trim() })} | ||
| disabled={submitSource.isPending || skipSource.isPending || !source.trim()} | ||
| > | ||
| Save answer | ||
| </Button> | ||
| </div> | ||
| </CardContent> | ||
| </Card> | ||
| </aside> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,12 @@ | ||
| import type { User } from '@kilocode/db/schema'; | ||
|
|
||
| /** | ||
| * If the user has not yet completed the customer-source survey, | ||
| * wraps `destinationPath` so the user lands on the survey first, | ||
| * then continues to `destinationPath` after completing it. | ||
| * Preserves the existing call sites while the customer-source question is | ||
| * presented non-blockingly in the authenticated app shell. | ||
| */ | ||
| export function maybeInterceptWithSurvey( | ||
| user: Pick<User, 'customer_source'>, | ||
| _user: Pick<User, 'customer_source'>, | ||
| destinationPath: string | ||
| ): string { | ||
| if (user.customer_source === null && !destinationPath.startsWith('/customer-source-survey')) { | ||
| return `/customer-source-survey?callbackPath=${encodeURIComponent(destinationPath)}`; | ||
| } | ||
| return destinationPath; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WARNING: Survey card is not excluded from onboarding/welcome flows
<CustomerSourceSurvey />is mounted unconditionally in the(app)layout, so it renders on every route under this layout, including/gastown/onboarding(apps/web/src/app/(app)/gastown/onboarding) and the org welcome flow (apps/web/src/app/(app)/organizations/[id]/welcome). The PR description states a goal of "stop the survey from intercepting onboarding navigation," but there is no path-based exclusion here (unlike theshouldShowCustomerSourcePromptgating that existed earlier in this branch's history and was dropped). The card is non-blocking for routing, but it will still visually overlay the onboarding wizard and org welcome screens.Reply with
@kilocode-bot fix itto have Kilo Code address this issue.