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

Move user information to auth0 #1023

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ff98545
Remove user table and move information to auth0
jotjern Sep 24, 2024
73510c0
Give more proper names to columns
jotjern Sep 24, 2024
78da186
Update user repository to reflect db changes
jotjern Sep 24, 2024
eabd683
Correct user id type
jotjern Sep 24, 2024
059bfca
Clean attendee repository for ow_user references
jotjern Sep 24, 2024
1a57d9f
Fix attendee service
jotjern Sep 24, 2024
816f673
Add user data to next auth
jotjern Sep 24, 2024
cdd94a3
Merge branch 'main' into feature/dot-817-store-user-data-in-auth0-ins…
jotjern Sep 24, 2024
d321b8c
Retain ow_user table with only one column
jotjern Sep 24, 2024
3d1a180
Ensure auth0 id always added to owUser
jotjern Sep 24, 2024
963395d
Remove unecessary change
jotjern Sep 24, 2024
c891564
Cleanup
jotjern Sep 24, 2024
7743bd6
Fix nullable types
jotjern Sep 24, 2024
d843e57
Fix auth types
jotjern Sep 24, 2024
7a14de3
Lint fix
jotjern Sep 24, 2024
83f61ad
Remove outdated user service tests
jotjern Sep 24, 2024
bf221ae
Fix data shape
jotjern Sep 25, 2024
2c28667
Fix user dashboard page
jotjern Sep 25, 2024
0151599
Merge branch 'main' into feature/dot-817-store-user-data-in-auth0-ins…
jotjern Sep 25, 2024
ccfefe6
Lint
jotjern Sep 25, 2024
5708d1b
Fixed errors and removed unintentional changes
jotjern Sep 25, 2024
76958fb
Fix type problems
jotjern Sep 25, 2024
e06e233
LINT
jotjern Sep 25, 2024
44dc29c
Revert disabled e2e test to original state
jotjern Sep 25, 2024
ce228c0
Cleaned up user mapping code
jotjern Sep 26, 2024
6954629
Revert changes from other branch
jotjern Sep 26, 2024
69f1bd7
Fix again
jotjern Sep 26, 2024
9223f2d
Fix profile settings page
jotjern Nov 20, 2024
7ea7ac2
Lots of cleanup
jotjern Nov 20, 2024
a566624
Unrenamed file
jotjern Nov 20, 2024
6b3133e
Fix renamed propery
jotjern Nov 20, 2024
24047a1
Fix dashboard property names
jotjern Nov 20, 2024
89aac6a
Merge with main
jotjern Nov 20, 2024
14d5561
Merge branch 'main' into feature/dot-817-store-user-data-in-auth0-ins…
jotjern Nov 20, 2024
c991374
Remove unnecessary changes
jotjern Nov 20, 2024
14ddacd
Retain user id in ow_user table
jotjern Nov 20, 2024
04eb5d6
Fix type
jotjern Nov 20, 2024
7b6743c
Fix type problems
jotjern Nov 20, 2024
5161419
LINT
jotjern Nov 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions apps/dashboard/src/app/(dashboard)/event/all-users-table.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AttendanceId, AttendeeId, AttendeeUser } from "@dotkomonline/types"
import type { AttendanceId, Attendee, AttendeeId } from "@dotkomonline/types"
import { Button, Checkbox } from "@mantine/core"
import { createColumnHelper, getCoreRowModel, useReactTable } from "@tanstack/react-table"
import { useMemo } from "react"
Expand Down Expand Up @@ -37,21 +37,17 @@ export const AllAttendeesTable = ({ attendanceId }: AllAttendeesTableProps) => {

const { attendees } = useEventAttendeesGetQuery(attendanceId)

const columnHelper = createColumnHelper<AttendeeUser>()
const columnHelper = createColumnHelper<Attendee>()
const columns = useMemo(
() => [
columnHelper.accessor((attendee) => attendee, {
id: "userId",
header: () => "Bruker",
cell: (info) => {
const attendee = info.getValue()
// return `${attendee.user.givenName} ${attendee.user.familyName}`
return `${attendee.user.name}`
return `${attendee.firstName} ${attendee.lastName}`
},
}),
columnHelper.accessor("user.studyYear", {
header: () => "Klassetrinn",
}),
columnHelper.accessor((attendee) => attendee, {
id: "attend",
header: () => "Møtt",
Expand Down
29 changes: 24 additions & 5 deletions apps/dashboard/src/app/(dashboard)/user/[id]/edit-card.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
import { UserWriteSchema } from "@dotkomonline/types"
import { Title } from "@mantine/core"
import type { FC } from "react"
import { useUpdateUserMutation } from "../../../../modules/user/mutations"
import { useUserEditForm } from "../edit-form"
import { useUserProfileEditForm } from "./edit-form"
import { useUserDetailsContext } from "./provider"

export const UserEditCard: FC = () => {
const { user } = useUserDetailsContext()
const update = useUpdateUserMutation()

const FormComponent = useUserEditForm({
label: "Oppdater bruker",
const EditUserProfileComponent = useUserProfileEditForm({
label: "Oppdater profil",
onSubmit: (data) => {
const result = UserWriteSchema.parse(data)

if (result.address === "") {
result.address = undefined
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
if (result.phone === "") {
result.phone = undefined
}
if (result.rfid === "") {
result.rfid = undefined
}

update.mutate({
data: result,
input: result,
id: user.id,
})
},
defaultValues: { ...user },
})
return <FormComponent />

return (
<>
<Title>Profil</Title>
<EditUserProfileComponent />
</>
)
}
53 changes: 53 additions & 0 deletions apps/dashboard/src/app/(dashboard)/user/[id]/edit-form.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { type UserWrite, UserWriteSchema } from "@dotkomonline/types"
import { createCheckboxInput, createSelectInput, createTextInput, useFormBuilder } from "../../../form"

interface UseUserProfileWriteFormProps {
onSubmit(data: UserWrite): void
defaultValues?: Partial<UserWrite>
label?: string
}

export const useUserProfileEditForm = ({ defaultValues, onSubmit, label = "Bruker" }: UseUserProfileWriteFormProps) =>
useFormBuilder({
schema: UserWriteSchema,
onSubmit,
defaultValues,
label,
fields: {
firstName: createTextInput({
label: "Fornavn",
placeholder: "Ola",
}),
lastName: createTextInput({
label: "Etternavn",
placeholder: "Ola",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nordmann?

}),
phone: createTextInput({
label: "Telefon",
placeholder: "12345678",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dette eksempelet er ikke gyldig, og merk at for internasjonale må man ha med +xx

}),
gender: createSelectInput({
label: "Kjønn",
data: [
{ label: "Mann", value: "male" },
{ label: "Kvinne", value: "female" },
{ label: "Annet", value: "other" },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kan vi ha med "Ønsker ikke svare"?

],
}),
allergies: createTextInput({
label: "Allergier",
placeholder: "Melk, nøtter, gluten",
}),
rfid: createTextInput({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jeg tror ikke dette er noe vi burde be brukere skrive selv, er litt jobb å dra frem NTNU-kortet, og vi bruker det ikke til noe atm

label: "RFID",
placeholder: "123456",
}),
compiled: createCheckboxInput({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jeg syntes dette er et felt Online skal styre og ikke brukeren selv, ser ikke poenget i at vi skal ha det som en bruker-styrt checkmark

label: "Kompilert",
}),
address: createTextInput({
Copy link
Member

@henrikhorluck henrikhorluck Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jeg ville heller samlet inn adresse ved bestilling av noe i en (poentiensiell) nettbutikk. Dette bare samler data som vi ikke bruker til noe og har minimal nytte (for ikke si negativ! I tilfelle feilbestilling) for brukeren

label: "Adresse",
placeholder: "Osloveien 1, 0001 Oslo",
}),
},
})
2 changes: 1 addition & 1 deletion apps/dashboard/src/app/(dashboard)/user/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function UserDetailsPage() {
<Box p="md">
<Group>
<CloseButton onClick={() => router.back()} />
<Title>{user.name}</Title>
<Title>{user.firstName || user.lastName ? `${user.firstName} ${user.lastName}` : user.email}</Title>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flytt denne logikken til brukeren?

</Group>

<Tabs defaultValue={SIDEBAR_LINKS[0].slug}>
Expand Down
57 changes: 0 additions & 57 deletions apps/dashboard/src/app/(dashboard)/user/edit-form.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const UserSearch: FC<UserSearchProps> = ({ onSubmit }) => {
onSubmit(user)
}}
items={users}
dataMapper={(item: User) => `${item.name}`}
dataMapper={(item: User) => `${item.email} ${item.firstName} ${item.lastName}`}
placeholder="Søk etter bruker..."
resetOnClick
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const AttendanceRegisteredModal: FC<ContextModalProps<AttendanceRegistere
}, 3000)
return (
<div className="w-full">
<h1>{innerProps.user.name}</h1>
<h1>{`${innerProps.user.firstName} ${innerProps.user.lastName}`}</h1>
<p>{innerProps.user.email}</p>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const AlreadyAttendedModal: FC<ContextModalProps<AttendanceRegisteredModa
return (
<div className="w-full">
<h1>Bruker allerede påmeldt</h1>
<h2 className="text-">{innerProps.user.name}</h2>
<h2 className="text-">{`${innerProps.user.firstName} ${innerProps.user.lastName}`}</h2>
<p>{innerProps.user.email}</p>
</div>
)
Expand Down
12 changes: 6 additions & 6 deletions apps/dashboard/src/modules/user/use-user-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ export const useUserTable = ({ data }: Props) => {
const columnHelper = createColumnHelper<User>()
const columns = useMemo(
() => [
columnHelper.accessor("email", {
header: () => "E-post",
cell: (info) => info.getValue(),
}),
columnHelper.accessor("givenName", {
columnHelper.accessor("firstName", {
header: () => "Fornavn",
cell: (info) => info.getValue(),
}),
columnHelper.accessor("familyName", {
columnHelper.accessor("lastName", {
header: () => "Etternavn",
cell: (info) => info.getValue(),
}),
columnHelper.accessor("email", {
header: () => "E-post",
cell: (info) => info.getValue(),
}),
columnHelper.accessor((evt) => evt, {
id: "actions",
header: () => "Detaljer",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export const AttendanceBox: FC<Props> = ({ sessionUser, attendance, pools, event
new Date()
)
const userIsRegistered = Boolean(attendee)
const myGroups = user && pools?.find((a) => a.yearCriteria.includes(user?.studyYear))
// TODO: CORRECT THIS
const myGroups = user && pools?.find((a) => a.yearCriteria.includes(1))

const visiblePools = pools?.filter((pool) => pool.isVisible)

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/settings/components/ChangeAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const AvatarImgChange = (user: User) => (
<DropdownMenu>
<DropdownMenuTrigger className="relative border-[1px] rounded-full">
<Avatar className="w-40 h-auto">
<AvatarImage src={user.image} alt="UserAvatar" />
<AvatarImage src={user.image ?? undefined} alt="UserAvatar" />
<AvatarFallback className="w-40 h-40">{user.name}</AvatarFallback>
</Avatar>
<div className=" bg-slate-1 absolute top-0 w-full h-full rounded-full opacity-60 flex justify-center items-center hover:cursor-pointer">
Expand Down
16 changes: 11 additions & 5 deletions apps/web/src/app/settings/page.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
"use client"

import { SettingsLanding } from "@/components/views/SettingsView/components"
import { getServerSession } from "next-auth"
import { trpc } from "@/utils/trpc/client"
import { redirect } from "next/navigation"

const SettingsPage = async () => {
const session = await getServerSession()
const SettingsPage = () => {
const { data: user } = trpc.user.getMe.useQuery()

if (session === null) {
if (user === null) {
redirect("/")
}

return <SettingsLanding user={session.user} />
if (user === undefined) {
return <div>Loading...</div>
}

return <SettingsLanding user={user} />
}

export default SettingsPage
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const PersonalInfo: FC<PersonalInfoProps> = ({ user, className }) => {
return (
<div className={`flex flex-col items-center justify-center gap-3 ${className}`}>
<Avatar className="w-40 h-auto opacity-60">
<AvatarImage src={user.image} alt="UserAvatar" />
<AvatarImage src={user.image ?? undefined} alt="UserAvatar" />
<AvatarFallback className="w-40 h-40">{user.name}</AvatarFallback>
</Avatar>
<p className="text-lg">{user.name}</p>
Expand Down
Loading
Loading