diff --git a/src/app/(protected)/workorders/_components/detail/use-slide-over-edit-state.ts b/src/app/(protected)/workorders/_components/detail/use-slide-over-edit-state.ts index 28f71e2d..efdaefbf 100644 --- a/src/app/(protected)/workorders/_components/detail/use-slide-over-edit-state.ts +++ b/src/app/(protected)/workorders/_components/detail/use-slide-over-edit-state.ts @@ -77,6 +77,29 @@ function useSlideOverInitialization({ }, [row?.id, editMode]); } +// Re-apply the requested tab on every open, including a second notification for the work order +// already on screen (same row id) where the identity effect does not re-run. Tab-only so an +// in-flight edit draft is never discarded. +function useSlideOverOpenRequestTab({ + row, + editMode, + initialTab, + setTab, + openRequestKey, +}: { + row: WorkOrderTableRow | null; + editMode: boolean; + initialTab: SlideOverTab; + setTab: (tab: SlideOverTab) => void; + openRequestKey: number; +}) { + useEffect(() => { + if (!row) return; + setTab(editMode ? "info" : initialTab); + // eslint-disable-next-line react-hooks/exhaustive-deps -- openRequestKey gates each open + }, [openRequestKey]); +} + export function useSlideOverEditState({ row, editMode, @@ -109,14 +132,7 @@ export function useSlideOverEditState({ setUnsavedIntent, }); - // Re-apply the requested tab on every open, including a second notification for the work order - // already on screen (same row id) where the identity effect above does not re-run. Tab-only so - // an in-flight edit draft is never discarded. - useEffect(() => { - if (!row) return; - setTab(editMode ? "info" : initialTab); - // eslint-disable-next-line react-hooks/exhaustive-deps -- openRequestKey gates each open - }, [openRequestKey]); + useSlideOverOpenRequestTab({ row, editMode, initialTab, setTab, openRequestKey }); const lockStatus = infoSource?.status ?? row?.status; const isInfoLocked = isSlideOverInfoLocked(lockStatus);