Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | 5x 5x 5x 5x 20x 5x 5x 5x 5x 5x 5x | import { Outlet, useParams } from 'react-router-dom'
import { Page, EntityDetail, Crud } from '@/layers/L2R'
import type { PageConfig, DetailConfig, CrudConfig } from '@/layers/interfaces'
import { useEntityDetail } from '@/layers/L1/entityResolver'
import { formatDateTime } from '@/shared/utils/format'
import { BOT_ACCOUNT_FIELD_SET, BOT_ACCOUNT_FIELD_TYPES } from './botAccountsCrudConfig'
import { mockRepositories } from '@/msw/mock-data'
export function BotAccountDetailPage() {
const { id } = useParams<{ id: string }>()
const { data: account } = useEntityDetail('bot-accounts', id ?? '')
const pageConfig: PageConfig = {
title: account?.name ?? 'Bot Account',
breadcrumbs: [
{ label: 'Dashboard', href: '/' },
{ label: 'Repositories', href: '/repositories/repos' },
{ label: 'Bot Accounts', href: '/repositories/bot-accounts' },
{ label: account?.name ?? id ?? '' },
],
}
const usedByCount = account
? mockRepositories.filter((r) => (r as Record<string, unknown>).bot_account_id === account.id).length
: 0
const detailConfig: DetailConfig = {
entityPath: 'bot-accounts',
title: 'Bot Account',
actionTargets: { edit: '/repositories/bot-accounts/:id/edit', delete: true },
readGrouping: [
{
label: 'Details',
fields: ['name', 'description', 'created_at', 'updated_at'],
},
{
label: 'Usage',
fields: ['used_by'],
},
],
fieldFormatters: {
created_at: (value: unknown) => formatDateTime(value as string | null | undefined),
updated_at: (value: unknown) => formatDateTime(value as string | null | undefined),
used_by: () => `Used by ${usedByCount} repositor${usedByCount === 1 ? 'y' : 'ies'}`,
},
}
const crudConfig: CrudConfig = {
entityPath: 'bot-accounts',
fieldSet: BOT_ACCOUNT_FIELD_SET,
fieldTypes: BOT_ACCOUNT_FIELD_TYPES,
successTarget: '/repositories/bot-accounts/:id',
cancelTarget: '/repositories/bot-accounts/:id',
title: 'Edit Bot Account',
}
return (
<Page config={pageConfig}>
<EntityDetail config={detailConfig} />
<Crud config={crudConfig} />
<Outlet />
</Page>
)
}
|