umami/src/app/(main)/settings/websites/WebsitesDataTable.tsx

67 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-09-29 12:29:22 +00:00
'use client';
2023-10-08 05:42:49 +00:00
import { ReactNode } from 'react';
2023-10-03 23:05:17 +00:00
import WebsitesTable from 'app/(main)/settings/websites/WebsitesTable';
2023-09-29 12:29:22 +00:00
import useApi from 'components/hooks/useApi';
import DataTable from 'components/common/DataTable';
import useFilterQuery from 'components/hooks/useFilterQuery';
2023-10-08 01:55:14 +00:00
import useCache from 'store/cache';
2023-09-29 12:29:22 +00:00
2023-10-08 05:42:49 +00:00
export interface WebsitesDataTableProps {
2023-11-23 02:03:48 +00:00
userId: string;
2023-10-08 05:42:49 +00:00
allowEdit?: boolean;
allowView?: boolean;
showActions?: boolean;
showTeam?: boolean;
includeTeams?: boolean;
onlyTeams?: boolean;
children?: ReactNode;
}
2023-11-23 02:03:48 +00:00
function useWebsites(userId: string, { includeTeams, onlyTeams }) {
2023-09-29 12:29:22 +00:00
const { get } = useApi();
2023-10-08 05:42:49 +00:00
const modified = useCache((state: any) => state?.websites);
2023-10-08 01:55:14 +00:00
2023-10-04 08:46:00 +00:00
return useFilterQuery(
2023-10-08 01:55:14 +00:00
['websites', { includeTeams, onlyTeams, modified }],
(params: any) => {
2023-11-23 02:03:48 +00:00
return get(`/users/${userId}/websites`, {
2023-09-29 12:29:22 +00:00
includeTeams,
onlyTeams,
...params,
});
},
2023-11-23 02:03:48 +00:00
{ enabled: !!userId },
2023-09-29 12:29:22 +00:00
);
2023-10-04 08:46:00 +00:00
}
export function WebsitesDataTable({
2023-11-23 02:03:48 +00:00
userId,
2023-10-08 01:55:14 +00:00
allowEdit = true,
allowView = true,
2023-10-04 08:46:00 +00:00
showActions = true,
showTeam,
includeTeams,
onlyTeams,
children,
2023-10-08 05:42:49 +00:00
}: WebsitesDataTableProps) {
2023-11-23 02:03:48 +00:00
const queryResult = useWebsites(userId, { includeTeams, onlyTeams });
2023-09-29 12:29:22 +00:00
return (
2023-10-08 01:55:14 +00:00
<DataTable queryResult={queryResult}>
{({ data }) => (
<WebsitesTable
data={data}
showTeam={showTeam}
showActions={showActions}
allowEdit={allowEdit}
allowView={allowView}
>
{children}
</WebsitesTable>
)}
</DataTable>
2023-09-29 12:29:22 +00:00
);
}
2023-10-04 08:46:00 +00:00
export default WebsitesDataTable;