From 13bff288761599d7ceb9faa16fbd0ab0119c0c26 Mon Sep 17 00:00:00 2001 From: Sonny Date: Sat, 2 Nov 2024 02:52:39 +0100 Subject: [PATCH] fix: disable shortcut when we cant go back to home --- .../common/navigation/back_to_dashboard.tsx | 13 ++++++++++--- .../components/form/mantine_form_collection.tsx | 2 +- .../mantine/components/form/mantine_form_link.tsx | 2 +- .../mantine/layouts/mantine_dashboard_layout.tsx | 8 ++++++++ inertia/mantine/layouts/mantine_form_layout.tsx | 2 +- 5 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 inertia/mantine/layouts/mantine_dashboard_layout.tsx diff --git a/inertia/components/common/navigation/back_to_dashboard.tsx b/inertia/components/common/navigation/back_to_dashboard.tsx index e88d5cd..56bd574 100644 --- a/inertia/components/common/navigation/back_to_dashboard.tsx +++ b/inertia/components/common/navigation/back_to_dashboard.tsx @@ -1,17 +1,24 @@ import { router } from '@inertiajs/react'; import { route } from '@izzyjs/route/client'; -import { ReactNode } from 'react'; +import { PropsWithChildren } from 'react'; import useSearchParam from '~/hooks/use_search_param'; import useShortcut from '~/hooks/use_shortcut'; import { appendCollectionId } from '~/lib/navigation'; -export default function BackToDashboard({ children }: { children: ReactNode }) { +interface BackToDashboardProps extends PropsWithChildren { + disabled?: boolean; +} + +export default function BackToDashboard({ + disabled = false, + children, +}: BackToDashboardProps) { const collectionId = Number(useSearchParam('collectionId')); useShortcut( 'ESCAPE_KEY', () => router.visit(appendCollectionId(route('dashboard').url, collectionId)), - { disableGlobalCheck: true } + { disableGlobalCheck: true, enabled: !disabled } ); return <>{children}; } diff --git a/inertia/mantine/components/form/mantine_form_collection.tsx b/inertia/mantine/components/form/mantine_form_collection.tsx index 13a65e4..a3c8fe6 100644 --- a/inertia/mantine/components/form/mantine_form_collection.tsx +++ b/inertia/mantine/components/form/mantine_form_collection.tsx @@ -42,7 +42,7 @@ export default function MantineFormCollection({ return ( - + - + ( + {children} +); + +export { LayoutWrapper as MantineDashboardLayout }; diff --git a/inertia/mantine/layouts/mantine_form_layout.tsx b/inertia/mantine/layouts/mantine_form_layout.tsx index 656aeb3..4c87a20 100644 --- a/inertia/mantine/layouts/mantine_form_layout.tsx +++ b/inertia/mantine/layouts/mantine_form_layout.tsx @@ -58,7 +58,7 @@ function MantineFormLayout({ width: rem(600), }} > - + <Title order={1} size="h2" c="blue"> {title} {children}