From 1352b47546576e65a7a28eb02613bafde4090b15 Mon Sep 17 00:00:00 2001 From: Joshua Kitenge <83226114+joshuadkitenge@users.noreply.github.com> Date: Thu, 17 Aug 2023 14:36:41 +0100 Subject: [PATCH] address review comments --- src/api/sessions.tsx | 14 ++++ .../sessionDrawer.component.test.tsx.snap | 8 +- .../deleteSessionDialogue.component.test.tsx | 4 - .../deleteSessionDialogue.component.tsx | 13 +--- .../sessionDialogue.component.test.tsx | 6 -- src/session/sessionDialogue.component.tsx | 16 +--- src/session/sessionDrawer.component.test.tsx | 11 ++- src/session/sessionDrawer.component.tsx | 38 ++++------ .../sessionSaveButtons.component.test.tsx | 40 +++++----- src/session/sessionSaveButtons.component.tsx | 74 ++++++++----------- src/views/viewTabs.component.test.tsx | 29 ++++++++ src/views/viewTabs.component.tsx | 57 ++++++-------- 12 files changed, 145 insertions(+), 165 deletions(-) diff --git a/src/api/sessions.tsx b/src/api/sessions.tsx index 1eebf7099..80fe4c9e8 100644 --- a/src/api/sessions.tsx +++ b/src/api/sessions.tsx @@ -4,6 +4,7 @@ import { UseMutationResult, useQuery, UseQueryResult, + useQueryClient, } from '@tanstack/react-query'; import { Session, SessionListItem, SessionResponse } from '../app.types'; import { useAppSelector } from '../state/hooks'; @@ -32,10 +33,14 @@ export const useSaveSession = (): UseMutationResult< Session > => { const { apiUrl } = useAppSelector(selectUrls); + const queryClient = useQueryClient(); return useMutation((session: Session) => saveSession(apiUrl, session), { onError: (error) => { console.log('Got error ' + error.message); }, + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ['sessionList'] }); + }, }); }; @@ -65,12 +70,17 @@ export const useEditSession = (): UseMutationResult< SessionResponse > => { const { apiUrl } = useAppSelector(selectUrls); + const queryClient = useQueryClient(); return useMutation( (session: SessionResponse) => editSession(apiUrl, session), { onError: (error) => { console.log('Got error ' + error.message); }, + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ['sessionList'] }); + queryClient.invalidateQueries({ queryKey: ['session'] }); + }, } ); }; @@ -94,12 +104,16 @@ export const useDeleteSession = (): UseMutationResult< SessionResponse > => { const { apiUrl } = useAppSelector(selectUrls); + const queryClient = useQueryClient(); return useMutation( (session: SessionResponse) => deleteSession(apiUrl, session), { onError: (error) => { console.log('Got error ' + error.message); }, + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ['sessionList'] }); + }, } ); }; diff --git a/src/session/__snapshots__/sessionDrawer.component.test.tsx.snap b/src/session/__snapshots__/sessionDrawer.component.test.tsx.snap index 0bcd7c3f9..17fad4071 100644 --- a/src/session/__snapshots__/sessionDrawer.component.test.tsx.snap +++ b/src/session/__snapshots__/sessionDrawer.component.test.tsx.snap @@ -68,7 +68,7 @@ exports[`session Drawer renders correctly 1`] = `