feat(KAN-47): redesign teams and membership management
This commit is contained in:
+184
-336
@@ -1,356 +1,204 @@
|
||||
<script setup lang="ts">
|
||||
import { Form, Head } from '@inertiajs/vue3';
|
||||
import { Shield } from 'lucide-vue-next';
|
||||
import TeamController from '@/actions/App/Http/Controllers/TeamController';
|
||||
import Heading from '@/components/Heading.vue';
|
||||
import InputError from '@/components/InputError.vue';
|
||||
import { Head } from '@inertiajs/vue3';
|
||||
import { Plus, Search, Shield, Users } from 'lucide-vue-next';
|
||||
import { computed, ref } from 'vue';
|
||||
import FeedbackState from '@/components/FeedbackState.vue';
|
||||
import TeamEditorDialog from '@/components/teams/TeamEditorDialog.vue';
|
||||
import UserAvatar from '@/components/ui/avatar/UserAvatar.vue';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from '@/components/ui/card';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { useLocalization } from '@/composables/useLocalization';
|
||||
import AppLayout from '@/layouts/AppLayout.vue';
|
||||
import { index as teamsIndex } from '@/routes/teams';
|
||||
import { index } from '@/routes/teams';
|
||||
import type { BreadcrumbItem, TeamsIndexPageProps } from '@/types';
|
||||
import type { TeamEditorTarget } from '@/types/teams';
|
||||
|
||||
const props = defineProps<TeamsIndexPageProps>();
|
||||
|
||||
const breadcrumbs: BreadcrumbItem[] = [
|
||||
{
|
||||
title: 'Teams',
|
||||
href: teamsIndex(),
|
||||
},
|
||||
];
|
||||
|
||||
const hasPermission = (
|
||||
permissions: Record<string, string[]>,
|
||||
actorId: number,
|
||||
permission: string,
|
||||
) => (permissions[actorId] ?? []).includes(permission);
|
||||
|
||||
const permissionsForTeam = (teamId: number): Record<string, string[]> =>
|
||||
props.teamPermissions[teamId] ?? {};
|
||||
const { t } = useLocalization();
|
||||
const search = ref('');
|
||||
const target = ref<TeamEditorTarget | null>(null);
|
||||
const breadcrumbs = computed<BreadcrumbItem[]>(() => [
|
||||
{ title: t('navigation.teams'), href: index() },
|
||||
]);
|
||||
const visibleTeams = computed(() =>
|
||||
props.teams.filter((team) =>
|
||||
team.name
|
||||
.toLocaleLowerCase()
|
||||
.includes(search.value.trim().toLocaleLowerCase()),
|
||||
),
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout :breadcrumbs="breadcrumbs">
|
||||
<Head title="Teams" />
|
||||
|
||||
<div class="flex flex-1 flex-col gap-6 p-4">
|
||||
<div
|
||||
<Head :title="t('navigation.teams')" />
|
||||
<main
|
||||
class="mx-auto flex w-full max-w-7xl flex-1 flex-col gap-6 p-4 sm:p-6 lg:p-8"
|
||||
>
|
||||
<header
|
||||
class="flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between"
|
||||
>
|
||||
<Heading
|
||||
title="Teams"
|
||||
description="Create reusable teams, manage memberships, and assign team-scoped permissions to users."
|
||||
/>
|
||||
|
||||
<Badge variant="outline" class="gap-1.5 px-3 py-1">
|
||||
<Shield class="size-3.5" />
|
||||
{{ canCreateTeams ? 'Global admin' : 'Team-scoped access' }}
|
||||
</Badge>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="status"
|
||||
class="rounded-xl border border-emerald-200 bg-emerald-50 px-4 py-3 text-sm text-emerald-900 dark:border-emerald-900/70 dark:bg-emerald-950/40 dark:text-emerald-100"
|
||||
>
|
||||
{{ status }}
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="grid gap-6"
|
||||
:class="
|
||||
canCreateTeams
|
||||
? 'xl:grid-cols-[22rem_minmax(0,1fr)]'
|
||||
: 'xl:grid-cols-1'
|
||||
"
|
||||
>
|
||||
<Card v-if="canCreateTeams">
|
||||
<CardHeader>
|
||||
<CardTitle>Create team</CardTitle>
|
||||
<CardDescription>
|
||||
Teams group users so project permissions can be
|
||||
granted once and inherited by every member.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
|
||||
<CardContent>
|
||||
<Form
|
||||
v-bind="TeamController.store.form()"
|
||||
class="space-y-4"
|
||||
v-slot="{ errors, processing }"
|
||||
>
|
||||
<div class="grid gap-2">
|
||||
<Label for="name">Team name</Label>
|
||||
<Input
|
||||
id="name"
|
||||
name="name"
|
||||
required
|
||||
autofocus
|
||||
placeholder="Platform Team"
|
||||
/>
|
||||
<InputError :message="errors.name" />
|
||||
</div>
|
||||
|
||||
<Button type="submit" :disabled="processing">
|
||||
Create team
|
||||
</Button>
|
||||
</Form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<div class="grid gap-4">
|
||||
<Card
|
||||
v-for="team in teams"
|
||||
:key="team.id"
|
||||
class="gap-0 overflow-hidden"
|
||||
<div class="grid min-w-0 gap-2">
|
||||
<p
|
||||
class="text-primary text-xs font-semibold uppercase tracking-wider"
|
||||
>
|
||||
<CardHeader class="border-b">
|
||||
<div
|
||||
class="flex flex-col gap-3 md:flex-row md:items-start md:justify-between"
|
||||
>
|
||||
<div>
|
||||
<CardTitle>{{ team.name }}</CardTitle>
|
||||
<CardDescription>
|
||||
{{ team.users.length }} member{{
|
||||
team.users.length === 1 ? '' : 's'
|
||||
}}
|
||||
</CardDescription>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<Badge
|
||||
v-for="member in team.users"
|
||||
:key="member.id"
|
||||
variant="secondary"
|
||||
>
|
||||
{{ member.name }}
|
||||
</Badge>
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
|
||||
<CardContent class="space-y-6 pt-6">
|
||||
<Form
|
||||
v-bind="
|
||||
TeamController.updateMembers.form(team.id)
|
||||
"
|
||||
class="space-y-4"
|
||||
v-slot="{ processing }"
|
||||
>
|
||||
<div class="grid gap-2">
|
||||
<Label :for="`team-members-${team.id}`">
|
||||
Members
|
||||
</Label>
|
||||
<select
|
||||
:id="`team-members-${team.id}`"
|
||||
name="user_ids[]"
|
||||
multiple
|
||||
class="border-input bg-background shadow-xs focus-visible:border-ring focus-visible:ring-ring/50 min-h-44 rounded-md border px-3 py-2 text-sm outline-none transition-[color,box-shadow] focus-visible:ring-[3px]"
|
||||
>
|
||||
<option
|
||||
v-for="user in users"
|
||||
:key="user.id"
|
||||
:value="user.id"
|
||||
:selected="
|
||||
team.user_ids.includes(user.id)
|
||||
"
|
||||
>
|
||||
{{ user.name }} ({{ user.email }})
|
||||
</option>
|
||||
</select>
|
||||
<p class="text-muted-foreground text-sm">
|
||||
Hold Cmd or Ctrl to select multiple
|
||||
users.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
variant="outline"
|
||||
:disabled="processing"
|
||||
>
|
||||
Save members
|
||||
</Button>
|
||||
</Form>
|
||||
|
||||
<div class="space-y-4 border-t pt-6">
|
||||
<div class="space-y-1">
|
||||
<h3 class="text-foreground font-medium">
|
||||
Team permissions
|
||||
</h3>
|
||||
<p class="text-muted-foreground text-sm">
|
||||
Direct user permissions on this team are
|
||||
stored separately from team membership.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="overflow-x-auto">
|
||||
<table
|
||||
class="divide-border min-w-full divide-y text-sm"
|
||||
>
|
||||
<thead
|
||||
class="bg-muted/40 text-muted-foreground text-left"
|
||||
>
|
||||
<tr>
|
||||
<th
|
||||
class="px-4 py-3 font-medium"
|
||||
>
|
||||
User
|
||||
</th>
|
||||
<th
|
||||
class="px-4 py-3 font-medium"
|
||||
>
|
||||
Current permissions
|
||||
</th>
|
||||
<th
|
||||
class="px-4 py-3 text-right font-medium"
|
||||
>
|
||||
Action
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-border divide-y">
|
||||
<tr
|
||||
v-for="user in users"
|
||||
:key="`${team.id}-${user.id}`"
|
||||
class="bg-background align-top"
|
||||
>
|
||||
<td class="px-4 py-4">
|
||||
<div
|
||||
class="text-foreground font-medium"
|
||||
>
|
||||
{{ user.name }}
|
||||
</div>
|
||||
<div
|
||||
class="text-muted-foreground text-xs"
|
||||
>
|
||||
{{ user.email }}
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-4 py-4">
|
||||
<div
|
||||
class="flex flex-wrap gap-2"
|
||||
>
|
||||
<Badge
|
||||
v-for="option in permissionOptions"
|
||||
v-show="
|
||||
hasPermission(
|
||||
permissionsForTeam(
|
||||
team.id,
|
||||
),
|
||||
user.id,
|
||||
option.value,
|
||||
)
|
||||
"
|
||||
:key="`${team.id}-${user.id}-${option.value}-badge`"
|
||||
variant="secondary"
|
||||
>
|
||||
{{ option.label }}
|
||||
</Badge>
|
||||
<span
|
||||
v-if="
|
||||
(
|
||||
permissionsForTeam(
|
||||
team.id,
|
||||
)[
|
||||
user.id
|
||||
] ?? []
|
||||
).length === 0
|
||||
"
|
||||
class="text-muted-foreground"
|
||||
>
|
||||
No direct team
|
||||
permissions
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-4 py-4">
|
||||
<div
|
||||
class="flex justify-end"
|
||||
>
|
||||
<Form
|
||||
v-bind="
|
||||
TeamController.updateUserPermissions.form(
|
||||
[
|
||||
team.id,
|
||||
user.id,
|
||||
],
|
||||
)
|
||||
"
|
||||
class="flex flex-wrap justify-end gap-3"
|
||||
v-slot="{
|
||||
processing,
|
||||
}"
|
||||
>
|
||||
<label
|
||||
v-for="option in permissionOptions"
|
||||
:key="`${team.id}-${user.id}-${option.value}`"
|
||||
class="border-border inline-flex items-center gap-2 rounded-lg border px-3 py-2 text-sm"
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
name="permissions[]"
|
||||
:value="
|
||||
option.value
|
||||
"
|
||||
:checked="
|
||||
hasPermission(
|
||||
permissionsForTeam(
|
||||
team.id,
|
||||
),
|
||||
user.id,
|
||||
option.value,
|
||||
)
|
||||
"
|
||||
class="border-input text-primary focus:ring-ring size-4 rounded"
|
||||
/>
|
||||
<span>
|
||||
{{
|
||||
option.label
|
||||
}}
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<div
|
||||
class="w-full sm:hidden"
|
||||
/>
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
size="sm"
|
||||
variant="outline"
|
||||
:disabled="
|
||||
processing
|
||||
"
|
||||
>
|
||||
Save
|
||||
</Button>
|
||||
</Form>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card v-if="teams.length === 0">
|
||||
<CardContent class="text-muted-foreground p-6 text-sm">
|
||||
No teams are available for your current permissions.
|
||||
</CardContent>
|
||||
</Card>
|
||||
{{ t('teams.eyebrow') }}
|
||||
</p>
|
||||
<h1 class="text-headline-mobile sm:text-headline">
|
||||
{{ t('navigation.teams') }}
|
||||
</h1>
|
||||
<p class="text-muted-foreground max-w-2xl text-sm">
|
||||
{{ t('teams.description') }}
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
v-if="canCreateTeams"
|
||||
type="button"
|
||||
class="shrink-0"
|
||||
@click="target = { kind: 'create' }"
|
||||
><Plus class="size-4" aria-hidden="true" />{{
|
||||
t('teams.create')
|
||||
}}</Button
|
||||
>
|
||||
</header>
|
||||
<FeedbackState
|
||||
v-if="status"
|
||||
state="success"
|
||||
:title="t('teams.updated')"
|
||||
/>
|
||||
<div
|
||||
class="bg-card flex flex-col gap-4 rounded-xl border p-4 sm:flex-row sm:items-center sm:justify-between"
|
||||
>
|
||||
<div class="flex items-center gap-2">
|
||||
<Users class="text-primary size-5" aria-hidden="true" />
|
||||
<h2 class="font-semibold">{{ t('teams.yourTeams') }}</h2>
|
||||
<Badge variant="secondary">{{ teams.length }}</Badge>
|
||||
</div>
|
||||
<div class="relative sm:w-80">
|
||||
<Label for="team-search" class="sr-only">{{
|
||||
t('teams.search')
|
||||
}}</Label
|
||||
><Search
|
||||
class="text-muted-foreground pointer-events-none absolute left-3 top-3 size-4"
|
||||
aria-hidden="true"
|
||||
/><Input
|
||||
id="team-search"
|
||||
v-model="search"
|
||||
type="search"
|
||||
class="pl-9"
|
||||
:placeholder="t('teams.search')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<FeedbackState
|
||||
v-if="teams.length === 0"
|
||||
state="empty"
|
||||
:title="t('teams.empty')"
|
||||
:description="
|
||||
t(
|
||||
canCreateTeams
|
||||
? 'teams.emptyCreate'
|
||||
: 'teams.emptyDescription',
|
||||
)
|
||||
"
|
||||
/>
|
||||
<FeedbackState
|
||||
v-else-if="visibleTeams.length === 0"
|
||||
state="empty"
|
||||
:title="t('teams.noResults')"
|
||||
:description="t('teams.noResultsDescription')"
|
||||
><Button type="button" variant="outline" @click="search = ''">{{
|
||||
t('teams.clearSearch')
|
||||
}}</Button></FeedbackState
|
||||
>
|
||||
<ul
|
||||
v-else
|
||||
class="grid min-w-0 gap-4 lg:grid-cols-2"
|
||||
:aria-label="t('teams.yourTeams')"
|
||||
>
|
||||
<li
|
||||
v-for="team in visibleTeams"
|
||||
:key="team.id"
|
||||
class="bg-card flex min-w-0 flex-col rounded-xl border"
|
||||
:data-team-id="team.id"
|
||||
>
|
||||
<div class="flex min-w-0 items-start gap-3 p-5">
|
||||
<span
|
||||
class="bg-accent text-primary flex size-11 shrink-0 items-center justify-center rounded-lg"
|
||||
><Users class="size-5" aria-hidden="true"
|
||||
/></span>
|
||||
<div class="grid min-w-0 gap-1">
|
||||
<h3 class="break-words font-semibold">
|
||||
{{ team.name }}
|
||||
</h3>
|
||||
<p class="text-muted-foreground text-sm">
|
||||
{{
|
||||
t('teams.memberCount', {
|
||||
count: team.users.length,
|
||||
})
|
||||
}}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex-1 px-5 pb-5">
|
||||
<ul
|
||||
v-if="team.users.length"
|
||||
class="flex flex-wrap gap-2"
|
||||
:aria-label="t('teams.members')"
|
||||
>
|
||||
<li
|
||||
v-for="member in team.users"
|
||||
:key="member.id"
|
||||
class="bg-muted/60 flex min-w-0 max-w-full items-center gap-2 rounded-full py-1 pl-1 pr-3"
|
||||
>
|
||||
<UserAvatar
|
||||
:user="member"
|
||||
class="size-6 shrink-0"
|
||||
/><span class="min-w-0 break-words text-xs">{{
|
||||
member.name
|
||||
}}</span>
|
||||
</li>
|
||||
</ul>
|
||||
<p v-else class="text-muted-foreground text-sm">
|
||||
{{ t('teams.noMembers') }}
|
||||
</p>
|
||||
</div>
|
||||
<div
|
||||
class="bg-muted/20 grid gap-2 border-t p-4 sm:grid-cols-2"
|
||||
>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
:aria-label="
|
||||
t('teams.manageMembersFor', { name: team.name })
|
||||
"
|
||||
@click="target = { kind: 'members', team }"
|
||||
><Users class="size-4" aria-hidden="true" />{{
|
||||
t('teams.manageMembers')
|
||||
}}</Button
|
||||
><Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
:aria-label="
|
||||
t('teams.permissionsFor', { name: team.name })
|
||||
"
|
||||
@click="target = { kind: 'permissions', team }"
|
||||
><Shield class="size-4" aria-hidden="true" />{{
|
||||
t('teams.permissions')
|
||||
}}</Button
|
||||
>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</main>
|
||||
<TeamEditorDialog
|
||||
:target="target"
|
||||
:users="users"
|
||||
:permission-options="permissionOptions"
|
||||
:team-permissions="teamPermissions"
|
||||
@close="target = null"
|
||||
/>
|
||||
</AppLayout>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user