diff --git a/client/src/pages/data/index.tsx b/client/src/pages/data/index.tsx index c0ba453d9..d82678e22 100644 --- a/client/src/pages/data/index.tsx +++ b/client/src/pages/data/index.tsx @@ -1,4 +1,3 @@ -import { useMemo } from 'react'; import Head from 'next/head'; import { GetServerSideProps } from 'next'; import { dehydrate } from '@tanstack/react-query'; @@ -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 ( { Manage data | Landgriffon - - {thereIsData && lastTask?.status !== 'processing' && } - - {(['processing', 'failed'].includes(lastTask?.status) || - (!lastTask && lastTaskIsFetched)) && } + {showDataTable && } + {showDataUploader && } ); };