diff --git a/cypress/e2e/phase_4/annotation.cy.js b/cypress/e2e/phase_4/annotation.cy.js index 27033b61d..d6af571c9 100644 --- a/cypress/e2e/phase_4/annotation.cy.js +++ b/cypress/e2e/phase_4/annotation.cy.js @@ -234,6 +234,9 @@ describe('Annotation', () => { cy.findByText('Annotations').click(); + cy.wait(1000); + cy.findByRole('progressbar').should('not.exist'); + cy.findAllByRole('cell').then((cells) => { const firstUri = cells[0].textContent; const secondUri = cells[14].textContent; diff --git a/src/app/js/admin/annotations/useUpdateAnnotation.js b/src/app/js/admin/annotations/useUpdateAnnotation.js index a0cb3f2a4..d980e3f5d 100644 --- a/src/app/js/admin/annotations/useUpdateAnnotation.js +++ b/src/app/js/admin/annotations/useUpdateAnnotation.js @@ -1,5 +1,5 @@ import { useCallback, useMemo } from 'react'; -import { useMutation } from '@tanstack/react-query'; +import { useMutation, useQueryClient } from '@tanstack/react-query'; import { useTranslate } from '../../i18n/I18NContext'; import { getUserSessionStorageInfo } from '../api/tools'; import { getRequest } from '../../user'; @@ -10,6 +10,7 @@ import fetch from '../../lib/fetch'; export function useUpdateAnnotation() { const { translate } = useTranslate(); const history = useHistory(); + const queryClient = useQueryClient(); const mutation = useMutation({ mutationFn: async ({ id, annotation }) => { @@ -35,13 +36,17 @@ export function useUpdateAnnotation() { return response.data; }, - onSuccess: () => { - toast(translate('annotation_create_success'), { + onSuccess: (data) => { + queryClient.setQueryData(['get-annotation', data._id], data); + queryClient.invalidateQueries({ + predicate: (query) => query.queryKey[0] === 'get-annotations', + }); + toast(translate('annotation_update_success'), { type: toast.TYPE.SUCCESS, }); }, onError: () => { - toast(translate('annotation_create_error'), { + toast(translate('annotation_update_error'), { type: toast.TYPE.ERROR, }); },