Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 6 additions & 2 deletions apps/web/src/components/shared/LeaveTeamDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ import {
} from "@/components/ui/alert-dialog";
import { DropdownMenuItem } from "../ui/dropdown-menu";
import { UserX } from "lucide-react";
import { leaveTeamMutationClient as _unusedForNowleaveTeamMutationClientleaveTeamMutationClient } from "@/lib/queries";
import { leaveTeamMutationClient as _unusedForNowleaveTeamMutationClientleaveTeamMutationClient } from "@/lib/functions/queries";
Comment thread
christianhelp marked this conversation as resolved.
import { useMutation as _unusedForNowuseMutation } from "@tanstack/react-query";

/**
* Dialog component that allows a user to leave a team. It prompts the user for confirmation before proceeding with the action. If the team is private, it warns the user that they will need a new invitation to rejoin. If the team is public, it informs the user that they can rejoin later but will lose access to team data.
* @param param
* @returns
*/
export function LeaveTeamDialog({
teamId: _unusedForNowTeamId,
teamName,
Expand Down
7 changes: 5 additions & 2 deletions apps/web/src/components/shared/Navbar/UserButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ import {
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { useQuery } from "@tanstack/react-query";
import { getUserQueryClient, getUserTeamsQueryClient } from "@/lib/queries";
import {
getUserQueryClient,
getUserTeamsQueryClient,
} from "@/lib/functions/queries";
import { Skeleton } from "@/components/ui/skeleton";
import { getInitials } from "@/lib/utils";
import { getInitials } from "@/lib/functions/utils";
import { Plus, UserPlus } from "lucide-react";
import { Link } from "@tanstack/react-router";
import { authClient } from "@/lib/auth-client";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/shared/Navbar/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
NavigationMenuItem,
NavigationMenuList,
} from "@/components/ui/navigation-menu";
import { shouldShowNavbar } from "@/lib/utils";
import { shouldShowNavbar } from "@/lib/functions/utils";
import { useLocation } from "@tanstack/react-router";
import { SignedIn, SignedOut } from "@daveyplate/better-auth-ui";
import { Button } from "@/components/ui/button";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/ui/alert-dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from "react";
import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog";

import { cn } from "@/lib/utils";
import { cn } from "@/lib/functions/utils";
import { buttonVariants } from "@/components/ui/button";

function AlertDialog({
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/ui/alert.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from "react";
import { cva, type VariantProps } from "class-variance-authority";

import { cn } from "@/lib/utils";
import { cn } from "@/lib/functions/utils";

const alertVariants = cva(
"relative w-full rounded-lg border px-4 py-3 text-sm grid has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] grid-cols-[0_1fr] has-[>svg]:gap-x-3 gap-y-0.5 items-start [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current",
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/ui/avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import * as React from "react";
import * as AvatarPrimitive from "@radix-ui/react-avatar";

import { cn } from "@/lib/utils";
import { cn } from "@/lib/functions/utils";

function Avatar({
className,
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/ui/breadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from "react";
import { Slot } from "@radix-ui/react-slot";
import { ChevronRight, MoreHorizontal } from "lucide-react";

import { cn } from "@/lib/utils";
import { cn } from "@/lib/functions/utils";

function Breadcrumb({ ...props }: React.ComponentProps<"nav">) {
return <nav aria-label="breadcrumb" data-slot="breadcrumb" {...props} />;
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/ui/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from "react";
import { Slot } from "@radix-ui/react-slot";
import { cva, type VariantProps } from "class-variance-authority";

import { cn } from "@/lib/utils";
import { cn } from "@/lib/functions/utils";

const buttonVariants = cva(
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/ui/dropdown-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from "react";
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react";

import { cn } from "@/lib/utils";
import { cn } from "@/lib/functions/utils";

function DropdownMenu({
...props
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/ui/input.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from "react";

import { cn } from "@/lib/utils";
import { cn } from "@/lib/functions/utils";

function Input({ className, type, ...props }: React.ComponentProps<"input">) {
return (
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/ui/menubar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from "react";
import * as MenubarPrimitive from "@radix-ui/react-menubar";
import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react";

import { cn } from "@/lib/utils";
import { cn } from "@/lib/functions/utils";

function Menubar({
className,
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/ui/navigation-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as NavigationMenuPrimitive from "@radix-ui/react-navigation-menu";
import { cva } from "class-variance-authority";
import { ChevronDownIcon } from "lucide-react";

import { cn } from "@/lib/utils";
import { cn } from "@/lib/functions/utils";

function NavigationMenu({
className,
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/ui/scroll-area.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from "react";
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area";

import { cn } from "@/lib/utils";
import { cn } from "@/lib/functions/utils";

function ScrollArea({
className,
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/ui/separator.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from "react";
import * as SeparatorPrimitive from "@radix-ui/react-separator";

import { cn } from "@/lib/utils";
import { cn } from "@/lib/functions/utils";

function Separator({
className,
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/ui/sheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as React from "react";
import * as SheetPrimitive from "@radix-ui/react-dialog";
import { XIcon } from "lucide-react";

import { cn } from "@/lib/utils";
import { cn } from "@/lib/functions/utils";

function Sheet({ ...props }: React.ComponentProps<typeof SheetPrimitive.Root>) {
return <SheetPrimitive.Root data-slot="sheet" {...props} />;
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/ui/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { cva, type VariantProps } from "class-variance-authority";
import { PanelLeftIcon } from "lucide-react";

import { useIsMobile } from "@/hooks/use-mobile";
import { cn } from "@/lib/utils";
import { cn } from "@/lib/functions/utils";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Separator } from "@/components/ui/separator";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/ui/skeleton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cn } from "@/lib/utils";
import { cn } from "@/lib/functions/utils";

function Skeleton({ className, ...props }: React.ComponentProps<"div">) {
return (
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/ui/switch.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from "react";
import * as SwitchPrimitive from "@radix-ui/react-switch";

import { cn } from "@/lib/utils";
import { cn } from "@/lib/functions/utils";

function Switch({
className,
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/ui/tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from "react";
import * as TooltipPrimitive from "@radix-ui/react-tooltip";

import { cn } from "@/lib/utils";
import { cn } from "@/lib/functions/utils";

function TooltipProvider({
delayDuration = 0,
Expand Down
25 changes: 24 additions & 1 deletion apps/web/src/lib/functions/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,47 @@ import { authClient } from "../auth-client";
import { PUBLIC_ROUTES } from "shared/constants";
import type { RouterContext } from "../types";
import { redirect } from "@tanstack/react-router";

/**
* Checks if a given pathname is a public route.
* @param pathname - The pathname to check
* @returns True if the pathname is a public route, false otherwise
*/
export function isPublicRoute(pathname: string) {
return PUBLIC_ROUTES.includes(pathname);
}
Comment thread
christianhelp marked this conversation as resolved.

/**
* Checks if a given pathname is a protected route (i.e., not a public route).
* @param pathname - The pathname to check
* @returns True if the pathname is a protected route, false otherwise
*/
export function isProtectedRoute(pathname: string) {
return !isPublicRoute(pathname);
}

/**
* Retrieves the current user session from the authentication client.
* @returns The session data if a user is authenticated, or null if not authenticated
*/
export async function getSession() {
return authClient.getSession();
}

/**
* Signs out the current user.
* @returns An object containing the sign-out data and any error encountered
*/
export async function signOut() {
const { data, error } = await authClient.signOut();
return { data, error };
}

/**
* Redirects the user to a specified path if they are already signed in.
* @param ctx - The router context containing authentication information
* @param to - The path to redirect to if the user is signed in (default is "/")
* @throws A redirect to the specified path if the user is authenticated
*/
export function redirectIfSignedIn(ctx: RouterContext, to: string = "/") {
if (ctx.auth?.data) {
throw redirect({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { queryOptions, mutationOptions } from "@tanstack/react-query";
import { apiClient } from "./api-client";
import { authClient } from "./auth-client";
import { apiClient } from "../api-client";
import { authClient } from "../auth-client";

/**
* A query client for pinging the server to check its health status.
* @returns An object containing the query key and query function for pinging the server.
*/
export const pingServerQueryClient = queryOptions({
queryKey: ["ping"],
queryFn: async () => {
Expand All @@ -16,6 +20,10 @@ export const pingServerQueryClient = queryOptions({
},
});

/**
* A query client for retrieving the current authenticated user's information.
* @returns An object containing the query key and query function for fetching the user data.
*/
export const getUserQueryClient = queryOptions({
queryKey: ["user"],
queryFn: async () => {
Expand All @@ -28,6 +36,10 @@ export const getUserQueryClient = queryOptions({
},
});

/**
* A query client for fetching the teams that the current user belongs to.
* @returns An object containing the query key and query function for retrieving the user's teams.
*/
export const getUserTeamsQueryClient = queryOptions({
queryKey: ["user", "teams"],
queryFn: async () => {
Expand All @@ -39,7 +51,11 @@ export const getUserTeamsQueryClient = queryOptions({
throw new Error("Something went wrong");
},
});

/**
* A mutation client for joining a team using an invite code.
* @param inviteCode - The invite code for the team to join
* @returns An object containing the mutation key and mutation function for joining a team.
*/
export const joinTeamMutationclient = (inviteCode: string) =>
Comment thread
christianhelp marked this conversation as resolved.
Outdated
mutationOptions({
mutationKey: ["team", inviteCode, "join"],
Expand All @@ -59,6 +75,12 @@ export const joinTeamMutationclient = (inviteCode: string) =>
},
});

/**
* A mutation client for leaving a team.
* @param teamId - The ID of the team to leave
* @param userId - The ID of the user leaving the team
* @returns An object containing the mutation key and mutation function for leaving a team.
*/
export const leaveTeamMutationClient = (teamId: string, userId: string) =>
mutationOptions({
mutationKey: ["team", teamId, userId, "remove"],
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion apps/web/src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createFileRoute } from "@tanstack/react-router";
import { APP_NAME } from "shared/constants";
import { Button } from "@/components/ui/button";
import { toast } from "sonner";
import { pingServerQueryClient } from "@/lib/queries";
import { pingServerQueryClient } from "@/lib/functions/queries";
import { useQuery } from "@tanstack/react-query";
import { SignedIn, SignedOut } from "@daveyplate/better-auth-ui";
import { Link } from "@tanstack/react-router";
Expand Down