Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed missing error message when upload failed with no errors #1061

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions client/src/containers/admin/data-upload-error/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ const DataUploadError: React.FC<DataUploadErrorProps> = ({ task }) => {
</>
)}

{task?.status === 'failed' && task?.errors.length === 0 && (
<>
<h3>Upload failed</h3>
<p className="text-gray-500">
Sorry, we couldn&apos;t upload your latest changes made on{' '}
{format(new Date(task.createdAt), 'MMM 4, yyyy HH:mm z')}. We have{' '}
<strong className="text-gray-900">reverted to the previous version</strong> to avoid
data loss. Please try uploading again.
</p>
</>
)}

{task?.status === 'failed' && task?.errors.length > 0 && (
<>
<h3>Upload failed</h3>
Expand Down
13 changes: 7 additions & 6 deletions client/src/hooks/tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -22,9 +23,9 @@ const DEFAULT_QUERY_OPTIONS = {

export const useTasks = (
params: Record<string, string | number | boolean> = {},
options: UseQueryOptions<TasksAPIResponse['data']> = {},
options: UseQueryOptions<TasksAPIResponse> = {},
) => {
const query = useQuery<TasksAPIResponse['data'], ErrorResponse>(
const query = useQuery<TasksAPIResponse, ErrorResponse>(
['tasks', params],
() =>
apiService
Expand All @@ -33,7 +34,7 @@ export const useTasks = (
url: '/tasks',
params,
})
.then(({ data: responseData }) => responseData.data),
.then((response) => response.data),
{
...DEFAULT_QUERY_OPTIONS,
...options,
Expand All @@ -57,7 +58,7 @@ export const useLasTask = () => {
},
);

return { ...tasks, data: tasks.data?.[0] };
return { ...tasks, data: tasks?.data?.data?.[0] };
};

export function useTask(
Expand Down