Merge branch 'dev' into bugfix/user-website-error

This commit is contained in:
Mike Cao 2023-08-18 13:32:21 -10:00 committed by GitHub
commit 907253926e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 24 deletions

View File

@ -2,15 +2,13 @@ import useApi from 'hooks/useApi';
import WebsitesTable from 'components/pages/settings/websites/WebsitesTable';
import useMessages from 'hooks/useMessages';
import useApiFilter from 'hooks/useApiFilter';
import Page from 'components/layout/Page';
import useConfig from 'hooks/useConfig';
export function UserWebsites({ userId }) {
const { cloudMode } = useConfig();
const { formatMessage, messages } = useMessages();
const { filter, page, pageSize, handlePageSizeChange, handleFilterChange, handlePageChange } = useApiFilter();
const { filter, page, pageSize, handleFilterChange, handlePageChange, handlePageSizeChange } =
useApiFilter();
const { get, useQuery } = useApi();
const { data, isLoading, error } = useQuery(['user:websites', userId, filter, page, pageSize], () =>
const { data, isLoading } = useQuery(['user:websites', userId, filter, page, pageSize], () =>
get(`/users/${userId}/websites`, {
filter,
page,
@ -20,19 +18,18 @@ export function UserWebsites({ userId }) {
const hasData = data && data.length !== 0;
return (
<Page loading={isLoading} error={error}>
<div>
{hasData && (
<WebsitesTable
data={data}
onFilterChange={handleFilterChange}
onPageChange={handlePageChange}
<WebsitesTable
data={data}
onFilterChange={handleFilterChange}
onPageChange={handlePageChange}
onPageSizeChange={handlePageSizeChange}
filterValue={filter}
showEditButton={!cloudMode}
/>)
}
/>
)}
{!hasData && formatMessage(messages.noDataAvailable)}
</Page>
</div>
);
}

View File

@ -185,7 +185,9 @@ function getPageFilters(filters: SearchFilter<any>): [
orderBy: string;
},
] {
const { pageSize = 10, page = 1, orderBy } = filters;
const pageSize = filters?.pageSize || 10;
const page = filters?.page || 1;
const orderBy = filters?.orderBy;
return [
{

View File

@ -37,7 +37,7 @@ export async function getUserByUsername(username: string, options: GetUserOption
}
export async function getUsers(
UserSearchFilter: UserSearchFilter = {},
UserSearchFilter: UserSearchFilter,
options?: { include?: Prisma.UserInclude },
): Promise<FilterResult<User[]>> {
const { teamId, filter, filterType = USER_FILTER_TYPES.all } = UserSearchFilter;
@ -72,14 +72,22 @@ export async function getUsers(
...UserSearchFilter,
});
const users = await prisma.client.user.findMany({
where: {
...where,
deletedAt: null,
},
...pageFilters,
...(options?.include && { include: options.include }),
});
const users = await prisma.client.user
.findMany({
where: {
...where,
deletedAt: null,
},
...pageFilters,
...(options?.include && { include: options.include }),
})
.then(a => {
return a.map(a => {
const { password, ...rest } = a;
return rest;
});
});
const count = await prisma.client.user.count({
where: {
...where,