-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #174 from mikepsinn/develop
Added UserVariables and measurements to Next.js app and updated openapi docs
- Loading branch information
Showing
149 changed files
with
16,732 additions
and
2,807 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,3 +61,4 @@ desktop.ini | |
coverage/ | ||
/apps/js-examples/data | ||
/.42c | ||
/apps/next/ |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
dist | ||
node_modules | ||
.next | ||
package.json | ||
pnpm-lock.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
{ | ||
"WillLuke.nextjs.addTypesOnSave": true, | ||
"WillLuke.nextjs.hasPrompted": true | ||
"WillLuke.nextjs.hasPrompted": true, | ||
"files.associations": { | ||
"*.mdx": "markdown" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { getCurrentUser } from "@/lib/session" | ||
import Footer from "@/components/layout/footer" | ||
import Navbar from "@/components/layout/navbar" | ||
|
||
interface FrontPageLayoutProps { | ||
children: React.ReactNode | ||
} | ||
|
||
export default async function FrontPageLayout({ | ||
children, | ||
}: FrontPageLayoutProps) { | ||
const user = await getCurrentUser() | ||
|
||
return ( | ||
<> | ||
<Navbar | ||
user={{ | ||
name: user?.name, | ||
image: user?.image, | ||
email: user?.email, | ||
}} | ||
/> | ||
{children} | ||
<Footer /> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Icons } from "@/components/icons" | ||
|
||
export default function HomeLoading() { | ||
return ( | ||
<main className="flex justify-center p-8"> | ||
<Icons.spinner className="animate-spin text-4xl" /> | ||
</main> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Hero from "@/components/pages/hero" | ||
import { PWARedirect } from "@/components/pwa-redirect" | ||
|
||
export default function Home() { | ||
return ( | ||
<main> | ||
<Hero /> | ||
<PWARedirect /> | ||
</main> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,27 @@ | ||
import type { paths } from './fdai'; | ||
import createClient from 'openapi-fetch'; | ||
import { getCurrentUser } from '@/lib/session'; | ||
|
||
let bearerToken = "demo" | ||
|
||
export let { GET, POST, PATCH, PUT, DELETE, HEAD, TRACE } = createClient<paths>( | ||
{ | ||
baseUrl: 'https://safe.fdai.earth/api/v3', | ||
headers: { authorization: `Bearer ${bearerToken}` } //Add your auth here, not needed for public APIs like petstore in this example | ||
}, | ||
); | ||
|
||
const options = { | ||
method: 'POST', | ||
headers: { | ||
'X-CLIENT-ID': '<api-key>', | ||
'X-CLIENT-SECRET': '<api-key>', | ||
'Content-Type': 'application/json' | ||
}, | ||
body: '{"clientUserId":"<string>"}' | ||
}; | ||
|
||
fetch('https://safe.fdai.earth/api/v3/user', options) | ||
.then(response => response.json()) | ||
.then(response => console.log(response)) | ||
.catch(err => console.error(err)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { getServerSession } from "next-auth/next" | ||
import { authOptions } from "@/lib/auth" | ||
import {handleError} from "@/lib/errorHandler"; | ||
import { getOrCreateFdaiUser } from '@/lib/fdaiUserService'; | ||
export async function GET( | ||
req: Request | ||
) { | ||
try { | ||
const session = await getServerSession(authOptions) | ||
|
||
if (!session?.user) { | ||
return new Response(null, { status: 403 }) | ||
} | ||
const fdaiUser = await getOrCreateFdaiUser(session.user.id); | ||
return new Response(JSON.stringify(fdaiUser), { status: 200, headers: { 'Content-Type': 'application/json' } }) | ||
} catch (error) { | ||
return handleError(error) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { getServerSession } from "next-auth/next" | ||
|
||
import { authOptions } from "@/lib/auth" | ||
import { getUserVariables } from '@/lib/fdaiUserVariablesService'; | ||
export async function GET(req: Request) { | ||
try { | ||
const session = await getServerSession(authOptions) | ||
|
||
if (!session) { | ||
return new Response("Unauthorized", { status: 403 }) | ||
} | ||
// Parse the URL and query parameters from the request | ||
const url = new URL(req.url, `https://${req.headers.get('host')}`); | ||
const queryParams = Object.fromEntries(url.searchParams); | ||
const userVariables = await getUserVariables(session.user.id, queryParams); | ||
|
||
return new Response(JSON.stringify(userVariables)) | ||
} catch (error) { | ||
return new Response(null, { status: 500 }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { getServerSession } from "next-auth/next" | ||
import { z } from "zod" | ||
|
||
import { authOptions } from "@/lib/auth" | ||
import { db } from "@/lib/db" | ||
import { userNameSchema } from "@/lib/validations/user" | ||
import {handleError} from "@/lib/errorHandler"; | ||
|
||
const routeContextSchema = z.object({ | ||
params: z.object({ | ||
userId: z.string(), | ||
}), | ||
}) | ||
|
||
interface DatabaseError extends Error { | ||
code: string; | ||
meta?: { | ||
target?: string[]; | ||
}; | ||
} | ||
|
||
export async function PATCH( | ||
req: Request, | ||
context: z.infer<typeof routeContextSchema> | ||
) { | ||
try { | ||
const { params } = routeContextSchema.parse(context) | ||
const session = await getServerSession(authOptions) | ||
|
||
if (!session?.user || params.userId !== session?.user.id) { | ||
return new Response(null, { status: 403 }) | ||
} | ||
|
||
// Edit username based on input | ||
const body = await req.json() | ||
const payload = userNameSchema.parse(body) | ||
|
||
try { | ||
await db.user.update({ | ||
where: { | ||
id: session.user.id, | ||
}, | ||
data: { | ||
username: payload.username, | ||
updatedAt: new Date(), | ||
}, | ||
}) | ||
} catch (error) { | ||
const dbError = error as DatabaseError; | ||
if (dbError.code === 'P2002' && dbError.meta?.target?.includes('username')) { | ||
return new Response(JSON.stringify({ message: "Username is already taken" }), { status: 409, headers: { 'Content-Type': 'application/json' } }) | ||
} | ||
throw error; | ||
} | ||
|
||
return new Response(null, { status: 200 }) | ||
} catch (error) { | ||
return handleError(error) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { dashboardLinks } from "@/config/links" | ||
import { getCurrentUser } from "@/lib/session" | ||
import Footer from "@/components/layout/footer" | ||
import Navbar from "@/components/layout/navbar" | ||
import { DashboardNav } from "@/components/pages/dashboard/dashboard-nav" | ||
|
||
interface DashboardLayoutProps { | ||
children: React.ReactNode | ||
} | ||
|
||
export default async function DashboardLayout({ | ||
children, | ||
}: DashboardLayoutProps) { | ||
const user = await getCurrentUser() | ||
|
||
return ( | ||
<div className="flex min-h-screen flex-col space-y-6"> | ||
<Navbar | ||
user={{ | ||
name: user?.name, | ||
image: user?.image, | ||
email: user?.email, | ||
}} | ||
/> | ||
<div className="container grid flex-1 gap-12 md:grid-cols-[200px_1fr]"> | ||
<aside className="hidden w-[200px] flex-col md:flex"> | ||
<DashboardNav items={dashboardLinks.data} /> | ||
</aside> | ||
<main className="flex w-full flex-1 flex-col">{children}</main> | ||
</div> | ||
<Footer /> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Icons } from "@/components/icons" | ||
import { Shell } from "@/components/layout/shell" | ||
|
||
export default async function DashboardLoading() { | ||
return ( | ||
<Shell> | ||
<div className="flex justify-center p-8"> | ||
<Icons.spinner className="animate-spin text-4xl" /> | ||
</div> | ||
</Shell> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Metadata } from "next" | ||
import { redirect } from "next/navigation" | ||
|
||
import { authOptions } from "@/lib/auth" | ||
import { getCurrentUser } from "@/lib/session" | ||
import { ScrollArea } from "@/components/ui/scroll-area" | ||
import { measurementColumns } from "@/components/userVariable/measurements/measurements-columns" | ||
|
||
import { DataTable } from "@/components/data-table" | ||
import { Shell } from "@/components/layout/shell" | ||
import { DashboardHeader } from "@/components/pages/dashboard/dashboard-header" | ||
import { UserVariableList } from '@/components/userVariable/user-variable-list'; | ||
|
||
export const metadata: Metadata = { | ||
title: "Dashboard", | ||
description: "Monitor your progress.", | ||
} | ||
|
||
interface DashboardProps { | ||
searchParams: { from: string; to: string } | ||
} | ||
|
||
export default async function Dashboard({ searchParams }: DashboardProps) { | ||
const user = await getCurrentUser() | ||
|
||
if (!user) { | ||
redirect(authOptions?.pages?.signIn || "/signin") | ||
} | ||
|
||
|
||
const layout = "grid grid-cols-1 gap-4 md:grid-cols-2"; | ||
const scrollClass = "h-[17rem] rounded-lg border"; | ||
|
||
return ( | ||
<Shell> | ||
<DashboardHeader heading="Your Data" text="Monitor your symptoms and factors."> | ||
</DashboardHeader> | ||
<div className={layout}> | ||
<ScrollArea className={scrollClass}> | ||
<div className="divide-y divide-border"> | ||
<UserVariableList /> | ||
</div> | ||
</ScrollArea> | ||
</div> | ||
</Shell> | ||
) | ||
} |
Oops, something went wrong.