diff --git a/packages/manager/src/hooks/useEventHandlers.ts b/packages/manager/src/hooks/useEventHandlers.ts index dc674252841..659bec203e9 100644 --- a/packages/manager/src/hooks/useEventHandlers.ts +++ b/packages/manager/src/hooks/useEventHandlers.ts @@ -15,6 +15,7 @@ import { volumeEventsHandler } from 'src/queries/volumes'; import type { Event } from '@linode/api-v4'; import type { QueryClient } from '@tanstack/react-query'; +import { stackScriptEventHandler } from 'src/queries/stackscripts'; export interface EventHandlerData { event: Event; @@ -76,6 +77,10 @@ export const eventHandlers: { filter: (event) => event.action.startsWith('disk'), handler: diskEventHandler, }, + { + filter: (event) => event.action.startsWith('stackscript'), + handler: stackScriptEventHandler, + }, ]; export const useEventHandlers = () => { diff --git a/packages/manager/src/queries/stackscripts.ts b/packages/manager/src/queries/stackscripts.ts index b2eb2159179..5799751d14b 100644 --- a/packages/manager/src/queries/stackscripts.ts +++ b/packages/manager/src/queries/stackscripts.ts @@ -13,6 +13,7 @@ import { createQueryKeys } from '@lukemorales/query-key-factory'; import { useInfiniteQuery, useQuery } from '@tanstack/react-query'; import { getOneClickApps } from 'src/features/StackScripts/stackScriptUtils'; +import { EventHandlerData } from 'src/hooks/useEventHandlers'; import { getAll } from 'src/utilities/getAll'; import { queryPresets } from './base'; @@ -66,3 +67,18 @@ export const useStackScriptsInfiniteQuery = ( return page + 1; }, }); + +export const stackScriptEventHandler = ({ + event, + queryClient, +}: EventHandlerData) => { + // Keep the infinite store up to date + queryClient.invalidateQueries(stackscriptQueries.infinite._def); + + // If the event has a StackScript entity attached, invalidate it + if (event.entity?.id) { + queryClient.invalidateQueries( + stackscriptQueries.stackscript(event.entity.id).queryKey + ); + } +};