From b2053773e937777be74bf57e77aa9f32457f6112 Mon Sep 17 00:00:00 2001 From: Sphereso Date: Fri, 12 Jul 2024 01:48:40 +0200 Subject: [PATCH] web: update user working --- web/components.d.ts | 1 - .../NavBarIcons/UsersEditActions.vue | 24 ++++++++++++------- web/src/types.ts | 9 +++++-- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/web/components.d.ts b/web/components.d.ts index ed14298..374f265 100644 --- a/web/components.d.ts +++ b/web/components.d.ts @@ -9,7 +9,6 @@ declare module 'vue' { export interface GlobalComponents { CategoryContainer: typeof import('./src/components/CategoryContainer.vue')['default'] Clipboard: typeof import('./src/components/Clipboard.vue')['default'] - copy: typeof import("./src/components/UpdateDialog copy.vue")["default"] DeleteDialog: typeof import('./src/components/DeleteDialog.vue')['default'] HeaderBar: typeof import('./src/components/HeaderBar.vue')['default'] ListViewElement: typeof import('./src/components/ListViewElement.vue')['default'] diff --git a/web/src/components/NavBarIcons/UsersEditActions.vue b/web/src/components/NavBarIcons/UsersEditActions.vue index 6856cb3..a26c1d3 100644 --- a/web/src/components/NavBarIcons/UsersEditActions.vue +++ b/web/src/components/NavBarIcons/UsersEditActions.vue @@ -7,7 +7,7 @@ - + Edit User @@ -81,7 +81,7 @@ import { ref } from "vue"; import { SubmitEventPromise } from "vuetify"; import { axiosInstance } from "@/client"; import { useMutation, useQueryClient } from "@tanstack/vue-query"; -import { CreateLicenseDto, User } from "@/types"; +import { CreateLicenseDto, UpdateUserDto, User } from "@/types"; import { Users } from "lucide-vue-next"; const { user, adminMenu } = defineProps<{ user: User; adminMenu: boolean }>(); @@ -103,13 +103,21 @@ const editUserEmailRules = [ return "YOU MUST ENTER (A EMAIL NAME)"; }, ]; +const id = user.id; -async function submitGroup(event: SubmitEventPromise) { +async function submit(event: SubmitEventPromise) { const result = await event; if (result.valid) { - const userData = { + const userData = adminMenu ? { name: editUserName.value, - }; + email: editUserEmail.value, + password: !editUserPassword.value || editUserPassword.value === "" ? undefined : editUserPassword.value, + admin: editUserAdmin.value + } : { + name: editUserName.value, + email: editUserEmail.value, + password: !editUserPassword.value || editUserPassword.value === "" ? undefined : editUserPassword.value + } console.log(userData); userMutate(userData); } else { @@ -118,8 +126,8 @@ async function submitGroup(event: SubmitEventPromise) { } const { mutate: userMutate } = useMutation({ - mutationFn: async (newLicense: CreateLicenseDto) => { - await axiosInstance.post("/licenses", newLicense); + mutationFn: async (editUser: UpdateUserDto) => { + await axiosInstance.put(`/users/${id}`, editUser); }, onSuccess: () => { queryClient.invalidateQueries({ queryKey: ["users"] }); @@ -131,7 +139,7 @@ const edit = ref(false); const editUserName = ref(user.name); const editUserEmail = ref(user.email); const editUserAdmin = ref(user.admin); -const editUserPassword = ref(undefined); +const editUserPassword = ref(); diff --git a/web/src/types.ts b/web/src/types.ts index 083d761..ed5d66a 100644 --- a/web/src/types.ts +++ b/web/src/types.ts @@ -39,8 +39,13 @@ export interface CreateUserDto { admin: boolean; } +export interface UpdateUserDto { + name: string; + email: string; + password?: string; + admin?: boolean; +} + export type CreateGroupDto = Omit; export type UpdateLicenseDto = Omit; - -export type UpdateUserDto = Omit;