Skip to content

Commit

Permalink
Bugfix save custom widget
Browse files Browse the repository at this point in the history
  • Loading branch information
atrincas authored and Andrés González committed Dec 2, 2024
1 parent f14e105 commit 713f701
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
9 changes: 8 additions & 1 deletion client/src/containers/widget/create-widget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,14 @@ const CreateWidgetMenu: FC<CreateWidgetMenuProps> = ({
});
}
},
[session?.accessToken, session?.user.id, toast],
[
session?.accessToken,
session?.user.id,
visualization,
indicator,
filters,
toast,
],
);

if (!session) {
Expand Down
34 changes: 29 additions & 5 deletions client/src/containers/widget/update-widget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ const UpdateWidgetMenu: FC<UpdateWidgetMenuProps> = ({
setOpen(isOpen);
setShowOverlay(isOpen);
};
const invalidateQueries = useCallback(
(widgetId: string) =>
queryClient.invalidateQueries(
queryKeys.users.userChart(widgetId).queryKey,
),
[queryClient],
);

const createWidget = useCallback(
async (name: string) => {
Expand All @@ -70,6 +77,7 @@ const UpdateWidgetMenu: FC<UpdateWidgetMenuProps> = ({
});

if (status === 201) {
invalidateQueries(widgetId);
handleOnOpenChange(false);
toast({
description: (
Expand All @@ -90,7 +98,16 @@ const UpdateWidgetMenu: FC<UpdateWidgetMenuProps> = ({
});
}
},
[visualization, indicator, session?.accessToken, session?.user.id, toast],
[
visualization,
indicator,
filters,
session?.accessToken,
session?.user.id,
toast,
invalidateQueries,
router,
],
);

const updateWidget = useCallback(async () => {
Expand All @@ -110,9 +127,7 @@ const UpdateWidgetMenu: FC<UpdateWidgetMenuProps> = ({
});

if (status === 200) {
queryClient.invalidateQueries(
queryKeys.users.userChart(widgetId).queryKey,
);
invalidateQueries(widgetId);
handleOnOpenChange(false);
toast({
description: "Your chart has been successfully updated",
Expand All @@ -123,7 +138,16 @@ const UpdateWidgetMenu: FC<UpdateWidgetMenuProps> = ({
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 (
<Popover onOpenChange={handleOnOpenChange} open={open}>
Expand Down

0 comments on commit 713f701

Please sign in to comment.