diff --git a/app/(auth)/accept-invite/page.tsx b/app/(auth)/accept-invite/page.tsx index 2a0c407..2da07c8 100644 --- a/app/(auth)/accept-invite/page.tsx +++ b/app/(auth)/accept-invite/page.tsx @@ -1,22 +1,48 @@ "use client"; import { useState } from "react"; -import { useSearchParams } from "next/navigation"; +import { useSearchParams, useRouter } from "next/navigation"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; -import { authClient } from "@/lib/auth/client"; +import { authClient, useSession } from "@/lib/auth/client"; import { toast } from "sonner"; export default function AcceptInvitePage() { + const router = useRouter(); const searchParams = useSearchParams(); - const email = searchParams.get("email") || ""; + const emailFromUrl = searchParams.get("email") || ""; + const invitationId = searchParams.get("invitationId") || ""; + const [email, setEmail] = useState(emailFromUrl); const [isLoading, setIsLoading] = useState(false); + const [isAccepting, setIsAccepting] = useState(false); const [sent, setSent] = useState(false); + const { data: session, isPending } = useSession(); + + async function handleAcceptInvitation() { + setIsAccepting(true); + try { + const result = await authClient.organization.acceptInvitation({ + invitationId, + }); + + if (result.error) { + toast.error(result.error.message || "Failed to accept invitation"); + } else { + toast.success("Invitation accepted!"); + router.push("/start"); + } + } catch (error) { + console.error("Accept invitation error:", error); + toast.error("Failed to accept invitation"); + } finally { + setIsAccepting(false); + } + } async function handleSignIn() { if (!email) { - toast.error("No email provided"); + toast.error("Please enter your email"); return; } @@ -24,7 +50,7 @@ export default function AcceptInvitePage() { try { const result = await authClient.signIn.magicLink({ email, - callbackURL: "/start", + callbackURL: `/accept-invite?email=${encodeURIComponent(email)}${invitationId ? `&invitationId=${invitationId}` : ""}`, }); if (result.error) { @@ -41,6 +67,39 @@ export default function AcceptInvitePage() { } } + if (isPending) { + return ( +
+ You're signed in as {session.user.email} +
+- No billing is required for self-hosted instances. - All features are available. + No billing is required for self-hosted instances. All features are + available.
{permission.user.firstName}{" "} diff --git a/components/core/search-panel.tsx b/components/core/search-panel.tsx index 7529942..5374301 100644 --- a/components/core/search-panel.tsx +++ b/components/core/search-panel.tsx @@ -132,9 +132,7 @@ export function SearchSheet({ open, onOpenChange }: SearchSheetProps) { enabled: debouncedQuery.length > 0 && open, }); - const { data: projectsData } = useQuery( - trpc.user.getProjects.queryOptions(), - ); + const { data: projectsData } = useQuery(trpc.user.getProjects.queryOptions()); const projects = projectsData?.projects ?? []; @@ -417,76 +415,78 @@ export function SearchSheet({ open, onOpenChange }: SearchSheetProps) { {searchResults.length !== 1 ? "s" : ""} for "{debouncedQuery}"
{user.name}
-- {user.email} -
-{user.name}
++ {user.email} +
+{member.user.name || member.user.email}
-{member.user.email}
++ {member.user.firstName || member.user.lastName + ? `${member.user.firstName ?? ""} ${member.user.lastName ?? ""}`.trim() + : member.user.name || member.user.email} +
++ {member.user.email} +