From e071de92487b740dd3607403c3e483dddcb21cd8 Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Sun, 24 May 2026 16:01:50 +0100 Subject: [PATCH] feat(bases): add URL-driven row detail modal hook --- .../base/hooks/use-row-detail-modal.ts | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 apps/client/src/features/base/hooks/use-row-detail-modal.ts diff --git a/apps/client/src/features/base/hooks/use-row-detail-modal.ts b/apps/client/src/features/base/hooks/use-row-detail-modal.ts new file mode 100644 index 000000000..a1741b740 --- /dev/null +++ b/apps/client/src/features/base/hooks/use-row-detail-modal.ts @@ -0,0 +1,26 @@ +import { useCallback } from "react"; +import { useSearchParams } from "react-router-dom"; + +const PARAM = "row"; + +export function useRowDetailModal() { + const [searchParams, setSearchParams] = useSearchParams(); + const openRowId = searchParams.get(PARAM); + + const openRow = useCallback( + (rowId: string) => { + const next = new URLSearchParams(searchParams); + next.set(PARAM, rowId); + setSearchParams(next, { replace: false }); + }, + [searchParams, setSearchParams], + ); + + const closeRow = useCallback(() => { + const next = new URLSearchParams(searchParams); + next.delete(PARAM); + setSearchParams(next, { replace: false }); + }, [searchParams, setSearchParams]); + + return { openRowId, openRow, closeRow }; +}