import { Card, CardActions, CardActionsItem } from '@/components/card'; import { FullPageEmptyState } from '@/components/full-page-empty-state'; import { Button } from '@/components/ui/button'; import { useAppParams } from '@/hooks/use-app-params'; import { pushModal, showConfirm } from '@/modals'; import { cn } from '@/utils/cn'; import { PAGE_TITLES, createProjectTitle } from '@/utils/title'; import { format } from 'date-fns'; import { AreaChartIcon, BarChart3Icon, BarChartHorizontalIcon, ChartScatterIcon, ConeIcon, GitBranchIcon, Globe2Icon, HashIcon, LayoutPanelTopIcon, LineChartIcon, Pencil, PieChartIcon, PlusIcon, Trash, TrendingUpIcon, } from 'lucide-react'; import { toast } from 'sonner'; import FullPageLoadingState from '@/components/full-page-loading-state'; import { PageContainer } from '@/components/page-container'; import { PageHeader } from '@/components/page-header'; import { handleErrorToastOptions, useTRPC } from '@/integrations/trpc/react'; import { useMutation, useQuery } from '@tanstack/react-query'; import { Link, createFileRoute } from '@tanstack/react-router'; export const Route = createFileRoute( '/_app/$organizationId/$projectId/dashboards', )({ component: Component, head: () => { return { meta: [ { title: createProjectTitle('Dashboards'), }, ], }; }, async loader({ context, params }) { await context.queryClient.prefetchQuery( context.trpc.dashboard.list.queryOptions({ projectId: params.projectId, }), ); }, pendingComponent: FullPageLoadingState, }); function Component() { const { projectId } = Route.useParams(); const trpc = useTRPC(); const query = useQuery( trpc.dashboard.list.queryOptions({ projectId, }), ); const dashboards = query.data ?? []; const deletion = useMutation( trpc.dashboard.delete.mutationOptions({ onError: (error, variables) => { return handleErrorToastOptions({ action: { label: 'Force delete', onClick: () => { deletion.mutate({ forceDelete: true, id: variables.id, }); }, }, })(error); }, onSuccess() { query.refetch(); toast('Success', { description: 'Dashboard deleted.', }); }, }), ); if (dashboards.length === 0) { return ( You have not created any dashboards for this project yet pushModal('AddDashboard')} className="mt-14" icon={PlusIcon} > Create dashboard ); } return ( pushModal('AddDashboard')}> Create dashboard Dashboard } /> {dashboards.map((item) => { const visibleReports = item.reports.slice( 0, item.reports.length > 6 ? 5 : 6, ); return ( {item.name} {format(item.updatedAt, 'HH:mm ยท MMM d')} {visibleReports.map((report) => { const Icon = { bar: BarChartHorizontalIcon, linear: LineChartIcon, pie: PieChartIcon, metric: HashIcon, map: Globe2Icon, histogram: BarChart3Icon, funnel: ConeIcon, area: AreaChartIcon, retention: ChartScatterIcon, conversion: TrendingUpIcon, sankey: GitBranchIcon, }[report.chartType]; return ( {report.name} ); })} {item.reports.length > 6 && ( {item.reports.length - 5} more )} {/* {item.reports.length} reports {item.reports.map((item) => item.name).join(', ')} */} { pushModal('EditDashboard', item); }} > Edit { showConfirm({ title: 'Delete dashboard', text: 'Are you sure you want to delete this dashboard? All your reports will be deleted!', onConfirm: () => deletion.mutate({ id: item.id }), }); }} > Delete ); })} ); }
You have not created any dashboards for this project yet