Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecao committed Oct 16, 2023
2 parents 2732ed1 + 9732d0e commit 8cb1c4e
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/app/(main)/settings/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function SettingsLayout({ children }) {

const getKey = () => items.find(({ url }) => pathname === url)?.key;

if (cloudMode) {
if (cloudMode && pathname != '/settings/profile') {
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/common/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ export function DataTable({
const noResults = Boolean(!isLoading && query && !hasData);

const handleSearch = query => {
setParams({ ...params, query, page: params.query ? page : 1 });
setParams({ ...params, query, page: params.page ? page : 1 });
};

const handlePageChange = page => {
setParams({ ...params, page });
setParams({ ...params, query, page });
};

if (error) {
Expand Down
3 changes: 2 additions & 1 deletion src/components/hooks/useFilterQuery.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useState } from 'react';
import { useApi } from 'components/hooks/useApi';
import { UseQueryOptions } from '@tanstack/react-query';

export function useFilterQuery(key: any[], fn, options?: any) {
export function useFilterQuery(key: any[], fn, options?: UseQueryOptions) {
const [params, setParams] = useState({
query: '',
page: 1,
Expand Down
3 changes: 2 additions & 1 deletion src/pages/api/reports/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ export default async (
} = req.auth;

if (req.method === 'GET') {
const { page, query } = req.query;
const { page, query, pageSize } = req.query;

const data = await getReportsByUserId(userId, {
page,
pageSize: +pageSize || undefined,
query,
includeTeams: true,
});
Expand Down
5 changes: 4 additions & 1 deletion src/pages/api/teams/[id]/users/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { NextApiRequestQueryBody, SearchFilter } from 'lib/types';
import { NextApiResponse } from 'next';
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
import { getUsersByTeamId } from 'queries';
import { pageInfo } from 'lib/schema';

export interface TeamUserRequestQuery extends SearchFilter {
id: string;
Expand All @@ -13,6 +14,7 @@ export interface TeamUserRequestQuery extends SearchFilter {
const schema = {
GET: yup.object().shape({
id: yup.string().uuid().required(),
...pageInfo,
}),
};

Expand All @@ -30,11 +32,12 @@ export default async (
return unauthorized(res);
}

const { query, page } = req.query;
const { query, page, pageSize } = req.query;

const users = await getUsersByTeamId(teamId, {
query,
page,
pageSize: +pageSize || undefined,
});

return ok(res, users);
Expand Down
8 changes: 7 additions & 1 deletion src/pages/api/teams/[id]/websites/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ export default async (
return unauthorized(res);
}

const websites = await getWebsitesByTeamId(teamId, { ...req.query });
const { page, query, pageSize } = req.query;

const websites = await getWebsitesByTeamId(teamId, {
page,
query,
pageSize: +pageSize || undefined,
});

return ok(res, websites);
}
Expand Down
3 changes: 2 additions & 1 deletion src/pages/api/teams/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ export default async (
} = req.auth;

if (req.method === 'GET') {
const { page, query } = req.query;
const { page, query, pageSize } = req.query;

const results = await getTeamsByUserId(userId, {
page,
query,
pageSize: +pageSize || undefined,
});

return ok(res, results);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/users/[id]/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default async (
const teams = await getTeamsByUserId(userId, {
query,
page,
pageSize,
pageSize: +pageSize || undefined,
});

return ok(res, teams);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/users/[id]/websites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default async (

const websites = await getWebsitesByUserId(userId, {
page,
pageSize,
pageSize: +pageSize || undefined,
query,
orderBy,
includeTeams,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/api/users/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ export default async (
return unauthorized(res);
}

const { page, query } = req.query;
const { page, query, pageSize } = req.query;

const users = await getUsers({ page, query });
const users = await getUsers({ page, query, pageSize: +pageSize || undefined });

return ok(res, users);
}
Expand Down
7 changes: 5 additions & 2 deletions src/pages/api/websites/[id]/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { NextApiRequestQueryBody, SearchFilter } from 'lib/types';
import { NextApiResponse } from 'next';
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
import { getReportsByWebsiteId } from 'queries';
import { pageInfo } from 'lib/schema';

export interface ReportsRequestQuery extends SearchFilter {
id: string;
Expand All @@ -13,6 +14,7 @@ export interface ReportsRequestQuery extends SearchFilter {
const schema = {
GET: yup.object().shape({
id: yup.string().uuid().required(),
...pageInfo,
}),
};

Expand All @@ -27,14 +29,15 @@ export default async (
const { id: websiteId } = req.query;

if (req.method === 'GET') {
if (!(websiteId && (await canViewWebsite(req.auth, websiteId)))) {
if (!(await canViewWebsite(req.auth, websiteId))) {
return unauthorized(res);
}

const { page, query } = req.query;
const { page, query, pageSize } = req.query;

const data = await getReportsByWebsiteId(websiteId, {
page,
pageSize: +pageSize || undefined,
query,
});

Expand Down

0 comments on commit 8cb1c4e

Please sign in to comment.