Skip to content

Commit

Permalink
fix: unable to update user privileges
Browse files Browse the repository at this point in the history
  • Loading branch information
stonith404 committed Dec 5, 2022
1 parent c795b98 commit d4a0f1a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
4 changes: 2 additions & 2 deletions backend/src/user/dto/updateUser.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PartialType } from "@nestjs/mapped-types";
import { UserDTO } from "./user.dto";
import { CreateUserDTO } from "./createUser.dto";

export class UpdateUserDto extends PartialType(UserDTO) {}
export class UpdateUserDto extends PartialType(CreateUserDTO) {}
13 changes: 7 additions & 6 deletions frontend/src/components/admin/showCreateUserModal.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
Button,
Group,
Input,
PasswordInput,
Stack,
Switch,
Expand Down Expand Up @@ -51,7 +50,7 @@ const Body = ({
<Stack>
<form
onSubmit={form.onSubmit(async (values) => {
console.log(values)
console.log(values);
userService
.create(values)
.then(() => {
Expand All @@ -72,10 +71,12 @@ const Body = ({
label="New password"
{...form.getInputProps("password")}
/>


<Switch labelPosition="left" label="Admin privileges" {...form.getInputProps("isAdmin")} />

<Switch
mt="xs"
labelPosition="left"
label="Admin privileges"
{...form.getInputProps("isAdmin", { type: "checkbox" })}
/>
<Group position="right">
<Button type="submit">Create</Button>
</Group>
Expand Down
19 changes: 12 additions & 7 deletions frontend/src/components/admin/showUpdateUserModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Group,
PasswordInput,
Stack,
Switch,
TextInput,
Title,
} from "@mantine/core";
Expand Down Expand Up @@ -36,8 +37,9 @@ const Body = ({
}) => {
const accountForm = useForm({
initialValues: {
username: user?.username,
email: user?.email,
username: user.username,
email: user.email,
isAdmin: user.isAdmin,
},
validate: yupResolver(
yup.object().shape({
Expand All @@ -64,10 +66,7 @@ const Body = ({
id="accountForm"
onSubmit={accountForm.onSubmit(async (values) => {
userService
.update(user.id, {
email: values.email,
username: values.username,
})
.update(user.id, values)
.then(() => {
getUsers();
modals.closeAll();
Expand All @@ -85,11 +84,17 @@ const Body = ({
label="Email"
{...accountForm.getInputProps("email")}
/>
<Switch
mt="xs"
labelPosition="left"
label="Admin privileges"
{...accountForm.getInputProps("isAdmin", {type: "checkbox"})}
/>
</Stack>
</form>
<Accordion>
<Accordion.Item sx={{ borderBottom: "none" }} value="changePassword">
<Accordion.Control>Passwort ändern</Accordion.Control>
<Accordion.Control>Change password</Accordion.Control>
<Accordion.Panel>
<form
onSubmit={passwordForm.onSubmit(async (values) => {
Expand Down

0 comments on commit d4a0f1a

Please sign in to comment.