Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat: UpgradeModal in onboarding flow

Richie McIlroy4ca220eec099
diff --git a/apps/web/app/api/settings/onboarding/route.ts b/apps/web/app/api/settings/onboarding/route.ts
index 674b6d0ca..b2b0920d2 100644
--- a/apps/web/app/api/settings/onboarding/route.ts
+++ b/apps/web/app/api/settings/onboarding/route.ts
@@ -2,7 +2,7 @@ import { type NextRequest } from "next/server";
import { getCurrentUser } from "@cap/database/auth/session";
import { organizationMembers, organizations, users } from "@cap/database/schema";
import { db } from "@cap/database";
-import { eq, or } from "drizzle-orm";
+import { eq, or, and, ne } from "drizzle-orm";
import { nanoId } from "@cap/database/helpers";
export async function POST(request: NextRequest) {
@@ -28,6 +28,24 @@ export async function POST(request: NextRequest) {
fullName += ` ${lastName}`;
}
+ const memberButNotOwner = await db()
+ .select()
+ .from(organizationMembers)
+ .leftJoin(organizations, eq(organizationMembers.organizationId, organizations.id))
+ .where(
+ and(
+ eq(organizationMembers.userId, user.id),
+ ne(organizations.ownerId, user.id)
+ )
+ )
+ .limit(1);
+
+ console.log("memberButNotOwner", memberButNotOwner);
+
+ const isMemberOfOrganization = memberButNotOwner.length > 0;
+
+ console.log("isMemberOfOrganization", isMemberOfOrganization);
+
const [organization] = await db()
.select()
.from(organizations)
@@ -57,7 +75,11 @@ export async function POST(request: NextRequest) {
}
return Response.json(
- { success: true, message: "Onboarding completed successfully" },
+ {
+ success: true,
+ message: "Onboarding completed successfully",
+ isMemberOfOrganization
+ },
{ status: 200 }
);
}
diff --git a/apps/web/app/dashboard/_components/DynamicSharedLayout.tsx b/apps/web/app/dashboard/_components/DynamicSharedLayout.tsx
index 6a196004d..1c6c8f028 100644
--- a/apps/web/app/dashboard/_components/DynamicSharedLayout.tsx
+++ b/apps/web/app/dashboard/_components/DynamicSharedLayout.tsx
@@ -50,7 +50,9 @@ export default function DynamicSharedLayout({
initialSidebarCollapsed: boolean;
}) {
const [theme, setTheme] = useState<ITheme>(initialTheme);
- const [sidebarCollapsed, setSidebarCollapsed] = useState(initialSidebarCollapsed);
+ const [sidebarCollapsed, setSidebarCollapsed] = useState(
+ initialSidebarCollapsed
+ );
const [upgradeModalOpen, setUpgradeModalOpen] = useState(false);
const setThemeHandler = (newTheme: ITheme) => {
setTheme(newTheme);
@@ -88,7 +90,7 @@ export default function DynamicSharedLayout({
toggleSidebarCollapsed,
sidebarCollapsed,
upgradeModalOpen,
- setUpgradeModalOpen
+ setUpgradeModalOpen,
}}
>
{/* CSS Grid layout for dashboard */}
@@ -103,7 +105,7 @@ export default function DynamicSharedLayout({
<AdminMobileNav />
{children}
</div>
-
+
{/* Global upgrade modal that persists regardless of navigation state */}
<UpgradeModal
open={upgradeModalOpen}
diff --git a/apps/web/app/onboarding/Onboarding.tsx b/apps/web/app/onboarding/Onboarding.tsx
index fdbdf4b08..9e70d72dc 100644
--- a/apps/web/app/onboarding/Onboarding.tsx
+++ b/apps/web/app/onboarding/Onboarding.tsx
@@ -4,11 +4,13 @@ import { Button, Input } from "@cap/ui";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { toast } from "sonner";
+import { UpgradeModal } from "../../components/UpgradeModal";
export const Onboarding = () => {
const router = useRouter();
const [firstNameInput, setFirstNameInput] = useState("");
const [loading, setLoading] = useState(false);
+ const [showUpgradeModal, setShowUpgradeModal] = useState(false);
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
@@ -29,9 +31,14 @@ export const Onboarding = () => {
});
if (response.ok) {
- toast.success("Name updated successfully");
- // Redirect to dashboard after successful onboarding
- router.push("/dashboard");
+ const data = await response.json();
+
+ if (!data.isMemberOfOrganization) {
+ setShowUpgradeModal(true);
+ } else {
+ toast.success("Name updated successfully");
+ router.push("/dashboard");
+ }
} else {
toast.error("Failed to update name");
}
@@ -44,39 +51,51 @@ export const Onboarding = () => {
};
return (
- <form
- className="relative w-[calc(100%-2%)] p-[28px] max-w-[472px] bg-gray-2 border border-gray-4 rounded-2xl"
- onSubmit={handleSubmit}
- >
- <div className="space-y-3">
- <div className="flex flex-col space-y-1">
- <Input
- type="text"
- id="firstName"
- placeholder="First name"
- name="firstName"
- required
- value={firstNameInput}
- onChange={(e) => setFirstNameInput(e.target.value)}
- />
- </div>
- <div className="flex flex-col space-y-1">
- <Input
- type="text"
- id="lastName"
- name="lastName"
- placeholder="Last name"
- />
- </div>
- </div>
- <Button
- disabled={!firstNameInput}
- className="mx-auto mt-6 w-full"
- type="submit"
- spinner={loading}
+ <>
+ <form
+ className="relative w-[calc(100%-2%)] p-[28px] max-w-[472px] bg-gray-2 border border-gray-4 rounded-2xl"
+ onSubmit={handleSubmit}
>
- Complete
- </Button>
- </form>
+ <div className="space-y-3">
+ <div className="flex flex-col space-y-1">
+ <Input
+ type="text"
+ id="firstName"
+ placeholder="First name"
+ name="firstName"
+ required
+ value={firstNameInput}
+ onChange={(e) => setFirstNameInput(e.target.value)}
+ />
+ </div>
+ <div className="flex flex-col space-y-1">
+ <Input
+ type="text"
+ id="lastName"
+ name="lastName"
+ placeholder="Last name"
+ />
+ </div>
+ </div>
+ <Button
+ disabled={!firstNameInput}
+ className="mx-auto mt-6 w-full"
+ type="submit"
+ spinner={loading}
+ >
+ Complete
+ </Button>
+ </form>
+
+ <UpgradeModal
+ open={showUpgradeModal}
+ onOpenChange={(open) => {
+ setShowUpgradeModal(open);
+ if (!open) {
+ router.push("/dashboard");
+ }
+ }}
+ />
+ </>
);
};
diff --git a/apps/web/components/UpgradeModal.tsx b/apps/web/components/UpgradeModal.tsx
index aad0afaa8..9aa956fa4 100644
--- a/apps/web/components/UpgradeModal.tsx
+++ b/apps/web/components/UpgradeModal.tsx
@@ -2,7 +2,7 @@
import { Button, Dialog, DialogContent, DialogTitle, Switch } from "@cap/ui";
import { getProPlanId } from "@cap/utils";
-import NumberFlow from '@number-flow/react';
+import NumberFlow from "@number-flow/react";
import { Fit, Layout, useRive } from "@rive-app/react-canvas";
import { AnimatePresence, motion } from "framer-motion";
import {
@@ -70,12 +70,11 @@ export const UpgradeModal = ({ open, onOpenChange }: UpgradeModalProps) => {
artboard: "cap-pro-modal",
animations: ["animation"],
layout: new Layout({
- fit: Fit.Cover
+ fit: Fit.Cover,
}),
autoplay: true,
});
-
const iconStyling = "text-blue-500 size-[18px]";
const proFeatures = [
{
@@ -109,7 +108,7 @@ export const UpgradeModal = ({ open, onOpenChange }: UpgradeModalProps) => {
description: "Automatic video chapters, summaries & more",
},
{
- icon: <Infinity className={iconStyling} />,
+ icon: <Infinity className={iconStyling} />,
title: "Unlimited views",
description: "No limits on video views",
},
@@ -165,8 +164,10 @@ export const UpgradeModal = ({ open, onOpenChange }: UpgradeModalProps) => {
return (
<Dialog open={open} onOpenChange={onOpenChange}>
- <DialogContent className="sm:max-w-[1100px] w-[calc(100%-20px)] custom-scroll bg-gray-2 border
- border-gray-4 overflow-y-auto md:overflow-hidden max-h-[90vh] p-0">
+ <DialogContent
+ className="sm:max-w-[1100px] w-[calc(100%-20px)] custom-scroll bg-gray-2 border
+ border-gray-4 overflow-y-auto md:overflow-hidden max-h-[90vh] p-0"
+ >
<DialogTitle className="sr-only">Upgrade to Cap Pro</DialogTitle>
<AnimatePresence mode="wait">
{open && (
@@ -178,92 +179,108 @@ export const UpgradeModal = ({ open, onOpenChange }: UpgradeModalProps) => {
exit="exit"
>
<div className="flex relative flex-col flex-1 justify-between items-end self-stretch border-r-0 border-b md:border-b-0 md:border-r border-gray-4">
- <div
- className="h-[275px] border-b border-gray-4 w-full overflow-hidden">
- <ProRiveArt />
- </div>
- <div className="flex relative flex-col flex-1 justify-center items-center py-6 w-full">
- <div className="flex flex-col items-center">
- <h1 className="text-3xl font-bold text-gray-12">
- Upgrade to Cap Pro
- </h1>
+ <div className="h-[275px] border-b border-gray-4 w-full overflow-hidden">
+ <ProRiveArt />
</div>
- <p className="mt-1 text-lg text-center text-gray-11">
- You can cancel anytime. Early adopter pricing locked in.
- </p>
-
- <div className="flex flex-col items-center mt-3 mb-4 w-full">
- <div className="flex flex-col items-center mb-1 sm:items-end sm:flex-row">
- <NumberFlow
- value={totalPrice}
- className="text-3xl font-medium tabular-nums text-gray-12"
- format={{
- style: "currency",
- currency: "USD",
- }}
- />
- <span className="mb-1 ml-2 text-gray-11">
- {proQuantity === 1 ? (
- `per user, ${billingText}`
- ) : (
- <>
- for <NumberFlow value={proQuantity} className="tabular-nums text-gray-12" /> users,{" "}
- {billingText}
- </>
- )}
- </span>
+ <div className="flex relative flex-col flex-1 justify-center items-center py-6 w-full">
+ <div className="flex flex-col items-center">
+ <h1 className="text-3xl font-bold text-gray-12">
+ Upgrade to Cap Pro
+ </h1>
</div>
+ <p className="mt-1 text-lg text-center text-gray-11">
+ You can cancel anytime. Early adopter pricing locked in.
+ </p>
- <div className="flex flex-col gap-6 justify-evenly items-center mt-8 w-full max-w-md sm:gap-10 sm:flex-row">
- <div className="flex gap-3 items-center">
- <span className="text-gray-12">Annual billing</span>
- <Switch
- checked={isAnnual}
- onCheckedChange={() => setIsAnnual(!isAnnual)}
+ <div className="flex flex-col items-center mt-3 mb-4 w-full">
+ <div className="flex flex-col items-center mb-1 sm:items-end sm:flex-row">
+ <NumberFlow
+ value={totalPrice}
+ className="text-3xl font-medium tabular-nums text-gray-12"
+ format={{
+ style: "currency",
+ currency: "USD",
+ }}
/>
+ <span className="mb-2 ml-2 text-gray-11">
+ {proQuantity === 1 ? (
+ `per user, ${billingText}`
+ ) : (
+ <>
+ for{" "}
+ <NumberFlow
+ value={proQuantity}
+ className="tabular-nums text-gray-12"
+ />{" "}
+ users, {billingText}
+ </>
+ )}
+ </span>
</div>
- <div className="flex items-center">
- <span className="mr-3 text-gray-12">Users:</span>
+ <div className="flex flex-col gap-6 justify-evenly items-center mt-8 w-full max-w-md sm:gap-10 sm:flex-row">
+ <div className="flex gap-3 items-center">
+ <span className="text-gray-12">Annual billing</span>
+ <Switch
+ checked={isAnnual}
+ onCheckedChange={() => setIsAnnual(!isAnnual)}
+ />
+ </div>
+
<div className="flex items-center">
- <button
- onClick={() =>
- proQuantity > 1 && setProQuantity(proQuantity - 1)
- }
- className="flex justify-center items-center w-8 h-8 rounded-l-md bg-gray-4 hover:bg-gray-5"
- disabled={proQuantity <= 1}
- >
- <Minus className="w-4 h-4 text-gray-12" />
- </button>
- <NumberFlow value={proQuantity} className="mx-auto w-6 text-sm tabular-nums text-center text-gray-12" />
- <button
- onClick={() => setProQuantity(proQuantity + 1)}
- className="flex justify-center items-center w-8 h-8 rounded-r-md bg-gray-4 hover:bg-gray-5"
- >
- <Plus className="w-4 h-4 text-gray-12" />
- </button>
+ <span className="mr-3 text-gray-12">Users:</span>
+ <div className="flex items-center">
+ <button
+ onClick={() =>
+ proQuantity > 1 && setProQuantity(proQuantity - 1)
+ }
+ className="flex justify-center items-center w-8 h-8 rounded-l-md bg-gray-4 hover:bg-gray-5"
+ disabled={proQuantity <= 1}
+ >
+ <Minus className="w-4 h-4 text-gray-12" />
+ </button>
+ <NumberFlow
+ value={proQuantity}
+ className="mx-auto w-6 text-sm tabular-nums text-center text-gray-12"
+ />
+ <button
+ onClick={() => setProQuantity(proQuantity + 1)}
+ className="flex justify-center items-center w-8 h-8 rounded-r-md bg-gray-4 hover:bg-gray-5"
+ >
+ <Plus className="w-4 h-4 text-gray-12" />
+ </button>
+ </div>
</div>
</div>
</div>
- </div>
- <Button
- variant="primary"
- onClick={planCheckout}
- className="mt-5 w-full max-w-sm h-14 text-lg rounded-xl"
- disabled={proLoading}
- >
- {proLoading ? "Loading..." : "Upgrade to Cap Pro"}
- </Button>
- </div>
+ <Button
+ variant="primary"
+ onClick={planCheckout}
+ className="mt-5 w-full max-w-sm h-14 text-lg rounded-xl"
+ disabled={proLoading}
+ >
+ {proLoading ? "Loading..." : "Upgrade to Cap Pro"}
+ </Button>
+ <button
+ className="mt-2 w-full max-w-sm h-14 text-base rounded-xl hover:underline text-gray-11 hover:text-gray-12"
+ onClick={() => onOpenChange(false)}
+ >
+ Skip
+ </button>
+ </div>
</div>
-
<div className="flex flex-1 justify-center items-center self-stretch p-8 bg-transparent md:bg-gray-3">
<div className="grid grid-cols-1 gap-8 md:grid-cols-2">
{proFeatures.map((feature, index) => (
- <div key={index} className="flex flex-col justify-center items-center">
- <div className="mb-3.5 bg-gray-5 rounded-full size-10 flex items-center border border-gray-6 justify-center">{feature.icon}</div>
+ <div
+ key={index}
+ className="flex flex-col justify-center items-center"
+ >
+ <div className="mb-3.5 bg-gray-5 rounded-full size-10 flex items-center border border-gray-6 justify-center">
+ {feature.icon}
+ </div>
<h3 className="text-base font-medium text-center text-gray-12">
{feature.title}
</h3>
@@ -283,15 +300,15 @@ export const UpgradeModal = ({ open, onOpenChange }: UpgradeModalProps) => {
};
const ProRiveArt = memo(() => {
- const {RiveComponent: ProModal} = useRive({
+ const { RiveComponent: ProModal } = useRive({
src: "/rive/main.riv",
artboard: "cap-pro-modal",
animations: ["animation"],
layout: new Layout({
- fit: Fit.Cover
+ fit: Fit.Cover,
}),
autoplay: true,
});
return <ProModal className="w-full h-full" />;
-});
\ No newline at end of file
+});