fixed update user dto for proper role handling and changed back button in user settings
This commit is contained in:
@@ -52,6 +52,24 @@ function usernamesFromIds(ids: string[]): string {
|
||||
return ids.map(id => idToName.value.get(String(id))).filter(Boolean).join(', ')
|
||||
}
|
||||
|
||||
// ---- NEW: immediate UI updates for Users table ----
|
||||
function handleUserUpdated(
|
||||
row: Users,
|
||||
payload: { id: string; username: string; role: 'admin' | 'user' }
|
||||
) {
|
||||
const idNum = Number(payload.id || row.id)
|
||||
user_data.value = user_data.value.map(u =>
|
||||
u.id === idNum
|
||||
? { ...u, username: payload.username, role: payload.role }
|
||||
: u
|
||||
)
|
||||
}
|
||||
|
||||
function handleUserDeleted(row: Users) {
|
||||
const idNum = row.id
|
||||
user_data.value = user_data.value.filter(u => u.id !== idNum)
|
||||
}
|
||||
|
||||
// ---------------- Devices ----------------
|
||||
type ApiDeviceUser = { id: number; username: string; role: string }
|
||||
type ApiDevice = { guid: string; name: string; users?: ApiDeviceUser[] }
|
||||
@@ -201,6 +219,8 @@ onBeforeUnmount(() => {
|
||||
:columns="user_columns"
|
||||
:data="user_data"
|
||||
:dropdownComponent="AdminUserDropdonw"
|
||||
@row-updated="handleUserUpdated"
|
||||
@row-deleted="handleUserDeleted"
|
||||
/>
|
||||
</TabsContent>
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ function onSave() {
|
||||
</div>
|
||||
<div class="grid grid-cols-4 items-center gap-4">
|
||||
<Label for="isAdmin" class="text-right">Make admin</Label>
|
||||
<Switch id="isAdmin" v-model:checked="form.isAdmin"/>
|
||||
<Switch id="isAdmin" :default-value="form.isAdmin" v-model:checked="form.isAdmin"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import { computed, onMounted, ref } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import type { Users } from '@/lib/interfaces';
|
||||
import { api } from '@/lib/api';
|
||||
import { X } from 'lucide-vue-next';
|
||||
|
||||
const mode = useColorMode()
|
||||
const modeLabel = computed(() => {
|
||||
@@ -88,11 +89,16 @@ function goBack() {
|
||||
<div class="w-full h-full flex items-center justify-center px-4">
|
||||
<Card class="flex w-[600px]">
|
||||
<CardHeader>
|
||||
<CardTitle>
|
||||
Settings
|
||||
</CardTitle>
|
||||
<div class="flex items-center justify-between">
|
||||
<CardTitle>
|
||||
Settings
|
||||
</CardTitle>
|
||||
<Button variant="ghost" class="w-auto px-4" @click="goBack">
|
||||
<X/>
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
</CardHeader>
|
||||
<Button variant="secondary" @click="goBack">Back</Button>
|
||||
<CardContent>
|
||||
<form class="grid gap-4 py-4" @submit.prevent="submitChangePassword">
|
||||
<div class="grid grid-cols-4 items-center gap-4">
|
||||
|
||||
@@ -23,7 +23,7 @@ type CreateUserDto struct {
|
||||
type UpdateUserDto struct {
|
||||
Username string `json:"username,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
Role string `json:"role,omitempty" binding:"oneof=admin user"`
|
||||
Role string `json:"role,omitempty"`
|
||||
}
|
||||
|
||||
func MapUser(u models.User) UserDto {
|
||||
|
||||
Reference in New Issue
Block a user