Skip to content

Commit

Permalink
build: genericize eslint and add to apps/dashboard tests (#3394)
Browse files Browse the repository at this point in the history
* chore: switch build folder from 'lib' to 'dist'

* test: setup generic eslint config structure with dashboard

* build: add eslint rule to apps/dashboard

* build: add check-lint to apps/dashboard test suite

* chore: fix prettier lints

* chore: fix 'import/order' lints

* chore: fix '@typescript-eslint/no-unused-vars' lints

* chore: fix 'no-duplicate-imports' lints

* chore: fix 'import/no-unassigned-import' lints

* chore: update pnpm lock file

* build: add lib/eslint-config to root BUCK

* fix: root BUCK

* fix: export package-json from eslint-config BUCK

---------

Co-authored-by: bodymindarts <[email protected]>
  • Loading branch information
vindard and bodymindarts authored Oct 19, 2023
1 parent f9c9869 commit 1739e6c
Show file tree
Hide file tree
Showing 48 changed files with 839 additions and 579 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Compiled JavaScript files
lib/**/*.js
dist/**/*.js
**/*.js.map

# Typescript v1 declaration files
Expand All @@ -26,7 +26,7 @@ public/*
!public/logo.png

coverage
lib
dist
artifacts

generated.gql
Expand Down
3 changes: 2 additions & 1 deletion BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ pnpm_workspace(
child_packages = [
"//core/api:package.json",
"//apps/consent:package.json",
"//apps/dashboard:package.json"
"//apps/dashboard:package.json",
"//lib/eslint-config:package.json"
],
visibility = ["PUBLIC"],
)
3 changes: 3 additions & 0 deletions apps/dashboard/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
"extends": ["next/core-web-vitals", "@galoy/eslint-config/base"]
}
3 changes: 0 additions & 3 deletions apps/dashboard/.eslintrc.json

This file was deleted.

24 changes: 22 additions & 2 deletions apps/dashboard/BUCK
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
load("@toolchains//workspace-pnpm:macros.bzl", "build_node_modules", "next_build", "next_build_bin")
load(
"@toolchains//workspace-pnpm:macros.bzl",
"build_node_modules",
"next_build",
"next_build_bin",
"eslint"
)

export_file(
name = "package.json",
Expand Down Expand Up @@ -33,7 +39,21 @@ next_build_bin(
name = "dashboard",
)

dev_deps_srcs = {
"lib/eslint-config": "//lib/eslint-config:src",
}

eslint(
name = "check-lint",
srcs = [":src"] + glob([".eslint*"]),
extensions = [".ts", ".tsx"],
allow_warnings = True,
dev_deps_srcs = dev_deps_srcs,
)

test_suite(
name = "test",
tests = [],
tests = [
":check-lint",
],
)
54 changes: 28 additions & 26 deletions apps/dashboard/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import NextAuth, { AuthOptions } from "next-auth";
import { fetchUserData } from "@/services/graphql/queries/me-data";
import { env } from "@/env";
import { ApolloQueryResult } from "@apollo/client";
import { MeQuery } from "@/services/graphql/generated";
import NextAuth, { AuthOptions } from "next-auth"

import { ApolloQueryResult } from "@apollo/client"

import { fetchUserData } from "@/services/graphql/queries/me-data"
import { env } from "@/env"
import { MeQuery } from "@/services/graphql/generated"

declare module "next-auth" {
interface Profile {
id: string;
id: string
}
interface Session {
sub: string | null;
accessToken: string;
userData: ApolloQueryResult<MeQuery>;
sub: string | null
accessToken: string
userData: ApolloQueryResult<MeQuery>
}
}

const type = "oauth" as const;
const type = "oauth" as const
export const authOptions: AuthOptions = {
providers: [
{
Expand All @@ -32,7 +34,7 @@ export const authOptions: AuthOptions = {
profile(profile) {
return {
id: profile.sub,
};
}
},
},
],
Expand All @@ -42,32 +44,32 @@ export const authOptions: AuthOptions = {
async jwt({ token, account, profile }) {
// Persist the OAuth access_token and or the user id to the token right after signin
if (account) {
token.accessToken = account.access_token;
token.expiresAt = account.expires_at;
token.refreshToken = account.refresh_token;
token.id = profile?.id;
token.accessToken = account.access_token
token.expiresAt = account.expires_at
token.refreshToken = account.refresh_token
token.id = profile?.id
}
return token;
return token
},
async session({ session, token, user }) {
async session({ session, token }) {
if (
!token.accessToken ||
!token.sub ||
typeof token.accessToken !== "string" ||
typeof token.sub !== "string"
) {
throw new Error("Invalid token");
throw new Error("Invalid token")
}

const userData = await fetchUserData(token.accessToken);
session.sub = token.sub;
session.accessToken = token.accessToken;
session.userData = userData;
return session;
const userData = await fetchUserData(token.accessToken)
session.sub = token.sub
session.accessToken = token.accessToken
session.userData = userData
return session
},
},
};
}

const handler = NextAuth(authOptions);
const handler = NextAuth(authOptions)

export { handler as GET, handler as POST };
export { handler as GET, handler as POST }
33 changes: 17 additions & 16 deletions apps/dashboard/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import SessionProvider from "@/components/session-provider";
import "./globals.css";
import type { Metadata } from "next";
import { authOptions } from "./api/auth/[...nextauth]/route";
import Header from "@/components/header";
import Sidebar from "@/components/side-bar";
import { getServerSession } from "next-auth";
import ThemeRegistry from "@/theme/theme-registry";
import type { Metadata } from "next"
import { getServerSession } from "next-auth"

// eslint-disable-next-line import/no-unassigned-import
import "./globals.css"

import { authOptions } from "./api/auth/[...nextauth]/route"

import Header from "@/components/header"
import SessionProvider from "@/components/session-provider"
import Sidebar from "@/components/side-bar"

import ThemeRegistry from "@/theme/theme-registry"

export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};
}

export default async function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
const session = await getServerSession(authOptions);
export default async function RootLayout({ children }: { children: React.ReactNode }) {
const session = await getServerSession(authOptions)

return (
<html lang="en">
Expand All @@ -39,5 +40,5 @@ export default async function RootLayout({
</ThemeRegistry>
</body>
</html>
);
)
}
8 changes: 4 additions & 4 deletions apps/dashboard/app/loading.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { CircularProgress } from "@mui/joy";
import React from "react";
import { CircularProgress } from "@mui/joy"
import React from "react"

function Loading() {
return (
<div className="flex justify-center items-center min-h-screen">
<CircularProgress />
</div>
);
)
}

export default Loading;
export default Loading
17 changes: 9 additions & 8 deletions apps/dashboard/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { getServerSession } from "next-auth";
import { authOptions } from "./api/auth/[...nextauth]/route";
import PriceContainer from "@/components/price-container/price-container";
import ContentContainer from "@/components/content-container";
import { getServerSession } from "next-auth"

import { authOptions } from "./api/auth/[...nextauth]/route"

import PriceContainer from "@/components/price-container/price-container"
import ContentContainer from "@/components/content-container"

export default async function Home() {
const session = await getServerSession(authOptions);
const walletDetails =
session?.userData?.data?.me?.defaultAccount?.wallets || [];
const session = await getServerSession(authOptions)
const walletDetails = session?.userData?.data?.me?.defaultAccount?.wallets || []

return (
<main>
<ContentContainer>
<PriceContainer walletDetails={walletDetails}></PriceContainer>
</ContentContainer>
</main>
);
)
}
46 changes: 24 additions & 22 deletions apps/dashboard/app/transactions/page.tsx
Original file line number Diff line number Diff line change
@@ -1,47 +1,49 @@
import { getServerSession } from "next-auth";
import React from "react";
import { authOptions } from "../api/auth/[...nextauth]/route";
import TransactionDetails from "@/components/transaction-details/transaction-details-table";
import ContentContainer from "@/components/content-container";
import { getServerSession } from "next-auth"
import React from "react"

import { authOptions } from "../api/auth/[...nextauth]/route"

import TransactionDetails from "@/components/transaction-details/transaction-details-table"
import ContentContainer from "@/components/content-container"
import {
fetchFirstTransactions,
fetchPaginatedTransactions,
} from "@/services/graphql/queries/get-transactions";
import TransactionCard from "@/components/transaction-details/transaction-card-item";
import PageNumber from "@/components/transaction-details/page-number";
} from "@/services/graphql/queries/get-transactions"
import TransactionCard from "@/components/transaction-details/transaction-card-item"
import PageNumber from "@/components/transaction-details/page-number"

interface TransactionDetailsSearchParams {
cursor: string;
direction: "next" | "previous";
cursor: string
direction: "next" | "previous"
}

export default async function page({
searchParams,
}: {
searchParams: TransactionDetailsSearchParams;
searchParams: TransactionDetailsSearchParams
}) {
const { cursor, direction } = searchParams;
const session = await getServerSession(authOptions);
const token = session?.accessToken;
const { cursor, direction } = searchParams
const session = await getServerSession(authOptions)
const token = session?.accessToken
if (!token || typeof token !== "string") {
throw new Error("invalid token");
throw new Error("invalid token")
}

const numberOfTransactions = 50;
let response;
const numberOfTransactions = 50
let response
if (cursor && direction) {
response = await fetchPaginatedTransactions(
token,
direction,
cursor,
numberOfTransactions,
);
)
} else {
response = await fetchFirstTransactions(token, numberOfTransactions);
response = await fetchFirstTransactions(token, numberOfTransactions)
}

const rows = response?.edges?.map((edge) => ({ node: edge.node })) ?? [];
const pageInfo = response?.pageInfo;
const rows = response?.edges?.map((edge) => ({ node: edge.node })) ?? []
const pageInfo = response?.pageInfo
return (
<ContentContainer>
{rows.length > 0 ? (
Expand All @@ -54,5 +56,5 @@ export default async function page({
<span>No Transactions Found</span>
)}
</ContentContainer>
);
)
}
6 changes: 3 additions & 3 deletions apps/dashboard/app/url.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
interface UrlInfo {
title: string;
protected: boolean;
title: string
protected: boolean
}

export const URLS: Record<string, UrlInfo> = {
"/": { title: "Home", protected: true },
"/transactions": { title: "Transactions", protected: true },
};
}
Loading

0 comments on commit 1739e6c

Please sign in to comment.