Skip to content

Commit

Permalink
fix all linting errors in analytics-web and add .eslintrc.js, next.co…
Browse files Browse the repository at this point in the history
…nfig.js to eslint ignore patterns list
  • Loading branch information
mrkarimoff committed Feb 26, 2024
1 parent 560b3cb commit 3c940fe
Show file tree
Hide file tree
Showing 27 changed files with 89 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { ColumnDef } from "@tanstack/react-table";
import { type ColumnDef } from "@tanstack/react-table";
import { type Dispatch, type SetStateAction } from "react";
import { DataTableColumnHeader } from "~/components/DataTable/column-header";
import { MetadataDialog } from "~/components/MetadataDialog";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { useEffect, useMemo, useState } from "react";
import { DataTable } from "~/components/DataTable/data-table";
import ExportButton from "~/components/ExportButton";
import { Event } from "~/db/getEvents";
import { type Event } from "~/db/getEvents";
import { getColumns } from "./Columns";

export type EventType = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DialogButton } from "~/components/DialogButton";
import { Event } from "~/db/getEvents";
import { type Event } from "~/db/getEvents";

export function StackTraceDialog({ error }: { error: Event }) {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";
import { ColumnDef } from "@tanstack/react-table";
import { RegionTotal } from "~/utils/getRegionsTotals";
import { type ColumnDef } from "@tanstack/react-table";
import { type RegionTotal } from "~/utils/getRegionsTotals";
export const columns: ColumnDef<RegionTotal>[] = [
{
accessorKey: "country",
Expand Down
16 changes: 14 additions & 2 deletions apps/analytics-web/app/_components/users/UsersTable/Columns.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
"use client";
import { ColumnDef } from "@tanstack/react-table";

import { type ColumnDef } from "@tanstack/react-table";
import VerifyUserSwitch from "./VerifyUserSwitch";
export const columns: ColumnDef<any>[] = [

type UserColumn = ColumnDef<
{
id: string;
fullName: string;
username: string | null;
verified: boolean;
},
unknown
>;

export const columns: UserColumn[] = [
{
accessorKey: "user",
header: "User",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default async function VerifiedUsersTable() {
id: user.id,
fullName: user.firstName + " " + user.lastName,
username: user.username,
verified: user.publicMetadata.verified,
verified: !!user.publicMetadata.verified,
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@ export default function VerifyUserSwitch({

if (!response.ok) {
setLocalVerified(!localVerified);
// eslint-disable-next-line no-console
console.error("Database update failed.");
}
} catch (error) {
setLocalVerified;
// eslint-disable-next-line no-console
console.error("Error updating database:", error);
}
};

const handleToggle = async () => {
setLocalVerified(!localVerified);
updateMetadata();
await updateMetadata();
};

return <Switch checked={localVerified} onCheckedChange={handleToggle} />;
Expand Down
21 changes: 19 additions & 2 deletions apps/analytics-web/app/api/clerk/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
import { NextRequest, NextResponse } from "next/server";
import { type NextRequest, NextResponse } from "next/server";
import { clerkClient } from "@clerk/nextjs";
import z from "zod";

const clerkPayloadSchema = z.object({
verified: z.boolean(),
userId: z.string(),
});

export async function POST(request: NextRequest) {
const { verified, userId } = await request.json();
const payload: unknown = await request.json();

const parsedPayload = clerkPayloadSchema.safeParse(payload);

if (!parsedPayload.success) {
return NextResponse.json(
{ error: "Invalid clerk payload" },
{ status: 400 }
);
}

const { verified, userId } = parsedPayload.data;

await clerkClient.users.updateUserMetadata(userId, {
publicMetadata: {
Expand Down
4 changes: 2 additions & 2 deletions apps/analytics-web/app/api/event/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NextRequest, NextResponse } from "next/server";
import { type NextRequest, NextResponse } from "next/server";
import insertEvent from "~/db/insertEvent";
import { AnalyticsEventSchema } from "@codaco/analytics";

Expand Down Expand Up @@ -39,7 +39,7 @@ export async function POST(request: NextRequest) {
return NextResponse.json({ event }, { status: 200, headers: corsHeaders });
}

export async function OPTIONS() {
export function OPTIONS() {
return new NextResponse(null, {
status: 200,
headers: corsHeaders,
Expand Down
5 changes: 2 additions & 3 deletions apps/analytics-web/components/DataTable/column-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ import {
} from "~/components/ui/dropdown-menu";
import { cn } from "~/utils/shadcn";

interface DataTableColumnHeaderProps<TData, TValue>
extends React.HTMLAttributes<HTMLDivElement> {
type DataTableColumnHeaderProps<TData, TValue> = {
column: Column<TData, TValue>;
title?: string;
}
} & React.HTMLAttributes<HTMLDivElement>;

export function DataTableColumnHeader<TData, TValue>({
column,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ChevronsRight,
} from "lucide-react";

import { Table } from "@tanstack/react-table";
import { type Table } from "@tanstack/react-table";

import { Button } from "~/components/ui/button";
import {
Expand All @@ -16,9 +16,9 @@ import {
SelectValue,
} from "~/components/ui/select";

interface DataTablePaginationProps<TData> {
type DataTablePaginationProps<TData> = {
table: Table<TData>;
}
};

export function DataTablePagination<TData>({
table,
Expand Down
8 changes: 4 additions & 4 deletions apps/analytics-web/components/DataTable/data-table.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use client";

import {
ColumnDef,
SortingState,
type ColumnDef,
type SortingState,
flexRender,
getCoreRowModel,
getPaginationRowModel,
Expand All @@ -19,11 +19,11 @@ import {
TableRow,
} from "~/components/ui/table";

interface DataTableProps<TData, TValue> {
type DataTableProps<TData, TValue> = {
columns: ColumnDef<TData, TValue>[];
data: TData[];
pagination?: boolean;
}
};

import { DataTablePagination } from "~/components/DataTable/data-table-pagination";
import { useState } from "react";
Expand Down
6 changes: 3 additions & 3 deletions apps/analytics-web/components/DialogButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ReactNode } from "react";
import { type ReactNode } from "react";
import { Button } from "~/components/ui/button";
import {
Dialog,
Expand All @@ -9,12 +9,12 @@ import {
DialogTrigger,
} from "~/components/ui/dialog";

interface DialogButtonProps {
type DialogButtonProps = {
buttonLabel: string;
title: string;
description: string;
content: ReactNode;
}
};

export function DialogButton({
buttonLabel,
Expand Down
4 changes: 2 additions & 2 deletions apps/analytics-web/components/ExportButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import Papa from "papaparse";
import { Button } from "~/components/ui/button";
import { type Event } from "~/db/getEvents";

interface ExportButtonProps {
type ExportButtonProps = {
data: Event[];
filename: string;
}
};

const ExportButton: React.FC<ExportButtonProps> = ({ data, filename }) => {
const handleExportCSV = () => {
Expand Down
6 changes: 3 additions & 3 deletions apps/analytics-web/components/ui/badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ const badgeVariants = cva(
}
);

export interface BadgeProps
extends React.HTMLAttributes<HTMLDivElement>,
VariantProps<typeof badgeVariants> {}
export type BadgeProps = object &
React.HTMLAttributes<HTMLDivElement> &
VariantProps<typeof badgeVariants>;

function Badge({ className, variant, ...props }: BadgeProps) {
return (
Expand Down
7 changes: 3 additions & 4 deletions apps/analytics-web/components/ui/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ const buttonVariants = cva(
}
);

export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof buttonVariants> {
export type ButtonProps = {
asChild?: boolean;
}
} & React.ButtonHTMLAttributes<HTMLButtonElement> &
VariantProps<typeof buttonVariants>;

const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, asChild = false, ...props }, ref) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/analytics-web/db/db.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { sql } from "@vercel/postgres";
import { drizzle } from "drizzle-orm/vercel-postgres";
import * as schema from "./schema";
import { eventsTable } from "./schema";
import { type eventsTable } from "./schema";

// Use this object to send drizzle queries to your DB
export const db = drizzle(sql, { schema });
Expand Down
1 change: 1 addition & 0 deletions apps/analytics-web/db/getEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default async function getEvents() {

return events;
} catch (error) {
// eslint-disable-next-line no-console
console.error("Error getting events", error);
return [];
}
Expand Down
1 change: 1 addition & 0 deletions apps/analytics-web/db/insertEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default async function insertEvent(event: EventInsertType) {

return { data: insertedEvent, error: null };
} catch (error) {
// eslint-disable-next-line no-console
console.error("Error inserting events", error);
return { data: null, error: "Error inserting events" };
}
Expand Down
1 change: 1 addition & 0 deletions apps/analytics-web/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-process-env */
import dotenv from "dotenv";
dotenv.config();

Expand Down
3 changes: 2 additions & 1 deletion apps/analytics-web/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import { NextResponse } from "next/server";
export default authMiddleware({
publicRoutes: ["/verification"],
ignoredRoutes: ["/api/event"],
async afterAuth(auth, req, evt) {
async afterAuth(auth, req, _) {
// handle users who aren't authenticated
if (!auth.userId && !auth.isPublicRoute) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return redirectToSignIn({ returnBackUrl: req.url });
}

Expand Down
3 changes: 2 additions & 1 deletion apps/analytics-web/scripts/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ export async function runMigration() {
try {
await migrate(db, { migrationsFolder: "./drizzle" });
} catch (error) {
// eslint-disable-next-line no-console
console.error("Error running migration:", error);
}
}

runMigration();
await runMigration();
8 changes: 4 additions & 4 deletions apps/analytics-web/scripts/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import { db, type EventInsertType } from "~/db/db";
import { eventsTable } from "~/db/schema";
import { eventTypes } from "@codaco/analytics";

let installationIds: string[] = [];
const installationIds: string[] = [];
for (let i = 0; i < 20; i++) {
installationIds.push(faker.string.uuid());
}

async function seedEvents() {
// eslint-disable-next-line no-console
console.info("Starting to seed events");

try {
Expand Down Expand Up @@ -55,12 +56,11 @@ async function seedEvents() {
.returning();
}
} catch (error) {
// eslint-disable-next-line no-console
console.error("Error seeding events", error);
}

process.exit();
}

(async () => {
await seedEvents();
})();
await seedEvents();
8 changes: 1 addition & 7 deletions apps/analytics-web/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
"~/*": ["./*"],
},
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
".eslintrc.js",
],
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"],
}
8 changes: 4 additions & 4 deletions apps/analytics-web/utils/getRegionsTotals.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import getEvents, { type Event } from "~/db/getEvents";
import { getName } from "i18n-iso-countries";

export type RegionTotal = {
country: string;
Expand All @@ -7,24 +8,23 @@ export type RegionTotal = {

export default async function getRegionsTotals(): Promise<RegionTotal[]> {
const events: Event[] = await getEvents();
var countries = require("i18n-iso-countries");

const calculatedTotals: Record<string, number> = {};

for (const event of events) {
const isocode = event.countryISOCode;

if (isocode) {
calculatedTotals[isocode] = (calculatedTotals[isocode] || 0) + 1;
calculatedTotals[isocode] = (calculatedTotals[isocode] ?? 0) + 1;
}
}

const regionsTotals: RegionTotal[] = [];

for (const isocode in calculatedTotals) {
regionsTotals.push({
country: countries.getName(isocode, "en"),
total: calculatedTotals[isocode] || 0,
country: getName(isocode, "en") ?? "",
total: calculatedTotals[isocode] ?? 0,
});
}

Expand Down
8 changes: 1 addition & 7 deletions apps/documentation/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@
"~/*": ["./*"],
},
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
".eslintrc.js",
],
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"],
}
Loading

0 comments on commit 3c940fe

Please sign in to comment.