diff --git a/packages/admin-panel/package.json b/packages/admin-panel/package.json
index 263d09a98c..53a680437c 100644
--- a/packages/admin-panel/package.json
+++ b/packages/admin-panel/package.json
@@ -31,6 +31,8 @@
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "^4.0.0-alpha.47",
"@material-ui/styles": "^4.9.10",
+ "@tanstack/react-query": "4.36.1",
+ "@tanstack/react-query-devtools": "4.36.1",
"@tupaia/access-policy": "workspace:*",
"@tupaia/types": "workspace:*",
"@tupaia/ui-chart-components": "workspace:*",
@@ -64,7 +66,6 @@
"react-hook-form": "^6.8.3",
"react-icons": "^2.2.7",
"react-password-strength-bar": "^0.3.2",
- "react-query": "^3.19.0",
"react-redux": "^5.0.6",
"react-router": "6.3.0",
"react-router-dom": "6.3.0",
diff --git a/packages/admin-panel/src/VizBuilderApp/api/mutations/useExportDashboardVisualisation.js b/packages/admin-panel/src/VizBuilderApp/api/mutations/useExportDashboardVisualisation.js
index 20f2d44719..ef43c59be4 100644
--- a/packages/admin-panel/src/VizBuilderApp/api/mutations/useExportDashboardVisualisation.js
+++ b/packages/admin-panel/src/VizBuilderApp/api/mutations/useExportDashboardVisualisation.js
@@ -1,9 +1,9 @@
/**
* Tupaia
- * Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
+ * Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useMutation } from 'react-query';
+import { useMutation } from '@tanstack/react-query';
import { download } from '../api';
export const useExportDashboardVisualisation = config =>
diff --git a/packages/admin-panel/src/VizBuilderApp/api/mutations/useExportMapOverlayVisualisation.js b/packages/admin-panel/src/VizBuilderApp/api/mutations/useExportMapOverlayVisualisation.js
index 316bbfa554..9f06a33aae 100644
--- a/packages/admin-panel/src/VizBuilderApp/api/mutations/useExportMapOverlayVisualisation.js
+++ b/packages/admin-panel/src/VizBuilderApp/api/mutations/useExportMapOverlayVisualisation.js
@@ -1,9 +1,9 @@
/**
* Tupaia
- * Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
+ * Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useMutation } from 'react-query';
+import { useMutation } from '@tanstack/react-query';
import { download } from '../api';
export const useExportMapOverlayVisualisation = config =>
diff --git a/packages/admin-panel/src/VizBuilderApp/api/mutations/useSaveDashboardVisualisation.js b/packages/admin-panel/src/VizBuilderApp/api/mutations/useSaveDashboardVisualisation.js
index aba4f7aa28..e8583ac6d5 100644
--- a/packages/admin-panel/src/VizBuilderApp/api/mutations/useSaveDashboardVisualisation.js
+++ b/packages/admin-panel/src/VizBuilderApp/api/mutations/useSaveDashboardVisualisation.js
@@ -1,9 +1,9 @@
/*
* Tupaia
- * Copyright (c) 2017 - 20211Beyond Essential Systems Pty Ltd
+ * Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*
*/
-import { useMutation } from 'react-query';
+import { useMutation } from '@tanstack/react-query';
import { post, put } from '../api';
export const useSaveDashboardVisualisation = config =>
diff --git a/packages/admin-panel/src/VizBuilderApp/api/mutations/useSaveMapOverlayVisualisation.js b/packages/admin-panel/src/VizBuilderApp/api/mutations/useSaveMapOverlayVisualisation.js
index 0918d41436..2f11d3b941 100644
--- a/packages/admin-panel/src/VizBuilderApp/api/mutations/useSaveMapOverlayVisualisation.js
+++ b/packages/admin-panel/src/VizBuilderApp/api/mutations/useSaveMapOverlayVisualisation.js
@@ -1,9 +1,9 @@
/*
* Tupaia
- * Copyright (c) 2017 - 20211Beyond Essential Systems Pty Ltd
+ * Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*
*/
-import { useMutation } from 'react-query';
+import { useMutation } from '@tanstack/react-query';
import { post, put } from '../api';
export const useSaveMapOverlayVisualisation = config =>
diff --git a/packages/admin-panel/src/VizBuilderApp/api/mutations/useUploadTestData.js b/packages/admin-panel/src/VizBuilderApp/api/mutations/useUploadTestData.js
index 388a822c5c..678c5a14a0 100644
--- a/packages/admin-panel/src/VizBuilderApp/api/mutations/useUploadTestData.js
+++ b/packages/admin-panel/src/VizBuilderApp/api/mutations/useUploadTestData.js
@@ -1,13 +1,13 @@
/**
* Tupaia
- * Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
+ * Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useMutation } from 'react-query';
+import { useMutation } from '@tanstack/react-query';
import { upload } from '../api';
// Must match the file name expected by the back-end
const FILE_NAME = 'testData';
export const useUploadTestData = () =>
- useMutation('uploadTestData', file => upload('uploadTestData', {}, FILE_NAME, file));
+ useMutation(['uploadTestData'], file => upload('uploadTestData', {}, FILE_NAME, file));
diff --git a/packages/admin-panel/src/VizBuilderApp/api/queries/useCountries.js b/packages/admin-panel/src/VizBuilderApp/api/queries/useCountries.js
index df232bb419..11070e5536 100644
--- a/packages/admin-panel/src/VizBuilderApp/api/queries/useCountries.js
+++ b/packages/admin-panel/src/VizBuilderApp/api/queries/useCountries.js
@@ -1,8 +1,8 @@
/*
* Tupaia
- * Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
+ * Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { get } from '../api';
import { DEFAULT_REACT_QUERY_OPTIONS } from '../constants';
diff --git a/packages/admin-panel/src/VizBuilderApp/api/queries/useDashboardVisualisation.js b/packages/admin-panel/src/VizBuilderApp/api/queries/useDashboardVisualisation.js
index 2c2d5d90e1..987bfb6047 100644
--- a/packages/admin-panel/src/VizBuilderApp/api/queries/useDashboardVisualisation.js
+++ b/packages/admin-panel/src/VizBuilderApp/api/queries/useDashboardVisualisation.js
@@ -1,9 +1,9 @@
/*
* Tupaia
- * Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
+ * Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { get } from '../api';
import { DEFAULT_REACT_QUERY_OPTIONS } from '../constants';
diff --git a/packages/admin-panel/src/VizBuilderApp/api/queries/useEntities.js b/packages/admin-panel/src/VizBuilderApp/api/queries/useEntities.js
index ee6fc40413..6850135457 100644
--- a/packages/admin-panel/src/VizBuilderApp/api/queries/useEntities.js
+++ b/packages/admin-panel/src/VizBuilderApp/api/queries/useEntities.js
@@ -1,8 +1,8 @@
/**
* Tupaia
- * Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
+ * Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { stringifyQuery } from '@tupaia/utils';
import { get } from '../api';
import { DEFAULT_REACT_QUERY_OPTIONS } from '../constants';
diff --git a/packages/admin-panel/src/VizBuilderApp/api/queries/useLocations.js b/packages/admin-panel/src/VizBuilderApp/api/queries/useLocations.js
index 8da34e1367..516bea7b73 100644
--- a/packages/admin-panel/src/VizBuilderApp/api/queries/useLocations.js
+++ b/packages/admin-panel/src/VizBuilderApp/api/queries/useLocations.js
@@ -1,9 +1,9 @@
/*
* Tupaia
- * Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
+ * Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
import { useEffect } from 'react';
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import debounce from 'lodash.debounce';
import { get } from '../api';
diff --git a/packages/admin-panel/src/VizBuilderApp/api/queries/useMapOverlayVisualisation.js b/packages/admin-panel/src/VizBuilderApp/api/queries/useMapOverlayVisualisation.js
index 017db2e280..8bf50b3e92 100644
--- a/packages/admin-panel/src/VizBuilderApp/api/queries/useMapOverlayVisualisation.js
+++ b/packages/admin-panel/src/VizBuilderApp/api/queries/useMapOverlayVisualisation.js
@@ -1,9 +1,9 @@
/*
* Tupaia
- * Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
+ * Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { get } from '../api';
import { DEFAULT_REACT_QUERY_OPTIONS } from '../constants';
diff --git a/packages/admin-panel/src/VizBuilderApp/api/queries/useMapOverlays.js b/packages/admin-panel/src/VizBuilderApp/api/queries/useMapOverlays.js
index 537eb85e88..f4b4b99ba1 100644
--- a/packages/admin-panel/src/VizBuilderApp/api/queries/useMapOverlays.js
+++ b/packages/admin-panel/src/VizBuilderApp/api/queries/useMapOverlays.js
@@ -1,13 +1,13 @@
/*
* Tupaia
- * Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
+ * Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { get } from '../api';
import { DEFAULT_REACT_QUERY_OPTIONS } from '../constants';
export const useMapOverlays = () =>
- useQuery('mapOverlays', () => get('mapOverlays'), {
+ useQuery(['mapOverlays'], () => get('mapOverlays'), {
...DEFAULT_REACT_QUERY_OPTIONS,
});
diff --git a/packages/admin-panel/src/VizBuilderApp/api/queries/useProject.js b/packages/admin-panel/src/VizBuilderApp/api/queries/useProject.js
index f53c96a304..34eb087cbe 100644
--- a/packages/admin-panel/src/VizBuilderApp/api/queries/useProject.js
+++ b/packages/admin-panel/src/VizBuilderApp/api/queries/useProject.js
@@ -2,7 +2,7 @@
* Tupaia
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { stringifyQuery } from '@tupaia/utils';
diff --git a/packages/admin-panel/src/VizBuilderApp/api/queries/useProjects.js b/packages/admin-panel/src/VizBuilderApp/api/queries/useProjects.js
index e8166ace2b..1c22dbc202 100644
--- a/packages/admin-panel/src/VizBuilderApp/api/queries/useProjects.js
+++ b/packages/admin-panel/src/VizBuilderApp/api/queries/useProjects.js
@@ -1,8 +1,8 @@
/*
* Tupaia
- * Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
+ * Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { stringifyQuery } from '@tupaia/utils';
@@ -11,7 +11,7 @@ import { DEFAULT_REACT_QUERY_OPTIONS } from '../constants';
export const useProjects = columns =>
useQuery(
- 'projects',
+ ['projects'],
async () => {
const defaultColumns = ['project.code', 'entity.name'];
const endpoint = stringifyQuery(undefined, 'projects', {
diff --git a/packages/admin-panel/src/VizBuilderApp/api/queries/useReportPreview.js b/packages/admin-panel/src/VizBuilderApp/api/queries/useReportPreview.js
index 8aecefc140..c8187bab2b 100644
--- a/packages/admin-panel/src/VizBuilderApp/api/queries/useReportPreview.js
+++ b/packages/admin-panel/src/VizBuilderApp/api/queries/useReportPreview.js
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
*/
import moment from 'moment';
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { post } from '../api';
import { DEFAULT_REACT_QUERY_OPTIONS } from '../constants';
diff --git a/packages/admin-panel/src/VizBuilderApp/api/queries/useSearchPermissionGroups.js b/packages/admin-panel/src/VizBuilderApp/api/queries/useSearchPermissionGroups.js
index 85d044e737..e8920cc2fb 100644
--- a/packages/admin-panel/src/VizBuilderApp/api/queries/useSearchPermissionGroups.js
+++ b/packages/admin-panel/src/VizBuilderApp/api/queries/useSearchPermissionGroups.js
@@ -1,9 +1,9 @@
/*
* Tupaia
- * Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
+ * Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
import { stringifyQuery } from '@tupaia/utils';
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { get } from '../api';
import { DEFAULT_REACT_QUERY_OPTIONS } from '../constants';
diff --git a/packages/admin-panel/src/VizBuilderApp/api/queries/useSearchTransformSchemas.js b/packages/admin-panel/src/VizBuilderApp/api/queries/useSearchTransformSchemas.js
index 3f795b9c7d..9095ca1439 100644
--- a/packages/admin-panel/src/VizBuilderApp/api/queries/useSearchTransformSchemas.js
+++ b/packages/admin-panel/src/VizBuilderApp/api/queries/useSearchTransformSchemas.js
@@ -1,9 +1,9 @@
/*
* Tupaia
- * Copyright (c) 2017 - 2022 Beyond Essential Systems Pty Ltd
+ * Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
import { stringifyQuery } from '@tupaia/utils';
-import { useQuery, QueryClient } from 'react-query';
+import { useQuery, QueryClient } from '@tanstack/react-query';
import { get } from '../api';
import { DEFAULT_REACT_QUERY_OPTIONS } from '../constants';
diff --git a/packages/admin-panel/src/api/mutations/useEditSurveyResponse.js b/packages/admin-panel/src/api/mutations/useEditSurveyResponse.js
index e542311339..5de1e29fb2 100644
--- a/packages/admin-panel/src/api/mutations/useEditSurveyResponse.js
+++ b/packages/admin-panel/src/api/mutations/useEditSurveyResponse.js
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useMutation, useQueryClient } from 'react-query';
+import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useApiContext } from '../../utilities/ApiProvider';
export const useEditSurveyResponse = (surveyResponseId, updatedSurveyResponse) => {
diff --git a/packages/admin-panel/src/api/mutations/useLogin.js b/packages/admin-panel/src/api/mutations/useLogin.js
index 1644725b17..63cdf6d9cd 100644
--- a/packages/admin-panel/src/api/mutations/useLogin.js
+++ b/packages/admin-panel/src/api/mutations/useLogin.js
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useMutation, useQueryClient } from 'react-query';
+import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useLocation, useNavigate } from 'react-router-dom';
import { post } from '../../VizBuilderApp/api';
diff --git a/packages/admin-panel/src/api/mutations/useLogout.js b/packages/admin-panel/src/api/mutations/useLogout.js
index 0479bcb937..acf5256f7a 100644
--- a/packages/admin-panel/src/api/mutations/useLogout.js
+++ b/packages/admin-panel/src/api/mutations/useLogout.js
@@ -3,13 +3,13 @@
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useMutation, useQueryClient } from 'react-query';
+import { useMutation, useQueryClient } from '@tanstack/react-query';
import { post } from '../../VizBuilderApp/api';
export const useLogout = onSuccess => {
const queryClient = useQueryClient();
- return useMutation('logout', () => post('logout'), {
+ return useMutation(['logout'], () => post('logout'), {
onSuccess: () => {
queryClient.invalidateQueries();
if (onSuccess) onSuccess();
diff --git a/packages/admin-panel/src/api/mutations/useOneTimeLogin.js b/packages/admin-panel/src/api/mutations/useOneTimeLogin.js
index c3989ab853..e942352658 100644
--- a/packages/admin-panel/src/api/mutations/useOneTimeLogin.js
+++ b/packages/admin-panel/src/api/mutations/useOneTimeLogin.js
@@ -1,9 +1,9 @@
/*
* Tupaia
- * Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
+ * Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useMutation, useQueryClient } from 'react-query';
+import { useMutation, useQueryClient } from '@tanstack/react-query';
import { post } from '../../VizBuilderApp/api';
export const useOneTimeLogin = () => {
diff --git a/packages/admin-panel/src/api/mutations/useRequestResetPassword.js b/packages/admin-panel/src/api/mutations/useRequestResetPassword.js
index 20fe926659..222e460642 100644
--- a/packages/admin-panel/src/api/mutations/useRequestResetPassword.js
+++ b/packages/admin-panel/src/api/mutations/useRequestResetPassword.js
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useMutation } from 'react-query';
+import { useMutation } from '@tanstack/react-query';
import { post } from '../../VizBuilderApp/api';
export const useRequestResetPassword = () => {
diff --git a/packages/admin-panel/src/api/mutations/useResetPassword.js b/packages/admin-panel/src/api/mutations/useResetPassword.js
index 887a039120..9b2bfae7e8 100644
--- a/packages/admin-panel/src/api/mutations/useResetPassword.js
+++ b/packages/admin-panel/src/api/mutations/useResetPassword.js
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useMutation } from 'react-query';
+import { useMutation } from '@tanstack/react-query';
import { useLocation, useNavigate, useSearchParams } from 'react-router-dom';
import { post } from '../../VizBuilderApp/api';
import { PASSWORD_RESET_TOKEN_PARAM } from '../../authentication';
diff --git a/packages/admin-panel/src/api/mutations/useUpdateProfile.js b/packages/admin-panel/src/api/mutations/useUpdateProfile.js
index f5f67d0654..16252568fd 100644
--- a/packages/admin-panel/src/api/mutations/useUpdateProfile.js
+++ b/packages/admin-panel/src/api/mutations/useUpdateProfile.js
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useMutation, useQueryClient } from 'react-query';
+import { useMutation, useQueryClient } from '@tanstack/react-query';
import { put } from '../../VizBuilderApp/api';
export const useUpdateProfile = () => {
diff --git a/packages/admin-panel/src/api/queries/useResourceDetails.js b/packages/admin-panel/src/api/queries/useResourceDetails.js
index 2fe9813af3..deaabec3c1 100644
--- a/packages/admin-panel/src/api/queries/useResourceDetails.js
+++ b/packages/admin-panel/src/api/queries/useResourceDetails.js
@@ -1,8 +1,8 @@
/**
* Tupaia
- * Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
+ * Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { get } from '../../VizBuilderApp/api/api';
export const useItemDetails = (params, parent) => {
diff --git a/packages/admin-panel/src/api/queries/useSurveyResponses.js b/packages/admin-panel/src/api/queries/useSurveyResponses.js
index 1a533faa0b..d0a7ab0bb8 100644
--- a/packages/admin-panel/src/api/queries/useSurveyResponses.js
+++ b/packages/admin-panel/src/api/queries/useSurveyResponses.js
@@ -1,8 +1,8 @@
/**
* Tupaia
- * Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
+ * Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { get } from '../../VizBuilderApp/api/api';
import { DEFAULT_REACT_QUERY_OPTIONS } from '../../VizBuilderApp/api/constants';
diff --git a/packages/admin-panel/src/api/queries/useUser.js b/packages/admin-panel/src/api/queries/useUser.js
index 6ba99258dd..9aa6103bc3 100644
--- a/packages/admin-panel/src/api/queries/useUser.js
+++ b/packages/admin-panel/src/api/queries/useUser.js
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { get } from '../../VizBuilderApp/api';
export const useUser = () => {
diff --git a/packages/admin-panel/src/dataTables/query/useDataTablePreview.js b/packages/admin-panel/src/dataTables/query/useDataTablePreview.js
index f4eac23ae6..430beb7de0 100644
--- a/packages/admin-panel/src/dataTables/query/useDataTablePreview.js
+++ b/packages/admin-panel/src/dataTables/query/useDataTablePreview.js
@@ -1,8 +1,8 @@
/*
* Tupaia
- * Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
+ * Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { post } from '../../VizBuilderApp/api/api';
import { DEFAULT_REACT_QUERY_OPTIONS } from '../../VizBuilderApp/api/constants';
diff --git a/packages/admin-panel/src/dataTables/query/useExternalDatabaseConnections.js b/packages/admin-panel/src/dataTables/query/useExternalDatabaseConnections.js
index 1d82f1d044..13a4a902ab 100644
--- a/packages/admin-panel/src/dataTables/query/useExternalDatabaseConnections.js
+++ b/packages/admin-panel/src/dataTables/query/useExternalDatabaseConnections.js
@@ -1,8 +1,8 @@
/*
* Tupaia
- * Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
+ * Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { get } from '../../VizBuilderApp/api/api';
import { DEFAULT_REACT_QUERY_OPTIONS } from '../../VizBuilderApp/api/constants';
diff --git a/packages/admin-panel/src/dataTables/query/useFetchDataTableBuiltInParams.js b/packages/admin-panel/src/dataTables/query/useFetchDataTableBuiltInParams.js
index ea43c3457c..9617b2d77a 100644
--- a/packages/admin-panel/src/dataTables/query/useFetchDataTableBuiltInParams.js
+++ b/packages/admin-panel/src/dataTables/query/useFetchDataTableBuiltInParams.js
@@ -1,8 +1,8 @@
/*
* Tupaia
- * Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
+ * Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { get } from '../../VizBuilderApp/api/api';
import { DEFAULT_REACT_QUERY_OPTIONS } from '../../VizBuilderApp/api/constants';
diff --git a/packages/admin-panel/src/main.jsx b/packages/admin-panel/src/main.jsx
index 892485f594..d36538f916 100644
--- a/packages/admin-panel/src/main.jsx
+++ b/packages/admin-panel/src/main.jsx
@@ -1,9 +1,9 @@
/*
* Tupaia
- * Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
+ * Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
import React, { lazy, Suspense } from 'react';
-import { QueryClient, QueryClientProvider } from 'react-query';
+import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';
import { render as renderReactApp } from 'react-dom';
import styled, { ThemeProvider } from 'styled-components';
diff --git a/packages/admin-panel/src/pages/resources/PermissionGroupsViewerPage.jsx b/packages/admin-panel/src/pages/resources/PermissionGroupsViewerPage.jsx
index 7ec409c92b..630e739569 100644
--- a/packages/admin-panel/src/pages/resources/PermissionGroupsViewerPage.jsx
+++ b/packages/admin-panel/src/pages/resources/PermissionGroupsViewerPage.jsx
@@ -5,7 +5,7 @@
import React from 'react';
import styled from 'styled-components';
import { HorizontalTree } from '@tupaia/ui-components';
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { PageHeader, PageBody } from '../../widgets';
import { LogsModal } from '../../logsTable';
import { get } from '../../VizBuilderApp/api';
diff --git a/packages/admin-panel/src/surveyResponse/useGetExistingData.js b/packages/admin-panel/src/surveyResponse/useGetExistingData.js
index 9b52d5ee22..180d37e5cd 100644
--- a/packages/admin-panel/src/surveyResponse/useGetExistingData.js
+++ b/packages/admin-panel/src/surveyResponse/useGetExistingData.js
@@ -4,7 +4,7 @@
* Tupaia
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { get } from '../VizBuilderApp/api/api';
import { DEFAULT_REACT_QUERY_OPTIONS } from '../VizBuilderApp/api/constants';
diff --git a/packages/admin-panel/src/surveys/useSuggestSurveyCode.js b/packages/admin-panel/src/surveys/useSuggestSurveyCode.js
index dee1e5c239..dc76e51c64 100644
--- a/packages/admin-panel/src/surveys/useSuggestSurveyCode.js
+++ b/packages/admin-panel/src/surveys/useSuggestSurveyCode.js
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
/**
* @param {TupaiaApi} api
diff --git a/packages/admin-panel/src/utilities/StoreProvider.jsx b/packages/admin-panel/src/utilities/StoreProvider.jsx
index 2344ca544d..94006be40f 100644
--- a/packages/admin-panel/src/utilities/StoreProvider.jsx
+++ b/packages/admin-panel/src/utilities/StoreProvider.jsx
@@ -1,14 +1,14 @@
/*
* Tupaia
- * Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
+ * Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
import React from 'react';
import PropTypes from 'prop-types';
import { createStore, applyMiddleware, compose } from 'redux';
import { Provider } from 'react-redux';
-import { QueryClient, QueryClientProvider } from 'react-query';
-import { ReactQueryDevtools } from 'react-query/devtools';
+import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
+import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import thunk from 'redux-thunk';
import { rootReducer } from '../rootReducer';
diff --git a/packages/admin-panel/src/widgets/InputField/CheckboxListField.jsx b/packages/admin-panel/src/widgets/InputField/CheckboxListField.jsx
index 7c2fd144b5..86d1911825 100644
--- a/packages/admin-panel/src/widgets/InputField/CheckboxListField.jsx
+++ b/packages/admin-panel/src/widgets/InputField/CheckboxListField.jsx
@@ -5,7 +5,7 @@
import React, { useMemo, useState } from 'react';
import PropTypes from 'prop-types';
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import styled from 'styled-components';
import {
FormControl as MuiFormControl,
diff --git a/packages/central-server/src/dhis/pushLatest.js b/packages/central-server/src/dhis/pushLatest.js
index b06cb4b31d..ed3c00b5af 100644
--- a/packages/central-server/src/dhis/pushLatest.js
+++ b/packages/central-server/src/dhis/pushLatest.js
@@ -19,6 +19,7 @@ export async function pushLatest(models, syncQueue, dataBroker, batchSize) {
if (successfullyPushed) {
await syncQueue.use(change);
} else {
+ await syncQueue.registerBadRequest(change);
await syncQueue.deprioritise(change);
}
}
diff --git a/packages/central-server/src/dhis/pushers/entity/TrackedEntityPusher.js b/packages/central-server/src/dhis/pushers/entity/TrackedEntityPusher.js
index de63b1fb12..f6d1eb38ca 100644
--- a/packages/central-server/src/dhis/pushers/entity/TrackedEntityPusher.js
+++ b/packages/central-server/src/dhis/pushers/entity/TrackedEntityPusher.js
@@ -74,6 +74,10 @@ export class TrackedEntityPusher extends EntityPusher {
filter: { displayName: this.entityToTypeName(entity) },
});
+ if (!trackedEntityType) {
+ throw new Error(`Tracked entity type not found for ${type}`);
+ }
+
return trackedEntityType.id;
}
diff --git a/packages/central-server/src/externalApiSync/ExternalApiSyncQueue.js b/packages/central-server/src/externalApiSync/ExternalApiSyncQueue.js
index 113c243e79..1ca59e2fbe 100644
--- a/packages/central-server/src/externalApiSync/ExternalApiSyncQueue.js
+++ b/packages/central-server/src/externalApiSync/ExternalApiSyncQueue.js
@@ -165,11 +165,11 @@ export class ExternalApiSyncQueue {
}
registerBadRequest(change) {
- // Update also causes change_time to be reset to current time
- // so it will slot in at the back of its new priority group
+ // If the bad request count is over the limit, mark it as a dead letter
if (change.bad_request_count > BAD_REQUEST_LIMIT) {
return this.syncQueueModel.updateById(change.id, { is_dead_letter: true });
- } // Cap the priority
+ }
+ // Otherwise, increment the bad request count
return this.syncQueueModel.updateById(change.id, {
bad_request_count: change.bad_request_count + 1,
});
diff --git a/packages/datatrak-web/package.json b/packages/datatrak-web/package.json
index 1cbea0f9e2..04af35655d 100644
--- a/packages/datatrak-web/package.json
+++ b/packages/datatrak-web/package.json
@@ -15,6 +15,8 @@
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "^4.0.0-alpha.57",
"@material-ui/styles": "^4.9.10",
+ "@tanstack/react-query": "4.36.1",
+ "@testing-library/react-hooks": "^8.0.1",
"@tupaia/expression-parser": "workspace:*",
"@tupaia/types": "workspace:*",
"@tupaia/ui-components": "workspace:*",
@@ -32,7 +34,6 @@
"react-dom": "^16.13.1",
"react-hook-form": "^6.15.1",
"react-leaflet": "^3.2.1",
- "react-query": "^3.39.3",
"react-router": "6.3.0",
"react-router-dom": "6.3.0",
"styled-components": "^5.1.0",
diff --git a/packages/datatrak-web/src/AppProviders.tsx b/packages/datatrak-web/src/AppProviders.tsx
index 2823f853be..fc98ee1f4f 100755
--- a/packages/datatrak-web/src/AppProviders.tsx
+++ b/packages/datatrak-web/src/AppProviders.tsx
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
import React, { ReactNode } from 'react';
-import { MutationCache, QueryCache, QueryClient, QueryClientProvider } from 'react-query';
+import { MutationCache, QueryCache, QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ThemeProvider as MuiThemeProvider, StylesProvider } from '@material-ui/core/styles';
import CssBaseline from '@material-ui/core/CssBaseline';
import { ThemeProvider } from 'styled-components';
diff --git a/packages/datatrak-web/src/__tests__/features/Reports/Reports.test.tsx b/packages/datatrak-web/src/__tests__/features/Reports/Reports.test.tsx
index b497ec1b3f..8354dad3ed 100644
--- a/packages/datatrak-web/src/__tests__/features/Reports/Reports.test.tsx
+++ b/packages/datatrak-web/src/__tests__/features/Reports/Reports.test.tsx
@@ -184,10 +184,10 @@ describe('Reports', () => {
);
renderComponent();
await userEvent.click(await screen.findByPlaceholderText('Select survey...'));
- await userEvent.click(screen.getByText('Basic clinic data - Demo Land'));
+ await userEvent.click(await screen.findByText('Basic clinic data - Demo Land'));
await userEvent.click(await screen.findByLabelText('Country'));
- await userEvent.click(screen.getByPlaceholderText('Select country...'));
- await userEvent.click(screen.getByText('Demo Land'));
+ await userEvent.click(await screen.getByPlaceholderText('Select country...'));
+ await userEvent.click(await screen.findByText('Demo Land'));
const submitButton = await screen.findByRole('button', { name: 'Export' });
@@ -217,10 +217,10 @@ describe('Reports', () => {
);
renderComponent();
await userEvent.click(await screen.findByPlaceholderText('Select survey...'));
- await userEvent.click(screen.getByText('Basic clinic data - Demo Land'));
+ await userEvent.click(await screen.findByText('Basic clinic data - Demo Land'));
await userEvent.click(await screen.findByLabelText('Country'));
- await userEvent.click(screen.getByPlaceholderText('Select country...'));
- await userEvent.click(screen.getByText('Demo Land'));
+ await userEvent.click(await screen.getByPlaceholderText('Select country...'));
+ await userEvent.click(await screen.findByText('Demo Land'));
const submitButton = await screen.findByRole('button', { name: 'Export' });
@@ -244,10 +244,10 @@ describe('Reports', () => {
);
renderComponent();
await userEvent.click(await screen.findByPlaceholderText('Select survey...'));
- await userEvent.click(screen.getByText('Basic clinic data - Demo Land'));
+ await userEvent.click(await screen.findByText('Basic clinic data - Demo Land'));
await userEvent.click(await screen.findByLabelText('Country'));
- await userEvent.click(screen.getByPlaceholderText('Select country...'));
- await userEvent.click(screen.getByText('Demo Land'));
+ await userEvent.click(await screen.getByPlaceholderText('Select country...'));
+ await userEvent.click(await screen.findByText('Demo Land'));
const submitButton = await screen.findByRole('button', { name: 'Export' });
diff --git a/packages/datatrak-web/src/__tests__/helpers/render.tsx b/packages/datatrak-web/src/__tests__/helpers/render.tsx
index 390710e12e..a20a22605d 100644
--- a/packages/datatrak-web/src/__tests__/helpers/render.tsx
+++ b/packages/datatrak-web/src/__tests__/helpers/render.tsx
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
import React from 'react';
-import { UseMutationResult, QueryClient } from 'react-query';
+import { UseMutationResult, QueryClient } from '@tanstack/react-query';
import { MemoryRouter, Routes as Router } from 'react-router-dom';
import { renderHook } from '@testing-library/react-hooks';
import '@testing-library/jest-dom';
diff --git a/packages/datatrak-web/src/api/CurrentUserContext.tsx b/packages/datatrak-web/src/api/CurrentUserContext.tsx
index 205c769cb6..6c425b671c 100644
--- a/packages/datatrak-web/src/api/CurrentUserContext.tsx
+++ b/packages/datatrak-web/src/api/CurrentUserContext.tsx
@@ -22,7 +22,7 @@ export const useCurrentUserContext = (): CurrentUserContextType => {
export const CurrentUserContextProvider = ({ children }: { children: React.ReactNode }) => {
const currentUserQuery = useUser();
- if (currentUserQuery.isLoading) {
+ if (currentUserQuery.isLoading || currentUserQuery.isFetching) {
return ;
}
diff --git a/packages/datatrak-web/src/api/mutations/useEditUser.ts b/packages/datatrak-web/src/api/mutations/useEditUser.ts
index ce44980794..8740c9d26f 100644
--- a/packages/datatrak-web/src/api/mutations/useEditUser.ts
+++ b/packages/datatrak-web/src/api/mutations/useEditUser.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useMutation, useQueryClient } from 'react-query';
+import { useMutation, useQueryClient } from '@tanstack/react-query';
import { UserAccountDetails } from '../../types';
import { put } from '../api';
@@ -41,10 +41,10 @@ export const useEditUser = (onSuccess?: () => void) => {
},
{
onSuccess: (_, variables) => {
- queryClient.invalidateQueries('getUser');
+ queryClient.invalidateQueries(['getUser']);
// If the user changes their project, we need to invalidate the entity descendants query so that recent entities are updated if they change back to the previous project without refreshing the page
if (variables.projectId) {
- queryClient.invalidateQueries('entityDescendants');
+ queryClient.invalidateQueries(['entityDescendants']);
}
if (onSuccess) onSuccess();
},
diff --git a/packages/datatrak-web/src/api/mutations/useExportSurveyResponses.ts b/packages/datatrak-web/src/api/mutations/useExportSurveyResponses.ts
index b77612b103..a592e83fa2 100644
--- a/packages/datatrak-web/src/api/mutations/useExportSurveyResponses.ts
+++ b/packages/datatrak-web/src/api/mutations/useExportSurveyResponses.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useMutation } from 'react-query';
+import { useMutation } from '@tanstack/react-query';
import axios from 'axios';
import downloadJs from 'downloadjs';
import { API_URL, timeout } from '../api';
diff --git a/packages/datatrak-web/src/api/mutations/useLogin.ts b/packages/datatrak-web/src/api/mutations/useLogin.ts
index 8206366ccd..5f522213f1 100644
--- a/packages/datatrak-web/src/api/mutations/useLogin.ts
+++ b/packages/datatrak-web/src/api/mutations/useLogin.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useMutation, useQueryClient } from 'react-query';
+import { useMutation, useQueryClient } from '@tanstack/react-query';
import { gaEvent, useFromLocation } from '../../utils';
import { useNavigate } from 'react-router-dom';
import { post } from '../api';
@@ -35,15 +35,13 @@ export const useLogin = () => {
},
onSuccess: async ({ user }) => {
await queryClient.invalidateQueries();
+ await queryClient.removeQueries();
+
if (from) {
- navigate(from, {
- state: null,
- });
+ navigate(from, { state: null });
} else {
const path = user.projectId ? ROUTES.HOME : ROUTES.PROJECT_SELECT;
- navigate(path, {
- state: from,
- });
+ navigate(path, { state: from });
}
},
meta: {
diff --git a/packages/datatrak-web/src/api/mutations/useLogout.ts b/packages/datatrak-web/src/api/mutations/useLogout.ts
index c8b593af54..8db3bb0e27 100644
--- a/packages/datatrak-web/src/api/mutations/useLogout.ts
+++ b/packages/datatrak-web/src/api/mutations/useLogout.ts
@@ -3,13 +3,13 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useMutation, useQueryClient } from 'react-query';
+import { useMutation, useQueryClient } from '@tanstack/react-query';
import { post } from '../api';
export const useLogout = () => {
const queryClient = useQueryClient();
- return useMutation('logout', () => post('logout'), {
+ return useMutation(['logout'], () => post('logout'), {
onSuccess: () => {
queryClient.invalidateQueries();
},
diff --git a/packages/datatrak-web/src/api/mutations/useOneTimeLogin.ts b/packages/datatrak-web/src/api/mutations/useOneTimeLogin.ts
index df8298e33f..df4cf04023 100644
--- a/packages/datatrak-web/src/api/mutations/useOneTimeLogin.ts
+++ b/packages/datatrak-web/src/api/mutations/useOneTimeLogin.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useMutation, useQueryClient } from 'react-query';
+import { useMutation, useQueryClient } from '@tanstack/react-query';
import { post } from '../api';
type OneTimeLoginToken = string;
diff --git a/packages/datatrak-web/src/api/mutations/useRegister.ts b/packages/datatrak-web/src/api/mutations/useRegister.ts
index 4e18c13a28..d06ff797a2 100644
--- a/packages/datatrak-web/src/api/mutations/useRegister.ts
+++ b/packages/datatrak-web/src/api/mutations/useRegister.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useMutation } from 'react-query';
+import { useMutation } from '@tanstack/react-query';
import { post } from '../api';
// Todo: replace with request body type from backend
diff --git a/packages/datatrak-web/src/api/mutations/useRequestDeleteAccount.ts b/packages/datatrak-web/src/api/mutations/useRequestDeleteAccount.ts
index aa11c95ab0..5d386b6b26 100644
--- a/packages/datatrak-web/src/api/mutations/useRequestDeleteAccount.ts
+++ b/packages/datatrak-web/src/api/mutations/useRequestDeleteAccount.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useMutation } from 'react-query';
+import { useMutation } from '@tanstack/react-query';
import { post } from '../api';
import { useEditUser } from '.';
diff --git a/packages/datatrak-web/src/api/mutations/useRequestProjectAccess.ts b/packages/datatrak-web/src/api/mutations/useRequestProjectAccess.ts
index 26c3d0b6dc..ef42466ab8 100644
--- a/packages/datatrak-web/src/api/mutations/useRequestProjectAccess.ts
+++ b/packages/datatrak-web/src/api/mutations/useRequestProjectAccess.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useMutation, useQueryClient } from 'react-query';
+import { useMutation, useQueryClient } from '@tanstack/react-query';
import { Country, Project } from '@tupaia/types';
import { post } from '../api';
diff --git a/packages/datatrak-web/src/api/mutations/useRequestResetPassword.ts b/packages/datatrak-web/src/api/mutations/useRequestResetPassword.ts
index 89c3fde15d..bc69b0f3cc 100644
--- a/packages/datatrak-web/src/api/mutations/useRequestResetPassword.ts
+++ b/packages/datatrak-web/src/api/mutations/useRequestResetPassword.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useMutation } from 'react-query';
+import { useMutation } from '@tanstack/react-query';
import { post } from '../api';
type ResetPasswordParams = {
diff --git a/packages/datatrak-web/src/api/mutations/useResendVerificationEmail.ts b/packages/datatrak-web/src/api/mutations/useResendVerificationEmail.ts
index ac455ce47e..557c6facab 100644
--- a/packages/datatrak-web/src/api/mutations/useResendVerificationEmail.ts
+++ b/packages/datatrak-web/src/api/mutations/useResendVerificationEmail.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useMutation } from 'react-query';
+import { useMutation } from '@tanstack/react-query';
import { post } from '../api';
type RequestBody = {
diff --git a/packages/datatrak-web/src/api/mutations/useResetPassword.ts b/packages/datatrak-web/src/api/mutations/useResetPassword.ts
index dedf4d3de8..88b84e0239 100644
--- a/packages/datatrak-web/src/api/mutations/useResetPassword.ts
+++ b/packages/datatrak-web/src/api/mutations/useResetPassword.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useMutation } from 'react-query';
+import { useMutation } from '@tanstack/react-query';
import { useLocation, useNavigate, useSearchParams } from 'react-router-dom';
import { post } from '../api';
import { PASSWORD_RESET_TOKEN_PARAM } from '../../constants';
diff --git a/packages/datatrak-web/src/api/mutations/useResubmitSurveyResponse.ts b/packages/datatrak-web/src/api/mutations/useResubmitSurveyResponse.ts
index c03060a4e5..65e7033fef 100644
--- a/packages/datatrak-web/src/api/mutations/useResubmitSurveyResponse.ts
+++ b/packages/datatrak-web/src/api/mutations/useResubmitSurveyResponse.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useMutation } from 'react-query';
+import { useMutation } from '@tanstack/react-query';
import { generatePath, useNavigate, useParams } from 'react-router';
import { post } from '../api';
import { useSurveyResponse } from '../queries';
diff --git a/packages/datatrak-web/src/api/mutations/useSubmitSurveyResponse.ts b/packages/datatrak-web/src/api/mutations/useSubmitSurveyResponse.ts
index 72b4b05ee8..13f7193f4c 100644
--- a/packages/datatrak-web/src/api/mutations/useSubmitSurveyResponse.ts
+++ b/packages/datatrak-web/src/api/mutations/useSubmitSurveyResponse.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useMutation, useQueryClient } from 'react-query';
+import { useMutation, useQueryClient } from '@tanstack/react-query';
import { generatePath, useNavigate, useParams } from 'react-router';
import { getBrowserTimeZone } from '@tupaia/utils';
import { Coconut } from '../../components';
@@ -64,11 +64,11 @@ export const useSubmitSurveyResponse = () => {
gaEvent('submit_survey_by_user', user.id!);
},
onSuccess: data => {
- queryClient.invalidateQueries('surveyResponses');
- queryClient.invalidateQueries('recentSurveys');
- queryClient.invalidateQueries('rewards');
- queryClient.invalidateQueries('leaderboard');
- queryClient.invalidateQueries('entityDescendants'); // Refresh recent entities
+ queryClient.invalidateQueries(['surveyResponses']);
+ queryClient.invalidateQueries(['recentSurveys']);
+ queryClient.invalidateQueries(['rewards']);
+ queryClient.invalidateQueries(['leaderboard']);
+ queryClient.invalidateQueries(['entityDescendants']); // Refresh recent entities
const createNewAutocompleteQuestions = surveyResponseData?.questions?.filter(
question => question?.config?.autocomplete?.createNew,
diff --git a/packages/datatrak-web/src/api/mutations/useTupaiaRedirect.ts b/packages/datatrak-web/src/api/mutations/useTupaiaRedirect.ts
index 7cb318570b..8af4a80df8 100644
--- a/packages/datatrak-web/src/api/mutations/useTupaiaRedirect.ts
+++ b/packages/datatrak-web/src/api/mutations/useTupaiaRedirect.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useMutation } from 'react-query';
+import { useMutation } from '@tanstack/react-query';
import { useCurrentUserContext } from '../CurrentUserContext';
import { post } from '../api';
diff --git a/packages/datatrak-web/src/api/queries/useActivityFeed.ts b/packages/datatrak-web/src/api/queries/useActivityFeed.ts
index 66e764df43..d60713f376 100644
--- a/packages/datatrak-web/src/api/queries/useActivityFeed.ts
+++ b/packages/datatrak-web/src/api/queries/useActivityFeed.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useInfiniteQuery } from 'react-query';
+import { useInfiniteQuery } from '@tanstack/react-query';
import { DatatrakWebActivityFeedRequest, Project } from '@tupaia/types';
import { get } from '../api';
import { useCurrentUserContext } from '..';
diff --git a/packages/datatrak-web/src/api/queries/useAutocompleteOptions.ts b/packages/datatrak-web/src/api/queries/useAutocompleteOptions.ts
index ab358b0b11..df2a05438a 100644
--- a/packages/datatrak-web/src/api/queries/useAutocompleteOptions.ts
+++ b/packages/datatrak-web/src/api/queries/useAutocompleteOptions.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { Option } from '@tupaia/types';
import { get } from '../api';
import { useSurveyForm } from '../../features';
diff --git a/packages/datatrak-web/src/api/queries/useCountryAccessList.ts b/packages/datatrak-web/src/api/queries/useCountryAccessList.ts
index fbfdcc5718..38e4193aa6 100644
--- a/packages/datatrak-web/src/api/queries/useCountryAccessList.ts
+++ b/packages/datatrak-web/src/api/queries/useCountryAccessList.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { Project, ProjectCountryAccessListRequest } from '@tupaia/types';
import { get } from '../api';
diff --git a/packages/datatrak-web/src/api/queries/useEntities.ts b/packages/datatrak-web/src/api/queries/useEntities.ts
index bde6d7867f..ab216a381e 100644
--- a/packages/datatrak-web/src/api/queries/useEntities.ts
+++ b/packages/datatrak-web/src/api/queries/useEntities.ts
@@ -2,7 +2,7 @@
* Tupaia
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { DatatrakWebEntitiesRequest } from '@tupaia/types';
import { get } from '../api';
diff --git a/packages/datatrak-web/src/api/queries/useEntity.ts b/packages/datatrak-web/src/api/queries/useEntity.ts
index 881eec74b3..640a1b83e6 100644
--- a/packages/datatrak-web/src/api/queries/useEntity.ts
+++ b/packages/datatrak-web/src/api/queries/useEntity.ts
@@ -2,7 +2,7 @@
* Tupaia
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { get } from '../api';
export const useEntityByCode = (entityCode, options?) => {
diff --git a/packages/datatrak-web/src/api/queries/useLeaderboard.ts b/packages/datatrak-web/src/api/queries/useLeaderboard.ts
index c16ae488d0..6efefa4d9e 100644
--- a/packages/datatrak-web/src/api/queries/useLeaderboard.ts
+++ b/packages/datatrak-web/src/api/queries/useLeaderboard.ts
@@ -2,7 +2,7 @@
* Tupaia
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { DatatrakWebLeaderboardRequest, Project } from '@tupaia/types';
import { get } from '../api';
diff --git a/packages/datatrak-web/src/api/queries/useProject.ts b/packages/datatrak-web/src/api/queries/useProject.ts
index fa0d80b0e2..0e951245c0 100644
--- a/packages/datatrak-web/src/api/queries/useProject.ts
+++ b/packages/datatrak-web/src/api/queries/useProject.ts
@@ -4,7 +4,7 @@
*
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { WebServerProjectRequest } from '@tupaia/types';
import { get } from '../api';
diff --git a/packages/datatrak-web/src/api/queries/useProjectEntities.ts b/packages/datatrak-web/src/api/queries/useProjectEntities.ts
index 7f6afde00e..be556a3d56 100644
--- a/packages/datatrak-web/src/api/queries/useProjectEntities.ts
+++ b/packages/datatrak-web/src/api/queries/useProjectEntities.ts
@@ -2,7 +2,7 @@
* Tupaia
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { DatatrakWebEntityDescendantsRequest } from '@tupaia/types';
import { get } from '../api';
diff --git a/packages/datatrak-web/src/api/queries/useProjectSurveys.ts b/packages/datatrak-web/src/api/queries/useProjectSurveys.ts
index a35e7f7c30..cc668e034d 100644
--- a/packages/datatrak-web/src/api/queries/useProjectSurveys.ts
+++ b/packages/datatrak-web/src/api/queries/useProjectSurveys.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { DatatrakWebSurveyRequest, Project } from '@tupaia/types';
import { get } from '../api';
import { Entity } from '../../types';
diff --git a/packages/datatrak-web/src/api/queries/useProjects.ts b/packages/datatrak-web/src/api/queries/useProjects.ts
index 15d0c66492..7459a1121d 100644
--- a/packages/datatrak-web/src/api/queries/useProjects.ts
+++ b/packages/datatrak-web/src/api/queries/useProjects.ts
@@ -3,10 +3,10 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { DatatrakWebProjectsRequest } from '@tupaia/types';
import { get } from '../api';
export const useProjects = () => {
- return useQuery('projects', (): Promise => get('projects'));
+ return useQuery(['projects'], (): Promise => get('projects'));
};
diff --git a/packages/datatrak-web/src/api/queries/useRecentSurveys.ts b/packages/datatrak-web/src/api/queries/useRecentSurveys.ts
index be8cba7ac5..00214082ac 100644
--- a/packages/datatrak-web/src/api/queries/useRecentSurveys.ts
+++ b/packages/datatrak-web/src/api/queries/useRecentSurveys.ts
@@ -2,7 +2,7 @@
* Tupaia
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { DatatrakWebRecentSurveysRequest, Project, UserAccount } from '@tupaia/types';
import { get } from '../api';
import { useCurrentUserContext } from '../CurrentUserContext';
diff --git a/packages/datatrak-web/src/api/queries/useSurvey.ts b/packages/datatrak-web/src/api/queries/useSurvey.ts
index 1ea3a84269..944423ce74 100644
--- a/packages/datatrak-web/src/api/queries/useSurvey.ts
+++ b/packages/datatrak-web/src/api/queries/useSurvey.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { DatatrakWebSurveyRequest } from '@tupaia/types';
import { get } from '../api';
diff --git a/packages/datatrak-web/src/api/queries/useSurveyResponse.ts b/packages/datatrak-web/src/api/queries/useSurveyResponse.ts
index 6f0fd29f4f..ea8b444535 100644
--- a/packages/datatrak-web/src/api/queries/useSurveyResponse.ts
+++ b/packages/datatrak-web/src/api/queries/useSurveyResponse.ts
@@ -2,7 +2,7 @@
* Tupaia
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { useNavigate } from 'react-router';
import { DatatrakWebSingleSurveyResponseRequest, QuestionType } from '@tupaia/types';
import { get } from '../api';
diff --git a/packages/datatrak-web/src/api/queries/useSurveyResponses.ts b/packages/datatrak-web/src/api/queries/useSurveyResponses.ts
index fb52bf1e6d..cdf6ca87f4 100644
--- a/packages/datatrak-web/src/api/queries/useSurveyResponses.ts
+++ b/packages/datatrak-web/src/api/queries/useSurveyResponses.ts
@@ -2,7 +2,7 @@
* Tupaia
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { DatatrakWebSurveyResponsesRequest, UserAccount, Project } from '@tupaia/types';
import { useCurrentUserContext } from '../CurrentUserContext';
import { get } from '../api';
diff --git a/packages/datatrak-web/src/api/queries/useSurveys.ts b/packages/datatrak-web/src/api/queries/useSurveys.ts
index 3cb3ef4387..fd5cf9be34 100644
--- a/packages/datatrak-web/src/api/queries/useSurveys.ts
+++ b/packages/datatrak-web/src/api/queries/useSurveys.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { DatatrakWebSurveyRequest } from '@tupaia/types';
import { get } from '../api';
diff --git a/packages/datatrak-web/src/api/queries/useUser.ts b/packages/datatrak-web/src/api/queries/useUser.ts
index 1458325ec4..668bc34ef9 100644
--- a/packages/datatrak-web/src/api/queries/useUser.ts
+++ b/packages/datatrak-web/src/api/queries/useUser.ts
@@ -3,10 +3,10 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { DatatrakWebUserRequest } from '@tupaia/types';
import { get } from '../api';
export const useUser = () => {
- return useQuery('getUser', (): Promise => get('getUser'));
+ return useQuery(['getUser'], (): Promise => get('getUser'));
};
diff --git a/packages/datatrak-web/src/api/queries/useUserRewards.ts b/packages/datatrak-web/src/api/queries/useUserRewards.ts
index 81b9e959d5..eb9ee49759 100644
--- a/packages/datatrak-web/src/api/queries/useUserRewards.ts
+++ b/packages/datatrak-web/src/api/queries/useUserRewards.ts
@@ -2,7 +2,7 @@
* Tupaia
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { Project } from '@tupaia/types';
import { get } from '../api';
import { UserRewards } from '../../types';
diff --git a/packages/datatrak-web/src/views/AccountSettingsPage/RequestCountryAccessSection/AccessGrantedCountryList.tsx b/packages/datatrak-web/src/views/AccountSettingsPage/RequestCountryAccessSection/AccessGrantedCountryList.tsx
index a41702597a..d889fac3a8 100644
--- a/packages/datatrak-web/src/views/AccountSettingsPage/RequestCountryAccessSection/AccessGrantedCountryList.tsx
+++ b/packages/datatrak-web/src/views/AccountSettingsPage/RequestCountryAccessSection/AccessGrantedCountryList.tsx
@@ -16,7 +16,7 @@ import {
Typography,
} from '@material-ui/core';
import { ProjectCountryAccessListRequest } from '@tupaia/types';
-import { UseQueryResult } from 'react-query';
+import { UseQueryResult } from '@tanstack/react-query';
const StyledTableContainer = styled(TableContainer).attrs({
elevation: 0,
diff --git a/packages/datatrak-web/src/views/AccountSettingsPage/RequestCountryAccessSection/RequestCountryAccessForm.tsx b/packages/datatrak-web/src/views/AccountSettingsPage/RequestCountryAccessSection/RequestCountryAccessForm.tsx
index 4a1cdd3e51..d89570a156 100644
--- a/packages/datatrak-web/src/views/AccountSettingsPage/RequestCountryAccessSection/RequestCountryAccessForm.tsx
+++ b/packages/datatrak-web/src/views/AccountSettingsPage/RequestCountryAccessSection/RequestCountryAccessForm.tsx
@@ -6,7 +6,7 @@
import React, { useState } from 'react';
import styled from 'styled-components';
import { useForm } from 'react-hook-form';
-import { UseQueryResult } from 'react-query';
+import { UseQueryResult } from '@tanstack/react-query';
import { FormLabel, useMediaQuery, useTheme } from '@material-ui/core';
import { Entity, ProjectCountryAccessListRequest, ProjectResponse } from '@tupaia/types';
import { Form, FormInput, TextField } from '@tupaia/ui-components';
diff --git a/packages/datatrak-web/src/views/VerifyEmailPage.tsx b/packages/datatrak-web/src/views/VerifyEmailPage.tsx
index c45691328a..2ab39f7c6d 100644
--- a/packages/datatrak-web/src/views/VerifyEmailPage.tsx
+++ b/packages/datatrak-web/src/views/VerifyEmailPage.tsx
@@ -4,7 +4,7 @@
*/
import React, { useState } from 'react';
import { useNavigate, useSearchParams } from 'react-router-dom';
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { EMAIL_VERIFICATION_STATUS } from '@tupaia/ui-components';
import { get } from '../api';
import { LoginPage } from '.';
diff --git a/packages/lesmis/package.json b/packages/lesmis/package.json
index 5bc2c312a4..3468c269bc 100644
--- a/packages/lesmis/package.json
+++ b/packages/lesmis/package.json
@@ -28,6 +28,8 @@
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "^4.0.0-alpha.57",
"@material-ui/styles": "^4.9.10",
+ "@tanstack/react-query": "4.36.1",
+ "@tanstack/react-query-devtools": "4.36.1",
"@tupaia/access-policy": "workspace:*",
"@tupaia/admin-panel": "workspace:*",
"@tupaia/ui-chart-components": "workspace:*",
@@ -49,7 +51,6 @@
"react-hook-form": "^6.15.1",
"react-leaflet": "^3.2.1",
"react-password-strength-bar": "^0.3.3",
- "react-query": "^3.19.0",
"react-redux": "^5.0.6",
"react-router": "6.3.0",
"react-router-dom": "6.3.0",
diff --git a/packages/lesmis/src/AppProviders.jsx b/packages/lesmis/src/AppProviders.jsx
index 567f1c85fb..026f7c4475 100755
--- a/packages/lesmis/src/AppProviders.jsx
+++ b/packages/lesmis/src/AppProviders.jsx
@@ -4,7 +4,7 @@
*/
import React from 'react';
import PropTypes from 'prop-types';
-import { QueryClient, QueryClientProvider } from 'react-query';
+import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { MuiThemeProvider, StylesProvider } from '@material-ui/core/styles';
import { ThemeProvider } from 'styled-components';
import CssBaseline from '@material-ui/core/CssBaseline';
diff --git a/packages/lesmis/src/api/mutations/useLogin.js b/packages/lesmis/src/api/mutations/useLogin.js
index c6ab368167..e54399af51 100644
--- a/packages/lesmis/src/api/mutations/useLogin.js
+++ b/packages/lesmis/src/api/mutations/useLogin.js
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2020 Beyond Essential Systems Pty Ltd
*
*/
-import { useMutation, useQueryClient } from 'react-query';
+import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useLocation, useNavigate } from 'react-router-dom';
import { post } from '../api';
import { useUser } from '../queries';
diff --git a/packages/lesmis/src/api/mutations/useLogout.js b/packages/lesmis/src/api/mutations/useLogout.js
index 3cc351cf54..c1bbbc4c86 100644
--- a/packages/lesmis/src/api/mutations/useLogout.js
+++ b/packages/lesmis/src/api/mutations/useLogout.js
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2020 Beyond Essential Systems Pty Ltd
*
*/
-import { useMutation, useQueryClient } from 'react-query';
+import { useMutation, useQueryClient } from '@tanstack/react-query';
import { post } from '../api';
import { useHomeUrl } from '../../utils/useHomeUrl';
diff --git a/packages/lesmis/src/api/mutations/useRegisterUser.js b/packages/lesmis/src/api/mutations/useRegisterUser.js
index 8a6305b0ec..1ff23a573d 100644
--- a/packages/lesmis/src/api/mutations/useRegisterUser.js
+++ b/packages/lesmis/src/api/mutations/useRegisterUser.js
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2020 Beyond Essential Systems Pty Ltd
*
*/
-import { useMutation } from 'react-query';
+import { useMutation } from '@tanstack/react-query';
import { post } from '../api';
export const useRegisterUser = () => {
diff --git a/packages/lesmis/src/api/mutations/useUpdateFavouriteDashboardItem.js b/packages/lesmis/src/api/mutations/useUpdateFavouriteDashboardItem.js
index ae8f9a6200..9ca3b8228a 100644
--- a/packages/lesmis/src/api/mutations/useUpdateFavouriteDashboardItem.js
+++ b/packages/lesmis/src/api/mutations/useUpdateFavouriteDashboardItem.js
@@ -2,7 +2,7 @@
* Tupaia
* Copyright (c) 2017 - 2022 Beyond Essential Systems Pty Ltd
*/
-import { useMutation, useQueryClient } from 'react-query';
+import { useMutation, useQueryClient } from '@tanstack/react-query';
import { post } from '../api';
const updateExistingDashboardData = async (queryClient, { entityCode }) => {
diff --git a/packages/lesmis/src/api/queries/useDashboardData.js b/packages/lesmis/src/api/queries/useDashboardData.js
index b3c0268d25..676a5389d1 100644
--- a/packages/lesmis/src/api/queries/useDashboardData.js
+++ b/packages/lesmis/src/api/queries/useDashboardData.js
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2020 Beyond Essential Systems Pty Ltd
*
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { get } from '../api';
import { QUERY_OPTIONS } from './constants';
diff --git a/packages/lesmis/src/api/queries/useDashboardReportData.js b/packages/lesmis/src/api/queries/useDashboardReportData.js
index 0800ad473b..352e96e741 100644
--- a/packages/lesmis/src/api/queries/useDashboardReportData.js
+++ b/packages/lesmis/src/api/queries/useDashboardReportData.js
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2020 Beyond Essential Systems Pty Ltd
*
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { get } from '../api';
import { useDashboardData } from './useDashboardData';
import { combineQueries } from './utils';
diff --git a/packages/lesmis/src/api/queries/useEmailVerification.js b/packages/lesmis/src/api/queries/useEmailVerification.js
index cd3e45d691..4ea2bf6eff 100644
--- a/packages/lesmis/src/api/queries/useEmailVerification.js
+++ b/packages/lesmis/src/api/queries/useEmailVerification.js
@@ -2,7 +2,7 @@
* Tupaia
* Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { useUrlSearchParams } from '../../utils/useUrlSearchParams';
import { get } from '../api';
diff --git a/packages/lesmis/src/api/queries/useEntitiesData.js b/packages/lesmis/src/api/queries/useEntitiesData.js
index 0171209d52..a2a0a67f06 100644
--- a/packages/lesmis/src/api/queries/useEntitiesData.js
+++ b/packages/lesmis/src/api/queries/useEntitiesData.js
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2020 Beyond Essential Systems Pty Ltd
*
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import keyBy from 'lodash.keyby';
import { get } from '../api';
import { PROJECT_CODE } from '../../constants';
@@ -41,7 +41,7 @@ const PROJECT_PARAMS = {
export const useProjectEntitiesData = () => {
const query = useQuery(
- 'entities',
+ ['entities'],
() => get(`entities/${PROJECT_CODE}`, { params: PROJECT_PARAMS }),
{
staleTime: 1000 * 60 * 60 * 1,
diff --git a/packages/lesmis/src/api/queries/useEntityData.js b/packages/lesmis/src/api/queries/useEntityData.js
index ed0aeb1883..2ce8b4aecf 100644
--- a/packages/lesmis/src/api/queries/useEntityData.js
+++ b/packages/lesmis/src/api/queries/useEntityData.js
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2020 Beyond Essential Systems Pty Ltd
*
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { get } from '../api';
import { useValidatedQuery } from './useValidatedQuery';
diff --git a/packages/lesmis/src/api/queries/useMapOverlayReportData.js b/packages/lesmis/src/api/queries/useMapOverlayReportData.js
index 9f4b601ca5..a1f7e6b514 100644
--- a/packages/lesmis/src/api/queries/useMapOverlayReportData.js
+++ b/packages/lesmis/src/api/queries/useMapOverlayReportData.js
@@ -5,7 +5,7 @@
*/
import { useState, useEffect, useCallback } from 'react';
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import camelCase from 'camelcase';
import {
autoAssignColors,
diff --git a/packages/lesmis/src/api/queries/useMapOverlaysData.js b/packages/lesmis/src/api/queries/useMapOverlaysData.js
index dfa666cf13..958f64610a 100644
--- a/packages/lesmis/src/api/queries/useMapOverlaysData.js
+++ b/packages/lesmis/src/api/queries/useMapOverlaysData.js
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2020 Beyond Essential Systems Pty Ltd
*
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import camelCase from 'camelcase';
import { get } from '../api';
import { useEntitiesData } from './useEntitiesData';
diff --git a/packages/lesmis/src/api/queries/useUser.js b/packages/lesmis/src/api/queries/useUser.js
index 494fb1bd21..efd21f01af 100644
--- a/packages/lesmis/src/api/queries/useUser.js
+++ b/packages/lesmis/src/api/queries/useUser.js
@@ -3,11 +3,11 @@
* Copyright (c) 2017 - 2020 Beyond Essential Systems Pty Ltd
*
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { get } from '../api';
export const useUser = options => {
- const query = useQuery('user', () => get('user'), {
+ const query = useQuery(['user'], () => get('user'), {
retry: 0,
// should be refetched in the background every hour
staleTime: 1000 * 60 * 60 * 1,
diff --git a/packages/lesmis/src/api/queries/useVitalsData.js b/packages/lesmis/src/api/queries/useVitalsData.js
index 29c23321d6..f2630dd76f 100644
--- a/packages/lesmis/src/api/queries/useVitalsData.js
+++ b/packages/lesmis/src/api/queries/useVitalsData.js
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2020 Beyond Essential Systems Pty Ltd
*
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { utcMoment } from '@tupaia/utils';
import { post } from '../api';
import { useProjectEntitiesData } from './useEntitiesData';
diff --git a/packages/lesmis/src/components/DashboardExportModal/DashboardExportModal.jsx b/packages/lesmis/src/components/DashboardExportModal/DashboardExportModal.jsx
index 47e2a60ff5..c9cd7ba5cd 100644
--- a/packages/lesmis/src/components/DashboardExportModal/DashboardExportModal.jsx
+++ b/packages/lesmis/src/components/DashboardExportModal/DashboardExportModal.jsx
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2022 Beyond Essential Systems Pty Ltd
*/
import React, { useState } from 'react';
-import { useIsFetching } from 'react-query';
+import { useIsFetching } from '@tanstack/react-query';
import PropTypes from 'prop-types';
import styled from 'styled-components';
import DownloadIcon from '@material-ui/icons/GetApp';
diff --git a/packages/lesmis/src/components/LocaleMenu.jsx b/packages/lesmis/src/components/LocaleMenu.jsx
index 09b356a00a..95b83528a1 100644
--- a/packages/lesmis/src/components/LocaleMenu.jsx
+++ b/packages/lesmis/src/components/LocaleMenu.jsx
@@ -4,7 +4,7 @@
*
*/
import React, { useState } from 'react';
-import { useQueryClient } from 'react-query';
+import { useQueryClient } from '@tanstack/react-query';
import PropTypes from 'prop-types';
import styled from 'styled-components';
import { generatePath, useNavigate, useLocation } from 'react-router-dom';
diff --git a/packages/lesmis/src/main.jsx b/packages/lesmis/src/main.jsx
index 1022a1ce6f..5efa2199df 100755
--- a/packages/lesmis/src/main.jsx
+++ b/packages/lesmis/src/main.jsx
@@ -4,7 +4,7 @@
*/
import React from 'react';
import { render as renderReactApp } from 'react-dom';
-import { ReactQueryDevtools } from 'react-query/devtools';
+import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import { EnvBanner } from '@tupaia/ui-components';
import { App } from './App';
import { AppProviders } from './AppProviders';
@@ -21,4 +21,3 @@ const render = () => {
};
render(App);
-
diff --git a/packages/lesmis/src/views/AdminPanel/api/useUpdateSurveyResponseStatus.js b/packages/lesmis/src/views/AdminPanel/api/useUpdateSurveyResponseStatus.js
index 61747e76b8..72b3f03fe6 100644
--- a/packages/lesmis/src/views/AdminPanel/api/useUpdateSurveyResponseStatus.js
+++ b/packages/lesmis/src/views/AdminPanel/api/useUpdateSurveyResponseStatus.js
@@ -2,7 +2,7 @@
* Tupaia
* Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
*/
-import { useMutation } from 'react-query';
+import { useMutation } from '@tanstack/react-query';
export const useApproveSurveyResponseStatus = api =>
useMutation(id => api.post(`surveyResponse/${id}/resubmit`, {}, { approval_status: 'approved' }));
diff --git a/packages/lesmis/src/views/DashboardView.jsx b/packages/lesmis/src/views/DashboardView.jsx
index 8aaae607cf..b41b9e5575 100644
--- a/packages/lesmis/src/views/DashboardView.jsx
+++ b/packages/lesmis/src/views/DashboardView.jsx
@@ -6,7 +6,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
-import { useIsFetching } from 'react-query';
+import { useIsFetching } from '@tanstack/react-query';
import { Select } from '@tupaia/ui-components';
import MuiBox from '@material-ui/core/Box';
import { VitalsView } from './VitalsView';
diff --git a/packages/psss/package.json b/packages/psss/package.json
index bcf458cb18..76c2c80e7a 100644
--- a/packages/psss/package.json
+++ b/packages/psss/package.json
@@ -28,6 +28,8 @@
"@material-ui/lab": "^4.0.0-alpha.57",
"@material-ui/pickers": "^3.2.10",
"@material-ui/styles": "^4.9.10",
+ "@tanstack/react-query": "4.36.1",
+ "@tanstack/react-query-devtools": "4.36.1",
"@tupaia/ui-components": "workspace:*",
"@tupaia/utils": "workspace:*",
"axios": "^1.6.8",
@@ -44,7 +46,6 @@
"react-dom": "^16.13.1",
"react-hook-form": "^6.0.0",
"react-password-strength-bar": "^0.3.3",
- "react-query": "^3.19.0",
"react-redux": "^7.1.0",
"react-router-dom": "^5.1.2",
"redux": "^4.0.2",
diff --git a/packages/psss/src/AppProviders.jsx b/packages/psss/src/AppProviders.jsx
index f753f5abf6..f071d670de 100644
--- a/packages/psss/src/AppProviders.jsx
+++ b/packages/psss/src/AppProviders.jsx
@@ -5,7 +5,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Provider } from 'react-redux';
-import { QueryClient, QueryClientProvider } from 'react-query';
+import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { MuiThemeProvider, StylesProvider } from '@material-ui/core/styles';
import { ThemeProvider } from 'styled-components';
import CssBaseline from '@material-ui/core/CssBaseline';
diff --git a/packages/psss/src/api/mutations.js b/packages/psss/src/api/mutations.js
index 75a7680c41..58cc9ac059 100644
--- a/packages/psss/src/api/mutations.js
+++ b/packages/psss/src/api/mutations.js
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2020 Beyond Essential Systems Pty Ltd
*/
-import { useQueryClient, useMutation } from 'react-query';
+import { useQueryClient, useMutation } from '@tanstack/react-query';
import { remove, put, post } from './api';
export const useConfirmWeeklyReport = (countryCode, period) => {
diff --git a/packages/psss/src/api/queries/helpers/query.js b/packages/psss/src/api/queries/helpers/query.js
index f8a552a593..2e55002afb 100644
--- a/packages/psss/src/api/queries/helpers/query.js
+++ b/packages/psss/src/api/queries/helpers/query.js
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { get } from '../../api';
const COMMON_QUERY_OPTIONS = {
diff --git a/packages/psss/src/api/queries/useAlerts.js b/packages/psss/src/api/queries/useAlerts.js
index d03d845bcc..b14395e49a 100644
--- a/packages/psss/src/api/queries/useAlerts.js
+++ b/packages/psss/src/api/queries/useAlerts.js
@@ -4,7 +4,7 @@
*/
import orderBy from 'lodash.orderby';
-import { useQueryClient, useMutation } from 'react-query';
+import { useQueryClient, useMutation } from '@tanstack/react-query';
import { MIN_DATE, SYNDROMES } from '../../constants';
import { getPeriodByDate } from '../../utils';
import { useData } from './helpers';
diff --git a/packages/psss/src/api/queries/useSingleWeeklyReport.js b/packages/psss/src/api/queries/useSingleWeeklyReport.js
index 551562b8c7..396a26dd70 100644
--- a/packages/psss/src/api/queries/useSingleWeeklyReport.js
+++ b/packages/psss/src/api/queries/useSingleWeeklyReport.js
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2020 Beyond Essential Systems Pty Ltd
*/
-import { useQueryClient } from 'react-query';
+import { useQueryClient } from '@tanstack/react-query';
import { calculateWeekStatus } from '../../utils';
import { REPORT_STATUSES } from '../../constants';
import { EMPTY_SYNDROME_DATA, getSyndromeData, useReport } from './helpers';
diff --git a/packages/psss/src/api/queries/useUpcomingReport.js b/packages/psss/src/api/queries/useUpcomingReport.js
index bad7e061ec..e84e307999 100644
--- a/packages/psss/src/api/queries/useUpcomingReport.js
+++ b/packages/psss/src/api/queries/useUpcomingReport.js
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2020 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { subtractWeeksFromPeriod, getDaysTillDueDay, getCurrentPeriod } from '../../utils';
import { get } from '../api';
import { REPORT_STATUSES } from '../../constants';
diff --git a/packages/psss/src/api/useTableQuery.js b/packages/psss/src/api/useTableQuery.js
index 484ace7ce5..d5f35058a4 100644
--- a/packages/psss/src/api/useTableQuery.js
+++ b/packages/psss/src/api/useTableQuery.js
@@ -4,7 +4,7 @@
*/
import { useState } from 'react';
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { FakeAPI } from './FakeApi';
export const useTableQuery = (endpoint, options) => {
diff --git a/packages/psss/src/components/DateToolbar/DateToolbar.jsx b/packages/psss/src/components/DateToolbar/DateToolbar.jsx
index 09a39dc3af..884f78ec53 100644
--- a/packages/psss/src/components/DateToolbar/DateToolbar.jsx
+++ b/packages/psss/src/components/DateToolbar/DateToolbar.jsx
@@ -5,7 +5,7 @@
import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
-import { useIsFetching } from 'react-query';
+import { useIsFetching } from '@tanstack/react-query';
import { comparePeriods } from '@tupaia/utils';
import { connect } from 'react-redux';
import Typography from '@material-ui/core/Typography';
diff --git a/packages/psss/src/main.jsx b/packages/psss/src/main.jsx
index c99b11a23f..0d322c26da 100644
--- a/packages/psss/src/main.jsx
+++ b/packages/psss/src/main.jsx
@@ -4,7 +4,7 @@
*/
import React from 'react';
import { render as renderReactApp } from 'react-dom';
-import { ReactQueryDevtools } from 'react-query/devtools';
+import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import { EnvBanner } from '@tupaia/ui-components';
import App from './App';
import { AppProviders } from './AppProviders';
@@ -22,5 +22,3 @@ const render = () => {
};
render(App);
-
-
\ No newline at end of file
diff --git a/packages/tupaia-web/package.json b/packages/tupaia-web/package.json
index d2b9f430b6..d8e46853e7 100644
--- a/packages/tupaia-web/package.json
+++ b/packages/tupaia-web/package.json
@@ -26,6 +26,7 @@
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "^4.0.0-alpha.57",
"@material-ui/styles": "^4.9.10",
+ "@tanstack/react-query": "4.36.1",
"@tupaia/types": "workspace:*",
"@tupaia/ui-chart-components": "workspace:*",
"@tupaia/ui-components": "workspace:*",
@@ -40,7 +41,6 @@
"react-dom": "^16.13.1",
"react-hook-form": "^6.15.1",
"react-leaflet": "^3.2.1",
- "react-query": "^3.39.3",
"react-router": "6.3.0",
"react-router-dom": "6.3.0",
"react-slick": "^0.30.2",
diff --git a/packages/tupaia-web/src/AppProviders.tsx b/packages/tupaia-web/src/AppProviders.tsx
index 2d19459454..793074bb83 100644
--- a/packages/tupaia-web/src/AppProviders.tsx
+++ b/packages/tupaia-web/src/AppProviders.tsx
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
import React, { ReactNode } from 'react';
-import { QueryClient, QueryClientProvider } from 'react-query';
+import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ThemeProvider as MuiThemeProvider, StylesProvider } from '@material-ui/core/styles';
import CssBaseline from '@material-ui/core/CssBaseline';
import { ThemeProvider } from 'styled-components';
diff --git a/packages/tupaia-web/src/api/mutations/useDownloadFiles.ts b/packages/tupaia-web/src/api/mutations/useDownloadFiles.ts
index c9e4ef7f5d..d104905a33 100644
--- a/packages/tupaia-web/src/api/mutations/useDownloadFiles.ts
+++ b/packages/tupaia-web/src/api/mutations/useDownloadFiles.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useMutation } from 'react-query';
+import { useMutation } from '@tanstack/react-query';
import downloadJs from 'downloadjs';
import { getUniqueFileNameParts } from '@tupaia/utils';
import { get } from '../api';
diff --git a/packages/tupaia-web/src/api/mutations/useDownloadRawData.ts b/packages/tupaia-web/src/api/mutations/useDownloadRawData.ts
index b4db62fec9..32ae13f08e 100644
--- a/packages/tupaia-web/src/api/mutations/useDownloadRawData.ts
+++ b/packages/tupaia-web/src/api/mutations/useDownloadRawData.ts
@@ -2,7 +2,7 @@
* Tupaia
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useMutation } from 'react-query';
+import { useMutation } from '@tanstack/react-query';
import downloadJs from 'downloadjs';
import { get } from '..';
diff --git a/packages/tupaia-web/src/api/mutations/useEmailDashboard.tsx b/packages/tupaia-web/src/api/mutations/useEmailDashboard.tsx
index 883e2a76cd..865ac6f426 100644
--- a/packages/tupaia-web/src/api/mutations/useEmailDashboard.tsx
+++ b/packages/tupaia-web/src/api/mutations/useEmailDashboard.tsx
@@ -2,7 +2,7 @@
* Tupaia
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useMutation } from 'react-query';
+import { useMutation } from '@tanstack/react-query';
import { TupaiaWebEmailDashboardRequest } from '@tupaia/types';
import { API_URL, post } from '../api';
import { Dashboard, DashboardItem, EntityCode, ProjectCode } from '../../types';
diff --git a/packages/tupaia-web/src/api/mutations/useExportDashboard.tsx b/packages/tupaia-web/src/api/mutations/useExportDashboard.tsx
index 550b452b96..27f1036bca 100644
--- a/packages/tupaia-web/src/api/mutations/useExportDashboard.tsx
+++ b/packages/tupaia-web/src/api/mutations/useExportDashboard.tsx
@@ -2,7 +2,7 @@
* Tupaia
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useMutation } from 'react-query';
+import { useMutation } from '@tanstack/react-query';
import { TupaiaWebExportDashboardRequest } from '@tupaia/types';
import { API_URL, post } from '../api';
import { DashboardName, EntityCode, ProjectCode } from '../../types';
diff --git a/packages/tupaia-web/src/api/mutations/useExportMapOverlay.ts b/packages/tupaia-web/src/api/mutations/useExportMapOverlay.ts
index 3abefa0d4c..c4762c2c2a 100644
--- a/packages/tupaia-web/src/api/mutations/useExportMapOverlay.ts
+++ b/packages/tupaia-web/src/api/mutations/useExportMapOverlay.ts
@@ -2,7 +2,7 @@
* Tupaia
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useMutation } from 'react-query';
+import { useMutation } from '@tanstack/react-query';
import { LatLng } from 'leaflet';
import { MapOverlay } from '@tupaia/types';
import { LegendProps } from '@tupaia/ui-map-components';
diff --git a/packages/tupaia-web/src/api/mutations/useExportToExcel.ts b/packages/tupaia-web/src/api/mutations/useExportToExcel.ts
index 1ba82a2298..2a815be9d3 100644
--- a/packages/tupaia-web/src/api/mutations/useExportToExcel.ts
+++ b/packages/tupaia-web/src/api/mutations/useExportToExcel.ts
@@ -2,7 +2,7 @@
* Tupaia
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useMutation } from 'react-query';
+import { useMutation } from '@tanstack/react-query';
import { getBrowserTimeZone } from '@tupaia/utils';
import { DashboardItem, EntityCode, ProjectCode } from '../../types';
import { get } from '..';
diff --git a/packages/tupaia-web/src/api/mutations/useLogin.ts b/packages/tupaia-web/src/api/mutations/useLogin.ts
index 18ba4df1ff..bf5fa0f726 100644
--- a/packages/tupaia-web/src/api/mutations/useLogin.ts
+++ b/packages/tupaia-web/src/api/mutations/useLogin.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useMutation, useQueryClient } from 'react-query';
+import { useMutation, useQueryClient } from '@tanstack/react-query';
import { Location, useLocation, useNavigate } from 'react-router';
import { gaEvent, useModal } from '../../utils';
import { post } from '../api';
diff --git a/packages/tupaia-web/src/api/mutations/useLogout.ts b/packages/tupaia-web/src/api/mutations/useLogout.ts
index 398445cd3c..677134ef9a 100644
--- a/packages/tupaia-web/src/api/mutations/useLogout.ts
+++ b/packages/tupaia-web/src/api/mutations/useLogout.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useMutation, useQueryClient } from 'react-query';
+import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useLocation, useNavigate } from 'react-router-dom';
import { post } from '../api';
import { gaEvent } from '../../utils';
@@ -16,7 +16,7 @@ export const useLogout = () => {
const queryClient = useQueryClient();
const navigate = useNavigate();
- return useMutation('logout', () => post('logout'), {
+ return useMutation(['logout'], () => post('logout'), {
onMutate: () => {
gaEvent('User', 'Log out');
},
diff --git a/packages/tupaia-web/src/api/mutations/useOneTimeLogin.ts b/packages/tupaia-web/src/api/mutations/useOneTimeLogin.ts
index 0d386ab200..fe30230bb7 100644
--- a/packages/tupaia-web/src/api/mutations/useOneTimeLogin.ts
+++ b/packages/tupaia-web/src/api/mutations/useOneTimeLogin.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useMutation, useQueryClient } from 'react-query';
+import { useMutation, useQueryClient } from '@tanstack/react-query';
import { post } from '../api';
type LoginCredentials = {
diff --git a/packages/tupaia-web/src/api/mutations/useRegister.ts b/packages/tupaia-web/src/api/mutations/useRegister.ts
index 7bdda0cee7..771c1c4754 100644
--- a/packages/tupaia-web/src/api/mutations/useRegister.ts
+++ b/packages/tupaia-web/src/api/mutations/useRegister.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useMutation } from 'react-query';
+import { useMutation } from '@tanstack/react-query';
import { post } from '../api';
// Todo: replace with request body type from backend
diff --git a/packages/tupaia-web/src/api/mutations/useRequestCountryAccess.ts b/packages/tupaia-web/src/api/mutations/useRequestCountryAccess.ts
index 20ce5d569f..e5fcd5b927 100644
--- a/packages/tupaia-web/src/api/mutations/useRequestCountryAccess.ts
+++ b/packages/tupaia-web/src/api/mutations/useRequestCountryAccess.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useMutation, useQueryClient } from 'react-query';
+import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useParams, useSearchParams } from 'react-router-dom';
import { post } from '../api';
import { URL_SEARCH_PARAMS } from '../../constants';
diff --git a/packages/tupaia-web/src/api/mutations/useRequestResetPassword.ts b/packages/tupaia-web/src/api/mutations/useRequestResetPassword.ts
index bfe5b64f9b..2f3766dc43 100644
--- a/packages/tupaia-web/src/api/mutations/useRequestResetPassword.ts
+++ b/packages/tupaia-web/src/api/mutations/useRequestResetPassword.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useMutation } from 'react-query';
+import { useMutation } from '@tanstack/react-query';
import { post } from '../api';
type ResetPasswordParams = {
diff --git a/packages/tupaia-web/src/api/mutations/useResendVerificationEmail.ts b/packages/tupaia-web/src/api/mutations/useResendVerificationEmail.ts
index 099cf36290..1095f7a6b0 100644
--- a/packages/tupaia-web/src/api/mutations/useResendVerificationEmail.ts
+++ b/packages/tupaia-web/src/api/mutations/useResendVerificationEmail.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useMutation } from 'react-query';
+import { useMutation } from '@tanstack/react-query';
import { post } from '../api';
type RequestBody = {
diff --git a/packages/tupaia-web/src/api/mutations/useResetPassword.ts b/packages/tupaia-web/src/api/mutations/useResetPassword.ts
index 1b068fcbd6..751f209cee 100644
--- a/packages/tupaia-web/src/api/mutations/useResetPassword.ts
+++ b/packages/tupaia-web/src/api/mutations/useResetPassword.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useMutation } from 'react-query';
+import { useMutation } from '@tanstack/react-query';
import { useLocation, useNavigate, useSearchParams } from 'react-router-dom';
import { post } from '../api';
import { URL_SEARCH_PARAMS } from '../../constants';
diff --git a/packages/tupaia-web/src/api/mutations/useSubscribeDashboard.ts b/packages/tupaia-web/src/api/mutations/useSubscribeDashboard.ts
index 86adbf8e33..ca445fa5d3 100644
--- a/packages/tupaia-web/src/api/mutations/useSubscribeDashboard.ts
+++ b/packages/tupaia-web/src/api/mutations/useSubscribeDashboard.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useMutation } from 'react-query';
+import { useMutation } from '@tanstack/react-query';
import { TupaiaWebSubscribeDashboardRequest } from '@tupaia/types';
import { post } from '../api';
diff --git a/packages/tupaia-web/src/api/mutations/useUnsubscribeDashboard.ts b/packages/tupaia-web/src/api/mutations/useUnsubscribeDashboard.ts
index e0bb2628ca..c123332757 100644
--- a/packages/tupaia-web/src/api/mutations/useUnsubscribeDashboard.ts
+++ b/packages/tupaia-web/src/api/mutations/useUnsubscribeDashboard.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useMutation } from 'react-query';
+import { useMutation } from '@tanstack/react-query';
import { TupaiaWebUnsubscribeDashboardRequest } from '@tupaia/types';
import { put } from '../api';
diff --git a/packages/tupaia-web/src/api/mutations/useUnsubscribeDashboardMailingList.ts b/packages/tupaia-web/src/api/mutations/useUnsubscribeDashboardMailingList.ts
index dd512bd23c..aab149ecce 100644
--- a/packages/tupaia-web/src/api/mutations/useUnsubscribeDashboardMailingList.ts
+++ b/packages/tupaia-web/src/api/mutations/useUnsubscribeDashboardMailingList.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useMutation } from 'react-query';
+import { useMutation } from '@tanstack/react-query';
import { TupaiaWebUnsubscribeDashboardMailingListRequest } from '@tupaia/types';
import { put } from '../api';
diff --git a/packages/tupaia-web/src/api/queries/useDashboards.ts b/packages/tupaia-web/src/api/queries/useDashboards.ts
index 459504f92d..3d35331fac 100644
--- a/packages/tupaia-web/src/api/queries/useDashboards.ts
+++ b/packages/tupaia-web/src/api/queries/useDashboards.ts
@@ -2,7 +2,7 @@
* Tupaia
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { TupaiaWebDashboardsRequest } from '@tupaia/types';
import { EntityCode, ProjectCode } from '../../types';
import { get } from '../api';
diff --git a/packages/tupaia-web/src/api/queries/useEntities.ts b/packages/tupaia-web/src/api/queries/useEntities.ts
index 95af4b613f..45f1d2e1a7 100644
--- a/packages/tupaia-web/src/api/queries/useEntities.ts
+++ b/packages/tupaia-web/src/api/queries/useEntities.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
import { AxiosRequestConfig } from 'axios';
-import { useQuery, QueryObserverOptions } from 'react-query';
+import { useQuery, QueryObserverOptions } from '@tanstack/react-query';
import { get } from '../api';
import { Entity } from '../../types';
diff --git a/packages/tupaia-web/src/api/queries/useEntity.ts b/packages/tupaia-web/src/api/queries/useEntity.ts
index 9dfef79ac9..e1775b683c 100644
--- a/packages/tupaia-web/src/api/queries/useEntity.ts
+++ b/packages/tupaia-web/src/api/queries/useEntity.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { useLocation } from 'react-router';
import { EntityCode, ProjectCode, Entity } from '../../types';
import { get } from '../api';
diff --git a/packages/tupaia-web/src/api/queries/useEntityAncestors.ts b/packages/tupaia-web/src/api/queries/useEntityAncestors.ts
index cd9fb5aa69..2da433e727 100644
--- a/packages/tupaia-web/src/api/queries/useEntityAncestors.ts
+++ b/packages/tupaia-web/src/api/queries/useEntityAncestors.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { Entity, EntityCode, ProjectCode } from '../../types';
import { get } from '../api';
diff --git a/packages/tupaia-web/src/api/queries/useEntitySearch.ts b/packages/tupaia-web/src/api/queries/useEntitySearch.ts
index 54e75bbccd..facd47d31c 100644
--- a/packages/tupaia-web/src/api/queries/useEntitySearch.ts
+++ b/packages/tupaia-web/src/api/queries/useEntitySearch.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { ProjectCode, Entity } from '../../types';
import { get } from '../api';
import { useDebounce } from '../../utils';
diff --git a/packages/tupaia-web/src/api/queries/useLandingPage.ts b/packages/tupaia-web/src/api/queries/useLandingPage.ts
index 41cd5f4293..82ed832399 100644
--- a/packages/tupaia-web/src/api/queries/useLandingPage.ts
+++ b/packages/tupaia-web/src/api/queries/useLandingPage.ts
@@ -4,7 +4,7 @@
*
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { useParams } from 'react-router';
import { get } from '../api';
import { SingleLandingPage } from '../../types';
diff --git a/packages/tupaia-web/src/api/queries/useMapOverlayReport.ts b/packages/tupaia-web/src/api/queries/useMapOverlayReport.ts
index 90ff37a873..3b42a0bb08 100644
--- a/packages/tupaia-web/src/api/queries/useMapOverlayReport.ts
+++ b/packages/tupaia-web/src/api/queries/useMapOverlayReport.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
import moment, { Moment } from 'moment';
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { momentToDateString } from '@tupaia/utils';
import { TupaiaWebMapOverlaysRequest } from '@tupaia/types';
import {
diff --git a/packages/tupaia-web/src/api/queries/useMapOverlays.ts b/packages/tupaia-web/src/api/queries/useMapOverlays.ts
index a80addee9d..d341cb8711 100644
--- a/packages/tupaia-web/src/api/queries/useMapOverlays.ts
+++ b/packages/tupaia-web/src/api/queries/useMapOverlays.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
import { useSearchParams } from 'react-router-dom';
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { POLYGON_MEASURE_TYPES } from '@tupaia/ui-map-components';
import { TupaiaWebMapOverlaysRequest } from '@tupaia/types';
import { get } from '../api';
diff --git a/packages/tupaia-web/src/api/queries/useProject.ts b/packages/tupaia-web/src/api/queries/useProject.ts
index 47e4f1d3f9..571695e080 100644
--- a/packages/tupaia-web/src/api/queries/useProject.ts
+++ b/packages/tupaia-web/src/api/queries/useProject.ts
@@ -4,7 +4,7 @@
*
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { SingleProject } from '../../types';
import { get } from '../api';
import { useUser } from './useUser';
diff --git a/packages/tupaia-web/src/api/queries/useProjectCountryAccessList.ts b/packages/tupaia-web/src/api/queries/useProjectCountryAccessList.ts
index 3aea27dc3c..f4534c3952 100644
--- a/packages/tupaia-web/src/api/queries/useProjectCountryAccessList.ts
+++ b/packages/tupaia-web/src/api/queries/useProjectCountryAccessList.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { ProjectCountryAccessListRequest } from '@tupaia/types';
import { get } from '../api';
import { ProjectCode } from '../../types';
diff --git a/packages/tupaia-web/src/api/queries/useProjects.ts b/packages/tupaia-web/src/api/queries/useProjects.ts
index 85a29ab432..226f140446 100644
--- a/packages/tupaia-web/src/api/queries/useProjects.ts
+++ b/packages/tupaia-web/src/api/queries/useProjects.ts
@@ -3,12 +3,12 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { get } from '../api';
export const useProjects = () => {
return useQuery(
- 'projects',
+ ['projects'],
() =>
get('projects', {
params: {
diff --git a/packages/tupaia-web/src/api/queries/useReport.ts b/packages/tupaia-web/src/api/queries/useReport.ts
index 48319bc5f6..aeebe0b889 100644
--- a/packages/tupaia-web/src/api/queries/useReport.ts
+++ b/packages/tupaia-web/src/api/queries/useReport.ts
@@ -4,7 +4,7 @@
*
*/
import moment, { Moment } from 'moment';
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { formatDateForApi, getBrowserTimeZone } from '@tupaia/utils';
import { TupaiaWebReportRequest } from '@tupaia/types';
import { get } from '../api';
diff --git a/packages/tupaia-web/src/api/queries/useUser.ts b/packages/tupaia-web/src/api/queries/useUser.ts
index ed8f63d45e..445808c279 100644
--- a/packages/tupaia-web/src/api/queries/useUser.ts
+++ b/packages/tupaia-web/src/api/queries/useUser.ts
@@ -3,13 +3,13 @@
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
-import { useQuery } from 'react-query';
+import { useQuery } from '@tanstack/react-query';
import { TupaiaWebUserRequest } from '@tupaia/types';
import { get } from '../api';
export const useUser = () => {
const userResponse = useQuery(
- 'getUser',
+ ['getUser'],
(): Promise => get('getUser'),
);
const { data: user } = userResponse;
diff --git a/packages/tupaia-web/src/components/CheckboxList.tsx b/packages/tupaia-web/src/components/CheckboxList.tsx
index 29e2d5554c..4f57fcbf44 100644
--- a/packages/tupaia-web/src/components/CheckboxList.tsx
+++ b/packages/tupaia-web/src/components/CheckboxList.tsx
@@ -22,7 +22,7 @@ const Error = styled(Typography).attrs({
`;
interface CheckboxListProps {
- options: { value: string; label: string }[];
+ options: { value: string; label?: string }[];
legend: string;
name: string;
required?: boolean;
@@ -38,7 +38,7 @@ export const CheckboxList = ({ options, legend, name, required }: CheckboxListPr
{
+ const {
+ mutateAsync: fetchDownloadData,
+ isLoading,
+ error,
+ data: downloadResponse,
+ } = useDownloadRawData(report?.downloadUrl);
+
+ const { data } = report;
+
+ return (
+ ({
+ label: name,
+ value,
+ })) ?? []
+ }
+ isLoading={isLoading}
+ onDownload={fetchDownloadData}
+ isEnlarged={isEnlarged}
+ error={error as Error}
+ >
+ {downloadResponse?.emailTimeoutHit && (
+
+ This export is taking a while, and will continue in the background. You will be emailed
+ when the export process completes.
+
+ )}
+
+ );
+};
diff --git a/packages/tupaia-web/src/features/Visuals/View/Download/DownloadFiles.tsx b/packages/tupaia-web/src/features/Visuals/View/Download/DownloadFiles.tsx
new file mode 100644
index 0000000000..0959416441
--- /dev/null
+++ b/packages/tupaia-web/src/features/Visuals/View/Download/DownloadFiles.tsx
@@ -0,0 +1,39 @@
+/*
+ * Tupaia
+ * Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
+ */
+
+import React from 'react';
+import { ViewConfig, ViewReport } from '@tupaia/types';
+import { useDownloadFiles } from '../../../../api/mutations';
+import { DownloadVisual } from './DownloadVisual';
+
+interface DownloadFilesVisualProps {
+ report: ViewReport;
+ config: ViewConfig;
+ isEnlarged?: boolean;
+}
+
+export const DownloadFiles = ({ report, isEnlarged }: DownloadFilesVisualProps) => {
+ const { mutate: download, error, reset, isLoading } = useDownloadFiles();
+ const options =
+ report?.data?.map(({ label, uniqueFileName }) => ({
+ value: uniqueFileName,
+ label,
+ })) ?? [];
+
+ const downloadSelectedFiles = selectedValues => {
+ download(Array.isArray(selectedValues) ? selectedValues : [selectedValues]);
+ };
+
+ return (
+
+ );
+};
diff --git a/packages/tupaia-web/src/features/Visuals/View/DataDownload.tsx b/packages/tupaia-web/src/features/Visuals/View/Download/DownloadVisual.tsx
similarity index 56%
rename from packages/tupaia-web/src/features/Visuals/View/DataDownload.tsx
rename to packages/tupaia-web/src/features/Visuals/View/Download/DownloadVisual.tsx
index 46b639f4ce..ef74b682e8 100644
--- a/packages/tupaia-web/src/features/Visuals/View/DataDownload.tsx
+++ b/packages/tupaia-web/src/features/Visuals/View/Download/DownloadVisual.tsx
@@ -1,17 +1,15 @@
/**
* Tupaia
- * Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
+ * Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
import React from 'react';
import styled from 'styled-components';
-import { useSearchParams } from 'react-router-dom';
import { useForm } from 'react-hook-form';
-import { Alert, Button, SpinningLoader } from '@tupaia/ui-components';
+import { useSearchParams } from 'react-router-dom';
import { List, Typography } from '@material-ui/core';
-import { ViewReport } from '@tupaia/types';
-import { CheckboxList, Form as BaseForm } from '../../../components';
-import { URL_SEARCH_PARAMS } from '../../../constants';
-import { useDownloadRawData } from '../../../api/mutations';
+import { Button, SpinningLoader } from '@tupaia/ui-components';
+import { CheckboxList, Form as BaseForm } from '../../../../components';
+import { URL_SEARCH_PARAMS } from '../../../../constants';
const ListItem = styled.li`
text-align: center;
@@ -54,6 +52,7 @@ const FormButton = styled(Button)`
const CheckboxListWrapper = styled.div`
width: 30rem;
max-width: 100%;
+ flex-grow: 1;
`;
const ErrorMessage = styled(Typography).attrs({
@@ -63,67 +62,53 @@ const ErrorMessage = styled(Typography).attrs({
margin-bottom: 1rem;
`;
-const EmailDownloadAlert = styled(Alert).attrs({
- severity: 'info',
-})`
- margin-bottom: 1rem;
-`;
-
-interface DataDownloadProps {
- report: ViewReport;
+interface DownloadVisualProps {
+ options: { label?: string; value: any }[];
+ isLoading: boolean;
+ onDownload: (selectedValues: string[]) => void;
isEnlarged?: boolean;
+ children?: React.ReactNode;
+ error?: Error;
+ onClose?: () => void;
}
-export const DataDownload = ({ report, isEnlarged }: DataDownloadProps) => {
+/**
+ * @description Component for downloading data from a visual. This component is used in the DataDownload and DownloadFiles visuals.
+ */
+export const DownloadVisual = ({
+ options,
+ isLoading,
+ onDownload,
+ isEnlarged,
+ children,
+ error,
+ onClose,
+}: DownloadVisualProps) => {
const [urlSearchParams, setUrlSearchParams] = useSearchParams();
const reportCode = urlSearchParams.get(URL_SEARCH_PARAMS.REPORT);
const formContext = useForm({
mode: 'onChange',
});
- const selectedCodes = formContext.watch(reportCode!);
- const {
- mutateAsync: fetchDownloadData,
- isLoading,
- error,
- data: downloadResponse,
- } = useDownloadRawData(report?.downloadUrl);
+ const selectedValues = formContext.watch(reportCode!);
- const { data } = report;
if (!isEnlarged)
- return (
-
- {data?.map(({ name }) => (
- {name}
- ))}
-
- );
+ return {options?.map(({ label }) => {label})}
;
const closeModal = () => {
urlSearchParams.delete(URL_SEARCH_PARAMS.REPORT);
urlSearchParams.delete(URL_SEARCH_PARAMS.REPORT_PERIOD);
setUrlSearchParams(urlSearchParams);
+ if (onClose) onClose();
};
return isLoading ? (
) : (