Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions autobot-frontend/src/components/llc/LlcSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const links = computed<SidebarLink[]>(() => {
{ labelKey: 'nav.llcGoals', to: { path: `/llc/companies/${id}/goals` } },
{ labelKey: 'nav.llcOrgChart', to: { path: `/llc/companies/${id}/org-chart` } },
{ labelKey: 'nav.llcMembers', to: { path: `/llc/companies/${id}/members` } },
{ labelKey: 'nav.llcTeams', to: { path: `/llc/companies/${id}/teams` } },
{ labelKey: 'nav.llcRoles', to: { path: `/llc/companies/${id}/roles` } },
{ labelKey: 'nav.llcApprovals', to: { path: `/llc/companies/${id}/approvals` } },
{ labelKey: 'nav.llcCosts', to: { path: `/llc/companies/${id}/costs` } },
Expand Down
98 changes: 98 additions & 0 deletions autobot-frontend/src/composables/llc/useCompanyTeams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Copyright 2025-2026 mrveiss
// SPDX-License-Identifier: Apache-2.0
// AutoBot - AI-Powered Automation Platform
// Author: mrveiss
/**
* The teams of the company shown by TeamsView (#18245, mockup Teams).
*
* Reads `GET /api/llc/companies/{id}/teams` (company-scoped by path, #13938) and the company's members
* for names: teams carry user ids only. Reading only: writing a team waits for the company-scoped write
* routes (#14106).
*
* The view is not remounted when the route moves to another company, so everything is scoped to the
* company a request was sent for: the id is captured at send time, a change of company drops the rows,
* and a response for a company no longer shown is discarded.
*/
import { computed, ref, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import type { components } from '@/types/generated/api'
import { createLogger } from '@/utils/debugUtils'
import type { Member as CompanyMember } from '@/composables/llc/useCompanyMembers'

const logger = createLogger('useCompanyTeams')

/** A company member row; `is_active` is whether they may still be given work (#13956). */
export type Member = CompanyMember & { is_active?: boolean }
export type CompanyTeam = components['schemas']['CompanyTeam']
type CompanyTeamsResponse = components['schemas']['CompanyTeamsResponse']

/** loading: no answer yet. failed: the read errored (retry may work). unavailable: refused for this company. */
export type TeamsState = 'loading' | 'ready' | 'failed' | 'unavailable'

export interface TeamsApi {
get<T>(url: string): Promise<T>
}

const statusOf = (err: unknown): number | undefined => (err as { status?: number })?.status

export function useCompanyTeams(api: TeamsApi, companyId: () => string) {
const { t } = useI18n()
const teams = ref<CompanyTeam[]>([])
const members = ref<Member[]>([])
const state = ref<TeamsState>('loading')
const membersFailed = ref(false)
// Bumped when the company changes: a response captured under an older generation is discarded.
let generation = 0
// Counts loads: of overlapping reloads in one company only the newest may land.
let loadSeq = 0

const nameOf = (userId: string): string => {
const hit = members.value.find((m) => m.user_id === userId)
return hit ? hit.display_name : t('llcTeams.unknownMember')
}
const isInactive = (userId: string): boolean =>
members.value.find((m) => m.user_id === userId)?.is_active === false

async function load(): Promise<void> {
const id = companyId()
if (!id) return
const mine = generation
const req = ++loadSeq
const current = () => mine === generation && req === loadSeq
// A reload keeps the table on screen; only the first load of a company shows the loading state.
if (teams.value.length === 0) state.value = 'loading'
const [teamsResult, membersResult] = await Promise.allSettled([
api.get(`/api/llc/companies/${id}/teams`) as Promise<CompanyTeamsResponse>,
api.get(`/api/llc/companies/${id}/members`) as Promise<Member[]>,
])
if (!current()) return
membersFailed.value = membersResult.status === 'rejected'
members.value = membersResult.status === 'fulfilled' && Array.isArray(membersResult.value) ? membersResult.value : []
if (teamsResult.status === 'fulfilled') {
teams.value = Array.isArray(teamsResult.value?.teams) ? teamsResult.value.teams : []
state.value = 'ready'
return
}
logger.error('Failed to load teams', teamsResult.reason)
teams.value = []
const status = statusOf(teamsResult.reason)
state.value = status === 403 || status === 404 ? 'unavailable' : 'failed'
}

// Another company: drop what was shown and read again; late answers for the old one are discarded.
watch(companyId, () => {
generation++
teams.value = []
members.value = []
membersFailed.value = false
state.value = 'loading'
void load()
})

const hasTeams = computed(() => teams.value.length > 0)

return {
teams, members, state, membersFailed, hasTeams,
nameOf, isInactive, load,
}
}
24 changes: 24 additions & 0 deletions autobot-frontend/src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8213,6 +8213,7 @@
"llcDashboard": "Dashboard",
"llcOrgChart": "Org Chart",
"llcMembers": "Members",
"llcTeams": "Teams",
"llcGoals": "Goals",
"llcCompanies": "Companies",
"llcPortability": "Portability",
Expand Down Expand Up @@ -8304,6 +8305,29 @@
"confirm": "Confirm",
"updateError": "Could not change the company status."
},
"llcTeams": {
"title": "Teams",
"subtitle": "The teams of this company and the people on each.",
"peopleOnly": "Teams hold people with an account. Agents and contacts are not team members.",
"noCompany": "Select a company to see its teams.",
"loading": "Loading teams…",
"loadError": "Could not read this company's teams.",
"unavailable": "Teams are not available for this company, or you do not have access to them.",
"retry": "Try again",
"empty": "This company has no teams yet.",
"namesError": "Could not read the company's members, so team members are shown without names.",
"unknownMember": "Unknown member",
"inactive": "Inactive",
"colTeam": "Team",
"colMembers": "Members",
"colActions": "Actions",
"viewMembers": "View members",
"selectTeam": "Select a team to see its members.",
"membersOf": "Members of {name}",
"noMembers": "This team has no members yet.",
"colName": "Name",
"colRole": "Company role"
},
"llcMembers": {
"title": "Members",
"subtitle": "Manage the people who belong to this company and their roles.",
Expand Down
2 changes: 2 additions & 0 deletions autobot-frontend/src/router/llcRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ export const llcCompanyChildren: RouteRecordRaw[] = [
{ path: 'activity', name: 'llc-activity', component: () => import('@/views/llc/ActivityFeedView.vue'), props: true, meta: { title: 'Activity', requiresAuth: true } },
{ path: 'roles', name: 'llc-roles', component: () => import('@/views/llc/RolesView.vue'), props: true, meta: { title: 'Roles', requiresAuth: true } },
{ path: 'members', name: 'llc-members', component: () => import('@/views/llc/MembersView.vue'), props: true, meta: { title: 'Members', requiresAuth: true } },
// #18245: Organization > Teams -- company-scoped; the server limits writes to platform administrators.
{ path: 'teams', name: 'llc-teams', component: () => import('@/views/llc/TeamsView.vue'), props: true, meta: { title: 'Teams', requiresAuth: true } },
{ path: 'portability', name: 'llc-company-portability', component: () => import('@/views/llc/CompanyPortabilityView.vue'), props: true, meta: { title: 'Portability', requiresAuth: true } },
{ path: 'secrets', name: 'llc-company-secrets', component: () => import('@/views/llc/CompanySecretsView.vue'), props: true, meta: { title: 'Secrets', requiresAuth: true } },
// GH#10750 (B3): in-layout variants of the formerly top-level dashboard/
Expand Down
116 changes: 116 additions & 0 deletions autobot-frontend/src/views/llc/TeamsView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<!--
Copyright 2025-2026 mrveiss
SPDX-License-Identifier: Apache-2.0
AutoBot - AI-Powered Automation Platform
Author: mrveiss

TeamsView -- Company OS > Organization > Teams (#18245, mockup Teams).

Company-scoped child of LlcCompanyLayout (/llc/companies/:companyId/teams). Lists the company's
teams and who is on each (GET /api/llc/companies/{id}/teams). Read-only: creating, deleting and
changing the members of a team land with the company-scoped write routes (#14106). Reading says
"couldn't read" apart from "no teams" and "not available". Teams hold users only (the backend has no team column for agents or
contacts), so the mockup's team lead, projects and managers have no data behind them and are not
drawn.
-->
<template>
<div class="flex flex-col gap-4 p-4" data-testid="company-teams">
<PageHeader :title="t('llcTeams.title')" :subtitle="t('llcTeams.subtitle')" />

<p v-if="!companyId" class="m-0 text-autobot-text-secondary" data-testid="teams-no-company">{{ t('llcTeams.noCompany') }}</p>

<template v-else>
<div v-if="state === 'loading'" class="flex items-center gap-2 text-autobot-text-secondary" role="status" data-testid="teams-loading">
<BaseSpinner size="sm" />
<span>{{ t('llcTeams.loading') }}</span>
</div>

<BaseAlert v-else-if="state === 'failed'" variant="error" :message="t('llcTeams.loadError')" data-testid="teams-failed">
<template #actions>
<BaseButton variant="secondary" size="sm" data-testid="teams-retry" @click="load()">{{ t('llcTeams.retry') }}</BaseButton>
</template>
</BaseAlert>

<EmptyState v-else-if="state === 'unavailable'" :title="t('llcTeams.unavailable')" data-testid="teams-unavailable" />

<template v-else>
<p class="m-0 text-sm text-autobot-text-secondary">{{ t('llcTeams.peopleOnly') }}</p>

<EmptyState v-if="!hasTeams" :title="t('llcTeams.empty')" data-testid="teams-empty" />

<BaseTable v-else :columns="teamColumns" :rows="teamRows" row-key="id" :aria-label="t('llcTeams.title')" :actions-label="t('llcTeams.colActions')" data-testid="teams-table">
<template #actions="{ row }">
<BaseButton variant="secondary" size="sm" :aria-pressed="selectedId === row.id" @click="selectedId = String(row.id)">
{{ t('llcTeams.viewMembers') }}
</BaseButton>
</template>
</BaseTable>

<BaseCard v-if="hasTeams" data-testid="team-detail">
<p v-if="!selected" class="m-0 text-autobot-text-secondary">{{ t('llcTeams.selectTeam') }}</p>
<div v-else class="flex flex-col gap-3">
<h2 class="m-0 text-base text-autobot-text-primary">{{ t('llcTeams.membersOf', { name: selected.name }) }}</h2>
<BaseAlert v-if="membersFailed" variant="warning" :message="t('llcTeams.namesError')" data-testid="teams-names-error" />

<p v-if="memberRows.length === 0" class="m-0 text-autobot-text-secondary" data-testid="team-no-members">{{ t('llcTeams.noMembers') }}</p>
<BaseTable v-else :columns="memberColumns" :rows="memberRows" row-key="id" size="compact" :aria-label="t('llcTeams.membersOf', { name: selected.name })" data-testid="team-members">
<template #cell-name="{ row }">
<span>{{ row.name }}</span>
<BaseBadge v-if="row.inactive" size="sm" variant="warning" class="ms-2">{{ t('llcTeams.inactive') }}</BaseBadge>
</template>
</BaseTable>
</div>
</BaseCard>
</template>
</template>
</div>
</template>

<script setup lang="ts">
import { computed, onMounted, ref, watch } from 'vue'
import { useRoute } from 'vue-router'
import { useI18n } from 'vue-i18n'
import {
BaseAlert, BaseBadge, BaseButton, BaseCard, BaseSpinner, BaseTable, EmptyState, PageHeader,
type BaseTableColumn,
} from '@autobot/ui'
import { useApiClient } from '@/plugins/api'
import { useCompanyTeams, type CompanyTeam } from '@/composables/llc/useCompanyTeams'

const props = defineProps<{ companyId?: string }>()
const route = useRoute()
const { t } = useI18n()
const companyId = computed(() => (route.params.companyId as string) ?? props.companyId ?? '')

const { teams, members, state, membersFailed, hasTeams, nameOf, isInactive, load } =
useCompanyTeams(useApiClient(), () => companyId.value)

const selectedId = ref('')
const selected = computed<CompanyTeam | undefined>(() => teams.value.find((x) => x.id === selectedId.value))
// A team gone after a reload is no longer selected.
watch(teams, () => {
if (selectedId.value && !selected.value) selectedId.value = ''
})
watch(companyId, () => { selectedId.value = '' })

const teamColumns = computed<BaseTableColumn[]>(() => [
{ key: 'name', label: t('llcTeams.colTeam') },
{ key: 'count', label: t('llcTeams.colMembers'), numeric: true },
])
const teamRows = computed(() => teams.value.map((x) => ({ id: x.id, name: x.name, count: x.member_user_ids.length })))

const memberColumns = computed<BaseTableColumn[]>(() => [
{ key: 'name', label: t('llcTeams.colName') },
{ key: 'role', label: t('llcTeams.colRole') },
])
const memberRows = computed(() =>
(selected.value?.member_user_ids ?? []).map((userId) => ({
id: userId,
name: nameOf(userId),
role: members.value.find((m) => m.user_id === userId)?.role ?? '',
inactive: isInactive(userId),
})),
)

onMounted(() => load())
</script>
Loading