Skip to content

Commit

Permalink
mark onboarding completed
Browse files Browse the repository at this point in the history
  • Loading branch information
elie222 committed Oct 20, 2024
1 parent a006805 commit e906818
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 33 deletions.
24 changes: 24 additions & 0 deletions apps/web/app/(app)/onboarding/OnboardingFinish.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"use client";

import { Button } from "@/components/ui/button";
import Link from "next/link";
import { completedAppOnboardingAction } from "@/utils/actions/user";
import { env } from "@/env";
import { appHomePath } from "@/utils/config";

export const OnboardingFinish = () => {
return (
<Button asChild>
<Link
onClick={() => completedAppOnboardingAction()}
href={
env.NEXT_PUBLIC_WELCOME_UPGRADE_ENABLED
? "/welcome-upgrade"
: appHomePath
}
>
Continue
</Link>
</Button>
);
};
19 changes: 2 additions & 17 deletions apps/web/app/(app)/onboarding/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import Link from "next/link";
import { PageHeading, TypographyP } from "@/components/Typography";
import { Steps } from "@/app/(app)/onboarding/Steps";
import { OnboardingBulkUnsubscriber } from "@/app/(app)/onboarding/OnboardingBulkUnsubscriber";
import { OnboardingColdEmailBlocker } from "@/app/(app)/onboarding/OnboardingColdEmailBlocker";
import { OnboardingAIEmailAssistant } from "@/app/(app)/onboarding/OnboardingEmailAssistant";
import { Button } from "@/components/ui/button";
import { appHomePath } from "@/utils/config";
import { env } from "@/env";
import { OnboardingFinish } from "@/app/(app)/onboarding/OnboardingFinish";

export default function OnboardingPage({
searchParams,
Expand Down Expand Up @@ -48,19 +45,7 @@ export default function OnboardingPage({
{
title: "Continue",
description: "Get started with Inbox Zero",
content: (
<Button asChild>
<Link
href={
env.NEXT_PUBLIC_WELCOME_UPGRADE_ENABLED
? "/welcome-upgrade"
: appHomePath
}
>
Continue
</Link>
</Button>
),
content: <OnboardingFinish />,
active: searchParams.step === "4",
},
]}
Expand Down
11 changes: 1 addition & 10 deletions apps/web/app/(landing)/welcome/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,7 @@ export const OnboardingForm = (props: { questionIndex: number }) => {
submitPosthog(responses);
await completedOnboardingAction();

if (env.NEXT_PUBLIC_WELCOME_UPGRADE_ENABLED) {
router.push("/welcome-upgrade");
} else {
// send to automation home if AI Automation is chosen
if (responses["$survey_response"].includes("AI Automation")) {
router.push(aiHomePath);
} else {
router.push(appHomePath);
}
}
router.push("/onboarding");
} else {
router.push(`/welcome?${newSeachParams}`);
}
Expand Down
6 changes: 3 additions & 3 deletions apps/web/app/(landing)/welcome/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ export default async function WelcomePage({

const user = await prisma.user.findUnique({
where: { id: session.user.id },
select: { completedOnboarding: true, utms: true },
select: { completedOnboardingAt: true, utms: true },
});

if (!user) redirect("/login");

if (!searchParams.force && user.completedOnboarding) redirect(appHomePath);
if (!searchParams.force && user.completedOnboardingAt) redirect(appHomePath);

const questionIndex = searchParams.question
? Number.parseInt(searchParams.question)
Expand Down Expand Up @@ -65,7 +65,7 @@ export default async function WelcomePage({
<UTMs userId={session.user.id} />
</Suspense>
)}
{/* {!user.completedOnboarding && <SignUpEvent />} */}
{/* {!user.completedOnboardingAt && <SignUpEvent />} */}
<SignUpEvent />
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- AlterTable
ALTER TABLE "User"
ADD COLUMN "completedAppOnboardingAt" TIMESTAMP(3),
ADD COLUMN "completedOnboardingAt" TIMESTAMP(3);

-- UpdateData
UPDATE "User"
SET "completedOnboardingAt" = CASE
WHEN "completedOnboarding" = true THEN "createdAt"
ELSE NULL
END;
4 changes: 3 additions & 1 deletion apps/web/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ model User {
about String?
watchEmailsExpirationDate DateTime?
lastSyncedHistoryId String?
completedOnboarding Boolean @default(false)
completedOnboarding Boolean @default(false) // deprecated
completedOnboardingAt DateTime? // questions about the user. e.g. their role
completedAppOnboardingAt DateTime? // how to use the app
onboardingAnswers Json?
behaviorProfile Json?
lastLogin DateTime?
Expand Down
17 changes: 15 additions & 2 deletions apps/web/utils/actions/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,21 @@ export const completedOnboardingAction = withActionInstrumentation(
if (!session?.user.id) return { error: "Not logged in" };

await prisma.user.update({
where: { id: session.user.id },
data: { completedOnboarding: true },
where: { id: session.user.id, completedOnboardingAt: null },
data: { completedOnboardingAt: new Date() },
});
},
);

export const completedAppOnboardingAction = withActionInstrumentation(
"completedAppOnboarding",
async () => {
const session = await auth();
if (!session?.user.id) return { error: "Not logged in" };

await prisma.user.update({
where: { id: session.user.id, completedAppOnboardingAt: null },
data: { completedAppOnboardingAt: new Date() },
});
},
);
Expand Down

0 comments on commit e906818

Please sign in to comment.