Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feide study confirmation #1039

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
3 changes: 0 additions & 3 deletions apps/dashboard/src/app/(dashboard)/event/all-users-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ export const AllAttendeesTable = ({ attendanceId }: AllAttendeesTableProps) => {
return `${attendee.user.name}`
},
}),
columnHelper.accessor("user.studyYear", {
header: () => "Klassetrinn",
}),
columnHelper.accessor((attendee) => attendee, {
id: "attend",
header: () => "Møtt",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"use client"

import { Icon } from "@iconify/react"
import { Button, ButtonGroup, Card, Group, Skeleton, Stack } from "@mantine/core"
import { GenericTable } from "../../../components/GenericTable"
import { useCreateOfflineModal } from "../../../modules/offline/modals/create-offline-modal"
import { useOfflineTable } from "../../../modules/offline/use-offline-table"
import { trpc } from "src/utils/trpc"
import { useMembershipApplicationTable } from "./use-membership-application-table"

export default function OfflinePage() {
const { data, isLoading } = trpc.membershipApplication.all.useQuery({ take: 999 })

const open = useCreateOfflineModal()
const table = useMembershipApplicationTable({ data: data ?? [] })

return (
<Skeleton visible={isLoading}>
<Stack>
<GenericTable table={table} />
</Stack>
</Skeleton>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"use client"

import type { MembershipApplication} from "@dotkomonline/types"
import { formatDate } from "@dotkomonline/utils"
import { Anchor, Text } from "@mantine/core"
import { createColumnHelper, getCoreRowModel, useReactTable } from "@tanstack/react-table"
import Link from "next/link"
import { useMemo } from "react"

interface Props {
data: MembershipApplication[]
}

export const useMembershipApplicationTable = ({ data }: Props) => {
const columnHelper = createColumnHelper<MembershipApplication>()
const columns = useMemo(
() => [
columnHelper.accessor("documentation.fullName", {
header: () => "Navn",
cell: (info) => info.getValue(),
}),
columnHelper.accessor("fieldOfStudy", {
header: () => "Ønsket studieretning",
cell: (info) => <Text>{info.getValue()}</Text>,
}),
columnHelper.accessor("comment", {
header: () => "Kommentar",
cell: (info) => <Text>{info.getValue()}</Text>,
}),
],
[columnHelper]
)

return useReactTable({
data,
getCoreRowModel: getCoreRowModel(),
columns,
})
}
8 changes: 0 additions & 8 deletions apps/dashboard/src/app/(dashboard)/user/edit-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ export const useUserEditForm = ({ defaultValues, onSubmit, label = "Bruker" }: U
placeholder: "Kari",
withAsterisk: true,
}),
middleName: createTextInput({
label: "Mellomnavn",
withAsterisk: false,
}),
familyName: createTextInput({
label: "Etternavn",
placeholder: "Dahl",
Expand All @@ -45,10 +41,6 @@ export const useUserEditForm = ({ defaultValues, onSubmit, label = "Bruker" }: U
label: "Allergier",
placeholder: "Gluten",
}),
studyYear: createNumberInput({
label: "Studieår",
placeholder: "2",
}),
gender: createTextInput({
label: "Kjønn",
placeholder: "Kvinne",
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/src/app/ApplicationShell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const navigations = [
icon: "tabler:users-group",
children: [
{ label: "Brukere", href: "/user" },
{ label: "Medlemskap", href: "/membership" },
{ label: "Søknader om medlemsskap", href: "/membership-applications"},
],
},
] as const
Expand Down
1 change: 0 additions & 1 deletion apps/dashboard/src/app/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ export function useFormBuilder<T extends z.ZodRawShape>({
<form
onSubmit={(e) => {
e.preventDefault()
console.log(e)
return form.handleSubmit((values) => {
return onSubmit(values, form)
})(e)
Expand Down
2 changes: 1 addition & 1 deletion apps/web/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
/// <reference types="next/navigation-types/compat/navigation" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
2 changes: 1 addition & 1 deletion apps/web/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ const config = {
],
}

export default config
export default config;
30 changes: 15 additions & 15 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,31 @@
"@dotkomonline/ui": "workspace:*",
"@dotkomonline/utils": "workspace:*",
"@fadi-ui/react-country-flag": "^1.0.7",
"@next/env": "^14.0.3",
"@next/env": "^14.2.14",
"@portabletext/react": "^3.0.11",
"@radix-ui/colors": "^3.0.0",
"@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-avatar": "^1.1.1",
"@radix-ui/react-checkbox": "^1.1.2",
"@radix-ui/react-dropdown-menu": "^2.1.2",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-navigation-menu": "^1.1.4",
"@radix-ui/react-popover": "^1.0.7",
"@sanity/client": "^6.8.6",
"@radix-ui/react-navigation-menu": "^1.2.1",
"@radix-ui/react-popover": "^1.1.2",
"@sanity/client": "^6.22.1",
"@tailwindcss/typography": "^0.5.10",
"@tanstack/react-query": "^4.36.1",
"@trpc/client": "^10.45.0",
"@trpc/next": "^10.45.0",
"@trpc/react-query": "^10.45.0",
"@trpc/server": "^10.45.0",
"axios": "1.7.7",
"clsx": "^2.0.0",
"cors": "^2.8.5",
"date-fns": "^3.0.0",
"next": "^14.0.3",
"next-auth": "^4.24.5",
"jsonwebtoken": "^9.0.2",
"next": "^14.2.14",
"next-auth": "^4.24.8",
"next-superjson-plugin": "^0.6.0",
"next-themes": "^0.3.0",
"openid-client": "^5.7.0",
"pg": "^8.11.3",
"qrcode.react": "^3.1.0",
"react": "^18.2.0",
Expand All @@ -57,22 +58,21 @@
"zod": "^3.22.4"
},
"devDependencies": {
"@biomejs/biome": "^1.9.2",
"@biomejs/biome": "^1.9.3",
"@dotkomonline/config": "workspace:*",
"@dotkomonline/logger": "workspace:*",
"@dotkomonline/tsconfig": "workspace:*",
"@types/cors": "^2.8.17",
"@types/jsdom": "^21.1.6",
"@types/node": "^20.12.7",
"@types/react": "^18.2.38",
"@types/node": "^20.16.10",
"@types/react": "^18.3.11",
"@types/react-dom": "^18.2.17",
"autoprefixer": "^10.4.16",
"cva": "npm:class-variance-authority@^0.7.0",
"jsdom": "^22.1.0",
"postcss": "^8.4.31",
"tailwindcss": "^3.3.5",
"trpc-playground": "^1.0.4",
"tslib": "^2.6.2",
"typescript": "^5.4.5"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ export const AttendanceBox: FC<Props> = ({ sessionUser, attendance, pools, event
Meld meg av
</Button>
) : (
<Button className="mt-2 w-full" onClick={registerForAttendance}>
Meld meg på
<Button className="mt-2 w-full" onClick={registerForAttendance} disabled={!myGroups}>
{myGroups ? 'Meld meg på' : 'Ikke åpent for ditt årstrinn'}
</Button>
))}
</div>
Expand Down
65 changes: 65 additions & 0 deletions apps/web/src/app/feide/callback/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { getServerClient } from "@/utils/trpc/serverClient"
import { authOptions } from "@dotkomonline/auth/src/web.app"
import { env } from "@dotkomonline/env"
import { getServerSession } from "next-auth"
import { type NextRequest, NextResponse } from "next/server"
import { Issuer } from "openid-client"
import { z } from "zod"
import jwt from "jsonwebtoken"
import { FeideDocumentationSchema } from "@dotkomonline/types"
import { createFeideDocumentationJWT } from "@/utils/feideDocumentationJWT"

export async function GET(request: NextRequest) {
const session = await getServerSession(authOptions)

if (session === null) {
return Response.redirect("/", 302)
}

if (!session.user?.email) {
return new Response("Missing user email", { status: 400 })
}

const trpc = await getServerClient()

const code = new URL(request.url).searchParams.get("code")

if (code === null) {
return new Response("Missing code", { status: 400 })
}

const issuer = await Issuer.discover("https://auth.dataporten.no")
const client = new issuer.Client({
client_id: env.DATAPORTEN_CLIENT_ID,
client_secret: env.DATAPORTEN_CLIENT_SECRET,
redirect_uris: ["http://localhost:3000/feide/callback"],
})

const tokenSet = await client.grant({
code,
redirect_uri: "http://localhost:3000/feide/callback",
grant_type: "authorization_code",
})

if (!tokenSet || !tokenSet.access_token) {
return new Response("Failed to get token", { status: 500 })
}

const membershipDocumentation = await trpc.membership.getDocumentation({accessToken: tokenSet.access_token})

const user = await trpc.user.getByAuth0Id(session.sub)
const userExists = Boolean(user)

const response = NextResponse.redirect(
new URL(userExists ? "/settings/membership" : "/onboarding", request.url).toString(),
{
status: 302,
}
)

response.cookies.set("feideDocumentationJWT", createFeideDocumentationJWT(membershipDocumentation), {
expires: new Date(Date.now() + 1000 * 60 * 60 * 24),
})

return response
}
20 changes: 20 additions & 0 deletions apps/web/src/app/feide/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { env } from "@dotkomonline/env"
import { redirect } from "next/navigation"
import { NextResponse } from "next/server"

export async function GET(request: Request) {
const response = new NextResponse(null, { status: 302 })

const params = new URLSearchParams()

params.append("client_id", env.DATAPORTEN_CLIENT_ID)
params.append("response_type", "code")
params.append("scope", "openid userid-feide userid-name profile groups email")
params.append("redirect_uri", "http://localhost:3000/feide/callback")

const url = `https://auth.dataporten.no/oauth/authorization?${params.toString()}`

response.headers.set("Location", url)

return response
}
8 changes: 7 additions & 1 deletion apps/web/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import { Fraunces, Poppins } from "next/font/google"
import type { PropsWithChildren } from "react"
import "../styles/globals.css"
import { Providers } from "./providers"
import { getServerSession } from "next-auth"
import { authOptions } from "@dotkomonline/auth/src/web.app"
import { getServerClient } from "@/utils/trpc/serverClient"
import { redirect } from "next/navigation"
import { OnboardingRedirect } from "@/utils/OnboardingRedirect"
import { cookies } from "next/headers"

export const metadata = {
title: "Onlineweb 5",
Expand All @@ -15,7 +21,7 @@ export const metadata = {
const poppins = Poppins({ subsets: ["latin"], weight: ["400", "500", "600", "700"], variable: "--font-poppins" })
const fraunces = Fraunces({ subsets: ["latin"], weight: ["400", "500", "600", "700"], variable: "--font-fraunces" })

export default function RootLayout({ children }: PropsWithChildren) {
export default async function RootLayout({ children }: PropsWithChildren) {
return (
<html lang="en">
<body className={cn(fraunces.variable, poppins.variable, "h-full w-full")}>
Expand Down
Loading