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

[LANDGRIF-1555] fixes UI when no data #1191

Merged
merged 1 commit into from
Jun 10, 2024
Merged
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
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
Loading