⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
feat: improve invites for smtp off users
Andrej Acevski0282c0d4db51
diff --git a/apps/api/src/index.ts b/apps/api/src/index.tsindex d607c8fb1..5469f2295 100644--- a/apps/api/src/index.ts+++ b/apps/api/src/index.ts@@ -13,6 +13,7 @@ import externalLink from "./external-link";import githubIntegration, {handleGithubWebhookRoute,} from "./github-integration";+import invitation from "./invitation";import label from "./label";import notification from "./notification";import { initializePlugins } from "./plugins";@@ -69,6 +70,7 @@ const api = new Hono<{user: User | null;session: Session | null;userId: string;+ userEmail: string;apiKey?: ApiKey;};}>();@@ -86,7 +88,7 @@ api.get("/public-project/:id", async (c) => {api.post("/github-integration/webhook", handleGithubWebhookRoute);-const intvitationApi = api.get("/invitation/:id", async (c) => {+const invitationPublicApi = api.get("/invitation/public/:id", async (c) => {const { id } = c.req.param();const result = await getInvitationDetails(id);return c.json(result);@@ -163,6 +165,7 @@ api.use("*", async (c, next) => {c.set("user", session?.user || null);c.set("session", session?.session || null);c.set("userId", session?.user?.id || "");+ c.set("userEmail", session?.user?.email || "");if (!session?.user) {throw new HTTPException(401, { message: "Unauthorized" });@@ -183,6 +186,7 @@ const githubIntegrationApi = api.route(githubIntegration,);const externalLinkApi = api.route("/external-link", externalLink);+const invitationApi = api.route("/invitation", invitation);app.route("/api", api);@@ -229,6 +233,7 @@ export type AppType =| typeof searchApi| typeof githubIntegrationApi| typeof externalLinkApi- | typeof intvitationApi;+ | typeof invitationApi+ | typeof invitationPublicApi;export default app;diff --git a/apps/api/src/invitation/controllers/get-invitation-details.ts b/apps/api/src/invitation/controllers/get-invitation-details.tsnew file mode 100644index 000000000..894a66173--- /dev/null+++ b/apps/api/src/invitation/controllers/get-invitation-details.ts@@ -0,0 +1,7 @@+import { getInvitationDetails } from "../../utils/check-registration-allowed";++export default async function getInvitationDetailsController(+ invitationId: string,+) {+ return await getInvitationDetails(invitationId);+}diff --git a/apps/api/src/invitation/controllers/get-user-pending-invitations.ts b/apps/api/src/invitation/controllers/get-user-pending-invitations.tsnew file mode 100644index 000000000..6cc56a313--- /dev/null+++ b/apps/api/src/invitation/controllers/get-user-pending-invitations.ts@@ -0,0 +1,5 @@+import { getUserPendingInvitations as getUserPendingInvitationsUtil } from "../../utils/check-registration-allowed";++export default async function getUserPendingInvitations(userEmail: string) {+ return await getUserPendingInvitationsUtil(userEmail);+}diff --git a/apps/api/src/invitation/index.ts b/apps/api/src/invitation/index.tsnew file mode 100644index 000000000..bb9164e09--- /dev/null+++ b/apps/api/src/invitation/index.ts@@ -0,0 +1,90 @@+import { Hono } from "hono";+import { describeRoute, resolver, validator } from "hono-openapi";+import * as v from "valibot";+import getInvitationDetailsController from "./controllers/get-invitation-details";+import getUserPendingInvitations from "./controllers/get-user-pending-invitations";++const invitation = new Hono<{+ Variables: {+ userId: string;+ userEmail: string;+ };+}>()+ .get(+ "/pending",+ describeRoute({+ operationId: "getUserPendingInvitations",+ tags: ["Invitations"],+ description: "Get all pending invitations for the current user",+ responses: {+ 200: {+ description: "List of pending invitations",+ content: {+ "application/json": {+ schema: resolver(+ v.array(+ v.object({+ id: v.string(),+ email: v.string(),+ workspaceId: v.string(),+ workspaceName: v.string(),+ inviterName: v.string(),+ expiresAt: v.string(),+ createdAt: v.string(),+ status: v.string(),+ }),+ ),+ ),+ },+ },+ },+ },+ }),+ async (c) => {+ const userEmail = c.get("userEmail");+ const invitations = await getUserPendingInvitations(userEmail);+ return c.json(invitations);+ },+ )+ .get(+ "/:id",+ describeRoute({+ operationId: "getInvitationDetails",+ tags: ["Invitations"],+ description: "Get details of a specific invitation by ID",+ responses: {+ 200: {+ description: "Invitation details",+ content: {+ "application/json": {+ schema: resolver(+ v.object({+ valid: v.boolean(),+ invitation: v.optional(+ v.object({+ id: v.string(),+ email: v.string(),+ workspaceName: v.string(),+ inviterName: v.string(),+ expiresAt: v.string(),+ status: v.string(),+ expired: v.boolean(),+ }),+ ),+ error: v.optional(v.string()),+ }),+ ),+ },+ },+ },+ },+ }),+ validator("param", v.object({ id: v.string() })),+ async (c) => {+ const { id } = c.req.valid("param");+ const result = await getInvitationDetailsController(id);+ return c.json(result);+ },+ );++export default invitation;diff --git a/apps/api/src/utils/check-registration-allowed.ts b/apps/api/src/utils/check-registration-allowed.tsindex 29ec34615..64a7d10ef 100644--- a/apps/api/src/utils/check-registration-allowed.ts+++ b/apps/api/src/utils/check-registration-allowed.ts@@ -192,3 +192,35 @@ export async function getInvitationDetails(invitation: baseInvitation,};}++export async function getUserPendingInvitations(userEmail: string) {+ const now = new Date();++ const result = await db+ .select({+ id: invitationTable.id,+ email: invitationTable.email,+ workspaceId: invitationTable.workspaceId,+ workspaceName: workspaceTable.name,+ inviterName: userTable.name,+ expiresAt: invitationTable.expiresAt,+ createdAt: invitationTable.createdAt,+ status: invitationTable.status,+ })+ .from(invitationTable)+ .innerJoin(+ workspaceTable,+ eq(invitationTable.workspaceId, workspaceTable.id),+ )+ .innerJoin(userTable, eq(invitationTable.inviterId, userTable.id))+ .where(+ and(+ eq(invitationTable.email, userEmail.toLowerCase()),+ eq(invitationTable.status, "pending"),+ gt(invitationTable.expiresAt, now),+ ),+ )+ .orderBy(invitationTable.createdAt);++ return result;+}diff --git a/apps/docs/next-env.d.ts b/apps/docs/next-env.d.tsindex 9edff1c7c..c4b7818fb 100644--- a/apps/docs/next-env.d.ts+++ b/apps/docs/next-env.d.ts@@ -1,6 +1,6 @@/// <reference types="next" />/// <reference types="next/image-types/global" />-import "./.next/types/routes.d.ts";+import "./.next/dev/types/routes.d.ts";// NOTE: This file should not be edited// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.diff --git a/apps/web/src/components/auth/otp-sign-in-form.tsx b/apps/web/src/components/auth/otp-sign-in-form.tsxindex d18567b83..10b4ef908 100644--- a/apps/web/src/components/auth/otp-sign-in-form.tsx+++ b/apps/web/src/components/auth/otp-sign-in-form.tsx@@ -18,6 +18,8 @@ import { authClient } from "@/lib/auth-client";type OtpSignInFormProps = {invitationId?: string;+ defaultEmail?: string;+ onSuccess?: () => void;};const emailSchema = z.object({@@ -26,13 +28,17 @@ const emailSchema = z.object({type EmailFormValues = z.infer<typeof emailSchema>;-export function OtpSignInForm({ invitationId }: OtpSignInFormProps) {+export function OtpSignInForm({+ invitationId,+ defaultEmail,+ onSuccess,+}: OtpSignInFormProps) {const [isPending, setIsPending] = useState(false);const { history } = useRouter();const form = useForm<EmailFormValues>({resolver: standardSchemaResolver(emailSchema),- defaultValues: { email: "" },+ defaultValues: { email: defaultEmail || "" },});const onSubmit = async (data: EmailFormValues) => {@@ -49,17 +55,12 @@ export function OtpSignInForm({ invitationId }: OtpSignInFormProps) {}toast.success("Verification code sent! Check your email.");+const searchParams = new URLSearchParams({email: data.email,...(invitationId && { invitationId }),});history.push(`/auth/verify-otp?${searchParams.toString()}`);- } catch (error) {- toast.error(- error instanceof Error- ? error.message- : "Failed to send verification code",- );} finally {setIsPending(false);}diff --git a/apps/web/src/components/auth/sign-in-form.tsx b/apps/web/src/components/auth/sign-in-form.tsxindex bf4a2910a..2d981219d 100644--- a/apps/web/src/components/auth/sign-in-form.tsx+++ b/apps/web/src/components/auth/sign-in-form.tsx@@ -23,6 +23,7 @@ export type SignInFormValues = {type SignInFormProps = {onSuccess?: () => void;+ defaultEmail?: string;};const signInSchema = z.object({@@ -30,13 +31,13 @@ const signInSchema = z.object({password: z.string(),});-export function SignInForm({ onSuccess }: SignInFormProps) {+export function SignInForm({ onSuccess, defaultEmail }: SignInFormProps) {const [showPassword, setShowPassword] = useState(false);const [isPending, setIsPending] = useState(false);const form = useForm<SignInFormValues>({resolver: standardSchemaResolver(signInSchema),defaultValues: {- email: "",+ email: defaultEmail || "",password: "",},});diff --git a/apps/web/src/components/nav-main.tsx b/apps/web/src/components/nav-main.tsxindex fcff53194..175d5b0cb 100644--- a/apps/web/src/components/nav-main.tsx+++ b/apps/web/src/components/nav-main.tsx@@ -1,5 +1,5 @@import { useNavigate } from "@tanstack/react-router";-import { ChevronRight, FolderKanban, Users } from "lucide-react";+import { ChevronRight, FolderKanban, Mail, Users } from "lucide-react";import {Collapsible,@@ -13,6 +13,7 @@ import {SidebarMenuButton,SidebarMenuItem,} from "@/components/ui/sidebar";+import { usePendingInvitations } from "@/hooks/queries/invitation/use-pending-invitations";import useActiveWorkspace from "@/hooks/queries/workspace/use-active-workspace";import { cn } from "@/lib/cn";import { Button } from "./ui/button";@@ -20,9 +21,12 @@ import { Button } from "./ui/button";export function NavMain() {const { data: workspace } = useActiveWorkspace();const navigate = useNavigate();+ const { data: invitations = [] } = usePendingInvitations();if (!workspace) return null;+ const pendingCount = invitations.length;+const navItems = [{title: "Projects",@@ -31,6 +35,7 @@ export function NavMain() {isActive:window.location.pathname === `/dashboard/workspace/${workspace.id}`,isDisabled: false,+ badge: null,},{title: "Members",@@ -40,6 +45,15 @@ export function NavMain() {window.location.pathname ===`/dashboard/workspace/${workspace.id}/members`,isDisabled: false,+ badge: null,+ },+ {+ title: "Invitations",+ url: "/dashboard/invitations",+ icon: Mail,+ isActive: window.location.pathname === "/dashboard/invitations",+ isDisabled: false,+ badge: pendingCount > 0 ? pendingCount : null,},];@@ -81,7 +95,7 @@ export function NavMain() {variant="ghost"className={cn("w-full h-7 justify-start items-center gap-2 px-2 text-sm transition-all duration-200 relative",- item.isActive && "!bg-neutral-200 dark:!bg-neutral-800",+ item.isActive && "bg-neutral-200! dark:bg-neutral-800!",)}>{item.icon && (@@ -90,6 +104,11 @@ export function NavMain() {<span className="transition-colors duration-200 relative z-10">{item.title}</span>+ {item.badge !== null && (+ <span className="ml-auto flex h-4 min-w-[16px] items-center justify-center rounded-full bg-primary/90 px-1 text-[9px] font-medium text-primary-foreground">+ {item.badge}+ </span>+ )}</Button></SidebarMenuButton></SidebarMenuItem>diff --git a/apps/web/src/fetchers/invitation/get-invitation-details.ts b/apps/web/src/fetchers/invitation/get-invitation-details.tsindex b3f5dbbe0..8c148eaa0 100644--- a/apps/web/src/fetchers/invitation/get-invitation-details.ts+++ b/apps/web/src/fetchers/invitation/get-invitation-details.ts@@ -19,7 +19,7 @@ export type GetInvitationDetailsResponse = {export async function getInvitationDetails(invitationId: string,): Promise<GetInvitationDetailsResponse> {- const response = await client.invitation[":id"].$get({+ const response = await client.invitation.public[":id"].$get({param: {id: invitationId,},diff --git a/apps/web/src/fetchers/invitation/get-pending-invitations.ts b/apps/web/src/fetchers/invitation/get-pending-invitations.tsnew file mode 100644index 000000000..25faf392d--- /dev/null+++ b/apps/web/src/fetchers/invitation/get-pending-invitations.ts@@ -0,0 +1,14 @@+import { client } from "@kaneo/libs";+import type { WorkspaceUserInvitation } from "@/types/workspace-user";++export async function getPendingInvitations(): Promise<+ WorkspaceUserInvitation[]+> {+ const response = await client.invitation.pending.$get();++ if (!response.ok) {+ throw new Error("Failed to get pending invitations");+ }++ return response.json();+}diff --git a/apps/web/src/hooks/queries/invitation/use-pending-invitations.ts b/apps/web/src/hooks/queries/invitation/use-pending-invitations.tsnew file mode 100644index 000000000..122f9093f--- /dev/null+++ b/apps/web/src/hooks/queries/invitation/use-pending-invitations.ts@@ -0,0 +1,14 @@+import { useQuery } from "@tanstack/react-query";+import { getPendingInvitations } from "@/fetchers/invitation/get-pending-invitations";+import { authClient } from "@/lib/auth-client";++export function usePendingInvitations() {+ const { data: session } = authClient.useSession();++ return useQuery({+ queryKey: ["invitations", "pending", session?.user?.email],+ queryFn: getPendingInvitations,+ enabled: !!session?.user?.email,+ refetchInterval: 60000,+ });+}diff --git a/apps/web/src/routeTree.gen.ts b/apps/web/src/routeTree.gen.tsindex 21c94bfa6..26afc925c 100644--- a/apps/web/src/routeTree.gen.ts+++ b/apps/web/src/routeTree.gen.ts@@ -22,9 +22,11 @@ import { Route as LayoutAuthenticatedRouteImport } from './routes/_layout/_autheimport { Route as InvitationAcceptInviteIdRouteImport } from './routes/invitation/accept.$inviteId'import { Route as LayoutAuthenticatedProfileSetupRouteImport } from './routes/_layout/_authenticated/profile-setup'import { Route as LayoutAuthenticatedOnboardingRouteImport } from './routes/_layout/_authenticated/onboarding'+import { Route as LayoutAuthenticatedInvitationsRouteImport } from './routes/_layout/_authenticated/invitations'import { Route as LayoutAuthenticatedDashboardRouteImport } from './routes/_layout/_authenticated/dashboard'import { Route as LayoutAuthenticatedDashboardIndexRouteImport } from './routes/_layout/_authenticated/dashboard/index'import { Route as LayoutAuthenticatedDashboardSettingsRouteImport } from './routes/_layout/_authenticated/dashboard/settings'+import { Route as LayoutAuthenticatedDashboardInvitationsRouteImport } from './routes/_layout/_authenticated/dashboard/invitations'import { Route as LayoutAuthenticatedDashboardWorkspaceCreateRouteImport } from './routes/_layout/_authenticated/dashboard/workspace/create'import { Route as LayoutAuthenticatedDashboardWorkspaceWorkspaceIdRouteImport } from './routes/_layout/_authenticated/dashboard/workspace/$workspaceId'import { Route as LayoutAuthenticatedDashboardSettingsWorkspaceRouteImport } from './routes/_layout/_authenticated/dashboard/settings/workspace'@@ -111,6 +113,12 @@ const LayoutAuthenticatedOnboardingRoute =path: '/onboarding',getParentRoute: () => LayoutAuthenticatedRoute,} as any)+const LayoutAuthenticatedInvitationsRoute =+ LayoutAuthenticatedInvitationsRouteImport.update({+ id: '/invitations',+ path: '/invitations',+ getParentRoute: () => LayoutAuthenticatedRoute,+ } as any)const LayoutAuthenticatedDashboardRoute =LayoutAuthenticatedDashboardRouteImport.update({id: '/dashboard',@@ -129,6 +137,12 @@ const LayoutAuthenticatedDashboardSettingsRoute =path: '/settings',getParentRoute: () => LayoutAuthenticatedDashboardRoute,} as any)+const LayoutAuthenticatedDashboardInvitationsRoute =+ LayoutAuthenticatedDashboardInvitationsRouteImport.update({+ id: '/invitations',+ path: '/invitations',+ getParentRoute: () => LayoutAuthenticatedDashboardRoute,+ } as any)const LayoutAuthenticatedDashboardWorkspaceCreateRoute =LayoutAuthenticatedDashboardWorkspaceCreateRouteImport.update({id: '/workspace/create',@@ -272,9 +286,11 @@ export interface FileRoutesByFullPath {'/auth/verify-otp': typeof AuthVerifyOtpRoute'/public-project/$projectId': typeof PublicProjectProjectIdRoute'/dashboard': typeof LayoutAuthenticatedDashboardRouteWithChildren+ '/invitations': typeof LayoutAuthenticatedInvitationsRoute'/onboarding': typeof LayoutAuthenticatedOnboardingRoute'/profile-setup': typeof LayoutAuthenticatedProfileSetupRoute'/invitation/accept/$inviteId': typeof InvitationAcceptInviteIdRoute+ '/dashboard/invitations': typeof LayoutAuthenticatedDashboardInvitationsRoute'/dashboard/settings': typeof LayoutAuthenticatedDashboardSettingsRouteWithChildren'/dashboard/': typeof LayoutAuthenticatedDashboardIndexRoute'/dashboard/settings/account': typeof LayoutAuthenticatedDashboardSettingsAccountRouteWithChildren@@ -306,9 +322,11 @@ export interface FileRoutesByTo {'/auth/sign-up': typeof AuthSignUpRoute'/auth/verify-otp': typeof AuthVerifyOtpRoute'/public-project/$projectId': typeof PublicProjectProjectIdRoute+ '/invitations': typeof LayoutAuthenticatedInvitationsRoute'/onboarding': typeof LayoutAuthenticatedOnboardingRoute'/profile-setup': typeof LayoutAuthenticatedProfileSetupRoute'/invitation/accept/$inviteId': typeof InvitationAcceptInviteIdRoute+ '/dashboard/invitations': typeof LayoutAuthenticatedDashboardInvitationsRoute'/dashboard/settings': typeof LayoutAuthenticatedDashboardSettingsRouteWithChildren'/dashboard': typeof LayoutAuthenticatedDashboardIndexRoute'/dashboard/settings/account': typeof LayoutAuthenticatedDashboardSettingsAccountRouteWithChildren@@ -343,9 +361,11 @@ export interface FileRoutesById {'/auth/verify-otp': typeof AuthVerifyOtpRoute'/public-project/$projectId': typeof PublicProjectProjectIdRoute'/_layout/_authenticated/dashboard': typeof LayoutAuthenticatedDashboardRouteWithChildren+ '/_layout/_authenticated/invitations': typeof LayoutAuthenticatedInvitationsRoute'/_layout/_authenticated/onboarding': typeof LayoutAuthenticatedOnboardingRoute'/_layout/_authenticated/profile-setup': typeof LayoutAuthenticatedProfileSetupRoute'/invitation/accept/$inviteId': typeof InvitationAcceptInviteIdRoute+ '/_layout/_authenticated/dashboard/invitations': typeof LayoutAuthenticatedDashboardInvitationsRoute'/_layout/_authenticated/dashboard/settings': typeof LayoutAuthenticatedDashboardSettingsRouteWithChildren'/_layout/_authenticated/dashboard/': typeof LayoutAuthenticatedDashboardIndexRoute'/_layout/_authenticated/dashboard/settings/account': typeof LayoutAuthenticatedDashboardSettingsAccountRouteWithChildren@@ -380,9 +400,11 @@ export interface FileRouteTypes {| '/auth/verify-otp'| '/public-project/$projectId'| '/dashboard'+ | '/invitations'| '/onboarding'| '/profile-setup'| '/invitation/accept/$inviteId'+ | '/dashboard/invitations'| '/dashboard/settings'| '/dashboard/'| '/dashboard/settings/account'@@ -414,9 +436,11 @@ export interface FileRouteTypes {| '/auth/sign-up'| '/auth/verify-otp'| '/public-project/$projectId'+ | '/invitations'| '/onboarding'| '/profile-setup'| '/invitation/accept/$inviteId'+ | '/dashboard/invitations'| '/dashboard/settings'| '/dashboard'| '/dashboard/settings/account'@@ -450,9 +474,11 @@ export interface FileRouteTypes {| '/auth/verify-otp'| '/public-project/$projectId'| '/_layout/_authenticated/dashboard'+ | '/_layout/_authenticated/invitations'| '/_layout/_authenticated/onboarding'| '/_layout/_authenticated/profile-setup'| '/invitation/accept/$inviteId'+ | '/_layout/_authenticated/dashboard/invitations'| '/_layout/_authenticated/dashboard/settings'| '/_layout/_authenticated/dashboard/'| '/_layout/_authenticated/dashboard/settings/account'@@ -578,6 +604,13 @@ declare module '@tanstack/react-router' {preLoaderRoute: typeof LayoutAuthenticatedOnboardingRouteImportparentRoute: typeof LayoutAuthenticatedRoute}+ '/_layout/_authenticated/invitations': {+ id: '/_layout/_authenticated/invitations'+ path: '/invitations'+ fullPath: '/invitations'+ preLoaderRoute: typeof LayoutAuthenticatedInvitationsRouteImport+ parentRoute: typeof LayoutAuthenticatedRoute+ }'/_layout/_authenticated/dashboard': {id: '/_layout/_authenticated/dashboard'path: '/dashboard'@@ -599,6 +632,13 @@ declare module '@tanstack/react-router' {preLoaderRoute: typeof LayoutAuthenticatedDashboardSettingsRouteImportparentRoute: typeof LayoutAuthenticatedDashboardRoute}+ '/_layout/_authenticated/dashboard/invitations': {+ id: '/_layout/_authenticated/dashboard/invitations'+ path: '/invitations'+ fullPath: '/dashboard/invitations'+ preLoaderRoute: typeof LayoutAuthenticatedDashboardInvitationsRouteImport+ parentRoute: typeof LayoutAuthenticatedDashboardRoute+ }'/_layout/_authenticated/dashboard/workspace/create': {id: '/_layout/_authenticated/dashboard/workspace/create'path: '/workspace/create'@@ -847,6 +887,7 @@ const LayoutAuthenticatedDashboardWorkspaceWorkspaceIdRouteWithChildren =)interface LayoutAuthenticatedDashboardRouteChildren {+ LayoutAuthenticatedDashboardInvitationsRoute: typeof LayoutAuthenticatedDashboardInvitationsRouteLayoutAuthenticatedDashboardSettingsRoute: typeof LayoutAuthenticatedDashboardSettingsRouteWithChildrenLayoutAuthenticatedDashboardIndexRoute: typeof LayoutAuthenticatedDashboardIndexRouteLayoutAuthenticatedDashboardWorkspaceWorkspaceIdRoute: typeof LayoutAuthenticatedDashboardWorkspaceWorkspaceIdRouteWithChildren@@ -855,6 +896,8 @@ interface LayoutAuthenticatedDashboardRouteChildren {const LayoutAuthenticatedDashboardRouteChildren: LayoutAuthenticatedDashboardRouteChildren ={+ LayoutAuthenticatedDashboardInvitationsRoute:+ LayoutAuthenticatedDashboardInvitationsRoute,LayoutAuthenticatedDashboardSettingsRoute:LayoutAuthenticatedDashboardSettingsRouteWithChildren,LayoutAuthenticatedDashboardIndexRoute:@@ -872,6 +915,7 @@ const LayoutAuthenticatedDashboardRouteWithChildren =interface LayoutAuthenticatedRouteChildren {LayoutAuthenticatedDashboardRoute: typeof LayoutAuthenticatedDashboardRouteWithChildren+ LayoutAuthenticatedInvitationsRoute: typeof LayoutAuthenticatedInvitationsRouteLayoutAuthenticatedOnboardingRoute: typeof LayoutAuthenticatedOnboardingRouteLayoutAuthenticatedProfileSetupRoute: typeof LayoutAuthenticatedProfileSetupRoute}@@ -879,6 +923,7 @@ interface LayoutAuthenticatedRouteChildren {const LayoutAuthenticatedRouteChildren: LayoutAuthenticatedRouteChildren = {LayoutAuthenticatedDashboardRoute:LayoutAuthenticatedDashboardRouteWithChildren,+ LayoutAuthenticatedInvitationsRoute: LayoutAuthenticatedInvitationsRoute,LayoutAuthenticatedOnboardingRoute: LayoutAuthenticatedOnboardingRoute,LayoutAuthenticatedProfileSetupRoute: LayoutAuthenticatedProfileSetupRoute,}diff --git a/apps/web/src/routes/_layout/_authenticated/dashboard.tsx b/apps/web/src/routes/_layout/_authenticated/dashboard.tsxindex e8915c7b4..35a0e9f58 100644--- a/apps/web/src/routes/_layout/_authenticated/dashboard.tsx+++ b/apps/web/src/routes/_layout/_authenticated/dashboard.tsx@@ -1,6 +1,5 @@import { createFileRoute, Outlet } from "@tanstack/react-router";import PageTitle from "@/components/page-title";-import { SidebarProvider } from "@/components/ui/sidebar";import useActiveWorkspace from "@/hooks/queries/workspace/use-active-workspace";export const Route = createFileRoute("/_layout/_authenticated/dashboard")({@@ -11,9 +10,9 @@ function DashboardLayoutComponent() {const { data: workspace } = useActiveWorkspace();return (- <SidebarProvider>+ <><PageTitle title="Projects" hideAppName={!workspace?.name} /><Outlet />- </SidebarProvider>+ </>);}diff --git a/apps/web/src/routes/_layout/_authenticated/dashboard/index.tsx b/apps/web/src/routes/_layout/_authenticated/dashboard/index.tsxindex 606f197a9..493222426 100644--- a/apps/web/src/routes/_layout/_authenticated/dashboard/index.tsx+++ b/apps/web/src/routes/_layout/_authenticated/dashboard/index.tsx@@ -1,4 +1,5 @@import { createFileRoute, redirect } from "@tanstack/react-router";+import { getPendingInvitations } from "@/fetchers/invitation/get-pending-invitations";import getWorkspaces from "@/fetchers/workspace/get-workspaces";import { authClient } from "@/lib/auth-client";import type Workspace from "@/types/workspace";@@ -6,6 +7,11 @@ import type Workspace from "@/types/workspace";export const Route = createFileRoute("/_layout/_authenticated/dashboard/")({beforeLoad: async () => {const workspaces: Workspace[] = await getWorkspaces();+ const invitations = await getPendingInvitations();++ if (invitations && invitations.length > 0 && !workspaces.length) {+ throw redirect({ to: "/invitations" });+ }const session = await authClient.getSession();const activeWorkspaceId = session?.data?.session?.activeOrganizationId;diff --git a/apps/web/src/routes/_layout/_authenticated/dashboard/invitations.tsx b/apps/web/src/routes/_layout/_authenticated/dashboard/invitations.tsxnew file mode 100644index 000000000..d5ba9c3e7--- /dev/null+++ b/apps/web/src/routes/_layout/_authenticated/dashboard/invitations.tsx@@ -0,0 +1,277 @@+import { useQueryClient } from "@tanstack/react-query";+import { createFileRoute, useNavigate } from "@tanstack/react-router";+import { CheckCircle, Loader2, Mail, X } from "lucide-react";+import { useState } from "react";+import { toast } from "sonner";+import Layout from "@/components/common/layout";+import PageTitle from "@/components/page-title";+import { Badge } from "@/components/ui/badge";+import { Button } from "@/components/ui/button";+import { Separator } from "@/components/ui/separator";+import { SidebarTrigger } from "@/components/ui/sidebar";+import {+ Table,+ TableBody,+ TableCell,+ TableHead,+ TableHeader,+ TableRow,+} from "@/components/ui/table";+import { usePendingInvitations } from "@/hooks/queries/invitation/use-pending-invitations";+import { authClient } from "@/lib/auth-client";+import { cn } from "@/lib/cn";++export const Route = createFileRoute(+ "/_layout/_authenticated/dashboard/invitations",+)({+ component: InvitationsPage,+});++function InvitationsPage() {+ const navigate = useNavigate();+ const queryClient = useQueryClient();+ const { data: invitations = [], isLoading } = usePendingInvitations();+ const [acceptingId, setAcceptingId] = useState<string | null>(null);+ const [rejectingId, setRejectingId] = useState<string | null>(null);++ const handleAcceptInvitation = async (+ invitationId: string,+ organizationId: string,+ ) => {+ setAcceptingId(invitationId);+ try {+ const { data, error } = await authClient.organization.acceptInvitation({+ invitationId,+ });++ if (error) {+ toast.error(error.message || "Failed to accept invitation");+ return;+ }++ await authClient.organization.setActive({+ organizationId: data?.invitation.organizationId || organizationId,+ });++ toast.success("Invitation accepted! Welcome to the team.");++ await queryClient.invalidateQueries({+ queryKey: ["invitations", "pending"],+ });++ navigate({+ to: "/dashboard/workspace/$workspaceId",+ params: {+ workspaceId: data?.invitation.organizationId || organizationId,+ },+ });+ } catch (error) {+ toast.error(+ error instanceof Error ? error.message : "Failed to accept invitation",+ );+ } finally {+ setAcceptingId(null);+ }+ };++ const handleRejectInvitation = async (invitationId: string) => {+ setRejectingId(invitationId);+ try {+ const { error } = await authClient.organization.rejectInvitation({+ invitationId,+ });++ if (error) {+ toast.error(error.message || "Failed to reject invitation");+ return;+ }++ toast.success("Invitation rejected");++ await queryClient.invalidateQueries({+ queryKey: ["invitations", "pending"],+ });+ } catch (error) {+ toast.error(+ error instanceof Error ? error.message : "Failed to reject invitation",+ );+ } finally {+ setRejectingId(null);+ }+ };++ const formatDate = (dateString: string) => {+ const date = new Date(dateString);+ return date.toLocaleDateString("en-US", {+ month: "short",+ day: "numeric",+ year: "numeric",+ });+ };++ const getExpiryStatus = (expiresAt: string) => {+ const expiryDate = new Date(expiresAt);+ const now = new Date();+ const daysDiff = Math.ceil(+ (expiryDate.getTime() - now.getTime()) / (1000 * 60 * 60 * 24),+ );++ const formattedDate = formatDate(expiresAt);++ if (daysDiff <= 1) {+ return {+ label: `${formattedDate}`,+ variant: "destructive" as const,+ isUrgent: true,+ };+ }+ if (daysDiff <= 3) {+ return {+ label: `${formattedDate}`,+ variant: "secondary" as const,+ isUrgent: true,+ };+ }+ return {+ label: formattedDate,+ variant: null,+ isUrgent: false,+ };+ };++ return (+ <>+ <PageTitle title="Invitations" />+ <Layout>+ <Layout.Header>+ <div className="flex items-center gap-1 w-full">+ <SidebarTrigger className="-ml-1 h-6 w-6" />+ <Separator+ orientation="vertical"+ className="mx-1.5 data-[orientation=vertical]:h-2.5"+ />+ <h1 className="text-xs text-card-foreground">+ Pending Invitations+ </h1>+ </div>+ </Layout.Header>+ <Layout.Content>+ <div className="p-6 space-y-6">+ {isLoading ? (+ <div className="flex items-center justify-center py-20">+ <Loader2 className="h-5 w-5 animate-spin text-muted-foreground" />+ </div>+ ) : invitations.length === 0 ? (+ <div className="flex flex-col items-center justify-center py-20 text-center">+ <div className="flex h-16 w-16 items-center justify-center rounded-full bg-muted/50 mb-4">+ <Mail className="h-8 w-8 text-muted-foreground/60" />+ </div>+ <h3 className="text-base font-semibold mb-2">+ No pending invitations+ </h3>+ <p className="text-sm text-muted-foreground max-w-md">+ You don't have any pending workspace invitations at the+ moment.+ </p>+ </div>+ ) : (+ <div className="rounded-lg border">+ <Table>+ <TableHeader>+ <TableRow className="border-b">+ <TableHead className="font-semibold">Workspace</TableHead>+ <TableHead className="font-semibold">+ Invited By+ </TableHead>+ <TableHead className="font-semibold">Expires</TableHead>+ <TableHead className="w-[100px]" />+ </TableRow>+ </TableHeader>+ <TableBody>+ {invitations.map((invitation) => {+ const expiryStatus = getExpiryStatus(+ invitation.expiresAt,+ );+ const isAccepting = acceptingId === invitation.id;+ const isRejecting = rejectingId === invitation.id;+ const isProcessing = isAccepting || isRejecting;++ return (+ <TableRow+ key={invitation.id}+ className={cn(+ expiryStatus.isUrgent &&+ expiryStatus.variant === "destructive" &&+ "bg-destructive/5",+ )}+ >+ <TableCell className="font-medium">+ {invitation.workspaceName}+ </TableCell>+ <TableCell className="text-muted-foreground text-sm">+ {invitation.inviterName}+ </TableCell>+ <TableCell>+ {expiryStatus.isUrgent && expiryStatus.variant ? (+ <Badge+ variant={expiryStatus.variant}+ className="text-xs font-normal"+ >+ {expiryStatus.label}+ </Badge>+ ) : (+ <span className="text-sm text-muted-foreground">+ {expiryStatus.label}+ </span>+ )}+ </TableCell>+ <TableCell className="text-right">+ <div className="flex items-center justify-end gap-1">+ <Button+ variant="ghost"+ size="sm"+ onClick={() =>+ handleAcceptInvitation(+ invitation.id,+ invitation.workspaceId,+ )+ }+ disabled={isProcessing}+ className="h-7 w-7 p-0"+ >+ {isAccepting ? (+ <Loader2 className="h-3 w-3 animate-spin" />+ ) : (+ <CheckCircle className="h-3 w-3" />+ )}+ </Button>+ <Button+ variant="ghost"+ size="sm"+ onClick={() =>+ handleRejectInvitation(invitation.id)+ }+ disabled={isProcessing}+ className="h-7 w-7 p-0 text-muted-foreground hover:text-destructive"+ >+ {isRejecting ? (+ <Loader2 className="h-3 w-3 animate-spin" />+ ) : (+ <X className="h-3 w-3" />+ )}+ </Button>+ </div>+ </TableCell>+ </TableRow>+ );+ })}+ </TableBody>+ </Table>+ </div>+ )}+ </div>+ </Layout.Content>+ </Layout>+ </>+ );+}diff --git a/apps/web/src/routes/_layout/_authenticated/invitations.tsx b/apps/web/src/routes/_layout/_authenticated/invitations.tsxnew file mode 100644index 000000000..1cc4ad631--- /dev/null+++ b/apps/web/src/routes/_layout/_authenticated/invitations.tsx@@ -0,0 +1,288 @@+import { useQueryClient } from "@tanstack/react-query";+import { createFileRoute, useNavigate } from "@tanstack/react-router";+import { CheckCircle, Loader2, Mail, X } from "lucide-react";+import { useState } from "react";+import { toast } from "sonner";+import PageTitle from "@/components/page-title";+import useAuth from "@/components/providers/auth-provider/hooks/use-auth";+import { Badge } from "@/components/ui/badge";+import { Button } from "@/components/ui/button";+import {+ Table,+ TableBody,+ TableCell,+ TableHead,+ TableHeader,+ TableRow,+} from "@/components/ui/table";+import { usePendingInvitations } from "@/hooks/queries/invitation/use-pending-invitations";+import { authClient } from "@/lib/auth-client";+import { cn } from "@/lib/cn";++export const Route = createFileRoute("/_layout/_authenticated/invitations")({+ component: InvitationsPage,+});++function InvitationsPage() {+ const navigate = useNavigate();+ const queryClient = useQueryClient();+ const { data: invitations = [], isLoading } = usePendingInvitations();+ const [acceptingId, setAcceptingId] = useState<string | null>(null);+ const [rejectingId, setRejectingId] = useState<string | null>(null);+ const { user } = useAuth();++ const handleSkip = () => {+ if (!user?.name) {+ navigate({ to: "/profile-setup" });+ return;+ }+ navigate({ to: "/onboarding" });+ };++ const handleAcceptInvitation = async (+ invitationId: string,+ organizationId: string,+ ) => {+ setAcceptingId(invitationId);+ try {+ const { data, error } = await authClient.organization.acceptInvitation({+ invitationId,+ });++ if (error) {+ toast.error(error.message || "Failed to accept invitation");+ return;+ }++ await authClient.organization.setActive({+ organizationId: data?.invitation.organizationId || organizationId,+ });++ toast.success("Invitation accepted! Welcome to the team.");++ await queryClient.invalidateQueries({+ queryKey: ["invitations", "pending"],+ });++ navigate({+ to: "/dashboard/workspace/$workspaceId",+ params: {+ workspaceId: data?.invitation.organizationId || organizationId,+ },+ });+ } catch (error) {+ toast.error(+ error instanceof Error ? error.message : "Failed to accept invitation",+ );+ } finally {+ setAcceptingId(null);+ }+ };++ const handleRejectInvitation = async (invitationId: string) => {+ setRejectingId(invitationId);+ try {+ const { error } = await authClient.organization.rejectInvitation({+ invitationId,+ });++ if (error) {+ toast.error(error.message || "Failed to reject invitation");+ return;+ }++ toast.success("Invitation rejected");++ await queryClient.invalidateQueries({+ queryKey: ["invitations", "pending"],+ });+ } catch (error) {+ toast.error(+ error instanceof Error ? error.message : "Failed to reject invitation",+ );+ } finally {+ setRejectingId(null);+ }+ };++ const formatDate = (dateString: string) => {+ const date = new Date(dateString);+ return date.toLocaleDateString("en-US", {+ month: "short",+ day: "numeric",+ year: "numeric",+ });+ };++ const getExpiryStatus = (expiresAt: string) => {+ const expiryDate = new Date(expiresAt);+ const now = new Date();+ const daysDiff = Math.ceil(+ (expiryDate.getTime() - now.getTime()) / (1000 * 60 * 60 * 24),+ );++ const formattedDate = formatDate(expiresAt);++ if (daysDiff <= 1) {+ return {+ label: `${formattedDate}`,+ variant: "destructive" as const,+ isUrgent: true,+ };+ }+ if (daysDiff <= 3) {+ return {+ label: `${formattedDate}`,+ variant: "secondary" as const,+ isUrgent: true,+ };+ }+ return {+ label: formattedDate,+ variant: null,+ isUrgent: false,+ };+ };++ return (+ <>+ <PageTitle title="Invitations" />+ <div className="flex w-full min-h-screen items-center justify-center p-6 bg-background">+ <div className="w-full max-w-2xl space-y-8">+ <div className="space-y-3 text-center">+ <h1 className="text-3xl font-semibold">Pending Invitations</h1>+ <p className="text-sm text-muted-foreground">+ Accept invitations to join workspaces+ </p>+ </div>++ {isLoading ? (+ <div className="flex items-center justify-center py-20">+ <Loader2 className="h-5 w-5 animate-spin text-muted-foreground" />+ </div>+ ) : invitations.length === 0 ? (+ <div className="flex flex-col items-center justify-center py-20 text-center">+ <div className="flex h-16 w-16 items-center justify-center rounded-full bg-muted/50 mb-4">+ <Mail className="h-8 w-8 text-muted-foreground/60" />+ </div>+ <h3 className="text-base font-semibold mb-2">+ No pending invitations+ </h3>+ <p className="text-sm text-muted-foreground max-w-md mb-6">+ You don't have any pending workspace invitations at the moment.+ </p>+ <Button onClick={handleSkip} variant="default">+ Continue to Setup+ </Button>+ </div>+ ) : (+ <div className="space-y-6">+ <div className="rounded-lg border bg-card shadow-sm">+ <Table>+ <TableHeader>+ <TableRow className="border-b">+ <TableHead className="font-semibold">Workspace</TableHead>+ <TableHead className="font-semibold">+ Invited By+ </TableHead>+ <TableHead className="font-semibold">Expires</TableHead>+ <TableHead className="w-[100px]" />+ </TableRow>+ </TableHeader>+ <TableBody>+ {invitations.map((invitation) => {+ const expiryStatus = getExpiryStatus(+ invitation.expiresAt,+ );+ const isAccepting = acceptingId === invitation.id;+ const isRejecting = rejectingId === invitation.id;+ const isProcessing = isAccepting || isRejecting;++ return (+ <TableRow+ key={invitation.id}+ className={cn(+ expiryStatus.isUrgent &&+ expiryStatus.variant === "destructive" &&+ "bg-destructive/5",+ )}+ >+ <TableCell className="font-medium">+ {invitation.workspaceName}+ </TableCell>+ <TableCell className="text-muted-foreground text-sm">+ {invitation.inviterName}+ </TableCell>+ <TableCell>+ {expiryStatus.isUrgent && expiryStatus.variant ? (+ <Badge+ variant={expiryStatus.variant}+ className="text-xs font-normal"+ >+ {expiryStatus.label}+ </Badge>+ ) : (+ <span className="text-sm text-muted-foreground">+ {expiryStatus.label}+ </span>+ )}+ </TableCell>+ <TableCell className="text-right">+ <div className="flex items-center justify-end gap-1">+ <Button+ variant="ghost"+ size="sm"+ onClick={() =>+ handleAcceptInvitation(+ invitation.id,+ invitation.workspaceId,+ )+ }+ disabled={isProcessing}+ className="h-7 w-7 p-0"+ >+ {isAccepting ? (+ <Loader2 className="h-3 w-3 animate-spin" />+ ) : (+ <CheckCircle className="h-3 w-3" />+ )}+ </Button>+ <Button+ variant="ghost"+ size="sm"+ onClick={() =>+ handleRejectInvitation(invitation.id)+ }+ disabled={isProcessing}+ className="h-7 w-7 p-0 text-muted-foreground hover:text-destructive"+ >+ {isRejecting ? (+ <Loader2 className="h-3 w-3 animate-spin" />+ ) : (+ <X className="h-3 w-3" />+ )}+ </Button>+ </div>+ </TableCell>+ </TableRow>+ );+ })}+ </TableBody>+ </Table>+ </div>+ <div className="flex justify-center pt-2">+ <Button+ variant="ghost"+ onClick={handleSkip}+ className="text-muted-foreground hover:text-foreground"+ >+ Skip for now+ </Button>+ </div>+ </div>+ )}+ </div>+ </div>+ </>+ );+}diff --git a/apps/web/src/routes/auth/sign-in.tsx b/apps/web/src/routes/auth/sign-in.tsxindex f3266b304..3f5ecefac 100644--- a/apps/web/src/routes/auth/sign-in.tsx+++ b/apps/web/src/routes/auth/sign-in.tsx@@ -41,6 +41,7 @@ function SignIn() {const { data: config, isLoading: isConfigLoading } = useGetConfig();const invitationId = search.invitationId;+ const defaultEmail = search.email;const getCallbackUrl = () => {const baseUrl = import.meta.env.VITE_CLIENT_URL;@@ -345,16 +346,34 @@ function SignIn() {{config?.hasSmtp ? (<OtpSignInForminvitationId={invitationId}+ defaultEmail={defaultEmail}onSuccess={handleSignInSuccess}/>) : (- <SignInForm onSuccess={handleSignInSuccess} />+ <SignInForm+ defaultEmail={defaultEmail}+ onSuccess={handleSignInSuccess}+ />+ )}+ {config?.disableRegistration ? (+ <div className="text-center pt-4">+ <p className="text-sm text-muted-foreground">+ Don't have an account?{" "}+ <a+ href="/auth/sign-up"+ className="text-primary hover:underline font-medium"+ >+ Sign up with invitation+ </a>+ </p>+ </div>+ ) : (+ <AuthToggle+ message="Don't have an account?"+ linkText="Create account"+ linkTo="/auth/sign-up"+ />)}- <AuthToggle- message="Don't have an account?"- linkText="Create account"- linkTo="/auth/sign-up"- /></div></AuthLayout></>diff --git a/apps/web/src/routes/auth/sign-up.tsx b/apps/web/src/routes/auth/sign-up.tsxindex e5b2fcaea..93fbca0c1 100644--- a/apps/web/src/routes/auth/sign-up.tsx+++ b/apps/web/src/routes/auth/sign-up.tsx@@ -1,6 +1,5 @@import {createFileRoute,- redirect,useNavigate,useSearch,} from "@tanstack/react-router";@@ -14,7 +13,6 @@ import { AuthToggle } from "@/components/auth/toggle";import PageTitle from "@/components/page-title";import { Alert, AlertDescription } from "@/components/ui/alert";import { Button } from "@/components/ui/button";-import { getConfig } from "@/fetchers/config/get-config";import useGetConfig from "@/hooks/queries/config/use-get-config";import { authClient } from "@/lib/auth-client";@@ -26,14 +24,6 @@ const signUpSearchSchema = z.object({export const Route = createFileRoute("/auth/sign-up")({component: SignUp,validateSearch: signUpSearchSchema,- beforeLoad: async ({ search }) => {- const config = await getConfig();-- const hasInvitation = !!search.invitationId;- if (config.disableRegistration && !hasInvitation) {- throw redirect({ to: "/auth/sign-in", replace: true });- }- },});function SignUp() {@@ -71,7 +61,9 @@ function SignUp() {subtitle={invitationId? "Create an account to accept your invitation"- : "Get started with your workspace"+ : config?.disableRegistration+ ? "Registration requires an invitation"+ : "Get started with your workspace"}><div className="space-y-4 mt-6">@@ -83,6 +75,15 @@ function SignUp() {</AlertDescription></Alert>)}+ {config?.disableRegistration && !invitationId && (+ <Alert>+ <AlertDescription>+ Registration is currently disabled. If you were invited, enter+ the email address that received the invitation to create your+ account.+ </AlertDescription>+ </Alert>+ )}{config?.hasGuestAccess && !invitationId && (<>diff --git a/apps/web/src/routes/invitation/accept.$inviteId.tsx b/apps/web/src/routes/invitation/accept.$inviteId.tsxindex c36c93779..a0aa88b54 100644--- a/apps/web/src/routes/invitation/accept.$inviteId.tsx+++ b/apps/web/src/routes/invitation/accept.$inviteId.tsx@@ -80,42 +80,12 @@ function AcceptInvitation() {}};- const handleSignIn = async () => {+ const handleSignIn = () => {const email = invitationData?.invitation?.email;- if (!email) {- navigate({ to: "/auth/sign-in", search: { invitationId: inviteId } });- return;- }-- try {- const result = await authClient.emailOtp.sendVerificationOtp({- email,- type: "sign-in",- });-- if (result.error) {- toast.error(result.error.message || "Failed to send verification code");- navigate({- to: "/auth/sign-in",- search: { invitationId: inviteId, email },- });- return;- }-- toast.success("Verification code sent! Check your email.");- navigate({- to: "/auth/verify-otp",- search: { email, invitationId: inviteId },- });- } catch {- toast.error(- "Failed to send verification code. Please try signing in manually.",- );- navigate({- to: "/auth/sign-in",- search: { invitationId: inviteId, email },- });- }+ navigate({+ to: "/auth/sign-in",+ search: { invitationId: inviteId, email },+ });};if (isLoading) {