Привести layout к эталону: alert с CTA, 6 KPI в ряд, помесячные графики платежей и расходов с фильтром года. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
1 parent
0e9a6a6a21
commit
77099b9ab0
5 files changed
+315
-51
No files matched your search
@@ -16,9 +16,23 @@ import {
|
||||
ChartLegendContent,
|
||||
type ChartConfig,
|
||||
} from '@cfdm/ui/components/chart'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@cfdm/ui/components/card'
|
||||
import {
|
||||
Card,
|
||||
CardAction,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from '@cfdm/ui/components/card'
|
||||
import type { ReactNode } from 'react'
|
||||
import { useMemo } from 'react'
|
||||
import { useMemo, useState } from 'react'
|
||||
|
||||
import { SelectField } from '@/components/select-field'
|
||||
import {
|
||||
aggregatePaymentsByMonthYear,
|
||||
availablePaymentYears,
|
||||
type PaymentChartFilter,
|
||||
} from '@/lib/chart-analytics'
|
||||
|
||||
import type { Vps, Provider, Payment, Settings, RatesData, ServerProject } from '@/types/entities'
|
||||
import {
|
||||
@@ -179,6 +193,132 @@ export function PaymentsPieChart({
|
||||
)
|
||||
}
|
||||
|
||||
function DashboardMonthlyBarChart({
|
||||
payments,
|
||||
settings,
|
||||
ratesData,
|
||||
title,
|
||||
description = 'Последние 12 мес',
|
||||
chartColor,
|
||||
paymentFilter,
|
||||
className,
|
||||
ariaLabel,
|
||||
}: {
|
||||
payments: Payment[]
|
||||
settings: Settings[]
|
||||
ratesData: RatesData | null
|
||||
title: string
|
||||
description?: string
|
||||
chartColor: string
|
||||
paymentFilter: PaymentChartFilter
|
||||
className?: string
|
||||
ariaLabel: string
|
||||
}) {
|
||||
const baseCurrency = (settings[0]?.baseCurrency ?? 'RUB').toUpperCase()
|
||||
const years = useMemo(() => availablePaymentYears(payments), [payments])
|
||||
const [year, setYear] = useState(() => years[0] ?? new Date().getFullYear())
|
||||
|
||||
const effectiveYear = years.includes(year) ? year : (years[0] ?? year)
|
||||
|
||||
const data = useMemo(
|
||||
() => aggregatePaymentsByMonthYear(payments, effectiveYear, settings, ratesData, paymentFilter),
|
||||
[payments, effectiveYear, settings, ratesData, paymentFilter],
|
||||
)
|
||||
|
||||
const chartConfig: ChartConfig = useMemo(
|
||||
() => ({
|
||||
amount: { label: title, color: chartColor },
|
||||
}),
|
||||
[title, chartColor],
|
||||
)
|
||||
|
||||
const hasData = data.some((row) => row.amount > 0)
|
||||
|
||||
return (
|
||||
<Card className={className}>
|
||||
<CardHeader>
|
||||
<CardTitle>{title}</CardTitle>
|
||||
<CardDescription>{description}</CardDescription>
|
||||
<CardAction>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<SelectField
|
||||
size="sm"
|
||||
triggerClassName="w-[130px]"
|
||||
aria-label="Группировка"
|
||||
value="month"
|
||||
options={[{ value: 'month', label: 'По месяцам' }]}
|
||||
/>
|
||||
<SelectField
|
||||
size="sm"
|
||||
triggerClassName="w-[100px]"
|
||||
aria-label="Год"
|
||||
value={String(effectiveYear)}
|
||||
onValueChange={(v) => {
|
||||
if (v) setYear(Number(v))
|
||||
}}
|
||||
options={years.map((y) => ({ value: String(y), label: String(y) }))}
|
||||
/>
|
||||
</div>
|
||||
</CardAction>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{!hasData ? (
|
||||
<ChartEmpty message="Нет данных за выбранный период" />
|
||||
) : (
|
||||
<ChartContainer config={chartConfig} className="h-72 w-full" aria-label={ariaLabel}>
|
||||
<BarChart data={data} margin={{ top: 8, right: 8, bottom: 8, left: 8 }}>
|
||||
<CartesianGrid vertical={false} strokeDasharray="3 3" />
|
||||
<XAxis dataKey="month" tickLine={false} axisLine={false} tickMargin={8} />
|
||||
<YAxis tickLine={false} axisLine={false} width={48} />
|
||||
<RechartsTooltip
|
||||
cursor={false}
|
||||
content={
|
||||
<ChartTooltipContent formatter={(v) => formatCurrency(Number(v), baseCurrency)} />
|
||||
}
|
||||
/>
|
||||
<Bar dataKey="amount" fill="var(--color-amount)" radius={4} />
|
||||
</BarChart>
|
||||
</ChartContainer>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
|
||||
export function DashboardPaymentsChart(props: {
|
||||
payments: Payment[]
|
||||
settings: Settings[]
|
||||
ratesData: RatesData | null
|
||||
className?: string
|
||||
}) {
|
||||
return (
|
||||
<DashboardMonthlyBarChart
|
||||
{...props}
|
||||
title="Платежи"
|
||||
chartColor="var(--chart-3)"
|
||||
paymentFilter="all"
|
||||
ariaLabel="График платежей по месяцам"
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export function DashboardExpensesChart(props: {
|
||||
payments: Payment[]
|
||||
settings: Settings[]
|
||||
ratesData: RatesData | null
|
||||
className?: string
|
||||
}) {
|
||||
return (
|
||||
<DashboardMonthlyBarChart
|
||||
{...props}
|
||||
title="Расходы"
|
||||
chartColor="var(--chart-1)"
|
||||
paymentFilter="expense"
|
||||
ariaLabel="График расходов по месяцам"
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export function MonthlyTrendChart({
|
||||
payments,
|
||||
settings,
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { AlertTriangleIcon } from 'lucide-react'
|
||||
import { Alert, AlertAction, AlertDescription, AlertTitle } from '@cfdm/ui/components/alert'
|
||||
import { Button } from '@cfdm/ui/components/button'
|
||||
|
||||
interface DashboardInventoryAlertProps {
|
||||
issuesCount: number
|
||||
onGoToIssues: () => void
|
||||
}
|
||||
|
||||
export function DashboardInventoryAlert({ issuesCount, onGoToIssues }: DashboardInventoryAlertProps) {
|
||||
if (issuesCount <= 0) return null
|
||||
|
||||
return (
|
||||
<Alert variant="destructive">
|
||||
<AlertTriangleIcon />
|
||||
<AlertTitle>Требуется внимание!</AlertTitle>
|
||||
<AlertDescription>
|
||||
Обнаружено {issuesCount} категорий проблем в инвентаре. Проверьте вкладку «Проблемы».
|
||||
</AlertDescription>
|
||||
<AlertAction>
|
||||
<Button variant="destructive" size="sm" onClick={onGoToIssues}>
|
||||
К проблемам
|
||||
</Button>
|
||||
</AlertAction>
|
||||
</Alert>
|
||||
)
|
||||
}
|
||||
@@ -26,9 +26,16 @@ function sectionGridClass(count: number): string {
|
||||
if (count === 3) return 'sm:grid-cols-2 lg:grid-cols-3'
|
||||
if (count === 4) return 'sm:grid-cols-2 lg:grid-cols-4'
|
||||
if (count === 5) return 'sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-5'
|
||||
if (count === 6) return 'sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-6'
|
||||
return 'sm:grid-cols-2 lg:grid-cols-3'
|
||||
}
|
||||
|
||||
const VALUE_VARIANT_CLASS: Record<NonNullable<SectionCardItem['variant']>, string> = {
|
||||
default: '',
|
||||
warning: 'text-warning-foreground',
|
||||
destructive: 'text-destructive',
|
||||
}
|
||||
|
||||
export function SectionCards({ items, className }: { items: SectionCardItem[]; className?: string }) {
|
||||
return (
|
||||
<div className={cn('grid gap-3', sectionGridClass(items.length), className)}>
|
||||
@@ -51,7 +58,14 @@ export function SectionCards({ items, className }: { items: SectionCardItem[]; c
|
||||
{item.badge ? <span className="shrink-0">{item.badge}</span> : null}
|
||||
</div>
|
||||
<div className="flex min-w-0 items-baseline gap-1.5">
|
||||
<span className="text-lg font-semibold tabular-nums">{item.value}</span>
|
||||
<span
|
||||
className={cn(
|
||||
'flex items-center gap-1 text-lg font-semibold tabular-nums',
|
||||
VALUE_VARIANT_CLASS[item.variant ?? 'default'],
|
||||
)}
|
||||
>
|
||||
{item.value}
|
||||
</span>
|
||||
{item.hint ? (
|
||||
typeof item.hint === 'string' ? (
|
||||
<TruncatedText className="text-xs text-muted-foreground">· {item.hint}</TruncatedText>
|
||||
|
||||
Reference in new issue
Block a user