Fixed lint issues.

This commit is contained in:
Mike Cao 2023-02-07 16:29:25 -08:00
parent 94726239aa
commit ad5e34a894
10 changed files with 58 additions and 72 deletions

View File

@ -20,7 +20,7 @@
"next" "next"
], ],
"plugins": ["@typescript-eslint","prettier"], "plugins": ["@typescript-eslint", "prettier"],
"settings": { "settings": {
"import/resolver": { "import/resolver": {
"alias": { "alias": {
@ -46,7 +46,9 @@
"react/react-in-jsx-scope": "off", "react/react-in-jsx-scope": "off",
"react/prop-types": "off", "react/prop-types": "off",
"import/no-anonymous-default-export": "off", "import/no-anonymous-default-export": "off",
"@next/next/no-img-element": "off" "@next/next/no-img-element": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-explicit-any": "off"
}, },
"globals": { "globals": {
"React": "writable" "React": "writable"

View File

@ -1,6 +1,6 @@
import { useState, useEffect, useCallback } from 'react'; import { useState, useEffect, useCallback } from 'react';
import { useIntl } from 'react-intl'; import { useIntl } from 'react-intl';
import { Button, Icon, Tooltip } from '../react-basics'; import { Button, Icon, Tooltip } from 'react-basics';
import useStore from 'store/queries'; import useStore from 'store/queries';
import { setDateRange } from 'store/websites'; import { setDateRange } from 'store/websites';
import useDateRange from 'hooks/useDateRange'; import useDateRange from 'hooks/useDateRange';

View File

@ -3,13 +3,12 @@ import { Icons, Loading } from 'react-basics';
import { useIntl } from 'react-intl'; import { useIntl } from 'react-intl';
import Link from 'next/link'; import Link from 'next/link';
import classNames from 'classnames'; import classNames from 'classnames';
import MenuLayout from 'components/layout/MenuLayout';
import Page from 'components/layout/Page'; import Page from 'components/layout/Page';
import WebsiteChart from 'components/metrics/WebsiteChart'; import WebsiteChart from 'components/metrics/WebsiteChart';
import useApi from 'hooks/useApi'; import useApi from 'hooks/useApi';
import usePageQuery from 'hooks/usePageQuery'; import usePageQuery from 'hooks/usePageQuery';
import { DEFAULT_ANIMATION_DURATION } from 'lib/constants'; import { DEFAULT_ANIMATION_DURATION } from 'lib/constants';
import { labels, messages } from 'components/messages'; import { labels } from 'components/messages';
import styles from './WebsiteDetails.module.css'; import styles from './WebsiteDetails.module.css';
import WebsiteTableView from './WebsiteTableView'; import WebsiteTableView from './WebsiteTableView';
import WebsiteMenuView from './WebsiteMenuView'; import WebsiteMenuView from './WebsiteMenuView';
@ -27,19 +26,6 @@ export default function WebsiteDetails({ websiteId }) {
query: { view }, query: { view },
} = usePageQuery(); } = usePageQuery();
const BackButton = () => (
<div key="back-button" className={classNames(styles.backButton, 'col-12')}>
<Link
key="back-button"
href={resolve({ view: undefined })}
icon={<Icons.ArrowRight />}
sizes="small"
>
{formatMessage(labels.back)}
</Link>
</div>
);
function handleDataLoad() { function handleDataLoad() {
if (!chartLoaded) { if (!chartLoaded) {
setTimeout(() => setChartLoaded(true), DEFAULT_ANIMATION_DURATION); setTimeout(() => setChartLoaded(true), DEFAULT_ANIMATION_DURATION);

View File

@ -1,4 +1,4 @@
import { Row, Column, Menu, Item, Icon, Text, Button } from 'react-basics'; import { Row, Column, Menu, Item, Icon, Button } from 'react-basics';
import Link from 'next/link'; import Link from 'next/link';
import BrowsersTable from 'components/metrics/BrowsersTable'; import BrowsersTable from 'components/metrics/BrowsersTable';
import CountriesTable from 'components/metrics/CountriesTable'; import CountriesTable from 'components/metrics/CountriesTable';

View File

@ -39,8 +39,6 @@ export interface Share {
token: string; token: string;
} }
export interface Empty {}
export interface WebsiteActive { export interface WebsiteActive {
x: number; x: number;
} }

View File

@ -1,12 +1,12 @@
const { Resolver } = require('dns').promises;
import isbot from 'isbot'; import isbot from 'isbot';
import ipaddr from 'ipaddr.js'; import ipaddr from 'ipaddr.js';
import { createToken, unauthorized, send, badRequest, forbidden } from 'next-basics'; import { createToken, ok, send, badRequest, forbidden } from 'next-basics';
import { savePageView, saveEvent } from 'queries'; import { savePageView, saveEvent } from 'queries';
import { useCors, useSession } from 'lib/middleware'; import { useCors, useSession } from 'lib/middleware';
import { getJsonBody, getIpAddress } from 'lib/detect'; import { getJsonBody, getIpAddress } from 'lib/detect';
import { secret } from 'lib/crypto'; import { secret } from 'lib/crypto';
import { NextApiRequest, NextApiResponse } from 'next'; import { NextApiRequest, NextApiResponse } from 'next';
import { Resolver } from 'dns/promises';
export interface NextApiRequestCollect extends NextApiRequest { export interface NextApiRequestCollect extends NextApiRequest {
session: { session: {
@ -26,7 +26,7 @@ export default async (req: NextApiRequestCollect, res: NextApiResponse) => {
await useCors(req, res); await useCors(req, res);
if (isbot(req.headers['user-agent']) && !process.env.DISABLE_BOT_CHECK) { if (isbot(req.headers['user-agent']) && !process.env.DISABLE_BOT_CHECK) {
return unauthorized(res); return ok(res);
} }
const { type, payload } = getJsonBody(req); const { type, payload } = getJsonBody(req);
@ -61,7 +61,7 @@ export default async (req: NextApiRequestCollect, res: NextApiResponse) => {
.map(n => resolver.resolve4(n.trim()).catch(() => {})); .map(n => resolver.resolve4(n.trim()).catch(() => {}));
await Promise.all(promises).then(resolvedIps => { await Promise.all(promises).then(resolvedIps => {
ips.push(...resolvedIps.filter(n => n).flatMap(n => n)); ips.push(...resolvedIps.filter(n => n).flatMap(n => n as string[]));
}); });
} }

View File

@ -0,0 +1,31 @@
import { useAuth, useCors } from 'lib/middleware';
import { NextApiRequestQueryBody } from 'lib/types';
import { NextApiResponse } from 'next';
import { methodNotAllowed, ok } from 'next-basics';
import { getUserWebsites } from 'queries';
export interface WebsitesRequestBody {
name: string;
domain: string;
shareId: string;
}
export default async (
req: NextApiRequestQueryBody<any, WebsitesRequestBody>,
res: NextApiResponse,
) => {
await useCors(req, res);
await useAuth(req, res);
const {
user: { id: userId },
} = req.auth;
if (req.method === 'GET') {
const websites = await getUserWebsites(userId);
return ok(res, websites);
}
return methodNotAllowed(res);
};

View File

@ -1,63 +1,34 @@
import { Prisma } from '@prisma/client';
import { canCreateWebsite } from 'lib/auth';
import { uuid } from 'lib/crypto';
import { useAuth, useCors } from 'lib/middleware'; import { useAuth, useCors } from 'lib/middleware';
import { NextApiRequestQueryBody } from 'lib/types'; import { NextApiRequestQueryBody } from 'lib/types';
import { NextApiResponse } from 'next'; import { NextApiResponse } from 'next';
import { methodNotAllowed, ok, unauthorized } from 'next-basics'; import { methodNotAllowed, ok, unauthorized } from 'next-basics';
import { createWebsite, getUserWebsites } from 'queries'; import { getUserWebsites } from 'queries';
export interface WebsitesRequestQuery {}
export interface WebsitesRequestBody { export interface WebsitesRequestBody {
name: string; name: string;
domain: string; domain: string;
shareId: string; shareId: string;
teamId?: string;
} }
export default async ( export default async (
req: NextApiRequestQueryBody<WebsitesRequestQuery, WebsitesRequestBody>, req: NextApiRequestQueryBody<any, WebsitesRequestBody>,
res: NextApiResponse, res: NextApiResponse,
) => { ) => {
await useCors(req, res); await useCors(req, res);
await useAuth(req, res); await useAuth(req, res);
const { const { user } = req.auth;
user: { id: userId }, const { id: userId } = req.query;
} = req.auth;
const { id } = req.query;
if (req.method === 'GET') { if (req.method === 'GET') {
const websites = await getUserWebsites(id as string); if (!user.isAdmin && user.id !== userId) {
return unauthorized(res);
}
const websites = await getUserWebsites(userId);
return ok(res, websites); return ok(res, websites);
} }
if (req.method === 'POST') {
const { name, domain, shareId, teamId } = req.body;
if (!(await canCreateWebsite(req.auth, teamId))) {
return unauthorized(res);
}
const data: Prisma.WebsiteUncheckedCreateInput = {
id: uuid(),
name,
domain,
shareId,
};
if (teamId) {
data.teamId = teamId;
} else {
data.userId = userId;
}
const website = await createWebsite(data);
return ok(res, website);
}
return methodNotAllowed(res); return methodNotAllowed(res);
}; };

View File

@ -90,15 +90,15 @@ export default async (
}); });
if (type === 'language') { if (type === 'language') {
let combined = {}; const combined = {};
for (let { x, y } of data) { for (const { x, y } of data) {
x = String(x).toLowerCase().split('-')[0]; const key = String(x).toLowerCase().split('-')[0];
if (!combined[x]) { if (!combined[key]) {
combined[x] = { x, y }; combined[key] = { x, y };
} else { } else {
combined[x].y += y; combined[key].y += y;
} }
} }

View File

@ -6,8 +6,6 @@ import { NextApiResponse } from 'next';
import { methodNotAllowed, ok, unauthorized } from 'next-basics'; import { methodNotAllowed, ok, unauthorized } from 'next-basics';
import { createWebsite, getUserWebsites } from 'queries'; import { createWebsite, getUserWebsites } from 'queries';
export interface WebsitesRequestQuery {}
export interface WebsitesRequestBody { export interface WebsitesRequestBody {
name: string; name: string;
domain: string; domain: string;
@ -16,7 +14,7 @@ export interface WebsitesRequestBody {
} }
export default async ( export default async (
req: NextApiRequestQueryBody<WebsitesRequestQuery, WebsitesRequestBody>, req: NextApiRequestQueryBody<any, WebsitesRequestBody>,
res: NextApiResponse, res: NextApiResponse,
) => { ) => {
await useCors(req, res); await useCors(req, res);