web: update user working
This commit is contained in:
parent
d627deed2d
commit
b2053773e9
3 changed files with 23 additions and 11 deletions
1
web/components.d.ts
vendored
1
web/components.d.ts
vendored
|
@ -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']
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
</v-btn>
|
||||
<v-dialog v-model="edit" width="600" persistent>
|
||||
<v-card max-width="600">
|
||||
<v-form @submit.prevent="submitGroup">
|
||||
<v-form @submit.prevent="submit">
|
||||
<v-card-title>
|
||||
<span class="headline">Edit User</span>
|
||||
</v-card-title>
|
||||
|
@ -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<string | undefined>();
|
||||
</script>
|
||||
|
||||
<style scoped></style>
|
||||
|
|
|
@ -39,8 +39,13 @@ export interface CreateUserDto {
|
|||
admin: boolean;
|
||||
}
|
||||
|
||||
export interface UpdateUserDto {
|
||||
name: string;
|
||||
email: string;
|
||||
password?: string;
|
||||
admin?: boolean;
|
||||
}
|
||||
|
||||
export type CreateGroupDto = Omit<LicenseGroup, "id" | "licenses">;
|
||||
|
||||
export type UpdateLicenseDto = Omit<License, "id">;
|
||||
|
||||
export type UpdateUserDto = Omit<LicenseGroup, "id">;
|
||||
|
|
Loading…
Reference in a new issue