web: updateEditActions vue to be more adaptive

This commit is contained in:
Mika 2024-07-11 23:32:00 +02:00
parent 16d3b8d5f8
commit cdebdaccdb
3 changed files with 29 additions and 9 deletions

View file

@ -13,13 +13,13 @@
<v-card-text> <v-card-text>
<v-data-table <v-data-table
:headers="headers" :headers="headers"
:items="items" :items="data ?? []"
:items-per-page="10" :items-per-page="10"
item-key="name" item-key="name"
class="elevation-5" class="elevation-5"
> >
<template v-slot:item.actions="{ item }"> <template v-slot:item.actions="{ item }">
<UsersEditAction /> <UsersEditAction :user="item" />
<UsersDeleteAction /> <UsersDeleteAction />
</template> </template>
</v-data-table> </v-data-table>
@ -39,17 +39,27 @@ import UsersDeleteAction from "./UsersDeleteActions.vue";
import UsersEditAction from "./UsersEditActions.vue"; import UsersEditAction from "./UsersEditActions.vue";
import { Users } from "lucide-vue-next"; import { Users } from "lucide-vue-next";
import { defineComponent, ref, computed, watch } from "vue"; import { defineComponent, ref, computed, watch } from "vue";
import { useQuery, useMutation, useQueryClient } from "@tanstack/vue-query";
import { axiosInstance } from "@/client";
import { User } from "@/types";
// Data Table values // Data Table values
const headers = ref([ const headers = ref([
{ title: "Name", value: "name" }, { title: "Name", value: "name" },
{ title: "Email", value: "email" }, { title: "Email", value: "email" },
{ title: "isAdmin", value: "admin" },
{ title: "Actions", value: "actions", sortable: false }, { title: "Actions", value: "actions", sortable: false },
]); ]);
const items = ref([ const queryClient = useQueryClient();
{ name: "John Doe", email: "test@john.doe", action: "Here CRUD" },
]); const { data } = useQuery({
queryKey: ["users"],
queryFn: async () => {
const res = await axiosInstance.get<User[]>("/users");
return res.data;
},
});
// Dialog open state // Dialog open state
const users = ref(false); const users = ref(false);

View file

@ -29,6 +29,12 @@
:rules="editUserEmailRules" :rules="editUserEmailRules"
class="mb-3" class="mb-3"
></v-text-field> ></v-text-field>
<v-switch
label="Admin"
inset
v-model="editUserAdmin"
color="primary"
></v-switch>
</div> </div>
</v-card-text> </v-card-text>
<v-card-actions> <v-card-actions>
@ -61,7 +67,9 @@ 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 } from "@/types"; import { CreateLicenseDto, User } from "@/types";
const { user } = defineProps<{ user: User }>();
const queryClient = useQueryClient(); const queryClient = useQueryClient();
@ -104,8 +112,9 @@ const { mutate: userMutate } = useMutation({
}, },
}); });
const editUserName = ref(""); const editUserName = ref(user.name);
const editUserEmail = ref(""); const editUserEmail = ref(user.email);
const editUserAdmin = ref(user.admin);
const edit = ref(false); const edit = ref(false);
</script> </script>

View file

@ -25,10 +25,11 @@ export interface CreateLicenseDto {
note?: string; note?: string;
} }
export interface UserDto { export interface User {
id: string; id: string;
name: string; name: string;
email: string; email: string;
admin: boolean;
} }
export type CreateGroupDto = Omit<LicenseGroup, "id" | "licenses">; export type CreateGroupDto = Omit<LicenseGroup, "id" | "licenses">;