Open source alternative to Semrush and Ahrefs
TypeScript backlink-analysisgoogle-search-console-mcpkeyword-researchmcpseoseo-agentseo-auditseo-automationseo-skillsseo-toolssite-audit
Move past the onboarding website step as soon as the site saves (EVE-440) (#988)
Carter Smith373ddaef1b00
diff --git a/src/client/features/dashboard/DashboardPage.tsx b/src/client/features/dashboard/DashboardPage.tsxindex a34c230d..59013b06 100644--- a/src/client/features/dashboard/DashboardPage.tsx+++ b/src/client/features/dashboard/DashboardPage.tsx@@ -47,8 +47,19 @@ export function DashboardPage({const overviewQuery = useQuery({queryKey: ["dashboardOverview", projectId],queryFn: () => getDashboardOverview({ data: { projectId } }),- refetchInterval: (query) =>- query.state.data?.audit?.status === "running" ? 3000 : false,+ refetchInterval: (query) => {+ const audit = query.state.data?.audit;+ if (audit?.status === "running") return 3000;+ // Onboarding starts a new site's first audit in the background, so it+ // can appear just after the dashboard loads. Keep checking for a minute.+ if (+ audit === null &&+ activationQuery.data?.domain &&+ query.state.dataUpdateCount < 20+ )+ return 3000;+ return false;+ },});const activation = activationQuery.data;diff --git a/src/client/features/onboarding/WebsiteOnboardingStep.tsx b/src/client/features/onboarding/WebsiteOnboardingStep.tsxindex 5d930cb0..4d5955e7 100644--- a/src/client/features/onboarding/WebsiteOnboardingStep.tsx+++ b/src/client/features/onboarding/WebsiteOnboardingStep.tsx@@ -1,5 +1,6 @@import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";import { revalidateLogic } from "@tanstack/react-form";+import { cn } from "cn";import { ArrowRight, ChevronDown } from "lucide-react";import { toast } from "sonner";import { z } from "zod";@@ -12,8 +13,8 @@ import {CollapsibleContent,CollapsibleTrigger,} from "@/client/components/ui/collapsible";+import { Spinner as SpinnerIcon } from "@/client/components/ui/spinner";import { WizardFooter } from "@/client/features/onboarding/WizardFooter";-import { toastInitialAudit } from "@/client/features/projects/initialAuditToast";import { ProjectMarketFields } from "@/client/features/projects/ProjectMarketFields";import { projectsQueryOptions } from "@/client/features/projects/projectQueries";import type { ProjectSummary } from "@/client/features/projects/types";@@ -22,12 +23,12 @@ import {getStandardErrorMessage,} from "@/client/lib/error-messages";import { captureClientEvent } from "@/client/lib/posthog";-import { updateProject } from "@/serverFunctions/projects";+import { saveOnboardingWebsite } from "@/serverFunctions/projects";/*** First onboarding step: save the website and country on the user's first- * project. Saving a new website starts its first site audit server-side, so- * the dashboard has results by the time the user reaches it.+ * project. Saving a new website starts its first site audit in the background,+ * so the dashboard has results by the time the user reaches it.*/export function WebsiteOnboardingStep({onNext,@@ -92,26 +93,21 @@ function WebsiteForm({const queryClient = useQueryClient();const saveMutation = useMutation({mutationFn: (values: z.infer<typeof websiteSchema>) =>- updateProject({+ saveOnboardingWebsite({data: {projectId: project.id,- // Name the auto-created project after the site it now tracks.- name:- project.name === "Default" ? values.domain.trim() : project.name,domain: values.domain.trim(),...values.market,},}),// The form shows the domain error inline and toasts the rest itself.meta: { errorToast: false },- onSuccess: async (saved) => {- await queryClient.invalidateQueries({- queryKey: projectsQueryOptions().queryKey,- });- captureClientEvent("onboarding:website_saved", {- audit_status: saved.initialAudit?.status ?? "existing",- });- toastInitialAudit(saved.initialAudit);+ onSuccess: (saved) => {+ // Move on without refetching: the save returned the project as stored.+ queryClient.setQueryData(projectsQueryOptions().queryKey, (projects) =>+ projects?.map((p) => (p.id === saved.id ? saved : p)),+ );+ captureClientEvent("onboarding:website_saved");onNext();},});@@ -184,10 +180,22 @@ function WebsiteForm({{({ empty, submitting }) => (<Buttontype="submit"- className="font-semibold disabled:bg-foreground/10 disabled:text-foreground/20 disabled:opacity-100"+ className="relative font-semibold disabled:bg-foreground/10 disabled:text-foreground/20 disabled:opacity-100"disabled={empty || submitting}+ aria-busy={submitting || undefined}>- Save and continue <ArrowRight className="size-4" />+ {/* Hidden, not removed, so the button keeps its width. */}+ <span+ className={cn(+ "inline-flex items-center gap-1.5",+ submitting && "invisible",+ )}+ >+ Save and continue <ArrowRight className="size-4" />+ </span>+ {submitting ? (+ <SpinnerIcon className="absolute inset-0 m-auto text-muted-foreground" />+ ) : null}</Button>)}</form.Subscribe>diff --git a/src/serverFunctions/projects.ts b/src/serverFunctions/projects.tsindex cf506452..30e2020e 100644--- a/src/serverFunctions/projects.ts+++ b/src/serverFunctions/projects.ts@@ -1,3 +1,4 @@+import { waitUntil } from "cloudflare:workers";import { DashboardFirstAuditService } from "@/server/features/dashboard/services/DashboardFirstAuditService";import { createServerFn } from "@tanstack/react-start";import { requireOrgPermission } from "@/server/auth/org-gate";@@ -10,6 +11,7 @@ import {archiveProjectSchema,createProjectSchema,restoreProjectSchema,+ setProjectWebsiteSchema,updateProjectSchema,} from "@/types/schemas/projects";import { z } from "zod";@@ -58,6 +60,26 @@ export const updateProject = createServerFn({ method: "POST" })return { ...project, initialAudit };});+// Onboarding's website step. Starting the first audit checks DNS and probes+// the site, which takes seconds on a slow host, so it runs after the response+// and the wizard moves on at once. start() skips projects that already have an+// audit and logs its own failures.+export const saveOnboardingWebsite = createServerFn({ method: "POST" })+ .middleware(requireProjectContext)+ .validator(setProjectWebsiteSchema)+ .handler(async ({ data, context }) => {+ const project = await ProjectService.updateProject(context.organizationId, {+ ...data,+ // Name the auto-created project after the site it now tracks.+ name:+ context.project.name === "Default" ? data.domain : context.project.name,+ });+ waitUntil(+ DashboardFirstAuditService.start(project.id, project.domain, context),+ );+ return project;+ });+export const archiveProject = createServerFn({ method: "POST" }).middleware(requireProjectContext).validator(archiveProjectSchema)