-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: main
Are you sure you want to change the base?
Changes from all commits
ff98545
73510c0
78da186
eabd683
059bfca
1a57d9f
816f673
cdd94a3
d321b8c
3d1a180
963395d
c891564
7743bd6
d843e57
7a14de3
83f61ad
bf221ae
2c28667
0151599
ccfefe6
5708d1b
76958fb
e06e233
44dc29c
ce228c0
6954629
69f1bd7
9223f2d
7ea7ac2
a566624
6b3133e
24047a1
89aac6a
14d5561
c991374
14ddacd
04eb5d6
7b6743c
5161419
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
} | ||
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 /> | ||
</> | ||
) | ||
} |
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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nordmann? |
||
}), | ||
phone: createTextInput({ | ||
label: "Telefon", | ||
placeholder: "12345678", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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", | ||
}), | ||
}, | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Flytt denne logikken til brukeren? |
||
</Group> | ||
|
||
<Tabs defaultValue={SIDEBAR_LINKS[0].slug}> | ||
|
This file was deleted.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete