From bd014b10a4926d340af3248f99a68a6caf3ce8f3 Mon Sep 17 00:00:00 2001 From: David Inga Date: Fri, 8 Sep 2023 11:33:37 +0200 Subject: [PATCH] fixed missing error message when upload failed with no errors --- client/CHANGELOG.md | 1 + .../admin/data-upload-error/component.tsx | 12 ++++++++++++ client/src/hooks/tasks/index.ts | 13 +++++++------ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/client/CHANGELOG.md b/client/CHANGELOG.md index 7d3595b97..d813a8537 100644 --- a/client/CHANGELOG.md +++ b/client/CHANGELOG.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/). ### Fixed +- Fixed error message when upload failed with no errors [LANDGRIF-1474](https://vizzuality.atlassian.net/browse/LANDGRIF-1474) - Fixed edit intervention admin region [LANDGRIF-1445](https://vizzuality.atlassian.net/browse/LANDGRIF-1445) - Fixed remove badge when unselecting 'T1 supplier' filter in analysis [LANDGRIF-1442](https://vizzuality.atlassian.net/browse/LANDGRIF-1442) - Fixed intervention creation: business units check strategy [LANDGRIF-1444](https://vizzuality.atlassian.net/browse/LANDGRIF-1444) diff --git a/client/src/containers/admin/data-upload-error/component.tsx b/client/src/containers/admin/data-upload-error/component.tsx index 24bf60502..6c9541c99 100644 --- a/client/src/containers/admin/data-upload-error/component.tsx +++ b/client/src/containers/admin/data-upload-error/component.tsx @@ -77,6 +77,18 @@ const DataUploadError: React.FC = ({ task }) => { )} + {task?.status === 'failed' && task?.errors.length === 0 && ( + <> +

Upload failed

+

+ Sorry, we couldn't upload your latest changes made on{' '} + {format(new Date(task.createdAt), 'MMM 4, yyyy HH:mm z')}. We have{' '} + reverted to the previous version to avoid + data loss. Please try uploading again. +

+ + )} + {task?.status === 'failed' && task?.errors.length > 0 && ( <>

Upload failed

diff --git a/client/src/hooks/tasks/index.ts b/client/src/hooks/tasks/index.ts index de2542d07..eaf9df96f 100644 --- a/client/src/hooks/tasks/index.ts +++ b/client/src/hooks/tasks/index.ts @@ -4,13 +4,14 @@ import { apiRawService, apiService } from 'services/api'; import type { UseQueryResult, UseQueryOptions, UseMutationResult } from '@tanstack/react-query'; import type { APIMetadataPagination, ErrorResponse, Task } from 'types'; +import type { AxiosResponse } from 'axios'; type TaskAPIResponse = Task; -type TasksAPIResponse = { +type TasksAPIResponse = AxiosResponse<{ data: Task[]; meta: APIMetadataPagination; -}; +}>; const DEFAULT_QUERY_OPTIONS = { retry: false, @@ -22,9 +23,9 @@ const DEFAULT_QUERY_OPTIONS = { export const useTasks = ( params: Record = {}, - options: UseQueryOptions = {}, + options: UseQueryOptions = {}, ) => { - const query = useQuery( + const query = useQuery( ['tasks', params], () => apiService @@ -33,7 +34,7 @@ export const useTasks = ( url: '/tasks', params, }) - .then(({ data: responseData }) => responseData.data), + .then((response) => response.data), { ...DEFAULT_QUERY_OPTIONS, ...options, @@ -57,7 +58,7 @@ export const useLasTask = () => { }, ); - return { ...tasks, data: tasks.data?.[0] }; + return { ...tasks, data: tasks?.data?.data?.[0] }; }; export function useTask(