Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions apps/dashboard/src/app/(internal)/brukere/[id]/edit-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createSelectInput } from "@/components/forms/SelectInput"
import { createTextInput } from "@/components/forms/TextInput"
import { USER_IMAGE_MAX_SIZE_KIB, type UserWrite, UserWriteSchema } from "@dotkomonline/types"
import { createTextareaInput } from "@/components/forms/TextareaInput"
import { useIsAdminQuery } from "../queries"

interface UseUserProfileWriteFormProps {
onSubmit(data: UserWrite): void
Expand All @@ -13,6 +14,7 @@ interface UseUserProfileWriteFormProps {
}

export const useUserProfileEditForm = ({ defaultValues, onSubmit, label = "Bruker" }: UseUserProfileWriteFormProps) => {
const { isAdmin } = useIsAdminQuery()
const fileUpload = useUserFileUploadMutation()

return useFormBuilder({
Expand All @@ -28,10 +30,12 @@ export const useUserProfileEditForm = ({ defaultValues, onSubmit, label = "Bruke
name: createTextInput({
label: "Navn",
placeholder: "Ola Nordmann",
disabled: isAdmin !== true,
}),
email: createTextInput({
label: "E-post",
placeholder: "ola.nordmann@gmail.com",
disabled: isAdmin !== true,
}),
phone: createTextInput({
label: "Telefon",
Expand Down
7 changes: 4 additions & 3 deletions apps/rpc/src/modules/user/user-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,15 @@ const updateUserProcedure = procedure
.use(withDatabaseTransaction())
.use(withAuditLogEntry())
.mutation(async ({ input, ctx }) => {
let { name, ...data } = input.input
let { name, email, ...data } = input.input

// Only admins can change the name field
// Only admins can change the name and email fields
if (!ctx.authorizationService.isAdministrator(ctx.principal.affiliations)) {
name = undefined
email = undefined
}

return ctx.userService.update(ctx.handle, input.id, { name, ...data })
return ctx.userService.update(ctx.handle, input.id, { name, email, ...data })
})

export type IsStaffInput = inferProcedureInput<typeof isStaffProcedure>
Expand Down
12 changes: 6 additions & 6 deletions apps/web/src/app/innstillinger/profil/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ export function ProfileForm({ user, onSubmit, isSaving, saveSuccess, saveError,
</div>

<div className="w-full flex flex-col gap-1">
<TextInput label="E-post" placeholder="ola.nordmann@epost.no" required {...register("email")} />
{errors.email && (
<Text className="text-red-600 dark:text-red-400 text-xs text-left transition-all fade-in fade-out">
{errors.email?.message ?? "En feil oppstod"}
</Text>
)}
<TextInput
label="E-post"
description="Det blir snart mulig å endre e-posten din."
placeholder="ola.nordmann@epost.no"
disabled
/>
</div>

<Controller
Expand Down
Loading