list users
This commit is contained in:
@@ -7,7 +7,7 @@ import {
|
||||
BreadcrumbPage,
|
||||
BreadcrumbSeparator,
|
||||
} from '@/components/ui/breadcrumb';
|
||||
import type { BreadcrumbData } from '~/types';
|
||||
import type { BreadcrumbData } from '#shared/types';
|
||||
const route = useRoute();
|
||||
const store = useWarrenStore();
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
ContextMenuSeparator,
|
||||
} from '@/components/ui/context-menu';
|
||||
import { deleteWarrenDirectory, deleteWarrenFile } from '~/lib/api/warrens';
|
||||
import type { DirectoryEntry } from '~/types';
|
||||
import type { DirectoryEntry } from '#shared/types';
|
||||
|
||||
const warrenStore = useWarrenStore();
|
||||
const renameDialog = useRenameDirectoryDialog();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||
import type { DirectoryEntry } from '~/types';
|
||||
import type { DirectoryEntry } from '#shared/types';
|
||||
const { entries } = defineProps<{
|
||||
entries: DirectoryEntry[];
|
||||
}>();
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import { Avatar, AvatarImage, AvatarFallback } from '@/components/ui/avatar';
|
||||
import { logout } from '~/lib/api/auth/logout';
|
||||
import type { AuthUser } from '~/types/auth';
|
||||
import type { AuthUser } from '#shared/types/auth';
|
||||
|
||||
const { isMobile } = useSidebar();
|
||||
const { user } = defineProps<{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import byteSize from 'byte-size';
|
||||
import type { UploadFile } from '~/types';
|
||||
import type { UploadFile } from '#shared/types';
|
||||
|
||||
const emit = defineEmits(['removeFile']);
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
AlertDialogTitle,
|
||||
AlertDialogTrigger,
|
||||
} from '@/components/ui/alert-dialog';
|
||||
import type { AuthUser } from '~/types/auth';
|
||||
import type { AuthUser } from '#shared/types/auth';
|
||||
|
||||
const adminStore = useAdminStore();
|
||||
// We'll only update this value if there is a user to prevent layout shifts on close
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import type { AuthUser } from '~/types/auth';
|
||||
import type { AuthUser } from '#shared/types/auth';
|
||||
|
||||
const { user } = defineProps<{
|
||||
user: AuthUser;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { AuthSession } from '~/types/auth';
|
||||
import type { AuthSession } from '#shared/types/auth';
|
||||
|
||||
const SAME_SITE_SETTINGS = ['strict', 'lax', 'none'] as const;
|
||||
|
||||
|
||||
@@ -1,4 +1,16 @@
|
||||
<script setup lang="ts"></script>
|
||||
<script setup lang="ts">
|
||||
import { listUsers } from '~/lib/api/admin/listUsers';
|
||||
|
||||
const adminStore = useAdminStore();
|
||||
|
||||
await useAsyncData('users', async () => {
|
||||
const response = await listUsers();
|
||||
|
||||
if (response.success) {
|
||||
adminStore.users = response.users;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NuxtLayout name="default">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { toast } from 'vue-sonner';
|
||||
import type { ApiResponse } from '~/types/api';
|
||||
import type { AuthUser, AuthUserFields } from '~/types/auth';
|
||||
import type { ApiResponse } from '#shared/types/api';
|
||||
import type { AuthUser, AuthUserFields } from '#shared/types/auth';
|
||||
import { getApiHeaders } from '..';
|
||||
|
||||
/** Admin function to create a new user */
|
||||
@@ -32,6 +32,8 @@ export async function createUser(
|
||||
};
|
||||
}
|
||||
|
||||
await refreshNuxtData('users');
|
||||
|
||||
toast.success('Create user', {
|
||||
description: 'Successfully created user',
|
||||
});
|
||||
|
||||
27
frontend/lib/api/admin/listUsers.ts
Normal file
27
frontend/lib/api/admin/listUsers.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import type { ApiResponse } from '~/shared/types/api';
|
||||
import type { AuthUser } from '~/shared/types/auth';
|
||||
import { getApiHeaders } from '..';
|
||||
|
||||
export async function listUsers(): Promise<
|
||||
{ success: true; users: AuthUser[] } | { success: false }
|
||||
> {
|
||||
const { data } = await useFetch<ApiResponse<AuthUser[]>>(
|
||||
getApiUrl('admin/users'),
|
||||
{
|
||||
method: 'GET',
|
||||
headers: getApiHeaders(),
|
||||
responseType: 'json',
|
||||
}
|
||||
);
|
||||
|
||||
if (data.value == null) {
|
||||
return {
|
||||
success: false,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
users: data.value.data,
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { AuthSessionType, AuthUser } from '~/types/auth';
|
||||
import type { ApiResponse } from '~/types/api';
|
||||
import type { AuthSessionType, AuthUser } from '#shared/types/auth';
|
||||
import type { ApiResponse } from '#shared/types/api';
|
||||
|
||||
export async function getAuthSessionData(params: {
|
||||
sessionType: AuthSessionType;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { toast } from 'vue-sonner';
|
||||
import type { ApiResponse } from '~/types/api';
|
||||
import type { AuthUser } from '~/types/auth';
|
||||
import type { ApiResponse } from '#shared/types/api';
|
||||
import type { AuthUser } from '#shared/types/auth';
|
||||
import { getApiHeaders } from '..';
|
||||
|
||||
export async function loginUser(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { toast } from 'vue-sonner';
|
||||
import type { ApiResponse } from '~/types/api';
|
||||
import type { ApiResponse } from '#shared/types/api';
|
||||
|
||||
export async function registerUser(
|
||||
username: string,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { toast } from 'vue-sonner';
|
||||
import type { DirectoryEntry } from '~/types';
|
||||
import type { ApiResponse } from '~/types/api';
|
||||
import type { Warren } from '~/types/warrens';
|
||||
import type { DirectoryEntry } from '#shared/types';
|
||||
import type { ApiResponse } from '#shared/types/api';
|
||||
import type { Warren } from '#shared/types/warrens';
|
||||
import { getApiHeaders } from '.';
|
||||
|
||||
export async function getWarrens(): Promise<Record<string, Warren>> {
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
<script setup lang="ts">
|
||||
import type { AuthUser } from '~/types/auth';
|
||||
|
||||
definePageMeta({
|
||||
layout: 'admin',
|
||||
middleware: ['is-admin'],
|
||||
@@ -8,21 +6,6 @@ definePageMeta({
|
||||
|
||||
const session = useAuthSession();
|
||||
const adminStore = useAdminStore();
|
||||
|
||||
const users: AuthUser[] = [
|
||||
{
|
||||
id: '5a307466-bf2e-4cf2-9b11-61f024e8fa71',
|
||||
name: '409',
|
||||
email: '409dev@protonmail.com',
|
||||
admin: true,
|
||||
},
|
||||
{
|
||||
id: '99132ce4-045c-4d4b-b957-61f5e99e708b',
|
||||
name: 'test-user',
|
||||
email: 'test@user.com',
|
||||
admin: false,
|
||||
},
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -41,7 +24,7 @@ const users: AuthUser[] = [
|
||||
<ScrollArea class="max-h-96">
|
||||
<div class="flex flex-col gap-4">
|
||||
<AdminUserListing
|
||||
v-for="user in users"
|
||||
v-for="user in adminStore.users"
|
||||
:key="user.id"
|
||||
:user
|
||||
class="group/user flex flex-row items-center justify-between gap-4"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||
import type { Warren } from '~/types/warrens';
|
||||
import type { Warren } from '#shared/types/warrens';
|
||||
|
||||
definePageMeta({
|
||||
middleware: ['authenticated'],
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import type { AuthUser, AuthUserFields } from '~/types/auth';
|
||||
import type { AuthUser, AuthUserFields } from '#shared/types/auth';
|
||||
|
||||
export const useAdminStore = defineStore('admin', {
|
||||
state: () => ({
|
||||
users: [] as AuthUser[],
|
||||
createUserDialog: null as { user: AuthUserFields } | null,
|
||||
deleteUserDialog: null as { user: AuthUser } | null,
|
||||
}),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import type { DirectoryEntry } from '~/types';
|
||||
import type { Warren } from '~/types/warrens';
|
||||
import type { DirectoryEntry } from '#shared/types';
|
||||
import type { Warren } from '#shared/types/warrens';
|
||||
|
||||
export const useWarrenStore = defineStore('warrens', {
|
||||
state: () => ({
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { UploadFile } from '~/types';
|
||||
import type { UploadFile } from '#shared/types';
|
||||
|
||||
export const useUploadStore = defineStore<
|
||||
'warren-upload',
|
||||
|
||||
Reference in New Issue
Block a user