Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions apps/web/app/(org)/onboarding/Onboarding.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";

import { Button, Input } from "@cap/ui";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { toast } from "sonner";
import { UpgradeModal } from "@/components/UpgradeModal";
Expand All @@ -10,6 +11,8 @@ export const Onboarding = () => {
const [firstName, setFirstName] = useState("");
const [lastName, setLastName] = useState("");
const [showUpgradeModal, setShowUpgradeModal] = useState(false);
const router = useRouter();
const [isRedirecting, setIsRedirecting] = useState(false);

const onboardingRequest = async () => {
const response = await fetch("/api/settings/onboarding", {
Expand All @@ -36,8 +39,8 @@ export const Onboarding = () => {
if (!response.isMemberOfOrganization) {
setShowUpgradeModal(true);
} else {
// Force complete page reload to bypass React cache
window.location.replace("/dashboard");
router.refresh();
setIsRedirecting(true);
}
} catch {
toast.error("Failed to complete onboarding");
Expand All @@ -61,6 +64,7 @@ export const Onboarding = () => {
name="firstName"
required
value={firstName}
disabled={loading || isRedirecting}
onChange={(e) => setFirstName(e.target.value)}
/>
</div>
Expand All @@ -72,17 +76,22 @@ export const Onboarding = () => {
placeholder="Last name"
required
value={lastName}
disabled={loading || isRedirecting}
onChange={(e) => setLastName(e.target.value)}
/>
</div>
</div>
<Button
disabled={!firstName || !lastName || loading}
disabled={!firstName || !lastName || loading || isRedirecting}
className="mx-auto mt-6 w-full"
type="submit"
spinner={loading}
spinner={loading || isRedirecting}
>
{loading ? "Submitting..." : "Submit"}
{isRedirecting
? "Redirecting..."
: loading
? "Submitting..."
: "Submit"}
</Button>
</form>

Expand All @@ -91,7 +100,8 @@ export const Onboarding = () => {
onOpenChange={(open) => {
setShowUpgradeModal(open);
if (!open) {
window.location.replace("/dashboard");
router.refresh();
setIsRedirecting(true);
}
}}
/>
Expand Down
1 change: 1 addition & 0 deletions apps/web/app/(org)/verify-otp/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export function VerifyOTPForm({
}
},
onSuccess: () => {
router.refresh();
router.replace(next || "/dashboard");
},
onError: (e) => {
Expand Down
1 change: 0 additions & 1 deletion apps/web/app/api/settings/onboarding/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export async function POST(request: NextRequest) {
}

revalidatePath("/onboarding");
revalidatePath("/dashboard");

return Response.json(
{
Expand Down
4 changes: 2 additions & 2 deletions packages/database/auth/auth-options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ export const authOptions = (): NextAuthOptions => {
name: `next-auth.session-token`,
options: {
httpOnly: true,
sameSite: "none",
sameSite: "lax",
path: "/",
secure: true,
secure: process.env.NODE_ENV === "production",
},
},
},
Expand Down
Loading