diff --git a/client/src/containers/widget/create-widget/index.tsx b/client/src/containers/widget/create-widget/index.tsx index c0226da8..109e28b5 100644 --- a/client/src/containers/widget/create-widget/index.tsx +++ b/client/src/containers/widget/create-widget/index.tsx @@ -80,7 +80,14 @@ const CreateWidgetMenu: FC = ({ }); } }, - [session?.accessToken, session?.user.id, toast], + [ + session?.accessToken, + session?.user.id, + visualization, + indicator, + filters, + toast, + ], ); if (!session) { diff --git a/client/src/containers/widget/update-widget/index.tsx b/client/src/containers/widget/update-widget/index.tsx index a8616f01..5f0d674e 100644 --- a/client/src/containers/widget/update-widget/index.tsx +++ b/client/src/containers/widget/update-widget/index.tsx @@ -49,6 +49,13 @@ const UpdateWidgetMenu: FC = ({ setOpen(isOpen); setShowOverlay(isOpen); }; + const invalidateQueries = useCallback( + (widgetId: string) => + queryClient.invalidateQueries( + queryKeys.users.userChart(widgetId).queryKey, + ), + [queryClient], + ); const createWidget = useCallback( async (name: string) => { @@ -70,6 +77,7 @@ const UpdateWidgetMenu: FC = ({ }); if (status === 201) { + invalidateQueries(widgetId); handleOnOpenChange(false); toast({ description: ( @@ -90,7 +98,16 @@ const UpdateWidgetMenu: FC = ({ }); } }, - [visualization, indicator, session?.accessToken, session?.user.id, toast], + [ + visualization, + indicator, + filters, + session?.accessToken, + session?.user.id, + toast, + invalidateQueries, + router, + ], ); const updateWidget = useCallback(async () => { @@ -110,9 +127,7 @@ const UpdateWidgetMenu: FC = ({ }); if (status === 200) { - queryClient.invalidateQueries( - queryKeys.users.userChart(widgetId).queryKey, - ); + invalidateQueries(widgetId); handleOnOpenChange(false); toast({ description: "Your chart has been successfully updated", @@ -123,7 +138,16 @@ const UpdateWidgetMenu: FC = ({ description: "Something went wrong updating the widget.", }); } - }, [session?.accessToken, session?.user.id, toast]); + }, [ + widgetId, + visualization, + indicator, + filters, + session?.accessToken, + session?.user.id, + toast, + invalidateQueries, + ]); return (