From c8a4233054075aa390569e9bf3bd2efce58c478b Mon Sep 17 00:00:00 2001 From: Joe Tannenbaum Date: Wed, 11 Feb 2026 11:25:10 -0500 Subject: [PATCH] Inertia globals (#276) Co-authored-by: WendellAdriel <11641518+WendellAdriel@users.noreply.github.com> Co-authored-by: Arthur Grand --- .npmrc | 1 + resources/js/components/app-header.tsx | 4 ++-- resources/js/components/app-shell.tsx | 3 +-- resources/js/components/nav-user.tsx | 3 +-- resources/js/layouts/auth/auth-split-layout.tsx | 4 ++-- resources/js/pages/settings/profile.tsx | 4 ++-- resources/js/pages/welcome.tsx | 3 +-- resources/js/types/global.d.ts | 12 ++++++++++++ resources/js/types/index.ts | 9 --------- 9 files changed, 22 insertions(+), 21 deletions(-) create mode 100644 .npmrc create mode 100644 resources/js/types/global.d.ts diff --git a/.npmrc b/.npmrc new file mode 100644 index 000000000..2a2592c56 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +public-hoist-pattern[]=@inertiajs/core diff --git a/resources/js/components/app-header.tsx b/resources/js/components/app-header.tsx index 6cada2112..48cf36f5c 100644 --- a/resources/js/components/app-header.tsx +++ b/resources/js/components/app-header.tsx @@ -32,7 +32,7 @@ import { useCurrentUrl } from '@/hooks/use-current-url'; import { useInitials } from '@/hooks/use-initials'; import { cn, toUrl } from '@/lib/utils'; import { dashboard } from '@/routes'; -import type { BreadcrumbItem, NavItem, SharedData } from '@/types'; +import type { BreadcrumbItem, NavItem } from '@/types'; import AppLogo from './app-logo'; import AppLogoIcon from './app-logo-icon'; @@ -65,7 +65,7 @@ const activeItemStyles = 'text-neutral-900 dark:bg-neutral-800 dark:text-neutral-100'; export function AppHeader({ breadcrumbs = [] }: Props) { - const page = usePage(); + const page = usePage(); const { auth } = page.props; const getInitials = useInitials(); const { isCurrentUrl, whenCurrentUrl } = useCurrentUrl(); diff --git a/resources/js/components/app-shell.tsx b/resources/js/components/app-shell.tsx index 37bf9dd98..49dd5acbd 100644 --- a/resources/js/components/app-shell.tsx +++ b/resources/js/components/app-shell.tsx @@ -1,7 +1,6 @@ import { usePage } from '@inertiajs/react'; import type { ReactNode } from 'react'; import { SidebarProvider } from '@/components/ui/sidebar'; -import type { SharedData } from '@/types'; type Props = { children: ReactNode; @@ -9,7 +8,7 @@ type Props = { }; export function AppShell({ children, variant = 'header' }: Props) { - const isOpen = usePage().props.sidebarOpen; + const isOpen = usePage().props.sidebarOpen; if (variant === 'header') { return ( diff --git a/resources/js/components/nav-user.tsx b/resources/js/components/nav-user.tsx index f3470e3d3..4075d17a0 100644 --- a/resources/js/components/nav-user.tsx +++ b/resources/js/components/nav-user.tsx @@ -14,10 +14,9 @@ import { import { UserInfo } from '@/components/user-info'; import { UserMenuContent } from '@/components/user-menu-content'; import { useIsMobile } from '@/hooks/use-mobile'; -import type { SharedData } from '@/types'; export function NavUser() { - const { auth } = usePage().props; + const { auth } = usePage().props; const { state } = useSidebar(); const isMobile = useIsMobile(); diff --git a/resources/js/layouts/auth/auth-split-layout.tsx b/resources/js/layouts/auth/auth-split-layout.tsx index 8cf412460..a567729f3 100644 --- a/resources/js/layouts/auth/auth-split-layout.tsx +++ b/resources/js/layouts/auth/auth-split-layout.tsx @@ -1,14 +1,14 @@ import { Link, usePage } from '@inertiajs/react'; import AppLogoIcon from '@/components/app-logo-icon'; import { home } from '@/routes'; -import type { AuthLayoutProps, SharedData } from '@/types'; +import type { AuthLayoutProps } from '@/types'; export default function AuthSplitLayout({ children, title, description, }: AuthLayoutProps) { - const { name } = usePage().props; + const { name } = usePage().props; return (
diff --git a/resources/js/pages/settings/profile.tsx b/resources/js/pages/settings/profile.tsx index ebab68171..c369fe139 100644 --- a/resources/js/pages/settings/profile.tsx +++ b/resources/js/pages/settings/profile.tsx @@ -11,7 +11,7 @@ import AppLayout from '@/layouts/app-layout'; import SettingsLayout from '@/layouts/settings/layout'; import { edit } from '@/routes/profile'; import { send } from '@/routes/verification'; -import type { BreadcrumbItem, SharedData } from '@/types'; +import type { BreadcrumbItem } from '@/types'; const breadcrumbs: BreadcrumbItem[] = [ { @@ -27,7 +27,7 @@ export default function Profile({ mustVerifyEmail: boolean; status?: string; }) { - const { auth } = usePage().props; + const { auth } = usePage().props; return ( diff --git a/resources/js/pages/welcome.tsx b/resources/js/pages/welcome.tsx index b6425dbf3..e3911d2ab 100644 --- a/resources/js/pages/welcome.tsx +++ b/resources/js/pages/welcome.tsx @@ -1,13 +1,12 @@ import { Head, Link, usePage } from '@inertiajs/react'; import { dashboard, login, register } from '@/routes'; -import type { SharedData } from '@/types'; export default function Welcome({ canRegister = true, }: { canRegister?: boolean; }) { - const { auth } = usePage().props; + const { auth } = usePage().props; return ( <> diff --git a/resources/js/types/global.d.ts b/resources/js/types/global.d.ts new file mode 100644 index 000000000..bd4459ee3 --- /dev/null +++ b/resources/js/types/global.d.ts @@ -0,0 +1,12 @@ +import type { Auth } from '@/types/auth'; + +declare module '@inertiajs/core' { + export interface InertiaConfig { + sharedPageProps: { + name: string; + auth: Auth; + sidebarOpen: boolean; + [key: string]: unknown; + }; + } +} diff --git a/resources/js/types/index.ts b/resources/js/types/index.ts index 93cefe73b..b1f0ee68c 100644 --- a/resources/js/types/index.ts +++ b/resources/js/types/index.ts @@ -1,12 +1,3 @@ export type * from './auth'; export type * from './navigation'; export type * from './ui'; - -import type { Auth } from './auth'; - -export type SharedData = { - name: string; - auth: Auth; - sidebarOpen: boolean; - [key: string]: unknown; -};