feat(KAN-47): redesign teams and membership management
# Conflicts: # resources/js/locales/en.ts
This commit is contained in:
@@ -0,0 +1,351 @@
|
||||
<script setup lang="ts">
|
||||
import { useForm } from '@inertiajs/vue3';
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import {
|
||||
store,
|
||||
updateMembers,
|
||||
updateUserPermissions,
|
||||
} from '@/actions/App/Http/Controllers/TeamController';
|
||||
import FormFeedback from '@/components/FormFeedback.vue';
|
||||
import InputError from '@/components/InputError.vue';
|
||||
import UserAvatar from '@/components/ui/avatar/UserAvatar.vue';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { useFormProtection } from '@/composables/useFormProtection';
|
||||
import { useLocalization } from '@/composables/useLocalization';
|
||||
import type { TeamEditorProps } from '@/types/teams';
|
||||
|
||||
const props = defineProps<TeamEditorProps>();
|
||||
const emit = defineEmits<{ close: [] }>();
|
||||
const { t } = useLocalization();
|
||||
const search = ref('');
|
||||
const userId = ref<number | null>(null);
|
||||
const form = useForm({
|
||||
name: '',
|
||||
user_ids: [] as number[],
|
||||
permissions: [] as string[],
|
||||
});
|
||||
const protection = useFormProtection(form, {
|
||||
isDirty: () => props.target !== null && form.isDirty,
|
||||
});
|
||||
const team = computed(() =>
|
||||
props.target && props.target.kind !== 'create' ? props.target.team : null,
|
||||
);
|
||||
const visibleUsers = computed(() =>
|
||||
props.users.filter((user) =>
|
||||
`${user.name} ${user.email}`
|
||||
.toLocaleLowerCase()
|
||||
.includes(search.value.trim().toLocaleLowerCase()),
|
||||
),
|
||||
);
|
||||
const title = computed(() =>
|
||||
t(
|
||||
props.target?.kind === 'create'
|
||||
? 'teams.create'
|
||||
: props.target?.kind === 'members'
|
||||
? 'teams.manageMembers'
|
||||
: 'teams.permissions',
|
||||
),
|
||||
);
|
||||
const selectionError = computed(
|
||||
() =>
|
||||
Object.entries(form.errors).find(([key]) =>
|
||||
key.startsWith(
|
||||
props.target?.kind === 'members' ? 'user_ids' : 'permissions',
|
||||
),
|
||||
)?.[1],
|
||||
);
|
||||
const permissionLabels = {
|
||||
'team:invite': 'teams.permissionInvite',
|
||||
'team:manage': 'teams.permissionManage',
|
||||
'team:admin': 'teams.permissionAdmin',
|
||||
} as const;
|
||||
function permissionLabel(value: string, fallback: string): string {
|
||||
return value in permissionLabels
|
||||
? t(permissionLabels[value as keyof typeof permissionLabels])
|
||||
: fallback;
|
||||
}
|
||||
watch(
|
||||
() => props.target,
|
||||
() => {
|
||||
userId.value = null;
|
||||
search.value = '';
|
||||
form.defaults({
|
||||
name: '',
|
||||
user_ids: [...(team.value?.user_ids ?? [])],
|
||||
permissions: [],
|
||||
});
|
||||
form.resetAndClearErrors();
|
||||
protection.clearFeedback();
|
||||
},
|
||||
);
|
||||
function chooseUser(event: Event): void {
|
||||
const select = event.target as HTMLSelectElement;
|
||||
if (!protection.confirmLeave()) {
|
||||
select.value = String(userId.value ?? '');
|
||||
return;
|
||||
}
|
||||
userId.value = select.value ? Number(select.value) : null;
|
||||
form.defaults('permissions', [
|
||||
...(props.teamPermissions[team.value?.id ?? '']?.[userId.value ?? ''] ??
|
||||
[]),
|
||||
]);
|
||||
form.resetAndClearErrors('permissions');
|
||||
protection.clearFeedback();
|
||||
}
|
||||
function close(open: boolean): void {
|
||||
if (open || form.processing || !protection.confirmLeave()) {
|
||||
return;
|
||||
}
|
||||
form.resetAndClearErrors();
|
||||
emit('close');
|
||||
}
|
||||
function submit(): void {
|
||||
const target = props.target;
|
||||
if (
|
||||
!target ||
|
||||
form.processing ||
|
||||
(target.kind === 'permissions' && userId.value === null)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const route =
|
||||
target.kind === 'create'
|
||||
? store()
|
||||
: target.kind === 'members'
|
||||
? updateMembers(target.team.id)
|
||||
: updateUserPermissions([target.team.id, userId.value!]);
|
||||
form.transform((data) =>
|
||||
target.kind === 'create'
|
||||
? { name: data.name }
|
||||
: target.kind === 'members'
|
||||
? { user_ids: data.user_ids }
|
||||
: { permissions: data.permissions },
|
||||
);
|
||||
protection.submit(route, {
|
||||
preserveScroll: true,
|
||||
onSuccess: () => {
|
||||
form.resetAndClearErrors();
|
||||
emit('close');
|
||||
},
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Dialog :open="target !== null" @update:open="close">
|
||||
<DialogContent
|
||||
:show-close-button="!form.processing"
|
||||
@escape-key-down="form.processing && $event.preventDefault()"
|
||||
@interact-outside="form.processing && $event.preventDefault()"
|
||||
>
|
||||
<DialogHeader>
|
||||
<DialogTitle>{{ title }}</DialogTitle>
|
||||
<DialogDescription class="break-words">{{
|
||||
team?.name ?? t('teams.createDescription')
|
||||
}}</DialogDescription>
|
||||
</DialogHeader>
|
||||
<form class="grid min-w-0 gap-5" @submit.prevent="submit">
|
||||
<FormFeedback
|
||||
:state="protection.state.value"
|
||||
:title="
|
||||
protection.responseStatus.value === 403
|
||||
? t('teams.forbidden')
|
||||
: undefined
|
||||
"
|
||||
:description="
|
||||
protection.responseStatus.value === 403
|
||||
? t('teams.forbiddenDescription')
|
||||
: undefined
|
||||
"
|
||||
:retryable="protection.responseStatus.value !== 403"
|
||||
@retry="submit"
|
||||
/>
|
||||
<fieldset
|
||||
:disabled="form.processing"
|
||||
class="grid min-w-0 gap-4"
|
||||
>
|
||||
<template v-if="target?.kind === 'create'">
|
||||
<div class="grid gap-2">
|
||||
<Label for="team-name">{{ t('teams.name') }}</Label>
|
||||
<Input
|
||||
id="team-name"
|
||||
v-model="form.name"
|
||||
required
|
||||
maxlength="255"
|
||||
:placeholder="t('teams.namePlaceholder')"
|
||||
:aria-invalid="!!form.errors.name"
|
||||
aria-describedby="team-name-error"
|
||||
/>
|
||||
<InputError
|
||||
id="team-name-error"
|
||||
:message="form.errors.name"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="target?.kind === 'members'">
|
||||
<p class="text-muted-foreground text-sm">
|
||||
{{ t('teams.membersHelp') }}
|
||||
</p>
|
||||
<div class="grid gap-2">
|
||||
<Label for="member-search">{{
|
||||
t('teams.searchPeople')
|
||||
}}</Label>
|
||||
<Input
|
||||
id="member-search"
|
||||
v-model="search"
|
||||
type="search"
|
||||
:placeholder="
|
||||
t('teams.searchPeoplePlaceholder')
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
<p class="text-muted-foreground text-sm" role="status">
|
||||
{{
|
||||
t('teams.selected', {
|
||||
count: form.user_ids.length,
|
||||
})
|
||||
}}
|
||||
</p>
|
||||
<div
|
||||
class="grid max-h-64 gap-1 overflow-y-auto rounded-md border p-2"
|
||||
role="group"
|
||||
:aria-label="t('teams.members')"
|
||||
:aria-invalid="!!selectionError"
|
||||
aria-describedby="team-selection-error"
|
||||
>
|
||||
<label
|
||||
v-for="user in visibleUsers"
|
||||
:key="user.id"
|
||||
class="hover:bg-accent flex min-w-0 cursor-pointer items-center gap-3 rounded-md p-2"
|
||||
>
|
||||
<input
|
||||
v-model="form.user_ids"
|
||||
type="checkbox"
|
||||
:value="user.id"
|
||||
class="accent-primary focus-visible:ring-ring size-5 shrink-0 focus-visible:ring-2"
|
||||
/>
|
||||
<UserAvatar
|
||||
:user="user"
|
||||
class="size-8 shrink-0"
|
||||
/>
|
||||
<span class="grid min-w-0 gap-0.5 text-sm"
|
||||
><span class="break-words font-medium">{{
|
||||
user.name
|
||||
}}</span
|
||||
><span
|
||||
class="text-muted-foreground break-all text-xs"
|
||||
>{{ user.email }}</span
|
||||
></span
|
||||
>
|
||||
</label>
|
||||
<p
|
||||
v-if="visibleUsers.length === 0"
|
||||
class="text-muted-foreground p-3 text-sm"
|
||||
>
|
||||
{{ t('teams.noPeople') }}
|
||||
</p>
|
||||
</div>
|
||||
<InputError
|
||||
id="team-selection-error"
|
||||
:message="selectionError"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="target?.kind === 'permissions'">
|
||||
<p class="text-muted-foreground text-sm">
|
||||
{{ t('teams.permissionsHelp') }}
|
||||
</p>
|
||||
<div class="grid gap-2">
|
||||
<Label for="permission-user">{{
|
||||
t('teams.person')
|
||||
}}</Label>
|
||||
<select
|
||||
id="permission-user"
|
||||
:value="userId ?? ''"
|
||||
class="border-input bg-background focus-visible:ring-ring h-11 w-full min-w-0 rounded-md border px-3 text-sm focus-visible:ring-2"
|
||||
@change="chooseUser"
|
||||
>
|
||||
<option value="" disabled>
|
||||
{{ t('teams.choosePerson') }}
|
||||
</option>
|
||||
<option
|
||||
v-for="user in users"
|
||||
:key="user.id"
|
||||
:value="user.id"
|
||||
>
|
||||
{{ user.name }} ({{ user.email }})
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<fieldset
|
||||
v-if="userId !== null"
|
||||
class="grid gap-2"
|
||||
:aria-invalid="!!selectionError"
|
||||
aria-describedby="team-selection-error"
|
||||
>
|
||||
<legend class="mb-2 text-sm font-medium">
|
||||
{{ t('teams.directPermissions') }}
|
||||
</legend>
|
||||
<label
|
||||
v-for="option in permissionOptions"
|
||||
:key="option.value"
|
||||
class="hover:bg-accent flex cursor-pointer items-center gap-3 rounded-md border p-3 text-sm"
|
||||
>
|
||||
<input
|
||||
v-model="form.permissions"
|
||||
type="checkbox"
|
||||
:value="option.value"
|
||||
class="accent-primary focus-visible:ring-ring size-5 shrink-0 focus-visible:ring-2"
|
||||
/>
|
||||
{{
|
||||
permissionLabel(option.value, option.label)
|
||||
}}
|
||||
</label>
|
||||
<p class="text-muted-foreground text-sm">
|
||||
{{ t('teams.permissionsClearHelp') }}
|
||||
</p>
|
||||
</fieldset>
|
||||
<InputError
|
||||
id="team-selection-error"
|
||||
:message="selectionError"
|
||||
/>
|
||||
</template>
|
||||
</fieldset>
|
||||
<DialogFooter>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
:disabled="form.processing"
|
||||
@click="close(false)"
|
||||
>{{ t('common.cancel') }}</Button
|
||||
>
|
||||
<Button
|
||||
type="submit"
|
||||
:disabled="
|
||||
form.processing ||
|
||||
(target?.kind === 'permissions' && userId === null)
|
||||
"
|
||||
>{{
|
||||
t(
|
||||
target?.kind === 'create'
|
||||
? 'teams.create'
|
||||
: target?.kind === 'members'
|
||||
? 'teams.saveMembers'
|
||||
: 'teams.savePermissions',
|
||||
)
|
||||
}}</Button
|
||||
>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</template>
|
||||
@@ -172,6 +172,52 @@ export const en = {
|
||||
'templates.deleteImpact':
|
||||
'{count} linked projects will stop inheriting from this template. Their current configuration and tickets are kept.',
|
||||
|
||||
'teams.eyebrow': 'People & access',
|
||||
'teams.description':
|
||||
'Bring people together in reusable teams. Manage membership and the permissions to administer each team.',
|
||||
'teams.create': 'Create team',
|
||||
'teams.createDescription':
|
||||
'Group people into a team to share project access.',
|
||||
'teams.name': 'Team name',
|
||||
'teams.namePlaceholder': 'Platform team',
|
||||
'teams.yourTeams': 'Teams you manage',
|
||||
'teams.search': 'Search teams',
|
||||
'teams.clearSearch': 'Clear search',
|
||||
'teams.empty': 'No teams to manage',
|
||||
'teams.emptyCreate': 'Create a team to start organizing your people.',
|
||||
'teams.emptyDescription':
|
||||
'No teams are available for your current permissions.',
|
||||
'teams.noResults': 'No matching teams',
|
||||
'teams.noResultsDescription': 'Try another team name or clear your search.',
|
||||
'teams.manageMembers': 'Manage members',
|
||||
'teams.manageMembersFor': 'Manage members of {name}',
|
||||
'teams.permissionsFor': 'Manage permissions for {name}',
|
||||
'teams.members': 'Members',
|
||||
'teams.noMembers': 'No members yet.',
|
||||
'teams.membersHelp':
|
||||
'Select the people who belong to this team. Changes apply when you save.',
|
||||
'teams.selected': '{count} selected',
|
||||
'teams.searchPeople': 'Find people',
|
||||
'teams.searchPeoplePlaceholder': 'Search by name or email',
|
||||
'teams.noPeople': 'No matching people.',
|
||||
'teams.saveMembers': 'Save members',
|
||||
'teams.permissions': 'Team permissions',
|
||||
'teams.permissionsHelp':
|
||||
'Direct team permissions are separate from membership. Choose any user to review or change their assignments.',
|
||||
'teams.person': 'User',
|
||||
'teams.choosePerson': 'Choose a user',
|
||||
'teams.directPermissions': 'Direct permissions',
|
||||
'teams.permissionInvite': 'Team invite',
|
||||
'teams.permissionManage': 'Team manage',
|
||||
'teams.permissionAdmin': 'Team admin',
|
||||
'teams.permissionsClearHelp':
|
||||
'Clear every checkbox to remove direct permissions. Other existing access remains in effect.',
|
||||
'teams.savePermissions': 'Save permissions',
|
||||
'teams.updated': 'Team changes saved.',
|
||||
'teams.forbidden': 'You no longer have permission',
|
||||
'teams.forbiddenDescription':
|
||||
'Your changes have not been saved. Close this dialog and reload the page to check your current access.',
|
||||
'teams.memberCount': { one: '{count} member', other: '{count} members' },
|
||||
'workflow.title': 'Board workflow',
|
||||
'workflow.pageTitle': '{project} · Board workflow',
|
||||
'workflow.description':
|
||||
|
||||
+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>
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import type { PermissionOption } from '@/types';
|
||||
import type { TeamModel } from '@/types/models/team-model';
|
||||
import type { UserModel } from '@/types/models/user-model';
|
||||
|
||||
export type TeamEditorTarget =
|
||||
| { kind: 'create' }
|
||||
| { kind: 'members' | 'permissions'; team: TeamModel };
|
||||
|
||||
export type TeamEditorProps = {
|
||||
target: TeamEditorTarget | null;
|
||||
users: UserModel[];
|
||||
permissionOptions: PermissionOption[];
|
||||
teamPermissions: Record<string, Record<string, string[]>>;
|
||||
};
|
||||
Reference in New Issue
Block a user