Skip to content

Commit

Permalink
fixes UI when no data
Browse files Browse the repository at this point in the history
  • Loading branch information
andresgnlez committed Jun 10, 2024
1 parent a1fc78d commit e623ed5
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions client/src/pages/data/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useMemo } from 'react';
import Head from 'next/head';
import { GetServerSideProps } from 'next';
import { dehydrate } from '@tanstack/react-query';
Expand All @@ -13,17 +12,21 @@ import Search from '@/components/search';
import { useLasTask } from '@/hooks/tasks';

const AdminDataPage: React.FC = () => {
const { data, isFetched } = useSourcingLocations({
const { data, isFetched: sourcingLocationsAreFetched } = useSourcingLocations({
fields: 'updatedAt',
'page[number]': 1,
'page[size]': 1,
});

const { data: lastTask, isFetched: lastTaskIsFetched } = useLasTask();

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

const showDataTable = hasData && lastTask?.status !== 'processing';
const showDataUploader =
['processing', 'failed'].includes(lastTask?.status) ||
(!lastTask && lastTaskIsFetched) ||
!hasData;

return (
<AdminLayout
Expand All @@ -41,11 +44,8 @@ const AdminDataPage: React.FC = () => {
<Head>
<title>Manage data | Landgriffon</title>
</Head>

{thereIsData && lastTask?.status !== 'processing' && <AdminDataTable />}

{(['processing', 'failed'].includes(lastTask?.status) ||
(!lastTask && lastTaskIsFetched)) && <AdminDataUploader />}
{showDataTable && <AdminDataTable />}
{showDataUploader && <AdminDataUploader />}
</AdminLayout>
);
};
Expand Down

0 comments on commit e623ed5

Please sign in to comment.