2023-09-29 12:29:22 +00:00
|
|
|
'use client';
|
2023-12-06 03:22:14 +00:00
|
|
|
import { ReactNode, useContext } 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-12-06 03:22:14 +00:00
|
|
|
import SettingsContext from '../SettingsContext';
|
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-12-06 03:22:14 +00:00
|
|
|
export function WebsitesDataTable({
|
|
|
|
|
userId,
|
|
|
|
|
allowEdit = true,
|
|
|
|
|
allowView = true,
|
|
|
|
|
showActions = true,
|
|
|
|
|
showTeam,
|
|
|
|
|
includeTeams,
|
|
|
|
|
onlyTeams,
|
|
|
|
|
children,
|
|
|
|
|
}: WebsitesDataTableProps) {
|
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-12-06 03:22:14 +00:00
|
|
|
const { websitesUrl } = useContext(SettingsContext);
|
2023-10-08 01:55:14 +00:00
|
|
|
|
2023-12-06 03:22:14 +00:00
|
|
|
const queryResult = useFilterQuery({
|
2023-12-02 04:27:59 +00:00
|
|
|
queryKey: ['websites', { includeTeams, onlyTeams, modified }],
|
|
|
|
|
queryFn: (params: any) => {
|
2023-12-06 03:22:14 +00:00
|
|
|
return get(websitesUrl, {
|
2023-09-29 12:29:22 +00:00
|
|
|
includeTeams,
|
|
|
|
|
onlyTeams,
|
|
|
|
|
...params,
|
|
|
|
|
});
|
|
|
|
|
},
|
2023-12-02 04:27:59 +00:00
|
|
|
enabled: !!userId,
|
|
|
|
|
});
|
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;
|