Fix UserWebsites.

This commit is contained in:
Brian Cao 2023-08-18 11:10:44 -07:00
parent bc7111a984
commit 87cf5d5298

View File

@ -2,12 +2,19 @@ import { Loading } from 'react-basics';
import useApi from 'hooks/useApi';
import WebsitesTable from 'components/pages/settings/websites/WebsitesTable';
import useMessages from 'hooks/useMessages';
import useApiFilter from 'hooks/useApiFilter';
export function UserWebsites({ userId }) {
const { formatMessage, messages } = useMessages();
const { filter, page, pageSize, handleFilterChange, handlePageChange, handlePageSizeChange } =
useApiFilter();
const { get, useQuery } = useApi();
const { data, isLoading } = useQuery(['user:websites', userId], () =>
get(`/users/${userId}/websites`),
const { data, isLoading } = useQuery(['user:websites', userId, filter, page, pageSize], () =>
get(`/users/${userId}/websites`, {
filter,
page,
pageSize,
}),
);
const hasData = data && data.length !== 0;
@ -17,7 +24,15 @@ export function UserWebsites({ userId }) {
return (
<div>
{hasData && <WebsitesTable data={data} />}
{hasData && (
<WebsitesTable
data={data}
onFilterChange={handleFilterChange}
onPageChange={handlePageChange}
onPageSizeChange={handlePageSizeChange}
filterValue={filter}
/>
)}
{!hasData && formatMessage(messages.noDataAvailable)}
</div>
);