Skip to content

Commit

Permalink
fixed when to show data table
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsingal committed Oct 16, 2023
1 parent 1baa0b4 commit 9b0a723
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
10 changes: 10 additions & 0 deletions client/src/containers/admin/data-upload-error/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ const DataUploadError: React.FC<DataUploadErrorProps> = ({ task }) => {
>
<div className="flex w-full space-x-6 items-center">
<div className="space-y-1.5 flex-1">
{task?.status === 'processing' && (
<>
<h3>Upload in progress</h3>
<p className="text-gray-500">
There is a uploading task in progress created at{' '}
{format(new Date(task.createdAt), 'MMM d, yyyy HH:mm z')}.
</p>
</>
)}

{task?.status === 'completed' && task?.errors.length === 0 && (
<>
<h3>Upload completed</h3>
Expand Down
2 changes: 1 addition & 1 deletion client/src/hooks/tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const useLasTask = () => {
},
);

return { ...tasks, data: tasks?.data?.data?.[0] };
return { ...tasks, data: tasks?.data?.data?.[0] } as UseQueryResult<TaskAPIResponse>;
};

export function useTask(
Expand Down
7 changes: 3 additions & 4 deletions client/src/pages/data/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useMemo } from 'react';
import Head from 'next/head';

import { useSourcingLocations } from 'hooks/sourcing-locations';
Expand All @@ -19,7 +20,7 @@ const AdminDataPage: React.FC = () => {
// Getting last task to check if there is a processing task
const { data: lastTask } = useLasTask();

const thereIsData = data?.meta?.totalItems > 0;
const thereIsData = useMemo(() => data?.meta?.totalItems > 0, [data?.meta?.totalItems]);

return (
<AdminLayout
Expand All @@ -45,9 +46,7 @@ const AdminDataPage: React.FC = () => {
)}

{/* Content when empty, or upload is processing or failed */}
{isFetched && (lastTask?.status === 'processing' || !thereIsData) && (
<AdminDataUploader task={lastTask} />
)}
{isFetched && !thereIsData && <AdminDataUploader task={lastTask} />}

{/* Content when data and upload is completed */}
{isFetched && thereIsData && <AdminDataTable task={lastTask} />}
Expand Down

0 comments on commit 9b0a723

Please sign in to comment.