feat(SPA): users page and invite modal
This commit is contained in:
1 parent
acdef18b37
commit
6afffc1984
20 files changed
+1880
-55
No files matched your search
@@ -0,0 +1,51 @@
|
||||
import { useApi } from '@/composables/useApi'
|
||||
|
||||
export type UserListItem =
|
||||
| {
|
||||
kind: 'user'
|
||||
id: number
|
||||
username: string
|
||||
display_name: string
|
||||
status: 'accepted'
|
||||
created_at: string
|
||||
}
|
||||
| {
|
||||
kind: 'invite'
|
||||
id: number
|
||||
email: string
|
||||
status: 'pending' | 'expired'
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export const USER_SKELETON_ROWS = 5
|
||||
|
||||
export function userRowKey(kind: UserListItem['kind'], id: number) {
|
||||
return `${kind}-${id}`
|
||||
}
|
||||
|
||||
export interface CreatedInvite {
|
||||
id: number
|
||||
kind: 'invite'
|
||||
email: string
|
||||
status: 'pending'
|
||||
created_at: string
|
||||
expires_at: string
|
||||
}
|
||||
|
||||
export function useUsers() {
|
||||
const { request } = useApi()
|
||||
|
||||
function listUsers(): Promise<UserListItem[]> {
|
||||
return request<UserListItem[]>('/v1/user/')
|
||||
}
|
||||
|
||||
function inviteUser(email: string): Promise<CreatedInvite> {
|
||||
return request<CreatedInvite>('/v1/user/invite', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ email }),
|
||||
})
|
||||
}
|
||||
|
||||
return { listUsers, inviteUser }
|
||||
}
|
||||
Reference in new issue
Block a user