Invalidate queries

This commit adds the functionality of query invalidation
- when a config is created
- when the calendar options are changed

It also makes it so the calendar doesn't update if the widget is currently being edited
This commit is contained in:
ajnart
2023-05-15 16:20:48 +09:00
parent 92e8d79c5a
commit 3efe18d06f
2 changed files with 12 additions and 3 deletions

View File

@@ -4,6 +4,7 @@ import { useMutation } from '@tanstack/react-query';
import { useTranslation } from 'next-i18next';
import { useConfigContext } from '../../../config/provider';
import { ConfigType } from '../../../types/config';
import { queryClient } from '../../server/configurations/tanstack/queryClient.tool';
export const useCopyConfigMutation = (configName: string) => {
const { config } = useConfigContext();
@@ -14,13 +15,15 @@ export const useCopyConfigMutation = (configName: string) => {
mutationFn: () => fetchCopy(configName, config),
onSuccess() {
showNotification({
title: t('modal.events.configCopied.title'),
title: t('modal.copy.events.configCopied.title'),
icon: <IconCheck />,
color: 'green',
autoClose: 1500,
radius: 'md',
message: t('modal.events.configCopied.message', { configName }),
message: t('modal.copy.events.configCopied.message', { configName }),
});
// Invalidate a query to fetch new config
queryClient.invalidateQueries(['config/get-all']);
},
onError() {
showNotification({