Skip to content

Commit

Permalink
show tenant name in user list
Browse files Browse the repository at this point in the history
  • Loading branch information
briskt committed Dec 28, 2023
1 parent d79e12c commit 0ac18c0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type User struct {
Email string
AvatarURL string
Role string
TenantID string
LastLoginAt *time.Time
CreatedAt time.Time
UpdatedAt time.Time
Expand Down
2 changes: 2 additions & 0 deletions assets/data/api/tenants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type {Tenant, TenantCreate, TenantUserCreate} from 'data/types/tenant'
import api from '../api'

// TODO: cache tenant list

export const addTenant = async (name: string): Promise<Tenant> => {
const body: TenantCreate = {
Name: name,
Expand Down
1 change: 1 addition & 0 deletions assets/data/types/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type User = {
UpdatedAt: string //date
LastName: string
Role: string
TenantID: string
}

export const isAdmin = (user: User) => user.Role == Admin
Expand Down
11 changes: 11 additions & 0 deletions assets/pages/admin/users.svelte
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
<script lang="ts">
import {getTenant, listTenants} from 'data/api/tenants'
import {listUsers} from 'data/api/users'
import type {Tenant} from 'data/types/tenant'
import type {User} from 'data/types/user'
import {localeTime} from 'helpers/time'
import {onMount} from 'svelte'
let tenants = [] as Tenant[]
let users = [] as User[]
onMount(async () => {
tenants = await listTenants()
users = await listUsers()
})
const getTenantNameFromID = (id: string): string => {
const tenant = tenants.find(t => t.ID === id)
return tenant?.Name || '(none)'
}
</script>

<h2>Users</h2>

<table>
<tr>
<th>Role</th>
<th>Tenant</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
Expand All @@ -27,6 +37,7 @@
{#each users as user (user.ID)}
<tr>
<td>{user.Role}</td>
<td>{getTenantNameFromID(user.TenantID)}</td>
<td>{user.FirstName}</td>
<td>{user.LastName}</td>
<td>{user.Email}</td>
Expand Down
8 changes: 6 additions & 2 deletions db/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func findUserByID(ctx echo.Context, id string) (User, error) {
}

func ConvertUser(_ echo.Context, u User) (app.User, error) {
return app.User{
user := app.User{
ID: u.ID,
FirstName: u.FirstName,
LastName: u.LastName,
Expand All @@ -133,5 +133,9 @@ func ConvertUser(_ echo.Context, u User) (app.User, error) {
LastLoginAt: u.LastLoginAt,
CreatedAt: u.CreatedAt,
UpdatedAt: u.UpdatedAt,
}, nil
}
if u.TenantID != nil {
user.TenantID = *u.TenantID
}
return user, nil
}

0 comments on commit 0ac18c0

Please sign in to comment.