Skip to content

Commit ad7d1fa

Browse files
fix(logs): re-hydrate data-retention form on org switch
The form hydrated once via a boolean ref, so switching the active org left stale retention days + PII rules and saves targeted the new org with old config. Key hydration on orgId so it re-loads per org.
1 parent 0605fcf commit ad7d1fa

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

apps/sim/ee/data-retention/components/data-retention-settings.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,16 @@ export function DataRetentionSettings() {
268268
const [modalOriginal, setModalOriginal] = useState<RuleDraft | null>(null)
269269
const [modalIsNew, setModalIsNew] = useState(false)
270270
const [showUnsaved, setShowUnsaved] = useState(false)
271-
const formInitializedRef = useRef(false)
271+
// Org the form was hydrated for; re-hydrate when the active org switches so
272+
// saves don't target the new org with the previous org's config.
273+
const hydratedOrgRef = useRef<string | null>(null)
272274

273275
function hoursSnapshot(log: string, soft: string, task: string): string {
274276
return JSON.stringify({ log, soft, task })
275277
}
276278

277279
useEffect(() => {
278-
if (!data || formInitializedRef.current) return
280+
if (!data || !orgId || hydratedOrgRef.current === orgId) return
279281
const log = hoursToDisplayDays(data.effective.logRetentionHours)
280282
const soft = hoursToDisplayDays(data.effective.softDeleteRetentionHours)
281283
const task = hoursToDisplayDays(data.effective.taskCleanupHours)
@@ -290,8 +292,8 @@ export function DataRetentionSettings() {
290292
workspaceId: r.workspaceId,
291293
}))
292294
)
293-
formInitializedRef.current = true
294-
}, [data])
295+
hydratedOrgRef.current = orgId
296+
}, [data, orgId])
295297

296298
const hoursChanged = hoursSnapshot(logDays, softDeleteDays, taskCleanupDays) !== savedHours
297299
const modalChanged =

0 commit comments

Comments
 (0)