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

67 lines
1.6 KiB
TypeScript
Raw Normal View History

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