web: update user working

This commit is contained in:
Sphereso 2024-07-12 01:48:40 +02:00
parent d627deed2d
commit b2053773e9
3 changed files with 23 additions and 11 deletions

1
web/components.d.ts vendored
View file

@ -9,7 +9,6 @@ declare module 'vue' {
export interface GlobalComponents { export interface GlobalComponents {
CategoryContainer: typeof import('./src/components/CategoryContainer.vue')['default'] CategoryContainer: typeof import('./src/components/CategoryContainer.vue')['default']
Clipboard: typeof import('./src/components/Clipboard.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'] DeleteDialog: typeof import('./src/components/DeleteDialog.vue')['default']
HeaderBar: typeof import('./src/components/HeaderBar.vue')['default'] HeaderBar: typeof import('./src/components/HeaderBar.vue')['default']
ListViewElement: typeof import('./src/components/ListViewElement.vue')['default'] ListViewElement: typeof import('./src/components/ListViewElement.vue')['default']

View file

@ -7,7 +7,7 @@
</v-btn> </v-btn>
<v-dialog v-model="edit" width="600" persistent> <v-dialog v-model="edit" width="600" persistent>
<v-card max-width="600"> <v-card max-width="600">
<v-form @submit.prevent="submitGroup"> <v-form @submit.prevent="submit">
<v-card-title> <v-card-title>
<span class="headline">Edit User</span> <span class="headline">Edit User</span>
</v-card-title> </v-card-title>
@ -81,7 +81,7 @@ import { ref } from "vue";
import { SubmitEventPromise } from "vuetify"; import { SubmitEventPromise } from "vuetify";
import { axiosInstance } from "@/client"; import { axiosInstance } from "@/client";
import { useMutation, useQueryClient } from "@tanstack/vue-query"; import { useMutation, useQueryClient } from "@tanstack/vue-query";
import { CreateLicenseDto, User } from "@/types"; import { CreateLicenseDto, UpdateUserDto, User } from "@/types";
import { Users } from "lucide-vue-next"; import { Users } from "lucide-vue-next";
const { user, adminMenu } = defineProps<{ user: User; adminMenu: boolean }>(); const { user, adminMenu } = defineProps<{ user: User; adminMenu: boolean }>();
@ -103,13 +103,21 @@ const editUserEmailRules = [
return "YOU MUST ENTER (A EMAIL NAME)"; 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; const result = await event;
if (result.valid) { if (result.valid) {
const userData = { const userData = adminMenu ? {
name: editUserName.value, 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); console.log(userData);
userMutate(userData); userMutate(userData);
} else { } else {
@ -118,8 +126,8 @@ async function submitGroup(event: SubmitEventPromise) {
} }
const { mutate: userMutate } = useMutation({ const { mutate: userMutate } = useMutation({
mutationFn: async (newLicense: CreateLicenseDto) => { mutationFn: async (editUser: UpdateUserDto) => {
await axiosInstance.post("/licenses", newLicense); await axiosInstance.put(`/users/${id}`, editUser);
}, },
onSuccess: () => { onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["users"] }); queryClient.invalidateQueries({ queryKey: ["users"] });
@ -131,7 +139,7 @@ const edit = ref(false);
const editUserName = ref(user.name); const editUserName = ref(user.name);
const editUserEmail = ref(user.email); const editUserEmail = ref(user.email);
const editUserAdmin = ref(user.admin); const editUserAdmin = ref(user.admin);
const editUserPassword = ref(undefined); const editUserPassword = ref<string | undefined>();
</script> </script>
<style scoped></style> <style scoped></style>

View file

@ -39,8 +39,13 @@ export interface CreateUserDto {
admin: boolean; admin: boolean;
} }
export interface UpdateUserDto {
name: string;
email: string;
password?: string;
admin?: boolean;
}
export type CreateGroupDto = Omit<LicenseGroup, "id" | "licenses">; export type CreateGroupDto = Omit<LicenseGroup, "id" | "licenses">;
export type UpdateLicenseDto = Omit<License, "id">; export type UpdateLicenseDto = Omit<License, "id">;
export type UpdateUserDto = Omit<LicenseGroup, "id">;